Skip to content

Keep withStartupTimeout() from changing the shared default wait strategy - #12172

Open
aymenjamaaoui wants to merge 1 commit into
testcontainers:mainfrom
aymenjamaaoui:fix/default-wait-strategy-timeout
Open

aymenjamaaoui wants to merge 1 commit into
testcontainers:mainfrom
aymenjamaaoui:fix/default-wait-strategy-timeout

Conversation

@aymenjamaaoui

@aymenjamaaoui aymenjamaaoui commented Nov 15, 2026 •

Copy link
Copy Markdown

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.

If you prefer another approach, I can change it.

Fixes #12171

Summary by CodeRabbit

  • Bug Fixes
    • 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.

@aymenjamaaoui
aymenjamaaoui requested a review from a team as a code owner November 15, 2026 21:28
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: eddumelendez, kiview

Merge Risk: Minimal · up to 90da9

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: Passed 7

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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 Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e16dca9 and 90da9ab.

Files selected for processing: 2

  • core/src/main/java/org/testcontainers/containers/GenericContainer.java
  • core/src/test/java/org/testcontainers/containers/GenericContainerTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@aaron-samuvel aaron-samuvel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@aymenjamaaoui

Copy link
Copy Markdown
Author

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!

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.

[Bug]: withStartupTimeout() changes the startup timeout of all containers that use the default wait strategy

2 participants