Skip to content

Commit

Permalink
Split tests once
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed May 17, 2024
1 parent 19f92ee commit 758c66f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 48 deletions.
57 changes: 38 additions & 19 deletions .github/workflows/pre-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
59 changes: 30 additions & 29 deletions .github/workflows/splitTestsByTime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SPLIT_COUNT; i++))
do
module_test_task=":${module_dir//\//:}:test"
module_tests=$( echo "${group_by_module[$module_dir]% }" | sed -e 's/^\| / --tests /g' )
echo "$module_test_task $module_tests"
# group tests by module
module_list=( $( echo "${tests[$i]}" | 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[$i]} )
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 current index
for module_dir in "${module_list[@]}"
do
module_test_task=":${module_dir//\//:}:test"
module_tests=$( echo "${group_by_module[$module_dir]% }" | sed -e 's/^\| / --tests /g' )
echo "$module_test_task $module_tests" >> "testList-$i.txt"
done
done

0 comments on commit 758c66f

Please sign in to comment.