You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keep withStartupTimeout() from changing the shared default wait strategy - #12172
GenericContainer.DEFAULT_WAIT_STRATEGY is one static instance, shared by every container without its own wait strategy. withStartupTimeout(Duration) changed this shared instance, so a timeout set on one container applied to all containers in the JVM that use the default wait strategy. A short timeout on one container could make another container fail, depending on the test order.
Now withStartupTimeout(Duration) first gives the container its own default wait strategy (Wait.defaultWaitStrategy()) when it still uses the shared one. Only this container gets the new timeout. Containers with their own wait strategy do not change. Code that relied on this side effect (a timeout on one container that also changed other containers) now gets the default timeout (60 seconds) for the other containers.
The new test sets a short timeout on one container and starts another container that needs more time. It fails without this change.
Setting a startup timeout for one container no longer changes the default startup behavior of other containers. Each container now retains its own startup timeout settings. This prevents one container’s configuration from unexpectedly affecting another container’s startup.
No actionable comments were generated in the recent review.
Walkthrough
withStartupTimeout now creates a container-specific default wait strategy before setting its timeout. A test checks that this timeout does not prevent a separate container from starting after its exposed port opens five seconds later.
Changes: Container startup timeout isolation
Layer / File(s)
Summary
Isolate timeout and verify container behavior core/src/main/java/org/testcontainers/containers/GenericContainer.java, core/src/test/java/org/testcontainers/containers/GenericContainerTest.java
withStartupTimeout replaces the shared default wait strategy with a new default instance before applying the timeout. The test configures a short timeout on one container, then checks that a separate container can start after its port opens.
withStartupTimeout now affects only the container on which it is set, and other containers keep the default timeout. A regression test covers the reported scenario. No merge-blocking risk is identified.
Pre-merge checks: 7
Check name
Status
Explanation
Title check
The title names the main change: withStartupTimeout() no longer changes the shared default wait strategy. The raw summary and objectives confirm that the change gives the container its own default wai…
Description check
The description covers the problem (shared DEFAULT_WAIT_STRATEGY instance), the fix (per-container default wait strategy when the shared one is in use), the behavior change for code that relied on the…
Linked Issues check
Issue #12171 requires that withStartupTimeout(Duration) affect only the container on which it is called. The PR adds a guard in GenericContainer.withStartupTimeout: when getWaitStrategy() == DEFAULT_W…
Out of Scope Changes check
The whole-PR diff against the merge base e16dca9 changes two files. GenericContainer.java adds a four-line guard in withStartupTimeout, which is the fix for #12171. GenericContainerTest.java adds one …
New Module Registration
The check applies only when the PR adds a new directory under modules/. The changed-file inventory for the reviewed range (refs/coderabbit/pre-merge-check/base to head) lists two modified files only: …
Public Api Compatibility
Summary: The check passes. The PR does not remove, rename, or change the signature, return type, or visibility of any public or protected API under src/main/java. Evidence: - git diff --name-status …
Tests For Behaviour Changes
The PR changes behaviour in src/main/java. The diff in core/src/main/java/org/testcontainers/containers/GenericContainer.java (withStartupTimeout, +4 lines) adds a branch. When the container still…
Full details: Title check
Explanation
The title names the main change: withStartupTimeout() no longer changes the shared default wait strategy. The raw summary and objectives confirm that the change gives the container its own default wait strategy before setting the timeout. The title is specific and matches the changeset.
Full details: Description check
Explanation
The description covers the problem (shared DEFAULT_WAIT_STRATEGY instance), the fix (per-container default wait strategy when the shared one is in use), the behavior change for code that relied on the side effect, the new test and its failure without the fix, and the linked issue (Fixes #12171). It does not follow the repository template's checklist items, such as running checkstyleMain, checkstyleTest and spotlessApply, but the template is mainly guidance and the required content for a bug fix is present.
Full details: Linked Issues check
Explanation
Issue #12171 requires that withStartupTimeout(Duration) affect only the container on which it is called. The PR adds a guard in GenericContainer.withStartupTimeout: when getWaitStrategy() == DEFAULT_WAIT_STRATEGY, it calls waitingFor(Wait.defaultWaitStrategy()) before setting the timeout. The shared static instance is no longer mutated, so other containers keep the default 60-second timeout. Containers with their own wait strategy take the existing path and are unchanged. The added test GenericContainerTest.shouldNotChangeStartupTimeoutOfOtherContainers reproduces the issue scenario: a 2-second timeout on an unstarted container, then a second container whose port opens after 5 seconds. The test covers the reported regression. The issue's follow-up for JdbcDatabaseContainer.withStartupTimeoutSeconds() (#12103) is not a requirement of this issue, and the PR correctly does not address it. Limitation: the test does not run in this review, so the fail-before/pass-after claim rests on the issue reproduction and the code logic.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base e16dca9 changes two files. GenericContainer.java adds a four-line guard in withStartupTimeout, which is the fix for #12171. GenericContainerTest.java adds one test that reproduces #12171. Both changes connect directly to the linked issue. No unrelated files or behavior changes appear in the diff.
Full details: New Module Registration
Explanation
The check applies only when the PR adds a new directory under modules/. The changed-file inventory for the reviewed range (refs/coderabbit/pre-merge-check/base to head) lists two modified files only: core/src/main/java/org/testcontainers/containers/GenericContainer.java and core/src/test/java/org/testcontainers/containers/GenericContainerTest.java. No file under modules/ is added or changed, so no new module is registered. The check is inapplicable and passes. The PR's fix for issue #12171 is confined to core and does not need module registration.
Full details: Public Api Compatibility
Explanation
Summary: The check passes. The PR does not remove, rename, or change the signature, return type, or visibility of any public or protected API under src/main/java. Evidence: - git diff --name-status over the reviewed range lists two modified files: core/src/main/java/org/testcontainers/containers/GenericContainer.java and core/src/test/java/org/testcontainers/containers/GenericContainerTest.java. - The src/main/java patch is a four-line addition to the body of public SELF withStartupTimeout(Duration startupTimeout). The method keeps its signature, return type, and public visibility. The new lines call waitingFor(Wait.defaultWaitStrategy()) when the current strategy is the shared DEFAULT_WAIT_STRATEGY. - No declarations, fields, or other methods changed in the main source. This is a behavioral fix, not an API change. The check does not cover behavior changes, so no failure condition applies.
Full details: Tests For Behaviour Changes
Explanation
The PR changes behaviour in src/main/java. The diff in core/src/main/java/org/testcontainers/containers/GenericContainer.java (withStartupTimeout, +4 lines) adds a branch. When the container still uses the shared DEFAULT_WAIT_STRATEGY, the branch assigns Wait.defaultWaitStrategy() before the timeout is set. This is a bug fix that changes how the default wait strategy is handled. The PR also adds a test under src/test. core/src/test/java/org/testcontainers/containers/GenericContainerTest.java gains shouldNotChangeStartupTimeoutOfOtherContainers. The test sets a 2-second startup timeout on one unstarted Alpine container. It then starts a second Alpine container with the default wait strategy. That container opens port 8080 after 5 seconds. Without the fix, the shared strategy keeps the 2-second timeout and the second container fails. The test therefore exercises the changed behaviour. The check passes because a behaviour change in src/main/java has a matching test change under src/test. I did not run the test. The sandbox does not build or run the project.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the change and regression test. Isolating the shared default wait strategy before applying a container-specific timeout addresses the reported cross-container leakage, and CI is passing. Looks good to merge.
Hi! The GitHub Actions workflows (CI, CI-Docker-Rootless) for this PR are waiting for approval since Nov 15. Could a maintainer please approve them when you have time?
This PR also unblocks #12103: that PR has the same problem with the shared default wait strategy, so I will update it after this one is merged.
Thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GenericContainer.DEFAULT_WAIT_STRATEGYis one static instance, shared by every container without its own wait strategy.withStartupTimeout(Duration)changed this shared instance, so a timeout set on one container applied to all containers in the JVM that use the default wait strategy. A short timeout on one container could make another container fail, depending on the test order.Now
withStartupTimeout(Duration)first gives the container its own default wait strategy (Wait.defaultWaitStrategy()) when it still uses the shared one. Only this container gets the new timeout. Containers with their own wait strategy do not change. Code that relied on this side effect (a timeout on one container that also changed other containers) now gets the default timeout (60 seconds) for the other containers.The new test sets a short timeout on one container and starts another container that needs more time. It fails without this change.
If you prefer another approach, I can change it.
Fixes #12171
Summary by CodeRabbit