From 3baaffeb03fd134c24e5b51899a3853afd84d0ec Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Mon, 4 Sep 2023 18:23:35 +0200 Subject: [PATCH] Improve error message and fail behavior of ParallelBuildChainTest #657 The ParallelBuildChainTest has some flaws in error message design and failure handling, which are addressed by this change: 1. The timeout for builds to start/finish is higher than the execution time of a long running build. Thus in case builds are unexpectedly not run in parallel, the assertion for timely build start/finish is not evaluated as expected. 2. In case an error occurs before starting a build operation, the number of expected builds in the TimerBuilder may be higher than the number of builds that will every be executed. Since the TimerBuilder abortion tries to wait for all expected builds indefinitely, the operation (and thus test tear down) may never terminate. --- .../tests/internal/builders/ParallelBuildChainTest.java | 2 +- .../core/tests/internal/builders/TimerBuilder.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ParallelBuildChainTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ParallelBuildChainTest.java index 45ca950e3ec..4fd4c329220 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ParallelBuildChainTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/ParallelBuildChainTest.java @@ -51,7 +51,7 @@ public class ParallelBuildChainTest extends AbstractBuilderTest { private static final int MAXIMUM_NUMBER_OF_CONCURRENT_BUILDS = 3; - private static final int TIMEOUT_IN_MILLIS = 60_000; + private static final int TIMEOUT_IN_MILLIS = 20_000; private static enum BuildDurationType { /* diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TimerBuilder.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TimerBuilder.java index 6545c6e2ac6..2d6325b85bc 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TimerBuilder.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/TimerBuilder.java @@ -36,6 +36,8 @@ public class TimerBuilder extends IncrementalProjectBuilder { public static final String DURATION_ARG = "duration"; public static final String RULE_TYPE_ARG = "ruleType"; + private static final int SHUTDOWN_TIMEOUT_IN_MILLIS = 60_000; + private static BuildExecutionState executionState = new BuildExecutionState(-1); private static class BuildExecutionState { @@ -72,11 +74,14 @@ private synchronized void endedExcecutingProject(IProject project) { private synchronized void abortAndWaitForAllBuilds() { shallAbort = true; - while (isExecuting()) { + long durationInMillis = 0; + long waitingStartTimeInMillis = System.currentTimeMillis(); + while (isExecuting() && durationInMillis < SHUTDOWN_TIMEOUT_IN_MILLIS) { try { - wait(); + wait(SHUTDOWN_TIMEOUT_IN_MILLIS); } catch (InterruptedException e) { } + durationInMillis = System.currentTimeMillis() - waitingStartTimeInMillis; } }