Repository navigation
test: synchronize stream cancellation test on an event instead of a sleep - #188
Merged
Merged
Conversation
…leep test_cancellation_propagates_cleanly slept 10 ms and assumed body consumption had begun and that the body's 1 s sleep was still running when it cancelled. A stall over 1 s let the body finish, and a cancel before consumption began still passed. The body now signals once the first chunk is consumed and then waits on an event that is never set.
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.
Closes #187
Problem
test_cancellation_propagates_cleanlyintests/test_client_stream.pystartedconsume(), slept 10 ms, and cancelled. It assumed two things about timing: that the consumer had read the first chunk by then, and that the body'sasyncio.sleep(1.0)was still running when the cancel arrived.Reproduction (before)
On
origin/main(b9e2861), with scratch copies of the test file:task.cancel()stands in for a stall longer than the body's hold. The body finished,consume()returned, and the test failed withDID NOT RAISE CancelledError.Fix
The body sets
first_chunk_consumedafter its firstyield, which only resumes once the consumer has taken that chunk and asked for the next one. It then waits on anasyncio.Eventthat is never set, so it holds until cancelled however long the test takes. The test waits onfirst_chunk_consumed(inside a 5 sasyncio.timeoutthat only guards against a hang) before cancelling. No sleep is involved in correctness.With the fix, the 1.1 s stall copy passes. On an 8-core Mac with 16
yes > /dev/nullprocesses running,pytest tests/test_client_stream.py -k cancellation --count 2000passed 2000 of 2000.Other timed sleeps in
tests/None outside the bulkhead tests share the flaw.
test_timeout.pysleeps 5 s against a 0.01 s timeout, and the timeout callback is due first even after a stall. The retry tests inject a recording_sleep.test_threading_with_shared_budget.pypasses realasyncio.sleepas the retry backoff, which affects speed only.test_circuit_breaker.pyandtest_circuit_breaker_props.pyusesleep(0)to yield.tests/test_client_stream_sync.pyhas no cancellation test and no sleeps.Checks
just lint,just lint-ciandjust test-cipass locally (1307 tests, 100% coverage).