Skip to content

Commit 84e02dc

Browse files
Handle Failsafe skipITs in CI Visibility module status
1 parent fb79f32 commit 84e02dc

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎dd-java-agent/instrumentation/maven/maven-3.2.1/src/main/java/datadog/trace/instrumentation/maven3/MavenExecutionListener.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ public void mojoSucceeded(ExecutionEvent event) {
150150
// configuration, since a POM can override the command-line skip properties.
151151
if (Boolean.parseBoolean(
152152
MavenUtils.getConfigurationValue(session, mojoExecution, "skipTests"))
153-
|| Boolean.parseBoolean(
154-
MavenUtils.getConfigurationValue(session, mojoExecution, "skip"))) {
153+
|| Boolean.parseBoolean(MavenUtils.getConfigurationValue(session, mojoExecution, "skip"))
154+
|| ("maven-failsafe-plugin".equals(mojoExecution.getArtifactId())
155+
&& Boolean.parseBoolean(
156+
MavenUtils.getConfigurationValue(session, mojoExecution, "skipITs")))) {
155157
buildEventsHandler.onTestModuleSkip(
156158
request, moduleName, "Tests were skipped by Maven configuration");
157159
}

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,47 @@ class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
9191
"test_maven_build_with_tests_generates_spans" | "-DskipTests=false" | "true" | "skip"
9292
}
9393

94+
def "Failsafe status follows skipITs: CLI=#cliSkipITs, POM=#pomSkipITs, unit tests skipped=#skipUnitTests"() {
95+
given:
96+
def pom = projectFolder.resolve("pom.xml").toFile()
97+
// An unrelated skipITs element must not mark Surefire tests as skipped.
98+
pom.text = pom.text.replace("<artifactId>maven-surefire-plugin</artifactId>",
99+
"<artifactId>maven-surefire-plugin</artifactId><configuration><skipTests>${skipUnitTests}</skipTests><skipITs>true</skipITs></configuration>")
100+
if (pomSkipITs != null) {
101+
pom.text = pom.text.replace("<artifactId>maven-failsafe-plugin</artifactId>",
102+
"<artifactId>maven-failsafe-plugin</artifactId><configuration><skipITs>${pomSkipITs}</skipITs></configuration>")
103+
}
104+
105+
when:
106+
def exitCode = executeMaven(["-B", "clean", "verify", "-DskipITs=${cliSkipITs}".toString()])
107+
108+
then:
109+
exitCode == 0
110+
spanFilter.waitForSpan({ span -> span.spanType == "test_session_end" }, TimeUnit.SECONDS.toMillis(20))
111+
def spans = TEST_WRITER.toList().flatten()
112+
def modules = spans.findAll { it.spanType == "test_module_end" }
113+
def sessions = spans.findAll { it.spanType == "test_session_end" }
114+
modules.size() == 2
115+
sessions.size() == 1
116+
def unitModule = modules.find { it.getTag("test.execution").toString().startsWith("maven-surefire-plugin:") }
117+
def integrationModule = modules.find { it.getTag("test.execution").toString().startsWith("maven-failsafe-plugin:") }
118+
unitModule.getTag("test.status").toString() == (skipUnitTests ? "skip" : "pass")
119+
integrationModule.getTag("test.status").toString() == expectedIntegrationStatus
120+
expectedIntegrationStatus != "skip" || integrationModule.getTag("test.skip_reason") == "Tests were skipped by Maven configuration"
121+
sessions[0].getTag("test.status").toString() == (skipUnitTests && expectedIntegrationStatus == "skip" ? "skip" : "pass")
122+
projectFolder.resolve("target/surefire-reports/TEST-org.example.TestSucceed.xml").toFile().exists() == !skipUnitTests
123+
projectFolder.resolve("target/failsafe-reports/TEST-org.example.ITSucceed.xml").toFile().exists() == (expectedIntegrationStatus == "pass")
124+
125+
where:
126+
cliSkipITs | pomSkipITs | skipUnitTests | expectedIntegrationStatus
127+
true | null | false | "skip"
128+
true | null | true | "skip"
129+
false | null | false | "pass"
130+
true | "false" | false | "pass"
131+
false | "true" | false | "skip"
132+
testcaseName = "test_maven_build_with_unit_and_integration_tests_generates_spans"
133+
}
134+
94135
private void givenMavenProjectFiles(String projectFilesSources) {
95136
def projectResourcesUri = this.getClass().getClassLoader().getResource(projectFilesSources).toURI()
96137
def projectResourcesPath = Paths.get(projectResourcesUri)

0 commit comments

Comments
 (0)