Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1928, if boot fails do not attempt to run other tests #1932

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstanceFactory;
import org.junit.jupiter.api.extension.TestInstanceFactoryContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import org.junit.jupiter.api.extension.TestInstantiationException;
import org.junit.platform.commons.JUnitException;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.opentest4j.TestAbortedException;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right exception you meant to throw?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, JUnit 5 does use opentest4j.


import io.quarkus.bootstrap.BootstrapClassLoaderFactory;
import io.quarkus.bootstrap.BootstrapException;
Expand All @@ -74,10 +74,11 @@
import io.quarkus.test.common.http.TestHTTPResourceManager;

public class QuarkusTestExtension
implements BeforeEachCallback, AfterEachCallback, TestInstanceFactory {
implements BeforeEachCallback, AfterEachCallback, TestInstanceFactory, BeforeAllCallback {

private URLClassLoader appCl;
private ClassLoader originalCl;
private static boolean failedBoot;

private ExtensionState doJavaStart(ExtensionContext context, TestResourceManager testResourceManager) {

Expand Down Expand Up @@ -271,27 +272,41 @@ public void beforeEach(ExtensionContext context) throws Exception {
@Override
public Object createTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext extensionContext)
throws TestInstantiationException {
if (failedBoot) {
try {
return extensionContext.getRequiredTestClass().newInstance();
} catch (Exception e) {
throw new TestInstantiationException("Boot failed", e);
}
}
ExtensionContext root = extensionContext.getRoot();
ExtensionContext.Store store = root.getStore(ExtensionContext.Namespace.GLOBAL);
ExtensionState state = store.get(ExtensionState.class.getName(), ExtensionState.class);
PropertyTestUtil.setLogFileProperty();
boolean substrateTest = extensionContext.getRequiredTestClass().isAnnotationPresent(SubstrateTest.class);
if (state == null) {
TestResourceManager testResourceManager = new TestResourceManager(extensionContext.getRequiredTestClass());
testResourceManager.start();

if (substrateTest) {
NativeImageLauncher launcher = new NativeImageLauncher(extensionContext.getRequiredTestClass());
try {
launcher.start();
} catch (IOException e) {
throw new JUnitException("Quarkus native image start failed, original cause: " + e);
try {
testResourceManager.start();

if (substrateTest) {
NativeImageLauncher launcher = new NativeImageLauncher(extensionContext.getRequiredTestClass());
try {
launcher.start();
} catch (IOException e) {
throw new JUnitException("Quarkus native image start failed, original cause: " + e);
}
state = new ExtensionState(testResourceManager, launcher, true);
} else {
state = doJavaStart(extensionContext, testResourceManager);
}
state = new ExtensionState(testResourceManager, launcher, true);
} else {
state = doJavaStart(extensionContext, testResourceManager);
store.put(ExtensionState.class.getName(), state);

} catch (RuntimeException e) {
testResourceManager.stop();
failedBoot = true;
throw e;
}
store.put(ExtensionState.class.getName(), state);
} else {
if (substrateTest != state.isSubstrate()) {
throw new RuntimeException(
Expand All @@ -318,6 +333,13 @@ private static ClassLoader setCCL(ClassLoader cl) {
return original;
}

@Override
public void beforeAll(ExtensionContext context) throws Exception {
if (failedBoot) {
throw new TestAbortedException("Not running test as boot failed");
}
}

class ExtensionState implements ExtensionContext.Store.CloseableResource {

private final TestResourceManager testResourceManager;
Expand Down