Skip to content

test: fix flaky test_background_task_runs_and_exits near the exit tick#216

Open
CyberDefenseOperations wants to merge 1 commit into
andrewyng:mainfrom
CyberDefenseOperations:contrib/fix-flaky-shell-background-test
Open

test: fix flaky test_background_task_runs_and_exits near the exit tick#216
CyberDefenseOperations wants to merge 1 commit into
andrewyng:mainfrom
CyberDefenseOperations:contrib/fix-flaky-shell-background-test

Conversation

@CyberDefenseOperations

Copy link
Copy Markdown

_poll_output returns the moment it sees status == "exited", but shell_task_output reads are incremental and the final output chunk can still be draining into the task buffer on the same tick the status flips to exited. Under load the first post-exit read returns empty, so the helper returns acc == "" and the test fails with 'quick_done' not in ''.

This is a harness race, not a shell bug — the incremental-read contract is correct; the poll helper just returned before the tail was drained. The fix keeps reading until a read yields nothing new (bounded 2s) after the terminal status, so the final output is captured deterministically. The existing again["output"] == "" assertion still holds (the drain leaves nothing buffered). Verified 15/15 in a loop.

The background-shell poll helper (_poll_output) returned the instant it saw
status=='exited', but shell_task_output reads are incremental and the final
output chunk can still be draining into the task buffer on the same tick the
status flips to exited. Under load the first post-exit read returns empty and
the helper returns acc='', failing 'quick_done' in acc. This is a harness race,
not a shell bug (the incremental-read contract is correct). Keep reading until a
read yields nothing new (bounded 2s) after the terminal status so the tail is
captured deterministically. Verified 15/15.
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.

1 participant