Repository navigation
fix(flaky): BaseComposeTest.verifyNoNetworks (ComposeContainerTest / ComposeContainerPortViaEnvTest) - #12181
fix(flaky): BaseComposeTest.verifyNoNetworks (ComposeContainerTest / ComposeContainerPortViaEnvTest)#12181kiview wants to merge 1 commit into
Conversation
verifyNoNetworks compared the daemon-wide Docker network list before and after each test. Core tests run in 4 parallel forks against one daemon, so networks created or removed by other tests made the assertion fail intermittently (seen in ComposeContainerTest.simpleTest, ComposeContainerPortViaEnvTest.simpleTest and ComposeContainerTest.shouldCreateContainerWhenFileNotPrefixedWithPath). Filter the listed networks by the com.docker.compose.project label of the test's own compose project, and assert that the filter matches at least one network so the check can't pass vacuously. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015e4ZbXupAdHuvgfiSLVmKn
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Broken behaviour
BaseComposeTest.verifyNoNetworks(@AfterEach) intermittently fails with:In the last 7 days on
mainthis was the most common flake in core. Each failure was then hidden by the Develocity test-retry plugin:ComposeContainerTest.simpleTestso6sa26paxfd_defaultComposeContainerPortViaEnvTest.simpleTestey9gm7tkaays_defaultComposeContainerTest.shouldCreateContainerWhenFileNotPrefixedWithPathzzahb2sc1n3o_defaultEach one passed when retried in the same job.
Root cause
The check lists every network on the Docker daemon before and after each test method and asserts that the two lists are equal. Core tests run with
maxParallelForks = 4against one daemon. Other forks create and remove networks the whole time, for example their own Compose projects'<project>_defaultnetworks andNetwork.newNetwork(). When one of those changes lands between the two snapshots, the assertion fails. The networks in the diffs above belong to other Compose projects, sometimes added and sometimes removed, which fits a cross-fork race rather than a leak.Fix
Scope the check to the test's own Compose project:
com.docker.compose.projectfrom theredis-1service container. Every subclass exposes that service.label=com.docker.compose.project=<project>filter.It still catches a test that changes its own project's networks, but ignores activity from unrelated tests. Test-only change; no main code touched.
Verification (local, Docker 29.10.0)
To simulate the other forks, a background loop ran
docker network create/docker network rmevery ~0.3s. I then ran the four subclasses (ComposeContainerTest,ComposeWithIdentifierTest,ComposeWithNetworkTest,ComposeContainerPortViaEnvTest):ComposeWithIdentifierTest.simpleTest,ComposeContainerTest.simpleTest) with the same[The networks]error as in CI../gradlew :testcontainers:checkstyleTestpasses.spotlessApplycouldn't run here because Spotless couldn't find Node. The file was formatted with the pinned prettier 2.5.1 + prettier-plugin-java 1.6.1 (tab 4, width 120), so CI's Spotless check should agree.This came out of an automated weekly flaky-test report covering 2026-11-16 to 2026-11-23.
Generated by Claude Code
Summary by CodeRabbit