Skip to content

chore: Wait for the background removal in the test of a container that Docker creates late, instead of polling for a fixed time. - #427

Merged
goloroden merged 2 commits into
mainfrom
chore/await-background-removal-in-test
Oct 19, 2026
Merged

goloroden merged 2 commits into
mainfrom
chore/await-background-removal-in-test

Conversation

@goloroden

Copy link
Copy Markdown
Member

Fixes a flaky test from #425, "removes a container that Docker creates only after the wait…", which failed once on preview.

  • Cause: after the creates returned, the test polled for 5 seconds for the containers to disappear. Their removal only runs once testcontainers gives up on them, which may take longer under load.
  • Fix: the stubbed create now waits for the test to release it after the start has failed, so the attempts give up on pending creations without any wall-clock assertion. startContainer hands the background removal to a test-only onBackgroundRemoval hook, and the test awaits it before checking that nothing is left.
  • Same pattern elsewhere: the watcher of created containers assumed that Docker's events had arrived by the time the start returned. It now creates a marker container and waits for its event, since Docker passes on its events in order.

The test passed 20 times in a row, 10 times with every core busy (load average up to 55), and the whole file twice under that load. Breaking the background removal or the cap still fails it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QykegdHe7vhHMBN3kWxgfH

…t Docker creates late, instead of polling for a fixed time.

The test held the creations back until the start had failed, and then polled
for 5 seconds for the containers to disappear, while their removal only runs
once testcontainers gives up on them, which may take longer under load. Now
the test lets Docker create the containers only after the start has failed,
and awaits the removals in the background through a test-only hook of
startContainer. The watcher of created containers no longer assumes that
Docker's events have arrived by the time the start returns: it creates a
marker container and waits for its event, after which all earlier events
have arrived.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QykegdHe7vhHMBN3kWxgfH
@goloroden
goloroden requested a review from a team as a code owner October 19, 2026 15:10
@goloroden goloroden self-assigned this Oct 19, 2026
@goloroden
goloroden merged commit 2da41b3 into main Oct 19, 2026
3 checks passed
@goloroden
goloroden deleted the chore/await-background-removal-in-test branch October 19, 2026 15:45
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