From 02b649fbc07aade152a9ca558d3ca28078b7c6d7 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Tue, 17 Nov 2026 10:10:06 +0100 Subject: [PATCH] build(otel): Register agent without-auto-init tests as a suite target 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 --- .cursor/rules/e2e_tests.mdc | 6 ++--- .../io/sentry/gradle/OtelAgentTestsPlugin.kt | 25 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.cursor/rules/e2e_tests.mdc b/.cursor/rules/e2e_tests.mdc index 8295253b07..da6fbf93d0 100644 --- a/.cursor/rules/e2e_tests.mdc +++ b/.cursor/rules/e2e_tests.mdc @@ -60,9 +60,9 @@ and server. The `io.sentry.otel-agent-tests` plugin in `build-logic` gives the S an `agentFixture` source set with the app, the `integrationTestOtelAgent` suite and the built agent jar; each module adds only the dependencies of its Spring Boot line. `AgentApp` starts the app once per test JVM in a child process, with `ChildJvmApp` and the agent jar passed through -`ChildJvmTestArguments`. The suite's task runs with the agent initializing Sentry, and -`integrationTestOtelAgentWithoutAutoInit` runs the same tests with the Spring Boot starter doing -it. Gradle runs the two in parallel. `otelAgentTests()` in a `springBootMatrix` block registers +`ChildJvmTestArguments`. The suite's task runs with the agent initializing Sentry, and its second +target, `integrationTestOtelAgentWithoutAutoInit`, runs the same tests with the Spring Boot starter +doing it. Gradle runs the two in parallel. `otelAgentTests()` in a `springBootMatrix` block registers both on each version. ## Running them diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/OtelAgentTestsPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/OtelAgentTestsPlugin.kt index 33271f731a..0f529fe8e0 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/OtelAgentTestsPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/OtelAgentTestsPlugin.kt @@ -9,7 +9,6 @@ import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.jvm.JvmTestSuite import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.testing.Test -import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.testing.base.TestingExtension private const val AGENT_FIXTURE = "agentFixture" @@ -24,9 +23,9 @@ private const val WITHOUT_AUTO_INIT = "${SUITE}WithoutAutoInit" * The agent must not run in the test's JVM, because it would instrument the test's own HTTP client * and server. So the app lives in the `agentFixture` source set and runs on its own classpath, like * a real app. The `integrationTestOtelAgent` suite's task runs the tests with the agent - * initializing Sentry, and `integrationTestOtelAgentWithoutAutoInit` runs them with the Spring Boot - * starter doing it. Each test JVM starts one app, so the second mode needs a task of its own, which - * Gradle runs in parallel with the suite's. + * initializing Sentry, and its second target, `integrationTestOtelAgentWithoutAutoInit`, runs them + * with the Spring Boot starter doing it. Each test JVM starts one app, so the second mode needs a + * task of its own, which Gradle runs in parallel with the suite's. * * The module adds the app's and the suite's dependencies, which differ per Spring Boot line. */ @@ -64,19 +63,15 @@ class OtelAgentTestsPlugin : Plugin { val testing = project.extensions.getByType(TestingExtension::class.java) testing.suites.register(SUITE, JvmTestSuite::class.java) { useJUnit() - targets.all { + targets.named(SUITE) { testTask.configure { runAgentFixture(autoInit = true, agentFixture.runtimeClasspath) } } - } - - project.tasks.register(WITHOUT_AUTO_INIT, Test::class.java) { - description = "Runs the OpenTelemetry agent tests with SENTRY_AUTO_INIT=false." - group = LifecycleBasePlugin.VERIFICATION_GROUP - val sources = sourceSets.getByName(SUITE) - testClassesDirs = sources.output.classesDirs - classpath = sources.runtimeClasspath - useJUnit() - runAgentFixture(autoInit = false, agentFixture.runtimeClasspath) + targets.register(WITHOUT_AUTO_INIT) { + testTask.configure { + description = "Runs the OpenTelemetry agent tests with SENTRY_AUTO_INIT=false." + runAgentFixture(autoInit = false, agentFixture.runtimeClasspath) + } + } } } }