@@ -2,13 +2,13 @@ import datadog.trace.api.config.CiVisibilityConfig
22import datadog.trace.civisibility.CiVisibilityInstrumentationTest
33import org.apache.maven.cli.MavenCli
44import org.codehaus.plexus.util.FileUtils
5+ import org.slf4j.MDC
56import spock.lang.TempDir
67
78import java.nio.file.Path
89import java.nio.file.Paths
910
1011import static org.junit.jupiter.api.Assertions.assertEquals
11- import static org.junit.jupiter.api.Assumptions.abort
1212
1313class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
1414
@@ -19,6 +19,14 @@ class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
1919
2020 @Override
2121 def setup () {
22+ // Workaround for maven-surefire 3.5.5 bug (https://github.com/apache/maven-surefire/pull/3241):
23+ // ThreadedStreamConsumer$Pumper.run() calls MDC.setContextMap(MDC.getCopyOfContextMap()),
24+ // but LogbackMDCAdapter.getCopyOfContextMap() returns null when MDC is uninitialized,
25+ // and LogbackMDCAdapter.setContextMap(null) throws NPE via HashMap.putAll(null).
26+ // Pre-initializing MDC ensures getCopyOfContextMap() returns an empty map instead of null.
27+ MDC . put(" _init" , " true" )
28+ MDC . remove(" _init" )
29+
2230 System . setProperty(" maven.multiModuleProjectDirectory" , projectFolder. toAbsolutePath(). toString())
2331 givenMavenProjectFiles((String ) specificationContext. currentIteration. dataVariables. testcaseName)
2432 givenMavenDependenciesAreLoaded()
@@ -32,10 +40,6 @@ class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
3240 }
3341
3442 def " test #testcaseName" () {
35- if (skipLatest && Boolean . getBoolean(" test.isLatestDepTest" )) {
36- abort(" Skipping latest dep test" )
37- }
38-
3943 String workingDirectory = projectFolder. toString()
4044
4145 def exitCode = new MavenCli (). doMain(args. toArray(new String [0 ]), workingDirectory, null , null )
@@ -44,15 +48,15 @@ class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
4448 assertSpansData(testcaseName)
4549
4650 where :
47- testcaseName | args | expectedExitCode | skipLatest
48- " test_maven_build_with_no_tests_generates_spans" | [" -B" , " verify" ] | 0 | false
49- " test_maven_build_with_incorrect_command_generates_spans" | [" -B" , " unknownPhase" ] | 1 | false
50- " test_maven_build_with_tests_generates_spans" | [" -B" , " clean" , " test" ] | 0 | false
51- " test_maven_build_with_failed_tests_generates_spans" | [" -B" , " clean" , " test" ] | 1 | false
52- " test_maven_build_with_tests_in_multiple_modules_generates_spans" | [" -B" , " clean" , " test" ] | 1 | false
53- " test_maven_build_with_tests_in_multiple_modules_run_in_parallel_generates_spans" | [" -B" , " -T4" , " clean" , " test" ] | 0 | false
54- " test_maven_build_with_unit_and_integration_tests_generates_spans" | [" -B" , " verify" ] | 0 | true // temporary workaround to avoid failures with maven-failsafe-plugin 3.5.5
55- " test_maven_build_with_no_fork_generates_spans" | [" -B" , " clean" , " test" ] | 0 | false
51+ testcaseName | args | expectedExitCode
52+ " test_maven_build_with_no_tests_generates_spans" | [" -B" , " verify" ] | 0
53+ " test_maven_build_with_incorrect_command_generates_spans" | [" -B" , " unknownPhase" ] | 1
54+ " test_maven_build_with_tests_generates_spans" | [" -B" , " clean" , " test" ] | 0
55+ " test_maven_build_with_failed_tests_generates_spans" | [" -B" , " clean" , " test" ] | 1
56+ " test_maven_build_with_tests_in_multiple_modules_generates_spans" | [" -B" , " clean" , " test" ] | 1
57+ " test_maven_build_with_tests_in_multiple_modules_run_in_parallel_generates_spans" | [" -B" , " -T4" , " clean" , " test" ] | 0
58+ " test_maven_build_with_unit_and_integration_tests_generates_spans" | [" -B" , " verify" ] | 0
59+ " test_maven_build_with_no_fork_generates_spans" | [" -B" , " clean" , " test" ] | 0
5660 }
5761
5862 private void givenMavenProjectFiles (String projectFilesSources ) {
0 commit comments