Fix queue-related intermittency in producer tests#868
Merged
Conversation
Fix another intermittency problem caused by relying on wall clock time
when testing queues in `TestProducer_WithNotifier/RegistersQueueStatus`
where they're upserted by a producer[1].
--- FAIL: TestProducer_WithNotifier (0.00s)
--- FAIL: TestProducer_WithNotifier/RegistersQueueStatus (7.04s)
producer_test.go:371: Generated schema "river_2025_04_26t04_16_54_schema_15" with migrations [1 2 3 4 5 6] on line "main" in 3.056885981s [15 generated] [8 reused]
producer_test.go:385:
Error Trace: /home/runner/work/river/river/producer_test.go:385
Error: Max difference between 2025-04-26 04:17:03.800146245 +0000 UTC and 2025-04-26 04:17:06.08229 +0000 UTC allowed is 2s, but difference was -2.282143755s
Test: TestProducer_WithNotifier/RegistersQueueStatus
logger.go:256: time=2025-04-26T04:17:06.091Z level=ERROR msg="producer: Queue status update, error updating in database" err="context canceled"
riverdbtest.go:277: Checked in schema "river_2025_04_26t04_16_54_schema_15"; 1 idle schema(s) [15 generated] [8 reused]
FAIL
FAIL github.com/riverqueue/river 34.065s
Switch over to using a version based on an injected clock and `now`.
[1] https://github.com/riverqueue/river/actions/runs/14677626265/job/41196195586
2f632ce to
a8706e7
Compare
bgentry
approved these changes
Apr 27, 2025
| @name::text, | ||
| coalesce(sqlc.narg('paused_at')::timestamptz, NULL), | ||
| coalesce(sqlc.narg('updated_at')::timestamptz, now()) | ||
| coalesce(sqlc.narg('updated_at')::timestamptz, sqlc.narg('now')::timestamptz, now()) |
Contributor
There was a problem hiding this comment.
should this particular one be handled outside of SQL so we don't have a 3-part coalesce? (or two of them, in fact)
I guess this is fine since we're already passing in all the values anyway.
Contributor
Author
There was a problem hiding this comment.
Yeah hmm, I guess a three-part coalesce is a little unusual, but I'm not sure that doing it in Go code instead would be that much better.
I'm inclined to say it's mostly okay since all the right things happen when you leave out all parameters, picking good defaults for everything. Let's see how it works out. Definitely open to changing it up in case it turns out to be bug prone/confusing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix another intermittency problem caused by relying on wall clock time
when testing queues in
TestProducer_WithNotifier/RegistersQueueStatuswhere they're upserted by a producer[1].
Switch over to using a version based on an injected clock and
now.[1] https://github.com/riverqueue/river/actions/runs/14677626265/job/41196195586