Skip to content

Commit

Permalink
Fix intermittent notifier stress test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brandur committed Mar 10, 2024
1 parent d9a7fc3 commit 88f9dd3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/notifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -430,7 +435,6 @@ func TestNotifier(t *testing.T) {
}
}()

var wg sync.WaitGroup
wg.Add(len(notifyChans))
for i := range notifyChans {
notifyChan := notifyChans[i]
Expand All @@ -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 {
Expand Down

0 comments on commit 88f9dd3

Please sign in to comment.