Skip to content

Commit 6af6deb

Browse files
authored
Fix intermittent test: TestNotifier/MultipleSubscribersStress (#865)
Try to fix one of the most commonly failing intermittent tests we have left, which is the stress test in the notifier [1]. --- FAIL: TestNotifier (0.00s) --- FAIL: TestNotifier/MultipleSubscribersStress (0.98s) notifier_test.go:409: Generated schema "notifier_2025_04_26t20_08_50_schema_04" with migrations [1 2 3 4 5 6] on line "main" in 376.579906ms [4 generated] [0 reused] notifier_test.go:434: Sending notification on "test_topic1": msg0 notifier_test.go:434: Sending notification on "test_topic1": msg1 notifier_test.go:434: Sending notification on "test_topic1": msg2 notifier_test.go:434: Sending notification on "test_topic1": msg3 notifier_test.go:434: Sending notification on "test_topic1": msg4 notifier_test.go:434: Sending notification on "test_topic1": msg5 notifier_test.go:434: Sending notification on "test_topic1": msg6 notifier_test.go:472: Channel 0 contains 5 message(s) notifier_test.go:472: Channel 1 contains 7 message(s) notifier_test.go:472: Channel 2 contains 0 message(s) notifier_test.go:477: Error Trace: /home/runner/work/river/river/internal/notifier/notifier_test.go:477 Error: Should NOT be empty, but was 0xc000244770 Test: TestNotifier/MultipleSubscribersStress riverdbtest.go:277: Checked in schema "notifier_2025_04_26t20_08_50_schema_04"; 1 idle schema(s) [4 generated] [2 reused] FAIL FAIL github.com/riverqueue/river/internal/notifier 2.025s Rebuild the test a little so that each listen goroutine waits for at least one message to come through instead of only an arbitrary sleep. The sleep ~always passes locally, but it seems to be that in CI it's possible for the sending goroutine to be entirely parked around when a listen/unlisten loop is happening. [1] https://github.com/riverqueue/river/actions/runs/14684674639/job/41211780010
1 parent 9a3f021 commit 6af6deb

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

internal/notifier/notifier_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ func TestNotifier(t *testing.T) {
459459
// Pause a random brief amount of time.
460460
serviceutil.CancellableSleep(ctx, randutil.DurationBetween(15*time.Millisecond, 50*time.Millisecond))
461461

462+
// Wait for at least one message to come through. This
463+
// generally isn't necessary, but we can run into strange
464+
// problems in slow environments like GitHub Actions where
465+
// the send goroutine can apparently be paused entirely
466+
// around the sleep above between listen and unlisten.
467+
riversharedtest.WaitOrTimeout(t, notifyChan)
468+
462469
sub.Unlisten(ctx)
463470
}
464471
}()
@@ -469,12 +476,12 @@ func TestNotifier(t *testing.T) {
469476
<-sendNotificationsDone // wait for notifications goroutine to finish
470477

471478
for i := range notifyChans {
472-
t.Logf("Channel %2d contains %3d message(s)", i, len(notifyChans[i]))
473-
474479
// Don't require a specific number of messages to have been received
475480
// since it's non-deterministic, but every channel should've gotten
476-
// at least one message. It my test runs, they receive ~15 each.
477-
require.NotEmpty(t, notifyChans[i])
481+
// at least one message (as measured by the WaitOrTimeout above).
482+
// In my test runs, they receive ~15 each. The WaitOrTimeout
483+
// consumes one message, so we add +1 when measuring each channel.
484+
t.Logf("Channel %2d contains %3d message(s)", i, len(notifyChans[i])+1)
478485
}
479486
})
480487

0 commit comments

Comments
 (0)