Skip to content

Commit 11ebb22

Browse files
authored
Fix intermittently failing test Test_Client_JobCompletion/JobThatReturnsErrIsRetryable (#1247)
Here, try to address an intermittently failing test seen in CI [1]. The problem seems to be that although the test case stubs the current time with `StubNow`, it's possible for the producer's fetch loop to be running concurrently and call `NowOrNil()` before the stub takes effect, causing a divergence from the stubbed time by a few milliseconds. The fix here drops the use of stubbed now, and instead asserts that the new `ScheduledAt` is `AttemptedAt` plus the expected retry interval, using a value from a reloaded job row to guarantee we don't have a race. We drop the use of time stubbing completely as this approach no longer requires it. [1] https://github.com/riverqueue/river/actions/runs/25657083352/job/75308035231
1 parent 4a75e68 commit 11ebb22

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

client_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7291,8 +7291,6 @@ func Test_Client_JobCompletion(t *testing.T) {
72917291

72927292
client, bundle := setup(t, config)
72937293

7294-
now := client.baseService.Time.StubNow(time.Now().UTC())
7295-
72967294
insertRes, err := client.Insert(ctx, JobArgs{}, nil)
72977295
require.NoError(t, err)
72987296

@@ -7304,7 +7302,7 @@ func Test_Client_JobCompletion(t *testing.T) {
73047302
require.NoError(t, err)
73057303

73067304
require.Equal(t, rivertype.JobStateRetryable, reloadedJob.State)
7307-
require.WithinDuration(t, now.Add(retryPolicy.Interval()), reloadedJob.ScheduledAt, time.Microsecond)
7305+
require.WithinDuration(t, reloadedJob.AttemptedAt.Add(retryPolicy.Interval()), reloadedJob.ScheduledAt, time.Microsecond)
73087306
require.Nil(t, reloadedJob.FinalizedAt)
73097307
})
73107308

0 commit comments

Comments
 (0)