[historyserver] Fix flaky TestShutdown_DrainsRetriedTasks - #5105
Open
1fanwang wants to merge 1 commit into
Open
Conversation
The test synchronised on the mock writer clearing failNext, but that flag is cleared at the start of the failing write, before processRotatedFile handles the error and calls retryProcess. Under CI load the test could resume and run shutdown inside that window, where retryProcess declines the retry by design, leaving the task unuploaded and the assertion red on PRs touching nothing in historyserver/. Signed-off-by: 1fanwang <1fannnw@gmail.com>
win5923
reviewed
Aug 8, 2026
win5923
left a comment
Member
There was a problem hiding this comment.
Thanks! Did you also run the test locally around 20 more times to make sure it passes consistently?
6 tasks
win5923
approved these changes
Aug 10, 2026
win5923
left a comment
Member
There was a problem hiding this comment.
This makes sense. Now synchronously driving processRotatedFile, which guarantees that the retry is registered before shutdown() starts, instead of relying on failNext as an indirect signal. This make the test deterministic.
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.
TestShutdown_DrainsRetriedTasksfails intermittently in CI on PRs that change nothing underhistoryserver/:The test waits for the mock writer to clear
failNextand treats that as "the retry goroutine now exists":But
failNextis cleared at the start of the failing write, before it even returns an error — so the signal fires well beforeprocessRotatedFilehandles that error and callsretryProcess. Ifshutdown()closesstopProducersinside that window,retryProcessdeclines the retry, which is deliberate:The product behaviour is correct — the declined file stays on disk and is picked up by
resumePendingFileson the next start. Only the test is wrong: it wants the "retry already registered, shutdown cuts its backoff short" path, but it never actually guarantees registration first.Driving the failing attempt inline makes that ordering a fact rather than a race.
processRotatedFilereturns only afterretryProcesshas registered the goroutine withconsumerWG, soshutdown()cannot get there first. The assertions and what they cover are unchanged, andfailPendinggoes with it since nothing calls it any more.Testing Done
The flake is load-sensitive, so it will not reproduce on an idle machine — 200 plain runs and 200
-raceruns pass both before and after. To reproduce deterministically I widened the window the race needs, simulating the worker being descheduled exactly where CI descheduled it:With that delay, the old test fails with the exact CI error and the new one passes:
Raw logs
golangci-lint run ./pkg/collector/eventcollector/...reports 52 findings on this package both before and after the change — none new.gofmtclean.