Skip to content
/ besu Public
forked from hyperledger/besu

Commit

Permalink
Split acceptance tests by time (hyperledger#6953)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 authored Apr 16, 2024
1 parent b1d8554 commit 941ab01
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
with:
distribution: temurin
java-version: 17
- name: Install required packages
run: sudo apt-get install -y xmlstarlet
- name: get acceptance test report
uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d
with:
Expand All @@ -48,19 +50,16 @@ jobs:
with:
cache-disabled: true
- name: Split tests
id: split-tests
uses: r7kamura/split-tests-by-timings@9322bd292d9423e2bc5a65bec548901801341e3f
run: .github/workflows/splitTestsByTime.sh tmp/junit-xml-reports-downloaded ${{env.total-runners}} ${{ matrix.runner_index }} > testList.txt
- name: Upload Timing
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
if: matrix.runner_index == 0
with:
reports: tmp/junit-xml-reports-downloaded
glob: 'acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/**/*Test.java'
total: ${{env.total-runners}}
index: ${{ matrix.runner_index }}
- name: write out test list
run: echo "${{ steps.split-tests.outputs.paths }}" >> testList.txt
name: acceptance-tests-timing
path: 'tmp/timing.tsv'
- name: format gradle args
#regex means: first truncate file paths to align with package name, then swap path delimiter with package delimiter,
#then drop file extension, then insert --tests option between each.
run: cat testList.txt | sed -e 's@acceptance-tests/tests/src/test/java/@--tests\ @g;s@/@.@g;s/\.java//g' > gradleArgs.txt
# insert --tests option between each.
run: cat testList.txt | sed -e 's/^\| / --tests /g' | tee gradleArgs.txt
- name: run acceptance tests
run: ./gradlew acceptanceTestNotPrivacy `cat gradleArgs.txt` -Dorg.gradle.parallel=true -Dorg.gradle.caching=true
- name: cleanup tempfiles
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/splitTestsByTime.sh
Original file line number Diff line number Diff line change
@@ -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]//,/ }

0 comments on commit 941ab01

Please sign in to comment.