Skip to content

Commit fdae88c

Browse files
runningcodeclaude
andauthored
build(otel): Register agent without-auto-init tests as a suite target (#6632)
The without-auto-init run uses the same classes and classpath as the integrationTestOtelAgent suite and differs only in one JVM argument. Registering it as a second target of the suite lets Gradle set up its test classes, classpath and test framework, instead of copying them into a hand-made Test task. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9feef75 commit fdae88c

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

‎.cursor/rules/e2e_tests.mdc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ and server. The `io.sentry.otel-agent-tests` plugin in `build-logic` gives the S
6060
an `agentFixture` source set with the app, the `integrationTestOtelAgent` suite and the built agent
6161
jar; each module adds only the dependencies of its Spring Boot line. `AgentApp` starts the app once
6262
per test JVM in a child process, with `ChildJvmApp` and the agent jar passed through
63-
`ChildJvmTestArguments`. The suite's task runs with the agent initializing Sentry, and
64-
`integrationTestOtelAgentWithoutAutoInit` runs the same tests with the Spring Boot starter doing
65-
it. Gradle runs the two in parallel. `otelAgentTests()` in a `springBootMatrix` block registers
63+
`ChildJvmTestArguments`. The suite's task runs with the agent initializing Sentry, and its second
64+
target, `integrationTestOtelAgentWithoutAutoInit`, runs the same tests with the Spring Boot starter
65+
doing it. Gradle runs the two in parallel. `otelAgentTests()` in a `springBootMatrix` block registers
6666
both on each version.
6767

6868
## Running them

‎build-logic/src/main/kotlin/io/sentry/gradle/OtelAgentTestsPlugin.kt‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.gradle.api.plugins.JavaPlugin
99
import org.gradle.api.plugins.jvm.JvmTestSuite
1010
import org.gradle.api.tasks.SourceSetContainer
1111
import org.gradle.api.tasks.testing.Test
12-
import org.gradle.language.base.plugins.LifecycleBasePlugin
1312
import org.gradle.testing.base.TestingExtension
1413

1514
private const val AGENT_FIXTURE = "agentFixture"
@@ -24,9 +23,9 @@ private const val WITHOUT_AUTO_INIT = "${SUITE}WithoutAutoInit"
2423
* The agent must not run in the test's JVM, because it would instrument the test's own HTTP client
2524
* and server. So the app lives in the `agentFixture` source set and runs on its own classpath, like
2625
* a real app. The `integrationTestOtelAgent` suite's task runs the tests with the agent
27-
* initializing Sentry, and `integrationTestOtelAgentWithoutAutoInit` runs them with the Spring Boot
28-
* starter doing it. Each test JVM starts one app, so the second mode needs a task of its own, which
29-
* Gradle runs in parallel with the suite's.
26+
* initializing Sentry, and its second target, `integrationTestOtelAgentWithoutAutoInit`, runs them
27+
* with the Spring Boot starter doing it. Each test JVM starts one app, so the second mode needs a
28+
* task of its own, which Gradle runs in parallel with the suite's.
3029
*
3130
* The module adds the app's and the suite's dependencies, which differ per Spring Boot line.
3231
*/
@@ -64,19 +63,15 @@ class OtelAgentTestsPlugin : Plugin<Project> {
6463
val testing = project.extensions.getByType(TestingExtension::class.java)
6564
testing.suites.register(SUITE, JvmTestSuite::class.java) {
6665
useJUnit()
67-
targets.all {
66+
targets.named(SUITE) {
6867
testTask.configure { runAgentFixture(autoInit = true, agentFixture.runtimeClasspath) }
6968
}
70-
}
71-
72-
project.tasks.register(WITHOUT_AUTO_INIT, Test::class.java) {
73-
description = "Runs the OpenTelemetry agent tests with SENTRY_AUTO_INIT=false."
74-
group = LifecycleBasePlugin.VERIFICATION_GROUP
75-
val sources = sourceSets.getByName(SUITE)
76-
testClassesDirs = sources.output.classesDirs
77-
classpath = sources.runtimeClasspath
78-
useJUnit()
79-
runAgentFixture(autoInit = false, agentFixture.runtimeClasspath)
69+
targets.register(WITHOUT_AUTO_INIT) {
70+
testTask.configure {
71+
description = "Runs the OpenTelemetry agent tests with SENTRY_AUTO_INIT=false."
72+
runAgentFixture(autoInit = false, agentFixture.runtimeClasspath)
73+
}
74+
}
8075
}
8176
}
8277
}

0 commit comments

Comments
 (0)