From 88f9dd3e577f427a2fed40d6a102619745f7adb6 Mon Sep 17 00:00:00 2001 From: Brandur Date: Sun, 10 Mar 2024 10:06:25 -0700 Subject: [PATCH] Fix intermittent notifier stress test Here, fix an intermittent stress test in the notifier package. This is one that I added last minute in #258 in response to code review, so I missed the intermittency because it didn't fail on any of the last pushes that I made, but I noticed it failing today [1]. Luckily, it's quite a simple where we just have to make sure that the test waits for one of the test goroutines to return before quitting. Ran at `-race -count 1000` locally and no longer seeing any intermittency. [1] https://github.com/riverqueue/river/actions/runs/8223455278/job/22486174354 --- internal/notifier/notifier_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/notifier/notifier_test.go b/internal/notifier/notifier_test.go index 7404c641..fda2a03c 100644 --- a/internal/notifier/notifier_test.go +++ b/internal/notifier/notifier_test.go @@ -410,9 +410,14 @@ func TestNotifier(t *testing.T) { notifyChans[i] = make(chan TopicAndPayload, 1000) } + var wg sync.WaitGroup + // Start a goroutine to send messages constantly. shutdown := make(chan struct{}) + wg.Add(1) go func() { + defer wg.Done() + ticker := time.NewTicker(10 * time.Millisecond) defer ticker.Stop() @@ -430,7 +435,6 @@ func TestNotifier(t *testing.T) { } }() - var wg sync.WaitGroup wg.Add(len(notifyChans)) for i := range notifyChans { notifyChan := notifyChans[i] @@ -443,15 +447,15 @@ func TestNotifier(t *testing.T) { require.NoError(t, err) // Pause a random brief amount of time. - notifier.BaseService.CancellableSleepRandomBetween(ctx, 5*time.Millisecond, 50*time.Millisecond) + notifier.BaseService.CancellableSleepRandomBetween(ctx, 15*time.Millisecond, 50*time.Millisecond) sub.Unlisten(ctx) } }() } - wg.Wait() close(shutdown) + wg.Wait() notifier.Stop() for i := range notifyChans {