Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ apply {
from("$rootDir/../gradle/repositories.gradle")
}

repositories {
gradlePluginPortal()
}

dependencies {
implementation(gradleApi())
implementation(localGroovy())
Expand All @@ -69,6 +73,8 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("com.fasterxml.jackson.core:jackson-annotations")
implementation("com.fasterxml.jackson.core:jackson-core")

compileOnly(libs.develocity)
}

tasks.compileKotlin {
Expand Down
135 changes: 135 additions & 0 deletions buildSrc/src/main/kotlin/datadog.configure-tests.gradle.kts
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
}
Comment on lines +31 to +37
Copy link
Contributor

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.


// 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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ protobuf {
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ muzzle {
}

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/configure_tests.gradle"

addTestSuiteForDir('latestDepTest', 'test')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ apply from: "$rootDir/gradle/java.gradle"
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

dependencies {
compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.0'
compileOnly group: 'com.amazonaws', name: 'amazon-sqs-java-messaging-lib', version: '1.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ apply from: "$rootDir/gradle/java.gradle"
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

dependencies {
compileOnly group: 'software.amazon.awssdk', name: 'sqs', version: '2.2.0'
compileOnly group: 'com.amazonaws', name: 'amazon-sqs-java-messaging-lib', version: '2.0.0'
Expand Down
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/cucumber/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ext.testingInstrumentation = true

apply from: "$rootDir/gradle/java.gradle"

muzzle {
Expand Down
1 change: 0 additions & 1 deletion dd-java-agent/instrumentation/jakarta-jms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ muzzle {
}

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/configure_tests.gradle"

repositories {
maven {
Expand Down
2 changes: 0 additions & 2 deletions dd-java-agent/instrumentation/jms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ repositories {
addTestSuite('latestDepTest')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/junit/junit-4.10/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins {
id 'org.jetbrains.kotlin.jvm'
}

ext.testingInstrumentation = true

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/test-with-kotlin.gradle"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ext.testingInstrumentation = true

apply from: "$rootDir/gradle/java.gradle"

muzzle {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ext.testingInstrumentation = true

apply from: "$rootDir/gradle/java.gradle"

muzzle {
Expand Down
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'

Expand Down
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/junit/junit-5.3/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ext.testingInstrumentation = true

apply from: "$rootDir/gradle/java.gradle"

// JUnit5 5.3.0+ version is needed because of the fix in the TestInheritance test suite names.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ext.testingInstrumentation = true

apply from: "$rootDir/gradle/java.gradle"

muzzle {
Expand Down
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'
Expand Down
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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ apply from: "$rootDir/gradle/java.gradle"
addTestSuite('latestDepTest')
addTestSuite('iastLatestDepTest3')

apply from: "$rootDir/gradle/configure_tests.gradle"

dependencies {
compileOnly group: 'org.apache.kafka', name: 'kafka-clients', version: '0.11.0.0'
implementation project(':dd-java-agent:instrumentation:kafka:kafka-common')
Expand All @@ -39,7 +37,6 @@ dependencies {
testRuntimeOnly project(':dd-java-agent:instrumentation:reactive-streams')
testImplementation project(':dd-java-agent:agent-iast:iast-test-fixtures')


// IAST testing dependencies
testRuntimeOnly project(':dd-java-agent:instrumentation:iast-instrumenter')
testRuntimeOnly project(':dd-java-agent:instrumentation:java:java-lang:java-lang-1.8')
Expand Down
1 change: 1 addition & 0 deletions dd-java-agent/instrumentation/karate/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ext {
// karate 1.4.0+ requires Java 11 or higher.
latestDepTestMinJavaVersionForTests = JavaVersion.VERSION_11
testingInstrumentation = true
}

apply from: "$rootDir/gradle/java.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ apply plugin: 'scala' // Don't use test-with-scala since we want to pick our own
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'forkedTest')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ apply plugin: 'scala' // Don't use test-with-scala since we want to pick our own
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'forkedTest')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/scalatest/build.gradle
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'

Expand Down
1 change: 1 addition & 0 deletions dd-java-agent/instrumentation/selenium/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

ext {
latestDepTestMinJavaVersionForTests = JavaVersion.VERSION_11
testingInstrumentation = true
}

apply from: "$rootDir/gradle/java.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ apply from: "$rootDir/gradle/java.gradle"
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ muzzle {
}

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/configure_tests.gradle"

addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')
Expand Down
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/testng/testng-6/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'java-test-fixtures'
}

ext.testingInstrumentation = true

apply from: "$rootDir/gradle/java.gradle"

muzzle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
ext {
// testng 7.6.0+ requires Java 11 or higher.
latestDepTestMinJavaVersionForTests = JavaVersion.VERSION_11
testingInstrumentation = true
}

apply from: "$rootDir/gradle/java.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ muzzle {
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ muzzle {
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ muzzle {
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ muzzle {
addTestSuiteForDir('latestDepTest', 'test')
addTestSuiteExtendingForDir('latestDepForkedTest', 'latestDepTest', 'test')

apply from: "$rootDir/gradle/configure_tests.gradle"

tasks.named("latestDepTest", Test) {
finalizedBy 'latestDepForkedTest'
}
Expand Down
Loading