Split acceptance tests by time (#6953)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/6959/head
Fabio Di Fabio 7 months ago committed by GitHub
parent b1d8554e23
commit 941ab01426
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 21
      .github/workflows/acceptance-tests.yml
  2. 52
      .github/workflows/splitTestsByTime.sh

@ -35,6 +35,8 @@ jobs:
with: with:
distribution: temurin distribution: temurin
java-version: 17 java-version: 17
- name: Install required packages
run: sudo apt-get install -y xmlstarlet
- name: get acceptance test report - name: get acceptance test report
uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d
with: with:
@ -48,19 +50,16 @@ jobs:
with: with:
cache-disabled: true cache-disabled: true
- name: Split tests - name: Split tests
id: split-tests run: .github/workflows/splitTestsByTime.sh tmp/junit-xml-reports-downloaded ${{env.total-runners}} ${{ matrix.runner_index }} > testList.txt
uses: r7kamura/split-tests-by-timings@9322bd292d9423e2bc5a65bec548901801341e3f - name: Upload Timing
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
if: matrix.runner_index == 0
with: with:
reports: tmp/junit-xml-reports-downloaded name: acceptance-tests-timing
glob: 'acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/**/*Test.java' path: 'tmp/timing.tsv'
total: ${{env.total-runners}}
index: ${{ matrix.runner_index }}
- name: write out test list
run: echo "${{ steps.split-tests.outputs.paths }}" >> testList.txt
- name: format gradle args - name: format gradle args
#regex means: first truncate file paths to align with package name, then swap path delimiter with package delimiter, # insert --tests option between each.
#then drop file extension, then insert --tests option between each. run: cat testList.txt | sed -e 's/^\| / --tests /g' | tee gradleArgs.txt
run: cat testList.txt | sed -e 's@acceptance-tests/tests/src/test/java/@--tests\ @g;s@/@.@g;s/\.java//g' > gradleArgs.txt
- name: run acceptance tests - name: run acceptance tests
run: ./gradlew acceptanceTestNotPrivacy `cat gradleArgs.txt` -Dorg.gradle.parallel=true -Dorg.gradle.caching=true run: ./gradlew acceptanceTestNotPrivacy `cat gradleArgs.txt` -Dorg.gradle.parallel=true -Dorg.gradle.caching=true
- name: cleanup tempfiles - name: cleanup tempfiles

@ -0,0 +1,52 @@
#!/bin/bash
REPORTS_DIR="$1"
SPLIT_COUNT=$2
SPLIT_INDEX=$3
# extract tests time from Junit XML reports
find "$REPORTS_DIR" -type f -name TEST-*.xml | xargs -I{} bash -c "xmlstarlet sel -t -v 'sum(//testcase/@time)' '{}'; echo '{}' | sed 's/.*TEST\-\(.*\)\.xml/ \1/'" > tmp/timing.tsv
# Sort times in descending order
IFS=$'\n' sorted=($(sort -nr tmp/timing.tsv))
unset IFS
sums=()
tests=()
# Initialize sums
for ((i=0; i<SPLIT_COUNT; i++))
do
sums[$i]=0
done
# add tests to groups trying to balance the sum of execution time of each group
for line in "${sorted[@]}"; do
line_parts=( $line )
test_time=${line_parts[0]//./} # convert to millis
test_time=${test_time##0} # remove leading zeros
test_name=${line_parts[1]}
# Find index of min sum
idx_min_sum=0
min_sum=${sums[0]}
for ((i=0; i<SPLIT_COUNT; i++))
do
if [[ ${sums[$i]} -lt $min_sum ]]
then
idx_min_sum=$i
min_sum=${sums[$i]}
fi
done
# Add the test to the min sum list
min_sum_tests=${tests[$idx_min_sum]}
tests[$idx_min_sum]="${min_sum_tests}${test_name},"
# Update the sums
((sums[idx_min_sum]+=test_time))
done
# return the requests index, without quotes to drop the last trailing space
echo ${tests[$SPLIT_INDEX]//,/ }
Loading…
Cancel
Save