[Test][History Server] Fix Build historyserver flaky unit test: TestShutdown_DrainsRetriedTasks - #5245
Open
markwu7 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Mark <markhww.jobs@gmail.com>
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.
Why are these changes needed?
After checking the log, I found that
TestShutdown_DrainsRetriedTaskswas flaky in the Build historyserver job. Before the fix, the test waited on!writer.failPending()before callingshutdown(). That flag becomes false inside the failedWriteFile, beforeretryProcessregisters the backoff goroutine onconsumerWG. Ifshutdown()closesstopProducersin that window,retryProcesslogsGiving up on retrying ... during shutdown and never uploaded.So I suggested driving the first failed attempt synchronously via
processRotatedFile, ensuring the retry is registered withconsumerWGbeforeshutdown()is called. The test then starts the upload worker and runs the real shutdown path: closingstopProducerscuts the backoff short, andconsumerWGwaits for the final attempt. there is no longer a window where shutdown() can race with retry registration.Related issue number
Labels
doc-updates-requiredlabel.breaking-changelabel.Checks
Manual test instructions
I reproduced the CI failure locally by inserting a 50ms sleep between the failed
WriteFileandretryProcessinhistoryserver/pkg/collector/eventcollector/eventcollector.go, which widens the same race. Fromhistoryserver/, I ran:go test -race -count=20 ./pkg/collector/eventcollector/ -run TestShutdown_DrainsRetriedTasks -vThe original test then failed consistently (20/20 runs) with
Giving up on retrying ... during shutdownandretried task never uploaded, matching the CI failure log.After the fix, the same command with the same sleep passed consistently (20/20 runs) because the retry is already registered before
shutdown().