Skip to content

Commit

Permalink
Merge pull request #35486 from geoand/#35464
Browse files Browse the repository at this point in the history
Close DevServices in a timely manner for integration tests
  • Loading branch information
geoand authored Aug 24, 2023
2 parents 3666595 + ec72175 commit 7bcbb88
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import static io.quarkus.test.junit.IntegrationTestUtil.readQuarkusArtifactProperties;
import static io.quarkus.test.junit.IntegrationTestUtil.startLauncher;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.time.Duration;
Expand All @@ -40,6 +42,7 @@
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import org.opentest4j.TestAbortedException;

import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.logging.InitialConfigurator;
import io.quarkus.runtime.logging.JBossVersion;
import io.quarkus.runtime.test.TestHttpEndpointProvider;
Expand Down Expand Up @@ -290,7 +293,9 @@ public void close() throws Throwable {
activateLogging();
startLauncher(launcher, additionalProperties, () -> ssl = true);

IntegrationTestExtensionState state = new IntegrationTestExtensionState(testResourceManager, launcher,
Closeable resource = new IntegrationTestExtensionStateResource(launcher,
devServicesLaunchResult.getCuratedApplication());
IntegrationTestExtensionState state = new IntegrationTestExtensionState(testResourceManager, resource,
sysPropRestore);
testHttpEndpointProviders = TestHttpEndpointProvider.load();

Expand Down Expand Up @@ -440,4 +445,32 @@ public Optional<String> containerNetworkId() {
return containerNetworkId;
}
}

private static final class IntegrationTestExtensionStateResource implements Closeable {

private final ArtifactLauncher<?> launcher;
private final CuratedApplication curatedApplication;

public IntegrationTestExtensionStateResource(ArtifactLauncher<?> launcher,
CuratedApplication curatedApplication) {
this.launcher = launcher;
this.curatedApplication = curatedApplication;
}

@Override
public void close() throws IOException {
if (launcher != null) {
try {
launcher.close();
} catch (Exception e) {
System.err.println("Unable to close ArtifactLauncher: " + e.getMessage());
}
}
try {
curatedApplication.close();
} catch (Exception e) {
System.err.println("Unable to close CuratedApplication: " + e.getMessage());
}
}
}
}

0 comments on commit 7bcbb88

Please sign in to comment.