@@ -481,7 +481,7 @@ func TestSilenceLimits(t *testing.T) {
481
481
// Insert sil2 should fail because maximum number of silences
482
482
// has been exceeded.
483
483
sil2 := & pb.Silence {
484
- Matchers : []* pb.Matcher {{Name : "a " , Pattern : "b " }},
484
+ Matchers : []* pb.Matcher {{Name : "c " , Pattern : "d " }},
485
485
StartsAt : time .Now (),
486
486
EndsAt : time .Now ().Add (5 * time .Minute ),
487
487
}
@@ -500,11 +500,7 @@ func TestSilenceLimits(t *testing.T) {
500
500
require .NoError (t , err )
501
501
require .NotEqual (t , "" , id2 )
502
502
503
- // Should be able to update sil2 without hitting the limit.
504
- _ , err = s .Set (sil2 )
505
- require .NoError (t , err )
506
-
507
- // Expire sil2.
503
+ // Expire sil2 and run the GC.
508
504
require .NoError (t , s .Expire (id2 ))
509
505
n , err = s .GC ()
510
506
require .NoError (t , err )
@@ -514,16 +510,16 @@ func TestSilenceLimits(t *testing.T) {
514
510
sil3 := & pb.Silence {
515
511
Matchers : []* pb.Matcher {
516
512
{
517
- Name : strings .Repeat ("a " , 2 << 9 ),
518
- Pattern : strings .Repeat ("b " , 2 << 9 ),
513
+ Name : strings .Repeat ("e " , 2 << 9 ),
514
+ Pattern : strings .Repeat ("f " , 2 << 9 ),
519
515
},
520
516
{
521
- Name : strings .Repeat ("c " , 2 << 9 ),
522
- Pattern : strings .Repeat ("d " , 2 << 9 ),
517
+ Name : strings .Repeat ("g " , 2 << 9 ),
518
+ Pattern : strings .Repeat ("h " , 2 << 9 ),
523
519
},
524
520
},
525
- CreatedBy : strings .Repeat ("e " , 2 << 9 ),
526
- Comment : strings .Repeat ("f " , 2 << 9 ),
521
+ CreatedBy : strings .Repeat ("i " , 2 << 9 ),
522
+ Comment : strings .Repeat ("j " , 2 << 9 ),
527
523
StartsAt : time .Now (),
528
524
EndsAt : time .Now ().Add (5 * time .Minute ),
529
525
}
@@ -533,6 +529,44 @@ func TestSilenceLimits(t *testing.T) {
533
529
// due to padding.
534
530
require .Contains (t , err .Error (), "silence exceeded maximum size" )
535
531
require .Equal (t , "" , id3 )
532
+
533
+ // Should be able to insert sil4 and then update it without modifications.
534
+ sil4 := & pb.Silence {
535
+ Matchers : []* pb.Matcher {{Name : "k" , Pattern : "l" }},
536
+ StartsAt : time .Now (),
537
+ EndsAt : time .Now ().Add (5 * time .Minute ),
538
+ }
539
+ id4 , err := s .Set (sil4 )
540
+ require .NoError (t , err )
541
+ require .NotEqual (t , "" , id4 )
542
+
543
+ // Update without modifications.
544
+ updateId4 , err := s .Set (sil4 )
545
+ require .NoError (t , err )
546
+ require .Equal (t , id4 , updateId4 )
547
+
548
+ // Should be able to update the comment.
549
+ sil5 := cloneSilence (sil4 )
550
+ sil5 .Comment = "m"
551
+ id5 , err := s .Set (sil5 )
552
+ require .NoError (t , err )
553
+ require .Equal (t , id4 , id5 )
554
+
555
+ // Should not be able to update the start and end time as this requires
556
+ // sil5 to be expired and a new silence to be created. However, this would
557
+ // exceed the maximum number of silences, which counts both active and
558
+ // expired silences.
559
+ sil6 := cloneSilence (sil5 )
560
+ sil6 .StartsAt = time .Now ().Add (5 * time .Minute )
561
+ sil6 .EndsAt = time .Now ().Add (10 * time .Minute )
562
+ id6 , err := s .Set (sil6 )
563
+ require .EqualError (t , err , "exceeded maximum number of silences: 1 (limit: 1)" )
564
+ require .Equal (t , "" , id6 )
565
+
566
+ // sil5 should not be expired because the update failed.
567
+ sil5 , err = s .QueryOne (QIDs (sil5 .Id ))
568
+ require .NoError (t , err )
569
+ require .Equal (t , types .SilenceStateActive , getState (sil5 , s .nowUTC ()))
536
570
}
537
571
538
572
func TestSetActiveSilence (t * testing.T ) {
0 commit comments