Skip to content

Commit 0132a90

Browse files
committed
Adding hamcrest matchers to the crash tracking smoke test
I spent a day or so digging and understanding why crash tracking smoke test wasn't working locally for me. Eventually, I tracked it down to the ancient version of bash being used on OS X. That version of bash doesn't support all the necessary elements used by the bash scripts. To debug the issue, I switched to using hamcrest matchers, so I could more easily see what was happening underneath. I've also added comments to the test class, so hopefully, others don't lose time on this again in the future.
1 parent 768ce77 commit 0132a90

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

dd-smoke-tests/crashtracking/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ jar {
1919
dependencies {
2020
testImplementation project(':dd-smoke-tests')
2121
testImplementation project(':dd-java-agent:agent-profiling:profiling-testing')
22+
2223
testImplementation libs.bundles.junit5
24+
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
2325
testImplementation libs.bundles.mockito
2426
}
2527

dd-smoke-tests/crashtracking/src/test/java/datadog/smoketest/CrashtrackingSmokeTest.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package datadog.smoketest;
22

3+
import static org.hamcrest.CoreMatchers.containsString;
4+
import static org.hamcrest.MatcherAssert.assertThat;
35
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4-
import static org.junit.jupiter.api.Assertions.assertTrue;
56
import static org.junit.jupiter.api.Assumptions.assumeFalse;
67

78
import datadog.trace.api.Platform;
@@ -23,6 +24,10 @@
2324
import org.junit.jupiter.api.BeforeEach;
2425
import org.junit.jupiter.api.Test;
2526

27+
/*
28+
* NOTE: The current implementation of crash tracking doesn't work with ancient version of bash
29+
* that ships with OS X by default.
30+
*/
2631
public class CrashtrackingSmokeTest {
2732
private MockWebServer tracingServer;
2833

@@ -76,6 +81,10 @@ private static String getExtension() {
7681
return Platform.isWindows() ? "bat" : "sh";
7782
}
7883

84+
/*
85+
* NOTE: The current implementation of crash tracking doesn't work with ancient version of bash
86+
* that ships with OS X by default.
87+
*/
7988
@Test
8089
void testCrashTracking() throws Exception {
8190
Path script = tempDir.resolve("dd_crash_uploader." + getExtension());
@@ -140,14 +149,17 @@ void testCrashTracking() throws Exception {
140149

141150
assertNotEquals(0, p.waitFor(), "Application should have crashed");
142151

143-
assertTrue(stdoutStr.toString().contains(" was uploaded successfully"));
144-
assertTrue(
145-
stderrStr
146-
.toString()
147-
.contains(
148-
"com.datadog.crashtracking.CrashUploader - Successfully uploaded the crash files"));
152+
assertThat(stdoutStr.toString(), containsString(" was uploaded successfully"));
153+
assertThat(
154+
stderrStr.toString(),
155+
containsString(
156+
"com.datadog.crashtracking.CrashUploader - Successfully uploaded the crash files"));
149157
}
150158

159+
/*
160+
* NOTE: The current implementation of crash tracking doesn't work with ancient version of bash
161+
* that ships with OS X by default.
162+
*/
151163
@Test
152164
void testCrashTrackingLegacy() throws Exception {
153165
Path script = tempDir.resolve("dd_crash_uploader." + getExtension());
@@ -212,14 +224,17 @@ void testCrashTrackingLegacy() throws Exception {
212224

213225
assertNotEquals(0, p.waitFor(), "Application should have crashed");
214226

215-
assertTrue(stdoutStr.toString().contains(" was uploaded successfully"));
216-
assertTrue(
217-
stderrStr
218-
.toString()
219-
.contains(
220-
"com.datadog.crashtracking.CrashUploader - Successfully uploaded the crash files"));
227+
assertThat(stdoutStr.toString(), containsString(" was uploaded successfully"));
228+
assertThat(
229+
stderrStr.toString(),
230+
containsString(
231+
"com.datadog.crashtracking.CrashUploader - Successfully uploaded the crash files"));
221232
}
222233

234+
/*
235+
* NOTE: The current implementation of crash tracking doesn't work with ancient version of bash
236+
* that ships with OS X by default.
237+
*/
223238
@Test
224239
void testOomeTracking() throws Exception {
225240
Path script = tempDir.resolve("dd_oome_notifier." + getExtension());
@@ -281,9 +296,10 @@ void testOomeTracking() throws Exception {
281296

282297
assertNotEquals(0, p.waitFor(), "Application should have crashed");
283298

284-
assertTrue(
285-
stderrStr.toString().contains("com.datadog.crashtracking.OOMENotifier - OOME event sent"));
286-
assertTrue(stdoutStr.toString().contains("OOME Event generated successfully"));
299+
assertThat(
300+
stderrStr.toString(),
301+
containsString("com.datadog.crashtracking.OOMENotifier - OOME event sent"));
302+
assertThat(stdoutStr.toString(), containsString("OOME Event generated successfully"));
287303
}
288304

289305
@Test
@@ -352,16 +368,16 @@ void testCombineTracking() throws Exception {
352368
assertNotEquals(0, p.waitFor(), "Application should have crashed");
353369

354370
// Crash uploader did get triggered
355-
assertTrue(stdoutStr.toString().contains(" was uploaded successfully"));
356-
assertTrue(
357-
stderrStr
358-
.toString()
359-
.contains(
360-
"com.datadog.crashtracking.CrashUploader - Successfully uploaded the crash files"));
371+
assertThat(stdoutStr.toString(), containsString(" was uploaded successfully"));
372+
assertThat(
373+
stderrStr.toString(),
374+
containsString(
375+
"com.datadog.crashtracking.CrashUploader - Successfully uploaded the crash files"));
361376

362377
// OOME notifier did get triggered
363-
assertTrue(
364-
stderrStr.toString().contains("com.datadog.crashtracking.OOMENotifier - OOME event sent"));
365-
assertTrue(stdoutStr.toString().contains("OOME Event generated successfully"));
378+
assertThat(
379+
stderrStr.toString(),
380+
containsString("com.datadog.crashtracking.OOMENotifier - OOME event sent"));
381+
assertThat(stdoutStr.toString(), containsString("OOME Event generated successfully"));
366382
}
367383
}

0 commit comments

Comments
 (0)