Skip to content

Commit 3ba178f

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 3ba178f

1 file changed

Lines changed: 65 additions & 66 deletions

File tree

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

Lines changed: 65 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,76 @@ 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())
69+
implementation(project(":smoke-tests:framework"))
70+
71+
implementation("org.junit.jupiter:junit-jupiter-api")
72+
implementation("org.junit.jupiter:junit-jupiter-params")
73+
runtimeOnly("org.junit.jupiter:junit-jupiter-engine")
74+
runtimeOnly("org.junit.platform:junit-platform-launcher")
75+
76+
implementation("org.assertj:assertj-core")
77+
}
78+
79+
targets {
80+
all {
81+
testTask.configure {
82+
useJUnitPlatform()
83+
84+
// this is just to force building the agent first
85+
dependsOn(":agent:agent:shadowJar")
86+
87+
shouldRunAfter(test)
88+
89+
// TODO (trask) experiment with parallelization
90+
// maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
91+
92+
doFirst {
93+
val appFile = aiSmokeTest.testAppArtifactDir.file(aiSmokeTest.testAppArtifactFilename.get()).get()
94+
val javaagentFile = agent.singleFile
95+
val old3xJavaagentFile = old3xAgent.singleFile
96+
97+
// need to delay for project to configure the extension
98+
systemProperty("ai.smoke-test.test-app-file", appFile)
99+
systemProperty("ai.smoke-test.javaagent-file", javaagentFile)
100+
systemProperty("ai.smoke-test.old-3x-javaagent-file", old3xJavaagentFile)
101+
102+
val smokeTestMatrix = findProperty("smokeTestMatrix") ?: System.getenv("CI") != null
103+
systemProperty("ai.smoke-test.matrix", smokeTestMatrix)
104+
105+
findProperty("smokeTestRemoteDebug")?.let { systemProperty("ai.smoke-test.remote-debug", it) }
106+
107+
systemProperty("io.opentelemetry.context.enableStrictContext", true)
108+
systemProperty("io.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext", true)
109+
}
110+
111+
testLogging {
112+
showStandardStreams = true
113+
exceptionFormat = TestExceptionFormat.FULL
114+
}
115+
116+
// TODO (trask) this is still a problem
117+
// e.g. changes in agent-tooling do not cause smoke tests to re-run
118+
outputs.upToDateWhen { false }
119+
}
120+
}
121+
}
122+
}
123+
}
124+
}
125+
83126
configurations.all {
84127
// spring boot 2.x requires slf4j 1.x
85128
val slf4jVersion = "1.7.36"
@@ -105,48 +148,4 @@ tasks {
105148
addStringOption("Xwerror", "-quiet")
106149
}
107150
}
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-
}
152151
}

0 commit comments

Comments
 (0)