test(proxy): require sustained event-loop interleaving across the buffered drain

The old assertion only compared the probe's first and last observed step, which passes when the drain yields once early and then monopolizes the loop again. The probe must now advance through at least half the backlog and make progress across at least a quarter of the chunk transitions, so a regression that starves other tasks mid-drain turns the test red

Addresses the review on PR #46810
This commit is contained in:
Rabari Mihir 2026-10-16 04:29:05 +00:00
parent ea4ee8ff21
commit 64b27eea92

View file

@ -4402,9 +4402,14 @@ async def test_async_data_generator_yields_to_event_loop_while_chunks_are_buffer
_, observed_progress = await asyncio.gather(probe(), consume())
assert observed_progress[0] < observed_progress[-1], (
assert observed_progress[-1] >= num_chunks // 2, (
f"Event loop starved while {num_chunks} buffered chunks were drained, "
f"probe progress stayed at {observed_progress[0]} the whole stream"
f"probe only reached {observed_progress[-1]} steps"
)
sustained_advances = sum(1 for a, b in zip(observed_progress, observed_progress[1:]) if b > a)
assert sustained_advances >= num_chunks // 4, (
f"Probe advanced in only {sustained_advances} of {num_chunks} chunks, "
f"the drain yields once at the start and then monopolizes the loop again"
)