Skip to content

Retain method failures for shared container lifecycle callbacks - #12083

Open
dlwhdgus0810 wants to merge 1 commit into
testcontainers:mainfrom
dlwhdgus0810:fix/shared-container-failure-recording
Open

dlwhdgus0810 wants to merge 1 commit into
testcontainers:mainfrom
dlwhdgus0810:fix/shared-container-failure-recording

Conversation

@dlwhdgus0810

@dlwhdgus0810 dlwhdgus0810 commented Sep 16, 2026

Copy link
Copy Markdown

Shared JUnit Jupiter containers receive their final lifecycle callback from the class context, which does not contain exceptions from individual test methods. As a result, a static BrowserWebDriverContainer configured with RECORD_FAILING discards its recording even when a test fails.

Retain the first failure per class context and report it when shared containers finish. Nested failures also reach enclosing shared containers without leaking into sibling contexts. Class-level exceptions keep precedence, and shared callback counts and instance-container behavior remain unchanged.

Validation: the initial JUnit-launcher regression failed on upstream for both direct and nested method failures. The final focused suite reports 15 tests, zero failures, and one intentional existing assumption-based skip. Spotless, main/test Checkstyle, and Javadoc pass. No Docker-backed Selenium recording test or full repository suite was run.

Fixes #10270

Summary by CodeRabbit

  • Bug Fixes

    • Improved failure handling for shared test containers across nested tests and lifecycle callbacks.
    • Ensured the first relevant test failure is reported correctly, including failures from setup and teardown methods.
    • Prevented duplicate failure notifications and avoided propagating failures to unrelated nested containers.
  • Tests

    • Added coverage for shared and per-test container failure behavior across successful, nested, and lifecycle-failure scenarios.

Preserve method and nested-context failures until shared containers receive their final lifecycle callback. Keep class-level failures and instance callbacks unchanged.

Fixes testcontainers#10270
@dlwhdgus0810
dlwhdgus0810 requested a review from a team as a code owner September 16, 2026 17:50
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0acb9edb-cd70-47ec-8d8a-84da184cfd5c

📥 Commits

Reviewing files that changed from the base of the PR and between 8e54951 and 02a7a3f.

📒 Files selected for processing (3)
  • modules/junit-jupiter/build.gradle
  • modules/junit-jupiter/src/main/java/org/testcontainers/junit/jupiter/TestcontainersExtension.java
  • modules/junit-jupiter/src/test/java/org/testcontainers/junit/jupiter/SharedContainerFailureTest.java

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Shared container failure handling

Layer / File(s) Summary
Context failure capture
modules/junit-jupiter/src/main/java/org/testcontainers/junit/jupiter/TestcontainersExtension.java
The extension stores a per-context AtomicReference<Throwable> and captures the first failure from the current context or its ancestors.
Lifecycle failure signaling
modules/junit-jupiter/src/main/java/org/testcontainers/junit/jupiter/TestcontainersExtension.java
afterEach and afterAll pass the direct or stored failure to shared container lifecycle callbacks.
Failure scenario validation
modules/junit-jupiter/build.gradle, modules/junit-jupiter/src/test/java/org/testcontainers/junit/jupiter/SharedContainerFailureTest.java
Tests cover method, nested, class, and successful execution. The test module adds the JUnit Platform Launcher dependency.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant JUnit Jupiter
  participant TestcontainersExtension
  participant Shared Container
  JUnit Jupiter->>TestcontainersExtension: run test lifecycle callback
  TestcontainersExtension->>TestcontainersExtension: capture first execution failure
  TestcontainersExtension->>Shared Container: signal after-test with failure
Loading

Suggested reviewers: eddumelendez

Merge Risk: ⚪ Minimal · up to 02a7a

The shared-container failure reporting change is covered across failing, nested, class-lifecycle, and successful paths, with no identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving method failures for shared container lifecycle callbacks.
Description check ✅ Passed The description explains the broken behavior, the fix, nested-context handling, precedence rules, validation results, and linked issue. It provides sufficient context for review.
Linked Issues check ✅ Passed Issue #10270 requires test-method failures to reach shared JUnit Jupiter containers so VncRecordingMode.RECORD_FAILING can generate recordings. TestcontainersExtension stores the first failure per…
Out of Scope Changes check ✅ Passed The changed build declaration adds a test-only JUnit Platform Launcher dependency required by the focused extension tests. The extension change implements failure propagation for shared containers. Th…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Junit5 {BrowserWebDriverContainer with VncRecordingMode.RECORD_FAILING is not recording}

1 participant