Skip to content

Commit 2ec3a87

Browse files
Workaround for latest maven-failsafe-plugin test (#10659)
fix: maven-failsafe-plugin 3.5.5 workaround Merge branch 'master' into daniel.mohedano/maven-integration-test-workaround chore: revert skips Co-authored-by: daniel.mohedano <daniel.mohedano@datadoghq.com>
1 parent a82be15 commit 2ec3a87

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

dd-java-agent/instrumentation/maven/maven-3.2.1/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ muzzle {
1111

1212
addTestSuiteForDir('latestDepTest', 'test')
1313

14-
tasks.named("latestDepTest", Test) {
15-
systemProperty 'test.isLatestDepTest', 'true'
16-
}
17-
1814
dependencies {
1915
compileOnly 'org.apache.maven:maven-embedder:3.2.1'
2016

dd-java-agent/instrumentation/maven/maven-3.2.1/src/test/groovy/MavenInstrumentationTest.groovy

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import datadog.trace.api.config.CiVisibilityConfig
22
import datadog.trace.civisibility.CiVisibilityInstrumentationTest
33
import org.apache.maven.cli.MavenCli
44
import org.codehaus.plexus.util.FileUtils
5+
import org.slf4j.MDC
56
import spock.lang.TempDir
67

78
import java.nio.file.Path
89
import java.nio.file.Paths
910

1011
import static org.junit.jupiter.api.Assertions.assertEquals
11-
import static org.junit.jupiter.api.Assumptions.abort
1212

1313
class 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

Comments
 (0)