Skip to content

Reimplement driver tests for PGAdvisoryXactLock so they don't involve clock timing#885

Merged
brandur merged 1 commit into
masterfrom
brandur-pg-advisory-lock-test-no-timing
May 9, 2025
Merged

Reimplement driver tests for PGAdvisoryXactLock so they don't involve clock timing#885
brandur merged 1 commit into
masterfrom
brandur-pg-advisory-lock-test-no-timing

Conversation

@brandur

@brandur brandur commented May 8, 2025

Copy link
Copy Markdown
Contributor

I've gotten a failure a couple times in the driver tests for
PGAdvisoryXactLock in that it times out when trying to use another
transaction to acquire or release the lock:

--- FAIL: TestDriverDatabaseSQLLibPQ (19.44s)
    driver_test.go:40: Generated schema "river_2025_05_08t01_05_22_schema_08" with migrations [1 2 3 4 5 6] on line "main" in 53.591381ms [9 generated] [5 reused]
    driver_test.go:40: Driver does not support listener; skipping listener tests
    --- FAIL: TestDriverDatabaseSQLLibPQ/PGAdvisoryXactLock (0.21s)
        riverdrivertest.go:2691: TestTx using schema: river_2025_05_08t01_05_22_schema_06
        riverdrivertest.go:2701: TestTx using schema: river_2025_05_08t01_05_22_schema_06
        riverdrivertest.go:2727:
                Error Trace:	/home/runner/work/river/river/internal/riverinternaltest/riverdrivertest/riverdrivertest.go:2727
                Error:      	Goroutine didn't finish in a timely manner
                Test:       	TestDriverDatabaseSQLLibPQ/PGAdvisoryXactLock
    riverdbtest.go:277: Checked in schema "river_2025_05_08t01_05_22_schema_08"; 1 idle schema(s) [137 generated] [133 reused]
FAIL
FAIL	github.com/riverqueue/river	27.844s

Here, reimplement this test wholesale, moving away from dependency on
clock timing and over to having the other test transaction use the
non-blocking pg_try_advisory_lock instead. This should eliminate all
intermittency from this test case.

[1] https://github.com/riverqueue/river/actions/runs/14896356386/job/41839541488

@brandur brandur force-pushed the brandur-pg-advisory-lock-test-no-timing branch from e100a8d to 118a116 Compare May 8, 2025 01:30
@brandur brandur requested a review from bgentry May 8, 2025 01:31

@bgentry bgentry left a comment

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.

Much better! ✨

Comment on lines +2694 to +2713
// It's possible for multiple versions of this test to be running at the
// same time (from different drivers), so make sure the lock we're
// acquiring per test is unique by using the complete test name.
lockHash := hashutil.NewAdvisoryLockHash(0)
lockHash.Write([]byte(t.Name()))
lockHash.Write([]byte("123456"))
key := lockHash.Key()

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.

Good fix!

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.

thx thx.

Comment thread internal/riverinternaltest/riverdrivertest/riverdrivertest.go Outdated
…ve clock timing

I've gotten a failure a couple times in the driver tests for
`PGAdvisoryXactLock` in that it times out when trying to use another
transaction to acquire or release the lock:

    --- FAIL: TestDriverDatabaseSQLLibPQ (19.44s)
        driver_test.go:40: Generated schema "river_2025_05_08t01_05_22_schema_08" with migrations [1 2 3 4 5 6] on line "main" in 53.591381ms [9 generated] [5 reused]
        driver_test.go:40: Driver does not support listener; skipping listener tests
        --- FAIL: TestDriverDatabaseSQLLibPQ/PGAdvisoryXactLock (0.21s)
            riverdrivertest.go:2691: TestTx using schema: river_2025_05_08t01_05_22_schema_06
            riverdrivertest.go:2701: TestTx using schema: river_2025_05_08t01_05_22_schema_06
            riverdrivertest.go:2727:
                    Error Trace:	/home/runner/work/river/river/internal/riverinternaltest/riverdrivertest/riverdrivertest.go:2727
                    Error:      	Goroutine didn't finish in a timely manner
                    Test:       	TestDriverDatabaseSQLLibPQ/PGAdvisoryXactLock
        riverdbtest.go:277: Checked in schema "river_2025_05_08t01_05_22_schema_08"; 1 idle schema(s) [137 generated] [133 reused]
    FAIL
    FAIL	github.com/riverqueue/river	27.844s

Here, reimplement this test wholesale, moving away from dependency on
clock timing and over to having the other test transaction use the
non-blocking `pg_try_advisory_lock `instead. This should eliminate all
intermittency from this test case.

[1] https://github.com/riverqueue/river/actions/runs/14896356386/job/41839541488
@brandur brandur force-pushed the brandur-pg-advisory-lock-test-no-timing branch from 3ec8b5d to 4d6abbe Compare May 9, 2025 00:14
@brandur brandur merged commit ec10378 into master May 9, 2025
@brandur brandur deleted the brandur-pg-advisory-lock-test-no-timing branch May 9, 2025 00:17
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