Skip to content

Fix queue-related intermittency in producer tests#868

Merged
brandur merged 1 commit into
masterfrom
brandur-fix-producer-intermittent-tests
Apr 28, 2025
Merged

Fix queue-related intermittency in producer tests#868
brandur merged 1 commit into
masterfrom
brandur-fix-producer-intermittent-tests

Conversation

@brandur
Copy link
Copy Markdown
Contributor

@brandur brandur commented Apr 26, 2025

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

@brandur brandur requested a review from bgentry April 26, 2025 22:03
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
@brandur brandur force-pushed the brandur-fix-producer-intermittent-tests branch from 2f632ce to a8706e7 Compare April 26, 2025 22:05
@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())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@brandur brandur merged commit 02ede34 into master Apr 28, 2025
19 of 20 checks passed
@brandur brandur deleted the brandur-fix-producer-intermittent-tests branch April 28, 2025 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants