Skip to content

Fix flaky TestNewCmdTaskInstantStop test#5743

Merged
stefanhaller merged 2 commits into
masterfrom
cmd-task-stop-priority
Jun 30, 2026
Merged

Fix flaky TestNewCmdTaskInstantStop test#5743
stefanhaller merged 2 commits into
masterfrom
cmd-task-stop-priority

Conversation

@stefanhaller

Copy link
Copy Markdown
Collaborator

TestNewCmdTaskInstantStop is flaky: it closes the stop channel from within start() and asserts the stopped task touched nothing. But Go's select picks uniformly at random among ready cases, so when opts.Stop and a data channel are both ready the loop can pick the data channel, call beforeStart() (which clears the view) and write the prefix before bailing. In production a task that's already been superseded thereby clobbers the output the incoming task is about to render.

Check stop with a non-blocking select before each blocking select, so the stop signal wins whenever it's already closed (Go has no built-in priority select; this is the idiomatic substitute). The selects keep their own stop case for liveness, to unblock when stop closes while parked waiting for data.

stefanhaller and others added 2 commits June 30, 2026 17:34
TestNewCmdTaskInstantStop is flaky: it closes the stop channel from
within start() and asserts the stopped task touched nothing. But Go's
select picks uniformly at random among ready cases, so when opts.Stop
and a data channel are both ready the loop can pick the data channel,
call beforeStart() (which clears the view) and write the prefix before
bailing. In production a task that's already been superseded thereby
clobbers the output the incoming task is about to render.

Check stop with a non-blocking select before each blocking select, so
the stop signal wins whenever it's already closed (Go has no built-in
priority select; this is the idiomatic substitute). The selects keep
their own stop case for liveness, to unblock when stop closes while
parked waiting for data.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@stefanhaller stefanhaller added the maintenance For refactorings, CI changes, tests, version bumping, etc label Jun 30, 2026
@stefanhaller stefanhaller enabled auto-merge June 30, 2026 15:38
@stefanhaller stefanhaller merged commit 760e9e5 into master Jun 30, 2026
14 checks passed
@stefanhaller stefanhaller deleted the cmd-task-stop-priority branch June 30, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance For refactorings, CI changes, tests, version bumping, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant