Skip to content

test: assert stream cancellation reaches transport - #151

Merged
rgarcia merged 2 commits into
mainfrom
hypeship/assert-transport-cancel
Aug 10, 2026
Merged

test: assert stream cancellation reaches transport#151
rgarcia merged 2 commits into
mainfrom
hypeship/assert-transport-cancel

Conversation

@rgarcia

@rgarcia rgarcia commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • assert consumer cancellation reaches the transport byte stream
  • remove the redundant route-path assertion and unreachable mock yield
  • keep the direct-routing configuration covered without treating asyncio task cancellation as sufficient evidence

Follow-up to #148.

Tests

  • full pytest suite: 673 passed, 2732 skipped
  • Pydantic v1 suite: 660 passed, 2745 skipped
  • Ruff, Pyright, and mypy

Note

Low Risk
Test-only change to async telemetry cancellation coverage; no production or routing logic modified.

Overview
Renames test_async_telemetry_stream_cancellation_survives_direct_routing to test_async_telemetry_stream_cancellation_reaches_transport and tightens what cancellation must prove for direct-routed async telemetry SSE.

The mock BlockingSSEStream now blocks on a chunk queue and records asyncio.CancelledError in __aiter__ instead of waiting on an eternal event and signaling stop via finally/aclose. The test waits on transport_cancelled after cancelling the consumer task, so passing means cancel propagates into the httpx transport byte stream—not merely that the asyncio task was cancelled.

The mock handler drops the redundant path assertion (routing is covered elsewhere), and removes the unreachable trailing yield after an infinite wait.

Reviewed by Cursor Bugbot for commit d281b8f. Bugbot is set up for automated code reviews on this repo. Configure here.

@Sayan-

Sayan- commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

This makes the assertion load-bearing. I mutation-tested it rather than assuming.

I shielded the transport read from consumer cancellation inside _streaming.py, so cancelling the consumer no longer reaches the byte stream. The test failed:

FAILED tests/test_browser_routing.py::test_async_telemetry_stream_cancellation_survives_direct_routing

That is exactly the property worth pinning, and it was not pinned before: the old read_stopped flag was set from both __aiter__'s finally and aclose(), so it could be satisfied without cancellation ever reaching the transport. Suite still green, 24 passed.

One small thing, not a blocker. Dropping the assert request.url.path == "/browser/kernel/telemetry/stream" means nothing in the test pins the direct-VM path anymore. With the rewrite disabled in rewrite_direct_vm_options, this test now passes and only the three pre-existing routing tests fail, so the survives_direct_routing in the name is no longer backed by an assertion. The path is already covered by test_telemetry_stream_routes_directly_to_vm, so this is redundancy rather than a gap.

If you want the name to hold, capturing the request and asserting after the async with block is better than asserting inside the handler, since an assertion that fires inside a mock transport surfaces as a connection error and masks the real reason.

Sayan-
Sayan- previously approved these changes Aug 10, 2026

@Sayan- Sayan- left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: the new assertion catches a shielded-cancellation regression, so it is genuinely load-bearing now. One optional note above about the dropped path assertion.

@rgarcia

rgarcia commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

addressed in d281b8f: renamed the test to test_async_telemetry_stream_cancellation_reaches_transport. That matches the load-bearing assertion directly without re-adding the routing-path assertion already covered by test_telemetry_stream_routes_directly_to_vm.

@rgarcia
rgarcia requested a review from Sayan- August 10, 2026 19:33
@Sayan-

Sayan- commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Re-reviewed after d281b8f. The only change since my last pass is the test rename, from ..._cancellation_survives_direct_routing to ..._cancellation_reaches_transport, and it is the right call: it drops the direct_routing claim the test no longer asserts and names what it actually pins.

Re-verified on the new head:

  • Suite green, 24 passed in this file.
  • Still load-bearing. Shielding the transport read from consumer cancellation in _streaming.py fails it:
FAILED tests/test_browser_routing.py::test_async_telemetry_stream_cancellation_reaches_transport

Nothing else changed, so my earlier note is resolved by the rename rather than by adding a path assertion, which is fine given test_telemetry_stream_routes_directly_to_vm already covers that. Re-approving.

@Sayan- Sayan- left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved on d281b8f. Rename is the right resolution, and the assertion still fails under a shielded-cancellation mutation.

@rgarcia
rgarcia merged commit 265ac16 into main Aug 10, 2026
11 checks passed
@rgarcia
rgarcia deleted the hypeship/assert-transport-cancel branch August 10, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants