fix(test): de-flake TestParallelismUpdate on coarse-resolution clocks#16224
Open
Joibel wants to merge 1 commit into
Open
fix(test): de-flake TestParallelismUpdate on coarse-resolution clocks#16224Joibel wants to merge 1 commit into
Joibel wants to merge 1 commit into
Conversation
TestParallelismUpdate adds six items, each in its own namespace, all with priority 0 and creationTime=time.Now(). When parallelism is raised it expects admission to follow insertion order (a..f). Because every item is in a distinct namespace, queueThrottled ranks the candidates across namespaces by (priority, creationTime), iterating the pending map. On clocks with coarse resolution (e.g. Windows CI), consecutive time.Now() calls can return identical instants; the resulting creationTime ties are then broken by Go's randomized map-iteration order, so the wrong item can win the freed slot and the test fails intermittently. Give the items strictly increasing creationTimes so ordering is deterministic on every platform. Test-only change; no production code is affected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Alan Clucas <alan@clucas.org>
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.
Motivation
workflow/sync.TestParallelismUpdatefails intermittently on Windows CI:The test adds six items —
a/0…f/0— each in its own namespace, allwith
priority 0andcreationTime = time.Now(), then raises parallelismand expects admission to follow insertion order (
ebeforef).Because each item is in a distinct namespace,
queueThrottledranks thecandidates across namespaces by
(priority, creationTime), iterating thependingmap. The items only differ bycreationTime, so ordering dependsentirely on those timestamps being distinct.
On clocks with coarse resolution (notably Windows, ~1–15 ms), consecutive
time.Now()calls can return the same instant. The resultingcreationTimeties are then broken by Go's randomized map-iteration order,so
f/0can win the freed slot instead ofe/0, and the test fails. Linux'snanosecond-resolution clock hides the bug, which is why it only shows up on
the Windows runner.
This was reproduced deterministically on Linux by forcing identical
timestamps: with ties, the test fails with exactly the CI symptom
(
e admitted=false, f admitted=true) on a fraction of runs.Modifications
Give the six items strictly increasing
creationTimes (now,now+1ms, …now+5ms) so the ordering is unambiguous on every platform, regardless ofclock resolution. Added a comment explaining why bare
time.Now()is unsafehere.
This is a test-only change — no production code is touched.
Verification
go test -run TestParallelismUpdate -count=200 ./workflow/sync/— passes(was non-deterministic under tied timestamps).
multi_throttler_test.goare unaffected: their tieditems sit within a single namespace (stable heap insertion order) or are
separated by distinct priorities / time offsets.
golangci-lintclean,gofmtclean.🤖 Generated with Claude Code