Skip to content

test: fix flaky TestAttachedServer_DeleteEmitsSessionExited#3418

Merged
Sayt-0 merged 1 commit into
docker:mainfrom
dgageot:worktree-board-8283588232ec4796
Jul 2, 2026
Merged

test: fix flaky TestAttachedServer_DeleteEmitsSessionExited#3418
Sayt-0 merged 1 commit into
docker:mainfrom
dgageot:worktree-board-8283588232ec4796

Conversation

@dgageot

@dgageot dgageot commented Jul 2, 2026

Copy link
Copy Markdown
Member

The SSE handler in the attached server flushes response headers before it subscribes to the event log via StreamEvents. In the test, the HasEventSource guard was effectively a no-op because the test itself registers the event source — so DeleteSession could race ahead and remove the event log before the handler had a chance to subscribe. The stream then closed with a clean EOF and no session_exited event, causing the test to fail intermittently (observed in CI run https://github.com/docker/docker-agent/actions/runs/28590850454/job/84773735898).

The fix adds a "hello" sentinel event to the fake event source. The test now reads that event from the SSE stream before calling DeleteSession, which proves the handler is actively subscribed before the session is torn down. The test then asserts the terminal session_exited event as before.

Validated with 100 runs under -race, the full pkg/server suite, go vet, and golangci-lint with zero issues.

Emit and read a first SSE event to guarantee the handler has subscribed
to the event log before calling DeleteSession, avoiding a race where the
stream closed with EOF before session_exited was delivered.

Assisted-By: Claude
@dgageot dgageot requested a review from a team as a code owner July 2, 2026 13:13

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

The sentinel-event synchronization approach is correct and well-designed. The "hello" event is emitted before DeleteSession is called, providing a deterministic proof that the SSE handler is actively subscribed — eliminating the race that caused intermittent failures. No bugs were introduced by the changed lines.

@Sayt-0 Sayt-0 merged commit 4bcc9a1 into docker:main Jul 2, 2026
9 of 10 checks passed
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.

3 participants