@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / cd775bdbe0
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 9, 16:00 UTC

[Tests] Replace flaky sleep with polling in test_background_cancel (#32986)

Signed-off-by: 7. Sun <jhao.sun@gmail.com>

7. Sun committed Jan 24, 2026 at 16:39 UTC cd775bdbe02f5e636c831ef467281c5b11624bc7
1 file changed +19 -6
tests/v1/entrypoints/openai/serving_responses/test_stateful.py
+19 -6
@@ -70,15 +70,28 @@ async def test_background_cancel(client: openai.AsyncOpenAI):
70 assert response.status == "queued"
71
72 # Cancel the response before it is completed.
73 - # FIXME: This test can be flaky.
74 - await asyncio.sleep(0.5)
73 + # Poll until the response is no longer queued (started processing) or timeout
74 + loop = asyncio.get_running_loop()
75 + start_time = loop.time()
76 + max_wait_seconds = 5.0
77 + poll_interval = 0.1
78 + while loop.time() - start_time < max_wait_seconds:
79 + response = await client.responses.retrieve(response.id)
80 + if response.status != "queued":
81 + # Started processing or completed - try to cancel
82 + break
83 + await asyncio.sleep(poll_interval)
84 +
85 response = await client.responses.cancel(response.id)
86 assert response.status == "cancelled"
87
78 - # Make sure the response status remains unchanged.
79 - await asyncio.sleep(5)
80 - response = await client.responses.retrieve(response.id)
81 - assert response.status == "cancelled"
88 + # Make sure the response status remains unchanged after some time.
89 + max_retries = 10
90 + for _ in range(max_retries):
91 + await asyncio.sleep(0.5)
92 + response = await client.responses.retrieve(response.id)
93 + # Verify status is still cancelled
94 + assert response.status == "cancelled"
95
96
97 @pytest.mark.asyncio