test(streams): harden take() ack tests against event-loop timing (fix PyPy flake)#709
Open
wbarnha wants to merge 2 commits into
Open
test(streams): harden take() ack tests against event-loop timing (fix PyPy flake)#709wbarnha wants to merge 2 commits into
wbarnha wants to merge 2 commits into
Conversation
The `test_take` / `test_take_wit_timestamp*` tests asserted that an event consumed via `stream.take()` had been acked after exactly two `await asyncio.sleep(0)` yields. `take()` acks consumed events from a background task, and on slower interpreters (notably PyPy) that task hasn't run within two event-loop ticks, so `event.message.acked` was still False and the assertion flaked -- as seen on the PyPy CI leg. Replace the fixed sleeps with `wait_for_stream_ack()`, which polls for the ack (up to a 1s timeout) instead of assuming a fixed number of ticks. The existing assertions are unchanged, so a genuinely missing ack still fails the test with the same signal after the timeout. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HHPL4VFWQRQPpjR1gXSKyL
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #709 +/- ##
=======================================
Coverage 94.15% 94.15%
=======================================
Files 104 104
Lines 11136 11136
Branches 1201 1201
=======================================
Hits 10485 10485
Misses 550 550
Partials 101 101 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Description
Fixes a flaky-test failure seen on the PyPy 3.11 CI leg (e.g. run
29672563646,
surfaced on #690). Four
stream.take()tests failed with:Root cause
stream.take()acks the events it consumes from a background task. Thetests asserted the ack had happened after exactly two
await asyncio.sleep(0)yields:
On slower interpreters (notably PyPy) that background task hasn't run within
two event-loop ticks, so
event.message.ackedis stillFalseand theassertion flakes. The tests' own comments already hinted at this fragility
("need one sleep on 3.6.0–3.6.6; need two on 3.6.7 :-/"). It is not a product
regression — every CPython leg (3.10–3.14) passed, and the run went green on
re-run.
Fix
Introduce a small
wait_for_stream_ack()helper that polls for the ack(up to a 1s timeout) instead of assuming a fixed number of ticks, and use it in
the four affected tests:
test_taketest_take_wit_timestamptest_take_wit_timestamp_wit_simple_valuetest_take_wit_timestamp_without_timestamp_fieldThe existing assertions are left unchanged, so a genuinely missing ack still
fails the test with the same signal once the timeout elapses — this only
removes the timing race, not the coverage.
Verified locally: all four tests pass.
🤖 Generated with Claude Code
Generated by Claude Code