Skip to content

Allow forked test tasks for source sets other than test - #12147

Draft
AlexeyKuznetsov-DD wants to merge 1 commit into
masterfrom
alexeyk/forked-test-source-set
Draft

Allow forked test tasks for source sets other than test#12147
AlexeyKuznetsov-DD wants to merge 1 commit into
masterfrom
alexeyk/forked-test-source-set

Conversation

@AlexeyKuznetsov-DD

Copy link
Copy Markdown
Contributor

What Does This Do

Lets a module register a forked-test task for a source set other than test.

gradle/java_no_deps.gradle registered a single hardcoded forkedTest task bound to sourceSets.test. This turns that registration into a reusable helper next to its siblings in gradle/test-suites.gradle, and calls it with 'test' from the same place as before:

ext.addForkedTestTask = { String sourceSetName ->
  def taskName = sourceSetName == 'test' ? 'forkedTest' : "${sourceSetName}ForkedTest"
  return tasks.register(taskName, Test) {
    group = LifecycleBasePlugin.VERIFICATION_GROUP
    useJUnitPlatform()
    testClassesDirs = sourceSets[sourceSetName].output.classesDirs
    classpath = sourceSets[sourceSetName].runtimeClasspath
  }
}

A module with its own suites now opts in with one line:

addTestSuite('baseTest')
addForkedTestTask('baseTest')  // registers 'baseTestForkedTest'

No behaviour changes for any existing module: forkedTest is still registered for every project, with the same name and the same configuration.

Motivation

Modules that do not use the default test source set silently do not run their forked tests.

The convention plugin excludes **/*ForkedTest* from every non-forked Test task, and the only task that runs them was bound to sourceSets.test. A module that keeps its tests in its own suites β€” for example to compile the same tests against several Scala versions β€” therefore has no task that runs its *ForkedTest classes at all.

Two modules are in exactly that state today, with forked tests that have never executed:

  • dd-java-agent/instrumentation/pekko/pekko-http-1.0 β€” 6 classes in src/baseTest
  • dd-java-agent/instrumentation/netty/netty-3.8 β€” 2 classes in src/latestDepTest

This PR only provides the mechanism. Switching those modules on is deliberately left out, because their dormant tests do not currently pass β€” running pekko's surfaces a real NPE in PekkoHttpClientHelpers$PekkoHttpHeaders during Data Streams injection β€” and each needs its own investigation.

Additional Notes

No wiring needed for CI. check, allTests and allLatestDepTests select Test tasks by type rather than by name, so a task registered through the helper is picked up automatically. The latest substring convention also routes latestDepTestForkedTest to allLatestDepTests and baseTestForkedTest to allTests without further work.

Follow-up refactor available. Around 10 call sites across 8 modules currently use addTestSuiteExtendingForDir(<name>, <parent>, <parent's own dir>), which creates a second source set that recompiles identical sources with identical dependencies purely to obtain a forked runner. Those collapse to a single addForkedTestTask('<parent>') call, removing a duplicate compilation and, in five of them, the compile<Name>ForkedTestGroovy { classpath += ... } fix-ups that exist only because of the duplicate source set. None of those suites declare their own dependencies, and none of the task names are referenced from CI, so the change is mechanical β€” but it renames tasks, so it belongs in its own PR. Candidates: akka-actor-2.5, akka-http-10.0, aws-java-sdk-1.11 (Γ—2), aws-java-sdk-2.2 (Γ—2), spring-scheduling-3.1, spring-webmvc-3.1, tomcat-5.5, vertx-web-4.0.

Why a plain closure and not a default parameter. The helper lives in test-suites.gradle alongside addTestSuite/addTestSuiteForDir/addTestSuiteExtendingForDir. In java_no_deps.gradle the Spotless Groovy formatter reformats a typed closure parameter onto its own line, which is why that file uses lambda syntax elsewhere; in test-suites.gradle the plain closure form is left alone, matching the neighbouring helpers.

Validation.

  • :internal-api:forkedTest (a module using the default test source set) runs and passes β€” 6 tests β€” confirming the default registration is unchanged.
  • Temporarily adding addForkedTestTask('baseTest') and addForkedTestTask('latestDepTest') to pekko-http-1.0 registered baseTestForkedTest and latestDepTestForkedTest next to the existing forkedTest; reverted afterwards.
  • With the change stashed, that same opt-in call fails with Could not find method addForkedTestTask(), confirming the helper is what provides it.
  • spotlessGroovyGradleCheck passes.

Executing forked tests in a module that builds the agent could not be verified locally: io.sqreen:libsqreen:17.5.0 currently returns 403 Forbidden from Maven Central on this machine. That reproduces on a clean checkout without this change, so it is unrelated to this PR.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

πŸ€– Generated with Claude Code

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD added tag: no release notes Changes to exclude from release notes type: refactoring comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM labels Aug 5, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
β€’ Patch Coverage: 100.00%
β€’ Overall Coverage: 57.90% (-0.02%)

This comment will be updated automatically if new data arrives.
πŸ”— Commit SHA: 36f6dd2 | Docs | Datadog PR Page | Give us feedback!

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD force-pushed the alexeyk/forked-test-source-set branch from b5e02c8 to 36f6dd2 Compare August 5, 2026 15:13
@dd-octo-sts

dd-octo-sts Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🟒 Java Benchmark SLOs β€” All performance SLOs passed

Suite Status
Startup 🟒 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Ξ” (95% CI of mean)
startup:insecure-bank:iast:Agent 14.01 s 13.96 s [-0.5%; +1.2%] (no difference)
startup:insecure-bank:tracing:Agent 12.92 s 13.01 s [-1.6%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 16.84 s 16.70 s [-0.2%; +1.8%] (no difference)
startup:petclinic:iast:Agent 16.91 s 16.92 s [-0.8%; +0.7%] (no difference)
startup:petclinic:profiling:Agent 16.33 s 16.84 s [-7.4%; +1.4%] (no difference)
startup:petclinic:sca:Agent 16.75 s 16.48 s [+0.9%; +2.3%] (maybe worse)
startup:petclinic:tracing:Agent 15.65 s 15.64 s [-5.8%; +5.9%] (unstable)

Commit: 36f6dd25 Β· CI Pipeline Β· Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant