From e869bd879b4553f6f99551f12a2e0cc9bb1d9411 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 24 Jan 2023 12:22:42 -0800 Subject: [PATCH] Parallelize tests across multiple GitHub Actions jobs (#7639) The build takes ~2 hours when there are changes to core modules that force re-running of all tests. Ran into the long test times (again) in #7632. This also affects release times since the version bump PR build takes 2 hours to run, and then another 2 hours to run release (or wait 2 hours for CI build to run and update gradle cache). --- .github/workflows/build-common.yml | 7 +++++++ build.gradle.kts | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/build-common.yml b/.github/workflows/build-common.yml index e5b1021fa3..7f834efea6 100644 --- a/.github/workflows/build-common.yml +++ b/.github/workflows/build-common.yml @@ -136,6 +136,7 @@ jobs: test: runs-on: ubuntu-latest + name: test${{ matrix.test-partition }} (${{ matrix.test-java-version }}, ${{ matrix.vm }}) strategy: matrix: test-java-version: @@ -146,6 +147,11 @@ jobs: vm: - hotspot - openj9 + test-partition: + - 0 + - 1 + - 2 + - 3 exclude: - vm: ${{ inputs.skip-openj9-tests && 'openj9' || '' }} - test-java-version: 19 @@ -193,6 +199,7 @@ jobs: -PtestJavaVM=${{ matrix.vm }} -Porg.gradle.java.installations.paths=${{ steps.setup-test-java.outputs.path }} -Porg.gradle.java.installations.auto-download=false + -PtestPartition=${{ matrix.test-partition }} ${{ inputs.no-build-cache && ' --no-build-cache' || '' }} # only push cache for one matrix option since github action cache space is limited cache-read-only: ${{ inputs.cache-read-only || matrix.test-java-version != 11 || matrix.vm != 'hotspot' }} diff --git a/build.gradle.kts b/build.gradle.kts index c11fed23b5..9b2b233742 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,3 +32,18 @@ nexusPublishing { } description = "OpenTelemetry instrumentations for Java" + +// total of 4 partitions (see modulo 4 below) +var testPartition = (project.findProperty("testPartition") as String?)?.toInt() +if (testPartition != null) { + var testPartitionCounter = 0 + subprojects { + // relying on predictable ordering of subprojects + // (see https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14CB4) + // since we are splitting these tasks across different github action jobs + val enabled = testPartitionCounter++ % 4 == testPartition + tasks.withType().configureEach { + this.enabled = enabled + } + } +}