Repository navigation
test: [#1006] wait for the worker to stop in the queue worker tests - #1566
Merged
Merged
Conversation
…tests Background goroutines asserted on run()'s error after Shutdown() returned, racing with testify resetting the suite's T when the subtest ended. Collect run()'s result through a channel and assert on it from the subtest goroutine instead.
darakanoit
force-pushed
the
fix/queue-worker-test-race
branch
from
September 27, 2026 23:56
8c844ed to
5a8b9fc
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1566 +/- ##
=======================================
Coverage 72.84% 72.84%
=======================================
Files 412 412
Lines 26846 26846
=======================================
Hits 19557 19557
Misses 7287 7287
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
The |
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.
📑 Description
Related to goravel/goravel#1006 (#1564)
Found while running the worker tests with
-raceafter #1564 (multiple queues in the worker)landed. The race is not introduced by that change: see below.
go test -race -run TestWorkerTestSuite ./queue/fails onmasterin 2 of 3 runs withrace detected during execution of test, in subtests such asTest_run/job_failed,_insert_failed_jobandTestShutdown/shutdown_blocks_until_goroutines_complete. CI runs these tests without-race, so it went unnoticed.The race is in the tests, not in
queue/worker.go. Every report pairs the same twoaccesses:
suite.(*Suite).SetT(), which restores the parentTwhen as.Runsubtest returns;Shutdown()waits forjobWgandfailedJobWg, butrun()also waits onjobWgandreturns in parallel with
Shutdown(). Nothing orders the goroutine'ss.NoErrorbefore thesubtest returns, so the assertion can run while testify is resetting
T.Shutdown()doesnot promise that
run()has returned, and no production code reads shared state after itdoes, so the worker itself is fine.
The pattern predates #1564:
dab1968c^fails the same way (2 of 5 runs with-race).What changed
Two suite helpers, following the pattern
worker_multi_queue_test.goalready uses:startWorker()runs the worker in a goroutine and returns a channel that receivesrun()'s error;shutdownWorker(runErrChan)callsShutdown(), then waits for that error (5s timeout)and asserts on it from the subtest goroutine.
All 20 background runs in
Test_run,Test_runWithReceiveandTestShutdownuse them.The two retry subtests now set
s.worker.triesbefore starting the worker instead ofinside the goroutine.
Verification
go test -race -count=1 -run TestWorkerTestSuite ./queue/(x3)go test -race -count=10 -run TestWorkerTestSuite ./queue/DATA RACEgo test -race ./queue/...go test ./queue/...Scope
queue/worker_test.goonly. No production code changed.✅ Checks