[Test][History Server] Fix Build historyserver flaky unit test: TestShutdown_DrainsRetriedTasks #5245
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 309 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.343
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5245"
general
weight: 0.35
machichima
<!-- Thank you for your contribution! -->
<!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. -->
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
Closes #5243
<!-- For example: "Closes #1234" -->
Labels
<!-- Please add the appropriate labels to this PR. -->
doc-updates-requiredlabel.breaking-changelabel.Checks
- [ ] Unit tests
- [X] Manual tests
- [ ] This PR is not tested :(
<!-- If you selected "Manual tests" above, please fill in the section below. Otherwise you can remove it. -->
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().