Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/datadog.configure-tests.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ tasks.withType<Test>().configureEach {
develocity.testRetry {
if (providers.environmentVariable("CI").isPresent()) {
maxRetries = 3
filter {
excludeAnnotationClasses.add("*NonRetryable") // allow to mark classes non retryable
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ void testLatestJdk() throws Exception {
snapshot -> {
snapshotReceived.set(true);
});
processRequests(snapshotReceived::get);
processRequests(
snapshotReceived::get,
() -> String.format("timeout snapshotReceived=%s", snapshotReceived.get()));
assertFalse(logHasErrors(logFilePath, it -> false));
}

Expand All @@ -53,7 +55,9 @@ void testShutdown() throws Exception {
snapshot -> {
snapshotReceived.set(true);
});
processRequests(snapshotReceived::get);
processRequests(
snapshotReceived::get,
() -> String.format("timeout snapshotReceived=%s", snapshotReceived.get()));
assertFalse(logHasErrors(logFilePath, it -> false));
// Wait for the app exit with some extra time.
// The expectation is that agent doesn't prevent app from exiting.
Expand All @@ -78,7 +82,9 @@ void testDestroy() throws Exception {
snapshot -> {
snapshotReceived.set(true);
});
processRequests(snapshotReceived::get);
processRequests(
snapshotReceived::get,
() -> String.format("timeout snapshotReceived=%s", snapshotReceived.get()));
targetProcess.destroy();
// Wait for the app exit with some extra time.
// The expectation is that agent doesn't prevent app from exiting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
Expand Down Expand Up @@ -118,6 +119,7 @@ static void setupAll() throws Exception {

@BeforeEach
void setup(TestInfo testInfo) throws Exception {
LOG.info("===== Starting {} ====", testInfo.getDisplayName());
datadogAgentServer = new MockWebServer();
probeMockDispatcher = new MockDispatcher();
probeMockDispatcher.setDispatcher(this::datadogAgentDispatch);
Expand All @@ -132,13 +134,14 @@ void setup(TestInfo testInfo) throws Exception {
}

@AfterEach
void teardown() throws Exception {
void teardown(TestInfo testInfo) throws Exception {
if (targetProcess != null) {
targetProcess.destroyForcibly();
}
datadogAgentServer.shutdown();
statsDServer.close();
ProbeRateLimiter.resetAll();
LOG.info("===== Ending {} ====", testInfo.getDisplayName());
}

protected ProcessBuilder createProcessBuilder(Path logFilePath, String... params) {
Expand Down Expand Up @@ -347,14 +350,15 @@ protected AtomicBoolean registerCheckReceivedInstalledEmitting() {
return result;
}

protected void processRequests(BooleanSupplier conditionOfDone) throws InterruptedException {
protected void processRequests(BooleanSupplier conditionOfDone, Supplier<String> timeoutMessage)
throws InterruptedException {
long start = System.currentTimeMillis();
try {
RecordedRequest request;
do {
request = datadogAgentServer.takeRequest(REQUEST_WAIT_TIMEOUT, TimeUnit.SECONDS);
if (request == null) {
throw new RuntimeException("timeout!");
throw new RuntimeException(timeoutMessage.get());
}
LOG.info("processRequests path={}", request.getPath());
for (RequestType requestType : RequestType.values()) {
Expand All @@ -364,7 +368,7 @@ protected void processRequests(BooleanSupplier conditionOfDone) throws Interrupt
}
}
} while (request != null && (System.currentTimeMillis() - start < 30_000));
throw new RuntimeException("timeout!");
throw new RuntimeException(timeoutMessage.get());
} finally {
probeStatusListeners.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void testCodeOriginTraceAnnotation() throws Exception {
}
}
});
processRequests(codeOrigin::get);
processRequests(
codeOrigin::get, () -> String.format("timeout codeOrigin=%s", codeOrigin.get()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,30 @@
import datadog.trace.bootstrap.debugger.CapturedContext;
import datadog.trace.test.agent.decoder.DecodedSpan;
import datadog.trace.test.agent.decoder.DecodedTrace;
import datadog.trace.test.util.Flaky;
import datadog.trace.test.util.NonRetryable;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;

@Flaky
@NonRetryable
public class ExceptionDebuggerIntegrationTest extends ServerAppDebuggerIntegrationTest {

private List<String> snapshotIdTags = new ArrayList<>();
private boolean traceReceived;
private boolean snapshotReceived;
private Map<String, Snapshot> snapshots = new HashMap<>();
private List<String> additionalJvmArgs = new ArrayList<>();
private Supplier<String> timeoutMessage =
() ->
String.format(
"Timeout! traceReceived=%s snapshotReceived=%s #snapshots=%d",
traceReceived, snapshotReceived, snapshots.size());

@Override
protected ProcessBuilder createProcessBuilder(Path logFilePath, String... params) {
Expand Down Expand Up @@ -74,7 +80,8 @@ void testSimpleSingleFrameException() throws Exception {
return true;
}
return false;
});
},
timeoutMessage);
}

@Test
Expand All @@ -98,7 +105,7 @@ void testNoSubsequentCaptureAfterFirst() throws Exception {
}
}
});
processRequests(() -> traceReceived && !snapshotReceived);
processRequests(() -> traceReceived && !snapshotReceived, timeoutMessage);
}

// DeepOops exception stacktrace:
Expand Down Expand Up @@ -163,7 +170,8 @@ void test3CapturedFrames() throws Exception {
return true;
}
return false;
});
},
timeoutMessage);
}

