-
Notifications
You must be signed in to change notification settings - Fork 315
Create configure_tests convention plugin
#9859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sarahchen6
merged 15 commits into
master
from
sarahchen6/configure-tests-convention-plugin
Nov 6, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2194059
Create configure-tests convention plugin
sarahchen6 96f586b
Use lazy providers for property evaluation
sarahchen6 7ff614b
Use more lazy API configurations
sarahchen6 be41722
Remove old file references and add missing configuration
sarahchen6 d85b522
Alphabetize instrumentations
sarahchen6 afa8ed9
Comment tasks
sarahchen6 f654867
Add comment for forked test memory limit
sarahchen6 01611f5
Address quick formatting review comments
sarahchen6 822e01a
Add develocity as a dependency
sarahchen6 6071635
Introduce testInstrumentation extension
sarahchen6 4e3c8a5
Merge branch 'master' into sarahchen6/configure-tests-convention-plugin
sarahchen6 5064dcf
Address review comments
sarahchen6 c82daa7
Typo
sarahchen6 8096191
Move extension definition to top of file
sarahchen6 97348c5
Merge branch 'master' into sarahchen6/configure-tests-convention-plugin
sarahchen6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
buildSrc/src/main/kotlin/datadog.configure-tests.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import org.gradle.api.tasks.testing.Test | ||
| import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions | ||
| import org.gradle.api.services.BuildService | ||
| import org.gradle.api.services.BuildServiceParameters | ||
| import org.gradle.testing.base.TestingExtension | ||
| import org.gradle.api.plugins.jvm.JvmTestSuite | ||
| import java.time.Duration | ||
| import java.time.temporal.ChronoUnit | ||
|
|
||
| val isTestingInstrumentation = providers.provider { | ||
| project.findProperty("testingInstrumentation") as? Boolean ?: false | ||
| } | ||
|
|
||
| // Need concrete implementation of BuildService in Kotlin | ||
| abstract class ForkedTestLimit : BuildService<BuildServiceParameters.None> | ||
| // Forked tests will fail with OOM if the memory is set too high. Gitlab allows at least a limit of 3. | ||
| val forkedTestsMemoryLimit = 3 | ||
|
|
||
| val forkedTestLimit = gradle.sharedServices.registerIfAbsent("forkedTestLimit", ForkedTestLimit::class.java) { | ||
| maxParallelUsages.set(forkedTestsMemoryLimit) | ||
| } | ||
|
|
||
| extensions.findByType<TestingExtension>()?.apply { | ||
| suites.withType<JvmTestSuite>().configureEach { | ||
| // Use JUnit 5 to run tests | ||
| useJUnitJupiter() | ||
| } | ||
| } | ||
|
|
||
| // Use lazy providers to avoid evaluating the property until it is needed | ||
| val skipTestsProvider = rootProject.providers.gradleProperty("skipTests") | ||
| val skipForkedTestsProvider = rootProject.providers.gradleProperty("skipForkedTests") | ||
| val skipFlakyTestsProvider = rootProject.providers.gradleProperty("skipFlakyTests") | ||
| val runFlakyTestsProvider = rootProject.providers.gradleProperty("runFlakyTests") | ||
| val activePartitionProvider = providers.provider { | ||
| project.extra.properties["activePartition"] as? Boolean ?: true | ||
| } | ||
|
|
||
| // Go through the Test tasks and configure them | ||
| tasks.withType<Test>().configureEach { | ||
| enabled = activePartitionProvider.get() | ||
|
|
||
| // Disable all tests if skipTests property was specified | ||
| onlyIf("skipTests are undefined or false") { !skipTestsProvider.isPresent } | ||
|
|
||
| // Enable force rerun of tests with -Prerun.tests.${project.name} | ||
| outputs.upToDateWhen { | ||
| !rootProject.providers.gradleProperty("rerun.tests.${project.name}").isPresent | ||
| } | ||
|
|
||
| // Avoid executing classes used to test testing frameworks instrumentation | ||
| if (isTestingInstrumentation.get()) { | ||
| exclude("**/TestAssumption*", "**/TestSuiteSetUpAssumption*") | ||
| exclude("**/TestDisableTestTrace*") | ||
| exclude("**/TestError*") | ||
| exclude("**/TestFactory*") | ||
| exclude("**/TestFailed*") | ||
| exclude("**/TestFailedWithSuccessPercentage*") | ||
| exclude("**/TestInheritance*", "**/BaseTestInheritance*") | ||
| exclude("**/TestParameterized*") | ||
| exclude("**/TestRepeated*") | ||
| exclude("**/TestSkipped*") | ||
| exclude("**/TestSkippedClass*") | ||
| exclude("**/TestSucceed*") | ||
| exclude("**/TestTemplate*") | ||
| exclude("**/TestUnskippable*") | ||
| exclude("**/TestWithSetup*") | ||
| } | ||
|
|
||
| // Split up tests that want to run forked in their own separate JVM for generated tasks | ||
| if (name.startsWith("forkedTest") || name.endsWith("ForkedTest")) { | ||
| setExcludes(emptyList()) | ||
| setIncludes(listOf("**/*ForkedTest*")) | ||
| forkEvery = 1 | ||
| // Limit the number of concurrent forked tests | ||
| usesService(forkedTestLimit) | ||
| onlyIf("skipForkedTests are undefined or false") { !skipForkedTestsProvider.isPresent } | ||
| } else { | ||
| exclude("**/*ForkedTest*") | ||
| } | ||
|
|
||
| // Set test timeout for 20 minutes. Default job timeout is 1h (configured on CI level). | ||
| timeout.set(Duration.of(20, ChronoUnit.MINUTES)) | ||
| } | ||
|
|
||
| // Register a task "allTests" that depends on all non-latest and non-traceAgentTest Test tasks. | ||
| // This is used when we only want to run the 'main' test sets. | ||
| tasks.register("allTests") { | ||
| dependsOn(tasks.withType<Test>().matching { testTask -> | ||
| !testTask.name.contains("latest", ignoreCase = true) && testTask.name != "traceAgentTest" | ||
| }) | ||
| } | ||
|
|
||
| // Register a task "allLatestDepTests" that depends on all Test tasks whose names include 'latest'. | ||
| // This is used when we want to run tests against the latest dependency versions. | ||
| tasks.register("allLatestDepTests") { | ||
| dependsOn(tasks.withType<Test>().matching { testTask -> | ||
| !testTask.name.contains("latest", ignoreCase = true) | ||
| }) | ||
| } | ||
|
|
||
| // Make the 'check' task depend on all Test tasks in the project. | ||
| // This means that when running the 'check' task, all Test tasks will run as well. | ||
| tasks.named("check") { | ||
| dependsOn(tasks.withType<Test>()) | ||
| } | ||
|
|
||
| tasks.withType<Test>().configureEach { | ||
| // Flaky tests management for JUnit 5 | ||
| if (testFramework is JUnitPlatformOptions) { | ||
| val junitPlatform = testFramework as JUnitPlatformOptions | ||
| if (skipFlakyTestsProvider.isPresent) { | ||
| junitPlatform.excludeTags("flaky") | ||
| } else if (runFlakyTestsProvider.isPresent) { | ||
| junitPlatform.includeTags("flaky") | ||
| } | ||
| } | ||
|
|
||
| // Flaky tests management for Spock | ||
| if (skipFlakyTestsProvider.isPresent) { | ||
| jvmArgs("-Drun.flaky.tests=false") | ||
| } else if (runFlakyTestsProvider.isPresent) { | ||
| jvmArgs("-Drun.flaky.tests=true") | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<Test>().configureEach { | ||
| // https://docs.gradle.com/develocity/flaky-test-detection/ | ||
| // https://docs.gradle.com/develocity/gradle-plugin/current/#test_retry | ||
| develocity.testRetry { | ||
| if (providers.environmentVariable("CI").isPresent()) { | ||
| maxRetries = 3 | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
|
|
||
| muzzle { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
dd-java-agent/instrumentation/junit/junit-4.10/cucumber-junit-4/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
|
|
||
| muzzle { | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
dd-java-agent/instrumentation/junit/junit-4.10/junit-4.13/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
|
|
||
| muzzle { | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
dd-java-agent/instrumentation/junit/junit-4.10/munit-junit-4/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
| apply plugin: 'scala' | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
dd-java-agent/instrumentation/junit/junit-5.3/cucumber-junit-5/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
|
|
||
| muzzle { | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
dd-java-agent/instrumentation/junit/junit-5.3/junit-5.8/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
|
|
||
| def jupiterVersion = '5.8.0' | ||
|
|
||
2 changes: 2 additions & 0 deletions
2
dd-java-agent/instrumentation/junit/junit-5.3/spock-junit-5/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
|
|
||
| def spockGroovyVersion = '3.0' | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| ext.testingInstrumentation = true | ||
|
|
||
| apply from: "$rootDir/gradle/java.gradle" | ||
| apply plugin: 'scala' | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Maybe, these could end-up in the extension I mentioned earlier. I'm kind if undecided there.