Add task timeout for tests.
MODIFY
dd-java-agent/dd-java-agent.gradle
dd-java-agent/dd-java-agent.gradle
@@ -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"

MODIFY
dd-java-agent/src/test/java/datadog/trace/agent/test/IntegrationTestUtils.java
dd-java-agent/src/test/java/datadog/trace/agent/test/IntegrationTestUtils.java
@@ -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();
}
}

MODIFY
gradle/java.gradle
gradle/java.gradle
+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") }
}

Add task timeout for tests.