From 2e1c1eba50b7027bdeacf43548ba1a94aba9ac5f Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Fri, 31 Jul 2026 21:14:35 +0200 Subject: [PATCH] Remove unessesary simulated test duration The count-down latch releases either the moment all threads have reached the latch or when the simulated duration has passed. In this case the simulated duration acts like timeout and isn't nessesary, in normal circumstances the latch will release wll before that time has passed. The only exception here was the `IsolatedTestCase` which requires two threads to unlock its count-down latch. This isn't possible, isolated tests are all executed on the same thread. This test would always time out. The Timeout at test level takes care of any actual time-outs due to programming errors. --- .../ParallelExecutionIntegrationTests.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java index d2effe7e6c05..884ab4f9cbc9 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java @@ -10,7 +10,7 @@ package org.junit.platform.engine.support.hierarchical; -import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -67,6 +67,7 @@ import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestReporter; +import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.extension.AfterTestExecutionCallback; import org.junit.jupiter.api.extension.DynamicTestInvocationContext; import org.junit.jupiter.api.extension.ExtendWith; @@ -94,6 +95,7 @@ */ @ParameterizedClass @EnumSource(ParallelExecutorServiceType.class) +@Timeout(value = 5, unit = SECONDS) record ParallelExecutionIntegrationTests(ParallelExecutorServiceType executorServiceType) { @Test @@ -321,7 +323,7 @@ static class IsolatedTestCase { @BeforeAll static void initialize() { sharedResource = new AtomicInteger(); - countDownLatch = new CountDownLatch(2); + countDownLatch = new CountDownLatch(1); } @Test @@ -1044,39 +1046,22 @@ private static void incrementBlockAndCheck(AtomicInteger sharedResource, CountDo assertEquals(value, sharedResource.get()); } - @SuppressWarnings("ResultOfMethodCallIgnored") private static int incrementAndBlock(AtomicInteger sharedResource, CountDownLatch countDownLatch) throws InterruptedException { var value = sharedResource.incrementAndGet(); countDownLatch.countDown(); - countDownLatch.await(estimateSimulatedTestDurationInMilliseconds(), MILLISECONDS); + countDownLatch.await(); return value; } - @SuppressWarnings("ResultOfMethodCallIgnored") private static void storeAndBlockAndCheck(AtomicInteger sharedResource, CountDownLatch countDownLatch) throws InterruptedException { var value = sharedResource.get(); countDownLatch.countDown(); - countDownLatch.await(estimateSimulatedTestDurationInMilliseconds(), MILLISECONDS); + countDownLatch.await(); assertEquals(value, sharedResource.get()); } - /* - * To simulate tests running in parallel tests will modify a shared - * resource, simulate work by waiting, then check if the shared resource was - * not modified by any other thread. - * - * Depending on system performance the simulation of work needs to be longer - * on slower systems to ensure tests can run in parallel. - * - * Currently, CI is known to be slow. - */ - private static long estimateSimulatedTestDurationInMilliseconds() { - var runningInCi = Boolean.parseBoolean(System.getenv("CI")); - return runningInCi ? 1000 : 100; - } - @NullMarked static class ThreadReporter implements AfterTestExecutionCallback, InvocationInterceptor {