Fix concurrency issues in TeaVM test runner

This commit is contained in:
Alexey Andreev 2016-11-30 00:06:20 +03:00
parent 86b78b8f5d
commit 0b4f8b9898

View File

@ -177,7 +177,7 @@ public class TeaVMTestRunner extends Runner {
private void runChild(Method child, RunNotifier notifier) { private void runChild(Method child, RunNotifier notifier) {
notifier.fireTestStarted(describeChild(child)); notifier.fireTestStarted(describeChild(child));
boolean run = false; boolean ran = false;
boolean success = true; boolean success = true;
MethodHolder methodHolder = classHolder.getMethod(getDescriptor(child)); MethodHolder methodHolder = classHolder.getMethod(getDescriptor(child));
@ -195,31 +195,42 @@ public class TeaVMTestRunner extends Runner {
if (!child.isAnnotationPresent(SkipJVM.class) if (!child.isAnnotationPresent(SkipJVM.class)
&& !child.getDeclaringClass().isAnnotationPresent(SkipJVM.class)) { && !child.getDeclaringClass().isAnnotationPresent(SkipJVM.class)) {
run = true; ran = true;
success = runInJvm(child, notifier, expectedExceptions); success = runInJvm(child, notifier, expectedExceptions);
} }
Description description = describeChild(child);
if (success && outputDir != null) { if (success && outputDir != null) {
Description description = describeChild(child);
List<TeaVMTestConfiguration> configurations = getConfigurations(); List<TeaVMTestConfiguration> configurations = getConfigurations();
int[] configurationIndex = new int[] { 0 }; int[] configurationIndex = new int[] { 0 };
List<Consumer<Boolean>> onSuccess = new ArrayList<>(); List<Consumer<Boolean>> onSuccess = new ArrayList<>();
List<TestRun> runs = new ArrayList<>();
onSuccess.add(runSuccess -> { onSuccess.add(runSuccess -> {
if (runSuccess && configurationIndex[0] < configurations.size()) { if (runSuccess && configurationIndex[0] < runs.size()) {
runInTeaVM(child, notifier, expectedExceptions, configurations.get(configurationIndex[0]++), submitRun(runs.get(configurationIndex[0]++));
onSuccess.get(0));
} else { } else {
notifier.fireTestFinished(description); notifier.fireTestFinished(description);
latch.countDown(); latch.countDown();
} }
}); });
for (TeaVMTestConfiguration configuration : configurations) {
TestRun run = compileByTeaVM(child, notifier, expectedExceptions, configuration, onSuccess.get(0));
if (run != null) {
runs.add(run);
} else {
notifier.fireTestFinished(description);
return;
}
}
onSuccess.get(0).accept(true); onSuccess.get(0).accept(true);
} else { } else {
if (!run) { if (!ran) {
notifier.fireTestIgnored(describeChild(child)); notifier.fireTestIgnored(description);
} }
notifier.fireTestFinished(describeChild(child)); notifier.fireTestFinished(description);
latch.countDown(); latch.countDown();
} }
} }
@ -262,7 +273,7 @@ public class TeaVMTestRunner extends Runner {
return true; return true;
} }
private boolean runInTeaVM(Method child, RunNotifier notifier, Set<Class<?>> expectedExceptions, private TestRun compileByTeaVM(Method child, RunNotifier notifier, Set<Class<?>> expectedExceptions,
TeaVMTestConfiguration configuration, Consumer<Boolean> onComplete) { TeaVMTestConfiguration configuration, Consumer<Boolean> onComplete) {
Description description = describeChild(child); Description description = describeChild(child);
@ -271,20 +282,17 @@ public class TeaVMTestRunner extends Runner {
compileResult = compileTest(child, configuration); compileResult = compileTest(child, configuration);
} catch (Exception e) { } catch (Exception e) {
notifier.fireTestFailure(new Failure(description, e)); notifier.fireTestFailure(new Failure(description, e));
onComplete.accept(false); return null;
return false;
} }
if (!compileResult.success) { if (!compileResult.success) {
notifier.fireTestFailure(new Failure(description, notifier.fireTestFailure(new Failure(description,
new AssertionError(compileResult.errorMessage))); new AssertionError(compileResult.errorMessage)));
onComplete.accept(false); return null;
return false;
} }
if (runStrategy == null) { if (runStrategy == null) {
onComplete.accept(true); return null;
return true;
} }
TestRunCallback callback = new TestRunCallback() { TestRunCallback callback = new TestRunCallback() {
@ -300,11 +308,9 @@ public class TeaVMTestRunner extends Runner {
} }
}; };
TestRun run = new TestRun(compileResult.file.getParentFile(), child, return new TestRun(compileResult.file.getParentFile(), child,
new MethodReference(testClass.getName(), getDescriptor(child)), new MethodReference(testClass.getName(), getDescriptor(child)),
description, callback, expectedExceptions); description, callback, expectedExceptions);
submitRun(run);
return true;
} }
private void submitRun(TestRun run) { private void submitRun(TestRun run) {