From 9883c77d408d99bd20fff2b4ed1ab146e2305696 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 14 Sep 2026 15:49:26 -0700 Subject: [PATCH] test: start a new fixture server when a test class is rerun ServerLifecycle stopped the server in afterAll but kept it in serverMap, so surefire reruns (PW_MAX_RETRIES) got the stopped server and failed with net::ERR_CONNECTION_REFUSED instead of retrying the test. Also make the map concurrent since test classes run in parallel. --- .../com/microsoft/playwright/junit/ServerLifecycle.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/playwright/src/test/java/com/microsoft/playwright/junit/ServerLifecycle.java b/playwright/src/test/java/com/microsoft/playwright/junit/ServerLifecycle.java index 0b9bdcb7f..38b27c5f1 100644 --- a/playwright/src/test/java/com/microsoft/playwright/junit/ServerLifecycle.java +++ b/playwright/src/test/java/com/microsoft/playwright/junit/ServerLifecycle.java @@ -20,8 +20,8 @@ import org.junit.jupiter.api.extension.*; import java.io.IOException; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import static com.microsoft.playwright.Utils.nextFreePort; @@ -31,7 +31,8 @@ public class ServerLifecycle implements BeforeAllCallback, AfterAllCallback, Par public static Map, Server> serverMap; static { - serverMap = new HashMap<>(); + // Test classes run concurrently. + serverMap = new ConcurrentHashMap<>(); } @Override @@ -41,7 +42,8 @@ public void beforeAll(ExtensionContext extensionContext) throws Exception { @Override public void afterAll(ExtensionContext extensionContext) { - Server server = serverMap.get(extensionContext.getRequiredTestClass()); + // Remove the stopped server so that a rerun of the class (e.g. surefire's rerunFailingTestsCount) starts a new one. + Server server = serverMap.remove(extensionContext.getRequiredTestClass()); if (server != null) { server.stop(); }