Skip to content

Commit 233b720

Browse files
Fix tracing JUnit5 tests in Maven projects with multiple forks (#8087)
1 parent baedf8d commit 233b720

File tree

9 files changed

+659
-1
lines changed

9 files changed

+659
-1
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import datadog.trace.civisibility.domain.headless.HeadlessTestSession;
2929
import datadog.trace.civisibility.domain.manualapi.ManualApiTestSession;
3030
import datadog.trace.civisibility.events.BuildEventsHandlerImpl;
31+
import datadog.trace.civisibility.events.NoOpTestEventsHandler;
3132
import datadog.trace.civisibility.events.TestEventsHandlerImpl;
3233
import datadog.trace.civisibility.ipc.SignalServer;
3334
import datadog.trace.civisibility.source.index.RepoIndex;
@@ -102,6 +103,8 @@ public static void start(Instrumentation inst, SharedCommunicationObjects sco) {
102103
new TestEventsHandlerFactory(
103104
services, repoServices, coverageServices, executionSettings));
104105
CoveragePerTestBridge.registerCoverageStoreRegistry(coverageServices.coverageStoreFactory);
106+
} else {
107+
InstrumentationBridge.registerTestEventsHandlerFactory(new NoOpTestEventsHandler.Factory());
105108
}
106109
}
107110

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ProcessHierarchy.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,18 @@ private boolean isParent() {
6262
* process that is not a build system, and not a JVM that runs tests.
6363
*/
6464
private boolean isWrapper() {
65+
// Maven Wrapper runs in the same JVM as Maven itself,
66+
// so it is not included here
6567
return isGradleLauncher();
6668
}
6769

6870
private boolean isMavenParent() {
6971
return System.getProperty("maven.home") != null
70-
&& System.getProperty("classworlds.conf") != null;
72+
&& System.getProperty("classworlds.conf") != null
73+
// when using Maven Wrapper
74+
|| ClassLoader.getSystemClassLoader()
75+
.getResource("org/apache/maven/wrapper/WrapperExecutor.class")
76+
!= null;
7177
}
7278

7379
private boolean isGradleDaemon() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package datadog.trace.civisibility.events;
2+
3+
import datadog.trace.api.civisibility.DDTest;
4+
import datadog.trace.api.civisibility.DDTestSuite;
5+
import datadog.trace.api.civisibility.config.TestIdentifier;
6+
import datadog.trace.api.civisibility.events.TestEventsHandler;
7+
import datadog.trace.api.civisibility.retry.TestRetryPolicy;
8+
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
9+
import datadog.trace.bootstrap.ContextStore;
10+
import datadog.trace.civisibility.retry.NeverRetry;
11+
import java.lang.reflect.Method;
12+
import java.util.Collection;
13+
import org.jetbrains.annotations.NotNull;
14+
import org.jetbrains.annotations.Nullable;
15+
16+
public class NoOpTestEventsHandler<SuiteKey, TestKey>
17+
implements TestEventsHandler<SuiteKey, TestKey> {
18+
19+
@Override
20+
public void onTestSuiteStart(
21+
SuiteKey descriptor,
22+
String testSuiteName,
23+
@Nullable String testFramework,
24+
@Nullable String testFrameworkVersion,
25+
@Nullable Class<?> testClass,
26+
@Nullable Collection<String> categories,
27+
boolean parallelized,
28+
TestFrameworkInstrumentation instrumentation) {
29+
// do nothing
30+
}
31+
32+
@Override
33+
public void onTestSuiteSkip(SuiteKey descriptor, @Nullable String reason) {
34+
// do nothing
35+
}
36+
37+
@Override
38+
public void onTestSuiteFailure(SuiteKey descriptor, @Nullable Throwable throwable) {
39+
// do nothing
40+
}
41+
42+
@Override
43+
public void onTestSuiteFinish(SuiteKey descriptor) {
44+
// do nothing
45+
}
46+
47+
@Override
48+
public void onTestStart(
49+
SuiteKey suiteDescriptor,
50+
TestKey descriptor,
51+
String testSuiteName,
52+
String testName,
53+
@Nullable String testFramework,
54+
@Nullable String testFrameworkVersion,
55+
@Nullable String testParameters,
56+
@Nullable Collection<String> categories,
57+
@Nullable Class<?> testClass,
58+
@Nullable String testMethodName,
59+
@Nullable Method testMethod,
60+
boolean isRetry) {
61+
// do nothing
62+
}
63+
64+
@Override
65+
public void onTestSkip(TestKey descriptor, @Nullable String reason) {
66+
// do nothing
67+
}
68+
69+
@Override
70+
public void onTestFailure(TestKey descriptor, @Nullable Throwable throwable) {
71+
// do nothing
72+
}
73+
74+
@Override
75+
public void onTestFinish(TestKey descriptor) {
76+
// do nothing
77+
}
78+
79+
@Override
80+
public void onTestIgnore(
81+
SuiteKey suiteDescriptor,
82+
TestKey testDescriptor,
83+
String testSuiteName,
84+
String testName,
85+
@Nullable String testFramework,
86+
@Nullable String testFrameworkVersion,
87+
@Nullable String testParameters,
88+
@Nullable Collection<String> categories,
89+
@Nullable Class<?> testClass,
90+
@Nullable String testMethodName,
91+
@Nullable Method testMethod,
92+
@Nullable String reason) {
93+
// do nothing
94+
}
95+
96+
@Override
97+
public boolean skip(TestIdentifier test) {
98+
return false;
99+
}
100+
101+
@Override
102+
public boolean shouldBeSkipped(TestIdentifier test) {
103+
return false;
104+
}
105+
106+
@NotNull
107+
@Override
108+
public TestRetryPolicy retryPolicy(TestIdentifier test) {
109+
return NeverRetry.INSTANCE;
110+
}
111+
112+
@Override
113+
public boolean isNew(TestIdentifier test) {
114+
return false;
115+
}
116+
117+
@Override
118+
public boolean isFlaky(TestIdentifier test) {
119+
return false;
120+
}
121+
122+
@Override
123+
public void close() {
124+
// do nothing
125+
}
126+
127+
public static final class Factory implements TestEventsHandler.Factory {
128+
@Override
129+
public <SuiteKey, TestKey> TestEventsHandler<SuiteKey, TestKey> create(
130+
String component,
131+
@Nullable ContextStore<SuiteKey, DDTestSuite> suiteStore,
132+
@Nullable ContextStore<TestKey, DDTest> testStore) {
133+
return new NoOpTestEventsHandler<>();
134+
}
135+
}
136+
}

dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
9999
"test_failed_maven_run_flaky_retries" | "3.9.9" | 8 | 5 | false | false | true | true | [] | 8
100100
"test_successful_maven_run_junit_platform_runner" | "3.9.9" | 4 | 0 | true | false | false | false | [] | 8
101101
"test_successful_maven_run_with_arg_line_property" | "3.9.9" | 4 | 0 | true | false | false | false | ["-DargLine='-Dmy-custom-property=provided-via-command-line'"] | 8
102+
"test_successful_maven_run_multiple_forks" | "3.9.9" | 5 | 1 | true | true | false | true | [] | 8
103+
"test_successful_maven_run_multiple_forks" | LATEST_MAVEN_VERSION | 5 | 1 | true | true | false | true | [] | 17
102104
}
103105

104106
private void givenWrapperPropertiesFile(String mavenVersion) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[ {
2+
"test_session_id" : ${content_test_session_id},
3+
"test_suite_id" : ${content_test_suite_id},
4+
"span_id" : ${content_span_id_6},
5+
"files" : [ {
6+
"filename" : "src/test/java/datadog/smoke/TestSucceed.java",
7+
"bitmap" : "ABg="
8+
}, {
9+
"filename" : "src/main/java/datadog/smoke/Calculator.java",
10+
"bitmap" : "IA=="
11+
} ]
12+
} ]

0 commit comments

Comments
 (0)