镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Open
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
25 changes: 14 additions & 11 deletions buildSrc/src/main/kotlin/dd-trace-java.configure-tests.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.gradle.kotlin.dsl.withType
import org.gradle.testing.base.TestingExtension
import java.time.Duration
import java.time.temporal.ChronoUnit
import java.util.concurrent.Callable

plugins {
id("dd-trace-java.modifiable-config")
Expand Down Expand Up @@ -41,6 +42,10 @@ val runFlakyTestsProvider = rootProject.providers.gradleProperty("runFlakyTests"
tasks.withType<Test>().configureEach {
configureTestAgentPostChecks()

// Test suites get the JUnit Platform from `useJUnitJupiter()` above, but tasks registered with
// `tasks.register(..., Test)` would default to JUnit 4 and discover no Spock 2 or JUnit 5 tests.
useJUnitPlatform()

// Disable all tests if skipTests property was specified
onlyIf("skipTests are undefined or false") { !skipTestsProvider.isPresent }

Expand All @@ -67,17 +72,15 @@ tasks.withType<Test>().configureEach {
onlyIf("skipForkedTests are undefined or false") { !skipForkedTestsProvider.isPresent }
} else {
exclude("**/*ForkedTest*")
// Starting from Gradle 9.3, Gradle will fail if a test task has no discovered tests.
// While this can be a misconfiguration, dd-trace-java test suite conventions allow suites
// to contain abstract base classes that are extended by concrete forked test suites.
//
// Many instrumentation suites indeed only ship *ForkedTest concrete classes
// (the non-forked peer task created by `addTestSuiteExtendingForDir` exists only
// to host shared configurations/sources). Those test tasks won't have executable tests
// by design under the `**/*ForkedTest*` exclude rule above. So let's allow them.
//
// Related but not the issue here https://github.com/gradle/gradle/issues/36508
failOnNoDiscoveredTests = false
// Gradle fails a test task that discovers no tests, which catches misconfigured tasks.
// The exception is a suite whose concrete tests are all *ForkedTest classes: the exclude rule
// above leaves its non-forked task with abstract base classes only, so allow it to be empty.
// The compiled classes are read lazily, once the task inputs are snapshotted.
val forkedTestClasses = objects.fileCollection()
.from(Callable { testClassesDirs })
.asFileTree
.matching { include("**/*ForkedTest*.class") }
failOnNoDiscoveredTests.set(forkedTestClasses.elements.map { it.isEmpty() })
}

// Set test timeout for 20 minutes. Default job timeout is 1h (configured on CI level).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ dependencies {
it.options.compilerArgs.addAll(['-Xlint:all,-processing,-options,-path'])
}
}

tasks.named("test", Test) {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ artifacts {
testArtifacts testJar
}

tasks.named('test', Test) {
// The test source set only holds the abstract base class reused by the play-ws modules
failOnNoDiscoveredTests = false
}


dependencies {
compileOnly group: 'com.typesafe.play', name: "play-ahc-ws-standalone_$scalaVersion", version: '1.0.2'
Expand Down
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/restlet-2.2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ addTestSuite('latestDepTest')

tasks.named("test", Test) {
dependsOn "baseForkedTest"
// The test source set only holds the abstract base and resources shared with baseForkedTest and latestDepTest
failOnNoDiscoveredTests = false
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ tasks.named("compileTestGroovy", GroovyCompile) {
classpath += files(sourceSets.test.scala.classesDirectory)
}

tasks.named("test", Test) {
// The test source set only holds the abstract base classes compiled by the scala-promise-2.x modules
failOnNoDiscoveredTests = false
}

dependencies {
compileOnly group: 'org.scala-lang', name: 'scala-library', version: '2.10.7' // First 2.10 version that accepts target 1.8
testImplementation group: 'org.scala-lang', name: 'scala-library', version: '2.10.7'
Expand Down
4 changes: 0 additions & 4 deletions dd-java-agent/testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,3 @@ configurations {
exclude group: 'org.eclipse.jetty.http2'
}
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
}
15 changes: 0 additions & 15 deletions dd-smoke-tests/appsec/spring-tomcat7/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,3 @@ tasks.withType(Test).configureEach {
}
})
}

tasks.register('testRuntimeActivation', Test) {
def shadowJarTask = tasks.named('shadowJar', ShadowJar)
jvmArgs '-Dsmoke_test.appsec.enabled=inactive'
jvmArgumentProviders.add(new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
return shadowJarTask.map { ["-Ddatadog.smoketest.appsec.springtomcat7.shadowJar.path=${it.archiveFile.get()}"] }.get()
}
})
}

tasks.named('check') {
dependsOn(testRuntimeActivation)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import okhttp3.MediaType
import okhttp3.Request
import okhttp3.RequestBody
import org.apache.commons.io.IOUtils
import spock.lang.IgnoreIf
import spock.lang.Shared

import java.nio.charset.StandardCharsets
Expand Down Expand Up @@ -100,6 +101,9 @@ class SpringBootGraphqlSmokeTest extends AbstractAppSecServerSmokeTest {
}
}

// testRuntimeActivation loads AppSec without ever activating it, so no attack can be detected.
// TODO APMLP-2199: activate AppSec through remote config and run this feature in that mode too.
@IgnoreIf({ System.getProperty('smoke_test.appsec.enabled') == 'inactive' })
def 'test detect #description'() {
setup:

Expand Down
3 changes: 0 additions & 3 deletions dd-smoke-tests/appsec/springboot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ tasks.withType(Test).configureEach {

tasks.register('testRuntimeActivation', Test) {
def shadowJarTask = tasks.named('shadowJar', ShadowJar)
// Without this, the task keeps Gradle's default JUnit 4 runner, which discovers none of the
// Spock specs in this module, so the task passes without running anything.
useJUnitPlatform()
// Limit to the exposure spec: the other specs in this source set expect AppSec active (e.g.
// SpringBootSmokeTest asserts 403 blocking responses), which is incompatible with the inactive
// mode this task runs under.
Expand Down
1 change: 0 additions & 1 deletion gradle/test-suites.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ 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
}
Expand Down
Loading