fix(streaming): replace sleep gate with _started event for cancel tests#1146
Draft
planetf1 wants to merge 2 commits into
Draft
fix(streaming): replace sleep gate with _started event for cancel tests#1146planetf1 wants to merge 2 commits into
planetf1 wants to merge 2 commits into
Conversation
test_external_task_cancellation_releases_consumers and test_external_cancellation_acomplete_raise_once both slept 10 ms before calling cancel() on the orchestration task. On a fast runner the mock backend (sleep(0) between tokens) can drain the entire stream within that window, making cancel() a no-op on an already-done task — no CancelledError is ever raised and the test fails. Add StreamChunkingResult._started (asyncio.Event), set at the very top of _orchestrate_streaming before its first suspension point. Tests now await _started before cancelling: after _started fires the orchestration is live but suspended, and cancel() is called without yielding back to the event loop, so the task cannot complete between the two calls. Fixes generative-computing#1132 Assisted-by: Claude Code Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
fa5713d to
767d0b9
Compare
…ne() guard Three improvements from code review: - Rename _started to _orchestration_started for consistency with the existing _orchestration_task and _orchestration_exception fields. - Expand the attribute comment to make explicit that the event is set synchronously before any await, and that the object is single-use. - Add `assert not result._orchestration_task.done()` after the _orchestration_started.wait() in both cancellation tests as a regression guard: if a future change makes the orchestration synchronous to its first yield, the tests would silently regress to vacuous-pass without this assertion. Assisted-by: Claude Code Signed-off-by: Nigel Jones <jonesn@uk.ibm.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.
Misc PR
Type of PR
Description
Two streaming cancellation tests gated on
await asyncio.sleep(0.01)before callingcancel(). On a fast runner,StreamingMockBackend(onlysleep(0)between tokens) can drain the whole 200-word stream inside that window —cancel()then no-ops on an already-done task and noCancelledErroris raised.Adds
_orchestration_started(asyncio.Event) toStreamChunkingResult, set synchronously at the top of_orchestrate_streamingbefore anyawait. The two tests now wait on this event instead of sleeping: once it fires the task is suspended at its first real I/O point, socancel()is guaranteed to land on a live task. Anassert not task.done()guard follows the wait to catch any future regression to vacuous-pass behaviour.Testing
Attribution