From 758c66f06695fe9df87ad188c20967b8fd4ecfb9 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 17 May 2024 18:08:21 +0300 Subject: [PATCH] Split tests once Signed-off-by: Fabio Di Fabio --- .github/workflows/pre-review.yml | 57 +++++++++++++++++--------- .github/workflows/splitTestsByTime.sh | 59 ++++++++++++++------------- 2 files changed, 68 insertions(+), 48 deletions(-) diff --git a/.github/workflows/pre-review.yml b/.github/workflows/pre-review.yml index 65a0912e4db..8f2c11aead5 100644 --- a/.github/workflows/pre-review.yml +++ b/.github/workflows/pre-review.yml @@ -72,18 +72,9 @@ jobs: cache-disabled: true - name: Gradle Compile run: ./gradlew build -x test -x spotlessCheck - unitTests: - env: - GRADLEW_UNIT_TEST_ARGS: ${{matrix.gradle_args}} + splitUnitTests: runs-on: ubuntu-22.04 needs: [spotless, gradle-wrapper, repolint] - permissions: - checks: write - statuses: write - strategy: - fail-fast: true - matrix: - runner_index: [0,1,2,3,4,5,6,7] steps: - name: Checkout Repo uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 @@ -113,26 +104,54 @@ jobs: path: tmp/junit-xml-reports-downloaded if_no_artifact_found: true - name: Split tests - run: .github/workflows/splitTestsByTime.sh tmp/junit-xml-reports-downloaded "tmp/junit-xml-reports-downloaded/unit-.*-test-results" "build/test-results" ${{env.total-runners}} ${{ matrix.runner_index }} > testList.txt - - name: Upload Timing + run: .github/workflows/splitTestsByTime.sh tmp/junit-xml-reports-downloaded "tmp/junit-xml-reports-downloaded/unit-.*-test-results" "build/test-results" ${{env.total-runners}} + - name: Upload timing uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 - if: matrix.runner_index == 0 with: name: acceptance-tests-timing path: 'tmp/timing.tsv' - - name: Upload Lists + - name: Upload working lists uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 - if: matrix.runner_index == 0 with: name: acceptance-tests-lists path: 'tmp/*.list' - - name: Upload gradle test tasks + - name: Upload gradle test lists uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 with: - name: testList-${{ matrix.runner_index }}.txt - path: testList.txt + name: testLists.txt + path: testList-*.txt + unitTests: + runs-on: ubuntu-22.04 + needs: [splitUnitTests] + permissions: + checks: write + statuses: write + strategy: + fail-fast: true + matrix: + runner_index: [0,1,2,3,4,5,6,7] + steps: + - name: Checkout Repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + with: + ref: ${{ github.event.pull_request.head.sha || github.ref }} + - name: Set up Java + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 + with: + distribution: temurin + java-version: 17 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@9e899d11ad247ec76be7a60bc1cf9d3abbb9e7f1 + with: + cache-disabled: true + - name: get unit test lists + uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe + with: + name: testLists.txt + - name: debug ls + run: ls -l - name: run unit tests - run: cat testList.txt | xargs -P 1 ./gradlew -Dorg.gradle.parallel=true -Dorg.gradle.caching=true + run: cat testList-${{ matrix.runner_index }}.txt | xargs -P 1 ./gradlew -Dorg.gradle.parallel=true - name: Upload Unit Test Results uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 with: diff --git a/.github/workflows/splitTestsByTime.sh b/.github/workflows/splitTestsByTime.sh index bb3a69431d3..a16bd11746c 100755 --- a/.github/workflows/splitTestsByTime.sh +++ b/.github/workflows/splitTestsByTime.sh @@ -18,7 +18,6 @@ REPORTS_DIR="$1" REPORT_STRIP_PREFIX="$2" REPORT_STRIP_SUFFIX="$3" SPLIT_COUNT=$4 -SPLIT_INDEX=$5 # extract tests time from Junit XML reports find "$REPORTS_DIR" -type f -name TEST-*.xml | xargs -I{} bash -c "xmlstarlet sel -t -v 'concat(sum(//testcase/@time), \" \", //testsuite/@name)' '{}'; echo '{}' | sed \"s#\${REPORT_STRIP_PREFIX}/\(.*\)/${REPORT_STRIP_SUFFIX}.*# \1#\"" > tmp/timing.tsv @@ -91,33 +90,35 @@ do tests[$i]="$test_list" done - -# group tests by module -module_list=( $( echo "${tests[$SPLIT_INDEX]}" | tr "," "\n" | awk '{print $2}' | sort -u ) ) - -declare -A group_by_module -for module_dir in "${module_list[@]}" -do - group_by_module[$module_dir]="" -done - -IFS="," test_list=( ${tests[$SPLIT_INDEX]} ) -unset IFS - -for line in "${test_list[@]}" -do - line_parts=( $line ) - test_name=${line_parts[0]} - module_dir=${line_parts[1]} - - module_group=${group_by_module[$module_dir]} - group_by_module[$module_dir]="$module_group$test_name " -done - -# return the requests index, without quotes to drop the last trailing space -for module_dir in "${module_list[@]}" +for ((i=0; i> "testList-$i.txt" + done done