fix(worker): replace time.Sleep with channel sync in consumer manager test#7971
Open
arzonus wants to merge 1 commit intocadence-workflow:masterfrom
Open
fix(worker): replace time.Sleep with channel sync in consumer manager test#7971arzonus wants to merge 1 commit intocadence-workflow:masterfrom
arzonus wants to merge 1 commit intocadence-workflow:masterfrom
Conversation
… test time.Sleep(50ms) after Advance() is unreliable under CI load. Add an afterIterFn test hook called after each ticker iteration so the test can synchronize precisely. Use BlockUntil(1) before the first Advance to ensure the run() goroutine has created the ticker. Fixes flaky TestConsumerManagerEnabledDisabled (3x in CI Jan-Apr 2026). Signed-off-by: Seva Kaloshin <seva.kaloshin@gmail.com>
e76c005 to
18e0c39
Compare
Code Review ✅ ApprovedReplaced time.Sleep with channel synchronization in the consumer manager test to improve reliability and execution speed. No issues found. Rules ✅ All requirements metRepository Rules
2 rules not applicable. Show all rules by commenting OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
Shaddoll
approved these changes
Apr 17, 2026
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.
What changed?
afterIterFn func()field andwithAfterIterFnoption toConsumerManager(service/worker/asyncworkflow/async_workflow_consumer_manager.go). Therun()loop calls the hook after each ticker iteration (nil-guarded; zero overhead in production).TestConsumerManagerEnabledDisabledto use the hook instead oftime.Sleep(50ms). AddedmockTimeSrc.BlockUntil(1)before the firstAdvanceto ensure the ticker is registered before advancing time.Why?
time.Sleep(50ms)is not a reliable synchronization primitive — under CI load the background goroutine may not finish processing the tick in time. The hook signals completion precisely.BlockUntil(1)prevents the race whereAdvancefires before therun()goroutine has calledNewTicker, which would leave the advance with no timer to fire and cause the test to deadlock.Detected as a flaky test:
TestConsumerManagerEnabledDisabledfired 3× in CI (Jan–Apr 2026).How did you test it?
All pass.
Potential risks
Low.
afterIterFnis unexported, nil-guarded (zero overhead in production), called only within theticker.Chan()select arm. The productionConsumerManageralways hasafterIterFn == nil.Release notes
N/A
Documentation Changes
N/A