Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🍒 8086] Fix tracing JUnit5 tests in Maven projects with multiple forks #8089

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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import datadog.trace.civisibility.domain.headless.HeadlessTestSession;
import datadog.trace.civisibility.domain.manualapi.ManualApiTestSession;
import datadog.trace.civisibility.events.BuildEventsHandlerImpl;
import datadog.trace.civisibility.events.NoOpTestEventsHandler;
import datadog.trace.civisibility.events.TestEventsHandlerImpl;
import datadog.trace.civisibility.ipc.SignalServer;
import datadog.trace.civisibility.source.index.RepoIndex;
Expand Down Expand Up @@ -102,6 +103,8 @@ public static void start(Instrumentation inst, SharedCommunicationObjects sco) {
new TestEventsHandlerFactory(
services, repoServices, coverageServices, executionSettings));
CoveragePerTestBridge.registerCoverageStoreRegistry(coverageServices.coverageStoreFactory);
} else {
InstrumentationBridge.registerTestEventsHandlerFactory(new NoOpTestEventsHandler.Factory());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ private boolean isParent() {
* process that is not a build system, and not a JVM that runs tests.
*/
private boolean isWrapper() {
// Maven Wrapper runs in the same JVM as Maven itself,
// so it is not included here
return isGradleLauncher();
}

private boolean isMavenParent() {
return System.getProperty("maven.home") != null
&& System.getProperty("classworlds.conf") != null;
&& System.getProperty("classworlds.conf") != null
// when using Maven Wrapper
|| ClassLoader.getSystemClassLoader()
.getResource("org/apache/maven/wrapper/WrapperExecutor.class")
!= null;
}

private boolean isGradleDaemon() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package datadog.trace.civisibility.events;

import datadog.trace.api.civisibility.DDTest;
import datadog.trace.api.civisibility.DDTestSuite;
import datadog.trace.api.civisibility.config.TestIdentifier;
import datadog.trace.api.civisibility.events.TestEventsHandler;
import datadog.trace.api.civisibility.retry.TestRetryPolicy;
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.civisibility.retry.NeverRetry;
import java.lang.reflect.Method;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class NoOpTestEventsHandler<SuiteKey, TestKey>
implements TestEventsHandler<SuiteKey, TestKey> {

@Override
public void onTestSuiteStart(
SuiteKey descriptor,
String testSuiteName,
@Nullable String testFramework,
@Nullable String testFrameworkVersion,
@Nullable Class<?> testClass,
@Nullable Collection<String> categories,
boolean parallelized,
TestFrameworkInstrumentation instrumentation) {
// do nothing
}

@Override
public void onTestSuiteSkip(SuiteKey descriptor, @Nullable String reason) {
// do nothing
}

@Override
public void onTestSuiteFailure(SuiteKey descriptor, @Nullable Throwable throwable) {
// do nothing
}

@Override
public void onTestSuiteFinish(SuiteKey descriptor) {
// do nothing
}

@Override
public void onTestStart(
SuiteKey suiteDescriptor,
TestKey descriptor,
String testSuiteName,
String testName,
@Nullable String testFramework,
@Nullable String testFrameworkVersion,
@Nullable String testParameters,
@Nullable Collection<String> categories,
@Nullable Class<?> testClass,
@Nullable String testMethodName,
@Nullable Method testMethod,
boolean isRetry) {
// do nothing
}

@Override
public void onTestSkip(TestKey descriptor, @Nullable String reason) {
// do nothing
}

@Override
public void onTestFailure(TestKey descriptor, @Nullable Throwable throwable) {
// do nothing
}

@Override
public void onTestFinish(TestKey descriptor) {
// do nothing
}

@Override
public void onTestIgnore(
SuiteKey suiteDescriptor,
TestKey testDescriptor,
String testSuiteName,
String testName,
@Nullable String testFramework,
@Nullable String testFrameworkVersion,
@Nullable String testParameters,
@Nullable Collection<String> categories,
@Nullable Class<?> testClass,
@Nullable String testMethodName,
@Nullable Method testMethod,
@Nullable String reason) {
// do nothing
}

@Override
public boolean skip(TestIdentifier test) {
return false;
}

@Override
public boolean shouldBeSkipped(TestIdentifier test) {
return false;
}

@NotNull
@Override
public TestRetryPolicy retryPolicy(TestIdentifier test) {
return NeverRetry.INSTANCE;
}

@Override
public boolean isNew(TestIdentifier test) {
return false;
}

@Override
public boolean isFlaky(TestIdentifier test) {
return false;
}

@Override
public void close() {
// do nothing
}

public static final class Factory implements TestEventsHandler.Factory {
@Override
public <SuiteKey, TestKey> TestEventsHandler<SuiteKey, TestKey> create(
String component,
@Nullable ContextStore<SuiteKey, DDTestSuite> suiteStore,
@Nullable ContextStore<TestKey, DDTest> testStore) {
return new NoOpTestEventsHandler<>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
"test_failed_maven_run_flaky_retries" | "3.9.9" | 8 | 5 | false | false | true | true | [] | 8
"test_successful_maven_run_junit_platform_runner" | "3.9.9" | 4 | 0 | true | false | false | false | [] | 8
"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
"test_successful_maven_run_multiple_forks" | "3.9.9" | 5 | 1 | true | true | false | true | [] | 8
"test_successful_maven_run_multiple_forks" | LATEST_MAVEN_VERSION | 5 | 1 | true | true | false | true | [] | 17
}

private void givenWrapperPropertiesFile(String mavenVersion) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[ {
"test_session_id" : ${content_test_session_id},
"test_suite_id" : ${content_test_suite_id},
"span_id" : ${content_span_id_6},
"files" : [ {
"filename" : "src/test/java/datadog/smoke/TestSucceed.java",
"bitmap" : "ABg="
}, {
"filename" : "src/main/java/datadog/smoke/Calculator.java",
"bitmap" : "IA=="
} ]
} ]
Loading
Loading