Skip to content

fix(junit): create a new Playwright when the previous launcher run closed it - #1988

Open
monkey (Develop-KIM) wants to merge 1 commit into
microsoft:mainfrom
Develop-KIM:fix-1751
Open

monkey (Develop-KIM) wants to merge 1 commit into
microsoft:mainfrom
Develop-KIM:fix-1751

Conversation

@Develop-KIM

Copy link
Copy Markdown
Contributor

Summary

  • Surefire's rerunFailingTestsCount (this repo's own CI uses it through PW_MAX_RETRIES) runs the launcher again in the same JVM and thread. The first run's PlaywrightRegistry has already closed every Playwright it created, but the ThreadLocal in PlaywrightExtension still hands one of them out, so the rerun launches a browser on a closed connection and fails with Playwright connection closed.
  • Reuses the ThreadLocal instance only when it belongs to the current run's registry and creates a fresh one otherwise. Clearing the ThreadLocal from close() would not reach other threads.
  • This only shows up with JUnit 5.13+: since Migrate ExtensionContext.Store.CloseableResource to AutoCloseable #1860 the registry is AutoCloseable, which older JUnit versions never close, so there the first Playwright just leaks and the rerun reuses it.
  • TestFixturesRerun runs RerunFixture through the launcher twice on one thread and fails on main with the error above. That needs junit-platform-launcher, which comes in through the junit-bom so it follows junit.version.

Fixes #1751

…osed it

Surefire's rerunFailingTestsCount (and similar retry tooling) executes the
launcher again in the same JVM and thread. The first run's PlaywrightRegistry
has already closed every Playwright it created, but the ThreadLocal in
PlaywrightExtension still holds one of them, so the rerun launches a browser
on a closed connection and fails with "Playwright connection closed".

Reuse the ThreadLocal instance only when it belongs to the current run's
registry and create a fresh one otherwise.

Fixes: microsoft#1751
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]: Playwright-Junit lifecycle incompatible with maven retries 'surefire.rerunFailingTestsCount'

1 participant