Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Uses separate ExecutorService to re-run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Janusz Baginski committed Jun 21, 2024
1 parent 977fde3 commit 2e84800
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions fork-runner/src/main/java/com/shazam/fork/ForkRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

import static com.shazam.fork.Utils.namedExecutor;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -66,15 +67,14 @@ public ForkRunner(PoolLoader poolLoader,
}

public boolean run() {
ExecutorService poolExecutor = null;
try {
Collection<Pool> pools = poolLoader.loadPools();
poolExecutor = namedExecutor(pools.size(), "PoolExecutor-%d");

Collection<TestCaseEvent> testCases = testClassLoader.loadTestSuite();
summaryGeneratorHook.registerHook(pools, testCases);

executeTests(poolExecutor, pools, testCases);
executeTests(pools, testCases);


AggregatedTestResult aggregatedTestResult = aggregator.aggregateTestResults(pools, testCases);
if (!aggregatedTestResult.getFatalCrashedTests().isEmpty()) {
Expand All @@ -83,7 +83,7 @@ public boolean run() {

Collection<TestCaseEvent> fatalCrashedTestCases =
findFatalCrashedTestCases(testCases, aggregatedTestResult.getFatalCrashedTests());
executeTests(poolExecutor, pools, fatalCrashedTestCases);
executeTests(pools, fatalCrashedTestCases);

aggregatedTestResult = aggregator.aggregateTestResults(pools, testCases);

Expand All @@ -107,28 +107,33 @@ public boolean run() {
} catch (Exception e) {
logger.error("Error while Fork was executing", e);
return false;
} finally {
if (poolExecutor != null) {
poolExecutor.shutdown();
}
}
}

private void executeTests(ExecutorService poolExecutor,
Collection<Pool> pools,
Collection<TestCaseEvent> testCases) throws InterruptedException {
private void executeTests(
Collection<Pool> pools,
Collection<TestCaseEvent> testCases
) throws InterruptedException {
ProgressReporter progressReporter = progressReporterFactory.createProgressReporter();
progressReporter.start();

CountDownLatch poolCountDownLatch = new CountDownLatch(pools.size());
ExecutorService poolExecutor = namedExecutor(pools.size(), "PoolExecutor-%d");

CountDownLatch poolCountDownLatch = new CountDownLatch(pools.size());
for (Pool pool : pools) {
Runnable poolTestRunner =
poolTestRunnerFactory.createPoolTestRunner(pool, testCases, poolCountDownLatch, progressReporter);
Runnable poolTestRunner = poolTestRunnerFactory.createPoolTestRunner(
pool,
testCases,
poolCountDownLatch,
progressReporter
);
poolExecutor.execute(poolTestRunner);
}
poolCountDownLatch.await();

poolExecutor.shutdown();
poolExecutor.awaitTermination(10, TimeUnit.MINUTES);

progressReporter.stop();
}

Expand Down

0 comments on commit 2e84800

Please sign in to comment.