Add task timeout for tests.

This commit is contained in:
Tyler Benson 2019-05-23 16:27:53 -07:00
parent 4d01f52b67
commit fd43210e07
3 changed files with 32 additions and 4 deletions

View File

@ -107,7 +107,8 @@ dependencies {
}
tasks.withType(Test).configureEach {
jvmArgs "-Ddd.writer.type=LogWriter", "-Ddd.service.name=java-app"
jvmArgs "-Ddd.service.name=java-agent-tests"
jvmArgs "-Ddd.writer.type=LoggingWriter"
jvmArgs "-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug"
jvmArgs "-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"

View File

@ -17,6 +17,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@ -201,7 +203,8 @@ public class IntegrationTestUtils {
final ProcessBuilder processBuilder = new ProcessBuilder(commands.toArray(new String[0]));
processBuilder.environment().putAll(envVars);
final Process process = processBuilder.start();
final int result = process.waitFor();
waitFor(process, 30, TimeUnit.SECONDS);
if (printOutputStreams) {
final BufferedReader stdInput =
@ -221,6 +224,25 @@ public class IntegrationTestUtils {
}
System.out.println("--- stderr end ---");
}
return result;
return process.exitValue();
}
private static void waitFor(final Process process, final long timeout, final TimeUnit unit)
throws InterruptedException, TimeoutException {
final long startTime = System.nanoTime();
long rem = unit.toNanos(timeout);
do {
try {
process.exitValue();
return;
} catch (final IllegalThreadStateException ex) {
if (rem > 0) {
Thread.sleep(Math.min(TimeUnit.NANOSECONDS.toMillis(rem) + 1, 100));
}
}
rem = unit.toNanos(timeout) - (System.nanoTime() - startTime);
} while (rem > 0);
throw new TimeoutException();
}
}

View File

@ -1,3 +1,5 @@
import java.time.Duration
apply plugin: 'java'
apply plugin: 'groovy'
@ -301,8 +303,11 @@ for (def env : System.getenv().entrySet()) {
}
}
// Disable all tests if skipTests property was specified
tasks.withType(Test).configureEach {
// All tests must complete within 2 minutes.
timeout = Duration.ofMinutes(2)
// Disable all tests if skipTests property was specified
onlyIf { !project.rootProject.hasProperty("skipTests") }
}