Skip to content

fix: flaky TestPrunePromptTermination test - #7168

Open
hirehamir wants to merge 3 commits into
docker:masterfrom
hirehamir:fix/flaky-test-prune-prompt-termination
Open

hirehamir wants to merge 3 commits into
docker:masterfrom
hirehamir:fix/flaky-test-prune-prompt-termination

Conversation

@hirehamir

@hirehamir hirehamir commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

- What I did

Fixes #5802

- How I did it

I kept the write end of the pipe alive for the duration of the test with

defer w.Close()

- How to verify it

# without the changes from this branch: fails most runs
# with the changes from this branch: 0 failures
GOGC=1 GOMEMLIMIT=8MiB go test ./cli/command/container/ -run TestContainerPrunePromptTermination -count=40 -v
GC forced (GOGC=1 GOMEMLIMIT=8MiB) GC off (GOGC=off)
without this change 33 of 40 fail 0 of 40 fail
with this change 0 of 40 fail 0 of 40 fail

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/test/cmd.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@GitNimay

GitNimay commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

I can confirm this fixes the flake, which also hit CI on #7408 (TestSystemPrunePromptTermination). The discarded write end of the pipe is garbage-collected, its finalizer closes it, and the prompt reads EOF (treated as "no"), so the command returns "prune has been cancelled" instead of prompt.ErrTerminated.

Reproduce on master with:

GOGC=1 go test -race -count=200 -run PromptTermination ./cli/command/system ./cli/command/image

That gave 11 failures on master, and 0 with the write end kept open.

Two things you may want to add here:

  • cmd/docker-trust/internal/test/cmd.go has an identical copy of TerminatePrompt with the same bug.
  • Under -race, the cli.OutBuffer().Len() check in the helper races with the prompt that is still writing to the buffer. The writer hook already guarantees a write happened, so that check can be dropped.

This is the flake tracked in #5802.

@hirehamir

Copy link
Copy Markdown
Contributor Author

That makes sense. I'll add those changes right now.

@hirehamir

Copy link
Copy Markdown
Contributor Author

@Benehiko anything else you'd like to see here?

@hirehamir
hirehamir force-pushed the fix/flaky-test-prune-prompt-termination branch from 0389b98 to 3f83a0c Compare October 19, 2026 16:30
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.

Flaky test: TestPrunePromptTermination

3 participants