Skip to content

Commit ca9e4d2

Browse files
committed
Adopt Gradle test suites for smoke tests
Replace manual source set and configuration setup with native Gradle JvmTestSuite. This aligns with upstream OpenTelemetry Java instrumentation patterns (adopted in v1.24.0) and provides better IDE integration. Changes: - Remove manual sourceSets.create("smokeTest") configuration - Remove manual configuration extensions (smokeTestImplementation, etc.) - Add testing.suites block with JvmTestSuite registration - Move dependencies into test suite DSL - Preserve all existing behavior (environment matrix, system properties, test logging, nested test classes with @Environment annotations) Test suite automatically creates smokeTestImplementation and other configurations, simplifying the build logic while maintaining full backward compatibility.
1 parent cbafd8d commit ca9e4d2

File tree

3 files changed

+73
-76
lines changed

3 files changed

+73
-76
lines changed

buildSrc/src/main/kotlin/ai.smoke-test.gradle.kts

Lines changed: 73 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,6 @@ plugins {
88

99
val aiSmokeTest = extensions.create<AiSmokeTestExtension>("aiSmokeTest")
1010

11-
sourceSets {
12-
create("smokeTest") {
13-
compileClasspath += sourceSets.main.get().output
14-
runtimeClasspath += sourceSets.main.get().output
15-
}
16-
}
17-
18-
val smokeTestImplementation by configurations.getting {
19-
extendsFrom(configurations.implementation.get())
20-
}
21-
22-
configurations["smokeTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())
23-
2411
// FIXME (trask) copy-pasted from ai.java-conventions.gradle
2512
java {
2613
toolchain {
@@ -66,20 +53,84 @@ dependencies {
6653
// FIXME (trask) copy-pasted from ai.java-conventions.gradle
6754
dependencyManagement(platform(project(":dependencyManagement")))
6855

69-
smokeTestImplementation(project(":smoke-tests:framework"))
70-
71-
smokeTestImplementation("org.junit.jupiter:junit-jupiter-api")
72-
smokeTestImplementation("org.junit.jupiter:junit-jupiter-params")
73-
smokeTestImplementation("org.junit.jupiter:junit-jupiter-engine")
74-
smokeTestImplementation("org.junit.platform:junit-platform-launcher")
75-
76-
smokeTestImplementation("org.assertj:assertj-core")
77-
7856
agent(project(":agent:agent", configuration = "shadow"))
7957

8058
old3xAgent("com.microsoft.azure:applicationinsights-agent:3.2.11")
8159
}
8260

61+
// Configure test suites
62+
testing {
63+
suites {
64+
val test by getting(JvmTestSuite::class)
65+
66+
register<JvmTestSuite>("smokeTest") {
67+
dependencies {
68+
implementation(project(":smoke-tests:framework"))
69+
70+
implementation("org.junit.jupiter:junit-jupiter-api")
71+
implementation("org.junit.jupiter:junit-jupiter-params")
72+
runtimeOnly("org.junit.jupiter:junit-jupiter-engine")
73+
runtimeOnly("org.junit.platform:junit-platform-launcher")
74+
75+
implementation("org.assertj:assertj-core")
76+
}
77+
78+
targets {
79+
all {
80+
testTask.configure {
81+
useJUnitPlatform()
82+
83+
// this is just to force building the agent first
84+
dependsOn(":agent:agent:shadowJar")
85+
86+
// ensure test app is built before running smoke tests
87+
dependsOn(tasks.named("assemble"))
88+
89+
shouldRunAfter(test)
90+
91+
// TODO (trask) experiment with parallelization
92+
// maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
93+
94+
doFirst {
95+
val appFile = aiSmokeTest.testAppArtifactDir.file(aiSmokeTest.testAppArtifactFilename.get()).get()
96+
val javaagentFile = agent.singleFile
97+
val old3xJavaagentFile = old3xAgent.singleFile
98+
99+
// need to delay for project to configure the extension
100+
systemProperty("ai.smoke-test.test-app-file", appFile)
101+
systemProperty("ai.smoke-test.javaagent-file", javaagentFile)
102+
systemProperty("ai.smoke-test.old-3x-javaagent-file", old3xJavaagentFile)
103+
104+
val smokeTestMatrix = findProperty("smokeTestMatrix") ?: System.getenv("CI") != null
105+
systemProperty("ai.smoke-test.matrix", smokeTestMatrix)
106+
107+
findProperty("smokeTestRemoteDebug")?.let { systemProperty("ai.smoke-test.remote-debug", it) }
108+
109+
systemProperty("io.opentelemetry.context.enableStrictContext", true)
110+
systemProperty("io.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext", true)
111+
}
112+
113+
testLogging {
114+
showStandardStreams = true
115+
exceptionFormat = TestExceptionFormat.FULL
116+
}
117+
118+
// TODO (trask) this is still a problem
119+
// e.g. changes in agent-tooling do not cause smoke tests to re-run
120+
outputs.upToDateWhen { false }
121+
}
122+
}
123+
}
124+
}
125+
}
126+
}
127+
128+
// Make smokeTest configuration extend from main implementation configuration
129+
// so that project dependencies (e.g., log4j in ClassicSdkLog4j1Interop2x) are available
130+
configurations.named("smokeTestImplementation") {
131+
extendsFrom(configurations.implementation.get())
132+
}
133+
83134
configurations.all {
84135
// spring boot 2.x requires slf4j 1.x
85136
val slf4jVersion = "1.7.36"
@@ -105,48 +156,4 @@ tasks {
105156
addStringOption("Xwerror", "-quiet")
106157
}
107158
}
108-
109-
register<Test>("smokeTest") {
110-
useJUnitPlatform()
111-
112-
// this is just to force building the agent first
113-
dependsOn(":agent:agent:shadowJar")
114-
115-
dependsOn(assemble)
116-
117-
testClassesDirs = sourceSets["smokeTest"].output.classesDirs
118-
classpath = sourceSets["smokeTest"].runtimeClasspath
119-
120-
// TODO (trask) experiment with parallelization
121-
// maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
122-
123-
doFirst {
124-
125-
val appFile = aiSmokeTest.testAppArtifactDir.file(aiSmokeTest.testAppArtifactFilename.get()).get()
126-
val javaagentFile = agent.singleFile
127-
val old3xJavaagentFile = old3xAgent.singleFile
128-
129-
// need to delay for project to configure the extension
130-
systemProperty("ai.smoke-test.test-app-file", appFile)
131-
systemProperty("ai.smoke-test.javaagent-file", javaagentFile)
132-
systemProperty("ai.smoke-test.old-3x-javaagent-file", old3xJavaagentFile)
133-
134-
val smokeTestMatrix = findProperty("smokeTestMatrix") ?: System.getenv("CI") != null
135-
systemProperty("ai.smoke-test.matrix", smokeTestMatrix)
136-
137-
findProperty("smokeTestRemoteDebug")?.let { systemProperty("ai.smoke-test.remote-debug", it) }
138-
139-
systemProperty("io.opentelemetry.context.enableStrictContext", true)
140-
systemProperty("io.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext", true)
141-
}
142-
143-
testLogging {
144-
showStandardStreams = true
145-
exceptionFormat = TestExceptionFormat.FULL
146-
}
147-
148-
// TODO (trask) this is still a problem
149-
// e.g. changes in agent-tooling do not cause smoke tests to re-run
150-
outputs.upToDateWhen { false }
151-
}
152159
}

smoke-tests/apps/OtlpMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OtlpLogAnalyticsOnAksTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.awaitility.Awaitility.await;
1919
import static org.mockserver.model.HttpRequest.request;
20-
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
2120

2221
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
2322
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
@@ -28,11 +27,7 @@
2827
import org.junit.jupiter.api.Test;
2928
import org.junit.jupiter.api.extension.RegisterExtension;
3029
import org.mockserver.model.HttpRequest;
31-
import org.springframework.boot.test.context.SpringBootTest;
3230

33-
@SpringBootTest(
34-
classes = {OtlpApplication.class},
35-
webEnvironment = RANDOM_PORT)
3631
@UseAgent
3732
abstract class OtlpLogAnalyticsOnAksTest {
3833

smoke-tests/apps/OtlpMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OtlpTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static org.assertj.core.api.Assertions.assertThat;
99
import static org.awaitility.Awaitility.await;
1010
import static org.mockserver.model.HttpRequest.request;
11-
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
1211

1312
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
1413
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
@@ -19,11 +18,7 @@
1918
import org.junit.jupiter.api.Test;
2019
import org.junit.jupiter.api.extension.RegisterExtension;
2120
import org.mockserver.model.HttpRequest;
22-
import org.springframework.boot.test.context.SpringBootTest;
2321

24-
@SpringBootTest(
25-
classes = {OtlpApplication.class},
26-
webEnvironment = RANDOM_PORT)
2722
@UseAgent
2823
abstract class OtlpTest {
2924

0 commit comments

Comments
 (0)