Replace java test version rule with property. (#1769)

* Replace java test version rule with property.

* Fix enabled check

* Update java.gradle
This commit is contained in:
Anuraag Agrawal 2020-11-26 16:53:20 +09:00 committed by GitHub
parent 412d9991be
commit 91a9e1885e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 38 deletions

View File

@ -76,7 +76,7 @@ jobs:
S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }} S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }}
S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }} S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }}
with: with:
command: ./gradlew testJava${{ matrix.java }} --stacktrace -Dorg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }} command: ./gradlew test -PtestJavaVersion=${{ matrix.java }} --stacktrace -Dorg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }}
timeout_minutes: 180 timeout_minutes: 180
max_attempts: 3 max_attempts: 3

View File

@ -63,7 +63,7 @@ jobs:
- name: Test - name: Test
uses: nick-invision/retry@v2.2.0 uses: nick-invision/retry@v2.2.0
with: with:
command: ./gradlew testJava${{ matrix.java }} --stacktrace -x :smoke-tests:test -Dorg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }} command: ./gradlew test -PtestJavaVersion=${{ matrix.java }} --stacktrace -x :smoke-tests:test -Dorg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }}
timeout_minutes: 90 timeout_minutes: 90
max_attempts: 3 max_attempts: 3

View File

@ -22,8 +22,9 @@ instrumented library.
#### Executing tests with specific java version #### Executing tests with specific java version
We run all tests on Java 11 by default, along with Java 8 and 15. To run on the later, use We run all tests on Java 11 by default, along with Java 8 and 15. To run on the later, set the
`./gradlew testJava8` or `./gradlew testJava15`. If you don't have a JDK of these versions `testJavaVersion` Gradle property to the desired major version, e.g., `./gradlew test -PtestJavaVersion=8`,
`./gradlew test -PtestJavaVersion=15`. If you don't have a JDK of these versions
installed, Gradle will automatically download it for you. installed, Gradle will automatically download it for you.
#### Executing tests against the latest versions of libraries under instrumentation #### Executing tests against the latest versions of libraries under instrumentation

View File

@ -194,44 +194,32 @@ def isJavaVersionAllowed(JavaVersion version) {
return true return true
} }
// We default to testing with Java 11 for most tests, but some tests don't support it, where we change def testJavaVersion = rootProject.findProperty('testJavaVersion')
// the default test task's version so commands like `./gradlew check` can test all projects regardless if (testJavaVersion != null) {
// of Java version. def requestedJavaVersion = JavaVersion.toVersion(testJavaVersion)
if (!isJavaVersionAllowed(JavaVersion.toVersion(DEFAULT_JAVA_VERSION))) { def gradleJavaVersion = JavaVersion.current()
tasks.withType(Test) {
javaLauncher = javaToolchains.launcherFor { if (gradleJavaVersion != requestedJavaVersion) {
languageVersion = JavaLanguageVersion.of(project.getProperty('maxJavaVersionForTests').majorVersion) tasks.withType(Test).all {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(requestedJavaVersion.majorVersion)
}
enabled = isJavaVersionAllowed(requestedJavaVersion)
} }
} }
} } else {
// We default to testing with Java 11 for most tests, but some tests don't support it, where we change
def addTestRule(String testTaskName) { // the default test task's version so commands like `./gradlew check` can test all projects regardless
def prefix = testTaskName + "Java" // of Java version.
tasks.addRule("Pattern: $prefix<Version>: Runs tests using given java version") { String taskName -> if (!isJavaVersionAllowed(JavaVersion.toVersion(DEFAULT_JAVA_VERSION))) {
if (taskName.startsWith(prefix)) { tasks.withType(Test) {
def requestedJavaVersion = JavaVersion.toVersion(taskName - prefix) javaLauncher = javaToolchains.launcherFor {
def gradleJavaVersion = JavaVersion.current() languageVersion = JavaLanguageVersion.of(project.getProperty('maxJavaVersionForTests').majorVersion)
if (gradleJavaVersion != requestedJavaVersion) {
tasks.withType(Test).all {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(requestedJavaVersion.majorVersion)
}
enabled = isJavaVersionAllowed(requestedJavaVersion)
}
}
task(taskName) {
if (project.tasks.findByName(testTaskName) != null) {
dependsOn testTaskName
}
} }
} }
} }
} }
addTestRule("test")
tasks.withType(Test).configureEach { tasks.withType(Test).configureEach {
useJUnitPlatform() useJUnitPlatform()
@ -239,9 +227,6 @@ tasks.withType(Test).configureEach {
// This value is quite big because with lower values (3 mins) we were experiencing large number of false positives // This value is quite big because with lower values (3 mins) we were experiencing large number of false positives
timeout = Duration.ofMinutes(15) timeout = Duration.ofMinutes(15)
// Disable all tests if skipTests property was specified
enabled = !project.rootProject.hasProperty("skipTests")
retry { retry {
// You can see tests that were retried by this mechanism in the collected test reports and build scans. // You can see tests that were retried by this mechanism in the collected test reports and build scans.
maxRetries = System.getenv("CI") != null ? 5 : 0 maxRetries = System.getenv("CI") != null ? 5 : 0