Skip to content

Commit

Permalink
Fix TestSilenceLimits tests
Browse files Browse the repository at this point in the history
This commit fixes silence tests that relied on the maintenance
function running at a fixed 100ms interval. If the go runtime
that runs the maintenance is not scheduled with 150ms then the
test will fail.

Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana committed Jun 5, 2024
1 parent 2c189d8 commit afd2a30
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions silence/silence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,8 @@ func TestSilenceLimits(t *testing.T) {
MaxSilences: 1,
MaxPerSilenceBytes: 2 << 11, // 4KB
},
Retention: 100 * time.Millisecond,
})
require.NoError(t, err)
stopCh := make(chan struct{})
defer close(stopCh)
go s.Maintenance(100*time.Millisecond, "", stopCh, nil)

// Insert sil1 should succeed without error.
sil1 := &pb.Silence{
Expand All @@ -493,10 +489,13 @@ func TestSilenceLimits(t *testing.T) {
require.EqualError(t, err, "exceeded maximum number of silences: 1 (limit: 1)")
require.Equal(t, "", id2)

// Expire sil1 and wait for the maintenance to finish.
// This should allow sil2 to be inserted.
// Expire sil1 and run the GC. This should allow sil2 to be
// inserted.
require.NoError(t, s.Expire(id1))
time.Sleep(150 * time.Millisecond)
n, err := s.GC()
require.NoError(t, err)
require.Equal(t, 1, n)

id2, err = s.Set(sil2)
require.NoError(t, err)
require.NotEqual(t, "", id2)
Expand All @@ -507,7 +506,9 @@ func TestSilenceLimits(t *testing.T) {

// Expire sil2.
require.NoError(t, s.Expire(id2))
time.Sleep(150 * time.Millisecond)
n, err = s.GC()
require.NoError(t, err)
require.Equal(t, 1, n)

// Insert sil3 should fail because it exceeds maximum size.
sil3 := &pb.Silence{
Expand Down

0 comments on commit afd2a30

Please sign in to comment.