Fix race in AsyncPollerTest.testSuspendPolling#2848
Draft
donald-pinckney wants to merge 1 commit intomasterfrom
Draft
Fix race in AsyncPollerTest.testSuspendPolling#2848donald-pinckney wants to merge 1 commit intomasterfrom
donald-pinckney wants to merge 1 commit intomasterfrom
Conversation
The test relied on the poller's second iteration racing past its suspend-latch check before the test thread called suspendPolling(). If the test thread won the race, iter 2 blocked at the suspend latch and never reached reserveSlot — so reservedCount stayed at 1 and the later `expected:<2> but was:<1>` assertion failed. Bumping the assertEventually timeout didn't help; the race either wins or loses deterministically on a given run. Remove the race: override reserveSlot on the slot supplier to count invocations, and wait for reserveCalls == 2 before suspending. That's a direct signal that iter 2 has passed the suspend check and called reserveSlot (its future can't complete until iter 1's slot is released, but the call itself happens immediately). After this signal, iter 2 is pinned past the suspend check, so the subsequent suspendPolling() only affects iter 3+. Also drop the now-redundant first assertEventually: once pollLatch counts down (inside the mocked poll()), iter 1's slot has already been issued, so reservedCount == 1 is synchronously visible. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.
What was changed
Remove the race: override reserveSlot on the slot supplier to count invocations, and wait for reserveCalls == 2 before suspending. That's a direct signal that iter 2 has passed the suspend check and called reserveSlot (its future can't complete until iter 1's slot is released, but the call itself happens immediately). After this signal, iter 2 is pinned past the suspend check, so the subsequent suspendPolling() only affects iter 3+.
Also drop the now-redundant first assertEventually: once pollLatch counts down (inside the mocked poll()), iter 1's slot has already been issued, so reservedCount == 1 is synchronously visible.
Why?
The test relied on the poller's second iteration racing past its suspend-latch check before the test thread called suspendPolling(). If the test thread won the race, iter 2 blocked at the suspend latch and never reached reserveSlot — so reservedCount stayed at 1 and the later
expected:<2> but was:<1>assertion failed. Bumping the assertEventually timeout didn't help; the race either wins or loses deterministically on a given run.AI Transparency
This PR was fully generated by Claude, and I have not yet reviewed it for accuracy with regards to fixing the flakiness. Don't yet review until I review it more.