Python
test: tighten the output drain (address PR review perf feedback)
Rocky DeStefanob0aeff63ed09
diff --git a/tests/test_shell.py b/tests/test_shell.pyindex 1b028da6..be26414e 100644--- a/tests/test_shell.py+++ b/tests/test_shell.py@@ -134,17 +134,22 @@ def _poll_output(reg, task_id, *, until_status=None, deadline=10.0):continueif until_status is not None:# Output reads are incremental and the status can flip to its- # terminal value on the same tick that the final output chunk is- # still being drained into the task buffer. Keep reading until a- # read yields nothing new (bounded), so the tail is captured- # deterministically instead of racing the status update.- drain_end = time.monotonic() + 2.0- while time.monotonic() < drain_end:+ # terminal value on the same tick the final chunk is still being+ # drained into the task buffer. Drain the tail: consume anything+ # already buffered greedily (no sleep), and only wait between+ # *empty* reads, stopping once two consecutive reads yield nothing+ # (robust to a one-tick gap between chunks). Bounded and cheap —+ # the common case is a couple of reads, not a tight 2s poll.+ grace_end = time.monotonic() + 0.5+ empty_reads = 0+ while empty_reads < 2 and time.monotonic() < grace_end:extra = reg.execute("shell_task_output", {"task_id": task_id})- if not extra["output"]:- break- acc += extra["output"]- res = extra+ if extra["output"]:+ acc += extra["output"]+ res = extra+ empty_reads = 0+ continue # more available now — keep draining, no sleep+ empty_reads += 1time.sleep(0.02)return acc, restime.sleep(0.1)