@Test
Expand Down Expand Up @@ -240,7 +248,8 @@ void test5CapturedFrames() throws Exception {
return true;
}
return false;
});
},
timeoutMessage);
}

@Test
Expand Down Expand Up @@ -276,7 +285,8 @@ void test3CapturedRecursiveFrames() throws Exception {
return true;
}
return false;
});
},
timeoutMessage);
}

private static void assertRecursiveSnapshot(Snapshot snapshot) {
Expand Down Expand Up @@ -321,7 +331,8 @@ void testLambdaHiddenFrames() throws Exception {
return true;
}
return false;
});
},
timeoutMessage);
}

private void resetSnapshotsAndTraces() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ void testInaccessibleObject() throws Exception {
snapshot -> {
snapshotReceived.set(true);
});
processRequests(snapshotReceived::get);
processRequests(
snapshotReceived::get,
() -> String.format("timeout snapshotReceived=%s", snapshotReceived.get()));
assertFalse(logHasErrors(logFilePath, it -> false));
}

Expand Down Expand Up @@ -92,7 +94,12 @@ void testFullMethod() throws Exception {
snapshotReceived.set(true);
});
AtomicBoolean statusResult = registerCheckReceivedInstalledEmitting();
processRequests(() -> snapshotReceived.get() && statusResult.get());
processRequests(
() -> snapshotReceived.get() && statusResult.get(),
() ->
String.format(
"timeout snapshotReceived=%s statusResult=%s",
snapshotReceived.get(), statusResult.get()));
}

@Test
Expand All @@ -119,7 +126,12 @@ void testFullMethodWithCondition() throws Exception {
snapshotReceived.set(true);
});
AtomicBoolean statusResult = registerCheckReceivedInstalledEmitting();
processRequests(() -> snapshotReceived.get() && statusResult.get());
processRequests(
() -> snapshotReceived.get() && statusResult.get(),
() ->
String.format(
"timeout snapshotReceived=%s statusResult=%s",
snapshotReceived.get(), statusResult.get()));
}

@Test
Expand Down Expand Up @@ -148,7 +160,12 @@ void testFullMethodWithConditionAtExit() throws Exception {
snapshotReceived.set(true);
});
AtomicBoolean statusResult = registerCheckReceivedInstalledEmitting();
processRequests(() -> snapshotReceived.get() && statusResult.get());
processRequests(
() -> snapshotReceived.get() && statusResult.get(),
() ->
String.format(
"timeout snapshotReceived=%s statusResult=%s",
snapshotReceived.get(), statusResult.get()));
}

@Test
Expand Down Expand Up @@ -176,7 +193,12 @@ void testFullMethodWithConditionFailed() throws Exception {
snapshotReceived.set(true);
});
AtomicBoolean statusResult = registerCheckReceivedInstalledEmitting();
processRequests(() -> snapshotReceived.get() && statusResult.get());
processRequests(
() -> snapshotReceived.get() && statusResult.get(),
() ->
String.format(
"timeout snapshotReceived=%s statusResult=%s",
snapshotReceived.get(), statusResult.get()));
}

