Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestSilenceLimits tests (#3866) #86

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading