From b38516da88ba4eb7ba3fa584e08133881f4d1108 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 3 Sep 2026 12:37:31 -0700 Subject: [PATCH] test(responses): make the background stream cancel deterministic A five-token response can complete before the cancel lands, which put the test back on the "Cannot cancel a completed response" path it used to swallow. Ask for a long generation so the cancel always beats completion, and assert the cancelled status unconditionally --- .../test_e2e_openai_responses_api.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py b/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py index 604f1c84d20..0dbecbe2801 100644 --- a/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py +++ b/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py @@ -162,7 +162,7 @@ def test_cancel_streaming_response(): started = time.monotonic() stream = client.responses.create( model="gpt-5.5", - input="just respond with the word 'ping'", + input="count from 1 to 500, one number per line", stream=True, background=True, timeout=BACKGROUND_STREAM_ADMISSION_DEADLINE_SECONDS, @@ -189,13 +189,7 @@ def test_cancel_streaming_response(): ) assert response_id is not None, f"no response event within {elapsed:.0f}s of streaming a background response" - try: - cancel_response = client.responses.cancel(response_id) - except BadRequestError as e: - if "Cannot cancel a completed response" not in str(e): - raise - print("response completed before cancel=", e) - return + cancel_response = client.responses.cancel(response_id) print("CANCEL streaming response=", cancel_response) assert cancel_response.status == "cancelled"