@Test
Expand Down Expand Up @@ -208,7 +230,12 @@ void testFullMethodWithLogTemplate() throws Exception {
snapshotReceived.set(true);
});
AtomicBoolean statusResult = registerCheckReceivedInstalledEmitting();
processRequests(() -> snapshotReceived.get() && correctLogMessage.get() && statusResult.get());
processRequests(
() -> snapshotReceived.get() && correctLogMessage.get() && statusResult.get(),
() ->
String.format(
"timeout snapshotReceived=%s correctLogMessage=%s statusResult=%s",
snapshotReceived.get(), correctLogMessage.get(), statusResult.get()));
}

@Test
Expand Down Expand Up @@ -255,7 +282,12 @@ void testFullMethodWithCaptureExpressions() throws Exception {
snapshotReceived.set(true);
});
AtomicBoolean statusResult = registerCheckReceivedInstalledEmitting();
processRequests(() -> snapshotReceived.get() && statusResult.get());
processRequests(
() -> snapshotReceived.get() && statusResult.get(),
() ->
String.format(
"timeout snapshotReceived=%s statusResult=%s",
snapshotReceived.get(), statusResult.get()));
}

@Test
Expand Down Expand Up @@ -296,7 +328,12 @@ void testMultiProbes() throws Exception {
&& statuses.values().stream()
.allMatch(status -> status == ProbeStatus.Status.EMITTING));
});
processRequests(() -> allSnapshotReceived.get() && allStatusEmitting.get());
processRequests(
() -> allSnapshotReceived.get() && allStatusEmitting.get(),
() ->
String.format(
"timeout allSnapshotReceived=%s allStatusEmitting=%s",
allSnapshotReceived.get(), allStatusEmitting.get()));
assertEquals(NB_PROBES, probeIds.size());
for (int i = 0; i < NB_PROBES; i++) {
assertTrue(probeIds.contains(String.valueOf(i)));
Expand Down Expand Up @@ -328,7 +365,12 @@ void testLineProbe() throws Exception {
snapshotReceived.set(true);
});
AtomicBoolean statusResult = registerCheckReceivedInstalledEmitting();
processRequests(() -> snapshotReceived.get() && statusResult.get());
processRequests(
() -> snapshotReceived.get() && statusResult.get(),
() ->
String.format(
"timeout snapshotReceived=%s statusResult=%s",
snapshotReceived.get(), statusResult.get()));
}

@Test
Expand Down Expand Up @@ -386,7 +428,8 @@ private void doSamplingSnapshot(ProbeCondition probeCondition, MethodLocation ev
() -> {
LOG.info("snapshots={}", snapshotCount.get());
return snapshotCount.get() >= 2 && snapshotCount.get() <= 20;
});
},
() -> String.format("timeout snapshotCount=%d", snapshotCount.get()));
}

@Test
Expand Down Expand Up @@ -420,7 +463,8 @@ void testSamplingLogDefault() throws Exception {
() -> {
LOG.info("snapshots={}", snapshotCount.get());
return snapshotCount.get() >= 850 && snapshotCount.get() <= 1000;
});
},
() -> String.format("timeout snapshotCount=%d", snapshotCount.get()));
}

@Test
Expand Down Expand Up @@ -454,7 +498,8 @@ void testSamplingLogCustom() throws Exception {
() -> {
LOG.info("snapshots={}", snapshotCount.get());
return snapshotCount.get() > 0 && snapshotCount.get() < 200;
});
},
() -> String.format("timeout snapshotCount=%d", snapshotCount.get()));
}

@Test
Expand Down Expand Up @@ -485,7 +530,9 @@ void testUncaughtException() throws Exception {
throwable.getStacktrace().get(0).getFunction());
snapshotReceived.set(true);
});
processRequests(snapshotReceived::get);
processRequests(
snapshotReceived::get,
() -> String.format("timeout snapshotReceived=%s", snapshotReceived.get()));
}

@Test
Expand Down Expand Up @@ -516,7 +563,9 @@ void testCaughtException() throws Exception {
throwable.getStacktrace().get(0).getFunction());
snapshotReceived.set(true);
});
processRequests(snapshotReceived::get);
processRequests(
snapshotReceived::get,
() -> String.format("timeout snapshotReceived=%s", snapshotReceived.get()));
}

private ProbeId getProbeId(int i) {
Expand Down
Loading