Skip to content

Commit

Permalink
Test-only: little cleanup of some Gradle ITs
Browse files Browse the repository at this point in the history
Also adds a shutdown hook for launched processes to kill those when tests are aborted w/ ctrl-c. A process, like the ones spawned by for example `FastJarFormatWorksTest`, can otherwise survive, still "hold" port 8080 and cause subsequent test failures.
  • Loading branch information
snazy committed Feb 14, 2023
1 parent bfe2ae9 commit 2740164
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
Expand All @@ -17,14 +16,15 @@
import io.quarkus.test.devmode.util.DevModeTestUtils;

public class FastJarFormatWorksTest extends QuarkusGradleWrapperTestBase {
private static Future<?> jarRun;

@Test
public void testFastJarFormatWorks() throws Exception {

final File projectDir = getProjectDir("test-that-fast-jar-format-works");

runGradleWrapper(projectDir, "clean", "build");
BuildResult result = runGradleWrapper(projectDir, "clean", "build");
result.getTasks().forEach((k, v) -> System.err.println(" " + k + " --> " + v));
System.err.println(result.getOutput());

final Path quarkusApp = projectDir.toPath().resolve("build").resolve("quarkus-app");
assertThat(quarkusApp).exists();
Expand All @@ -46,22 +46,9 @@ public void testFastJarFormatWorks() throws Exception {

String logs = FileUtils.readFileToString(output, "UTF-8");

assertThatOutputWorksCorrectly(logs);

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello", () -> {
return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null;
}).equals("hello"));
assertThat(logs).contains("INFO").contains("cdi, resteasy");
} finally {
process.destroy();
}
}

private void assertThatOutputWorksCorrectly(String logs) {
assertThat(logs.isEmpty()).isFalse();
String infoLogLevel = "INFO";
assertThat(logs.contains(infoLogLevel)).isTrue();
assertThat(logs.contains("cdi, resteasy")).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ protected static Process launch(Path jar, File output, Map<String, String> env)
if (env != null) {
processBuilder.environment().putAll(env);
}
return processBuilder.start();
Process process = processBuilder.start();
Runtime.getRuntime().addShutdownHook(new Thread(process::destroyForcibly));
return process;
}

public static void dumpFileContentOnFailure(final Callable<Void> operation, final File logFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
Expand All @@ -17,7 +16,6 @@
import io.quarkus.test.devmode.util.DevModeTestUtils;

public class LegacyJarFormatWorksTest extends QuarkusGradleWrapperTestBase {
private static Future<?> jarRun;

@Test
public void testLegacyJarFormatWorks() throws Exception {
Expand Down Expand Up @@ -45,22 +43,9 @@ public void testLegacyJarFormatWorks() throws Exception {

String logs = FileUtils.readFileToString(output, "UTF-8");

assertThatOutputWorksCorrectly(logs);

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello", () -> {
return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null;
}).equals("hello"));
assertThat(logs).contains("INFO").contains("cdi, resteasy");
} finally {
process.destroy();
}
}

private void assertThatOutputWorksCorrectly(String logs) {
assertThat(logs.isEmpty()).isFalse();
String infoLogLevel = "INFO";
assertThat(logs.contains(infoLogLevel)).isTrue();
assertThat(logs.contains("cdi, resteasy")).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
Expand All @@ -17,7 +16,6 @@
import io.quarkus.test.devmode.util.DevModeTestUtils;

public class MultiModuleUberJarTest extends QuarkusGradleWrapperTestBase {
private static Future<?> jarRun;

@Test
public void testUberJarForMultiModule() throws Exception {
Expand All @@ -44,20 +42,10 @@ public void testUberJarForMultiModule() throws Exception {
}, output, ConditionTimeoutException.class);

String logs = FileUtils.readFileToString(output, "UTF-8");
assertThatOutputWorksCorrectly(logs);

// test that the http response is correct
assertThat(DevModeTestUtils.getHttpResponse("/hello", () -> {
return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null;
}).equals("hello common"));
assertThat(logs).contains("INFO").contains("cdi, resteasy");
} finally {
process.destroy();
}
}

private void assertThatOutputWorksCorrectly(String logs) {
assertThat(logs.isEmpty()).isFalse();
assertThat(logs.contains("INFO")).isTrue();
assertThat(logs.contains("cdi, resteasy")).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
Expand All @@ -18,7 +17,6 @@
import io.quarkus.test.devmode.util.DevModeTestUtils;

public class MutableJarFormatBootsInDevModeTest extends QuarkusGradleWrapperTestBase {
private static Future<?> jarRun;

@Test
public void testFastJarFormatWorks() throws Exception {
Expand Down Expand Up @@ -47,22 +45,9 @@ public void testFastJarFormatWorks() throws Exception {

String logs = FileUtils.readFileToString(output, "UTF-8");

assertThatOutputWorksCorrectly(logs);

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello", () -> {
return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null;
}).equals("hello"));
assertThat(logs).contains("INFO").contains("cdi, resteasy");
} finally {
process.destroy();
}
}

private void assertThatOutputWorksCorrectly(String logs) {
assertThat(logs.isEmpty()).isFalse();
String infoLogLevel = "INFO";
assertThat(logs.contains(infoLogLevel)).isTrue();
assertThat(logs.contains("cdi, resteasy")).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public BuildResult runGradleWrapper(File projectDir, String... args) throws IOEx
.redirectError(logOutput)
.start();

Runtime.getRuntime().addShutdownHook(new Thread(p::destroyForcibly));

//long timeout for native tests
//that may also need to download docker
boolean done = p.waitFor(10, TimeUnit.MINUTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
Expand All @@ -18,8 +17,6 @@

public class UberJarFormatWorksTest extends QuarkusGradleWrapperTestBase {

private static Future<?> jarRun;

@Test
public void testUberJarFormatWorks() throws Exception {

Expand All @@ -45,23 +42,9 @@ public void testUberJarFormatWorks() throws Exception {

String logs = FileUtils.readFileToString(output, "UTF-8");

assertThatOutputWorksCorrectly(logs);

// test that the application name and version are properly set
assertThat(DevModeTestUtils.getHttpResponse("/hello", () -> {
return jarRun == null ? null : jarRun.isDone() ? "jar run mode has terminated" : null;
}).equals("hello"));
assertThat(logs).contains("INFO").contains("cdi, resteasy");
} finally {
process.destroy();
}

}

private void assertThatOutputWorksCorrectly(String logs) {
assertThat(logs.isEmpty()).isFalse();
String infoLogLevel = "INFO";
assertThat(logs.contains(infoLogLevel)).isTrue();
assertThat(logs.contains("cdi, resteasy")).isTrue();
}

}

0 comments on commit 2740164

Please sign in to comment.