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(); }