Skip to content

Commit da2106d

Browse files
authored
Merge pull request #1936 from lightninglabs/chore/ci-itest-split
ci: parallelize integration tests using matrix strategy
2 parents 443c864 + 146896e commit da2106d

File tree

2 files changed

+90
-22
lines changed

2 files changed

+90
-22
lines changed

.github/workflows/main.yaml

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ jobs:
274274
format: 'golang'
275275
parallel: true
276276

277-
# Integration tests on SQLite backend.
278-
integration-test:
279-
name: run itests
277+
# Build integration test binaries once, shared by all itest jobs.
278+
build-itest:
279+
name: build itest binaries
280280
runs-on: ubuntu-latest
281281
steps:
282282
- name: git checkout
@@ -290,69 +290,120 @@ jobs:
290290
with:
291291
go-version: '${{ env.GO_VERSION }}'
292292

293+
- name: Build itest binaries
294+
run: make build-itest build-itest-binary
295+
296+
- name: Upload itest binaries
297+
uses: actions/upload-artifact@v4
298+
with:
299+
name: itest-binaries
300+
path: |
301+
itest/itest.test
302+
itest/btcd-itest
303+
itest/lnd-itest
304+
itest/chantools/chantools
305+
306+
# Integration tests on SQLite backend.
307+
integration-test:
308+
name: run itests
309+
runs-on: ubuntu-latest
310+
needs: build-itest
311+
strategy:
312+
fail-fast: false
313+
matrix:
314+
tranche: [0, 1, 2, 3]
315+
steps:
316+
- name: git checkout
317+
uses: actions/checkout@v5
318+
319+
- name: Clean up runner space
320+
uses: ./.github/actions/cleanup-space
321+
322+
- name: Download itest binaries
323+
uses: actions/download-artifact@v4
324+
with:
325+
name: itest-binaries
326+
path: itest
327+
328+
- name: Initialize environment
329+
run: |
330+
chmod +x itest/itest.test itest/btcd-itest itest/lnd-itest itest/chantools/chantools
331+
mkdir -p ~/.aperture
332+
293333
- name: run itest
294-
run: make itest-parallel
334+
run: scripts/itest_part.sh ${{ matrix.tranche }} 4 0 --verbose
295335

296336
- name: Zip log files on failure
297337
if: ${{ failure() }}
298-
run: 7z a logs-itest.zip itest/**/*.log
338+
run: 7z a logs-itest-${{ matrix.tranche }}.zip itest/**/*.log
299339

300340
- name: Upload log files on failure
301341
uses: actions/upload-artifact@v4
302342
if: ${{ failure() }}
303343
with:
304-
name: logs-itest
305-
path: logs-itest.zip
344+
name: logs-itest-${{ matrix.tranche }}
345+
path: logs-itest-${{ matrix.tranche }}.zip
306346
retention-days: 5
307347

308348
- name: Send coverage
309349
uses: coverallsapp/github-action@v2
310350
if: ${{ success() }}
311351
continue-on-error: true
312352
with:
313-
file: itest/coverage.txt
314-
flag-name: 'itest'
353+
file: itest/regtest/cover/coverage-tranche${{ matrix.tranche }}.txt
354+
flag-name: 'itest-${{ matrix.tranche }}'
315355
format: 'golang'
316356
parallel: true
317357

318358
# Integration tests on Postgres backend.
319359
integration-test-postgres:
320360
name: run itests postgres
321361
runs-on: ubuntu-latest
362+
needs: build-itest
363+
strategy:
364+
fail-fast: false
365+
matrix:
366+
tranche: [0, 1, 2, 3]
322367
steps:
323368
- name: git checkout
324369
uses: actions/checkout@v5
325370

326371
- name: Clean up runner space
327372
uses: ./.github/actions/cleanup-space
328373

329-
- name: Setup go ${{ env.GO_VERSION }}
330-
uses: actions/setup-go@v5
374+
- name: Download itest binaries
375+
uses: actions/download-artifact@v4
331376
with:
332-
go-version: '${{ env.GO_VERSION }}'
377+
name: itest-binaries
378+
path: itest
379+
380+
- name: Initialize environment
381+
run: |
382+
chmod +x itest/itest.test itest/btcd-itest itest/lnd-itest itest/chantools/chantools
383+
mkdir -p ~/.aperture
333384
334385
- name: run itest
335-
run: make itest-parallel dbbackend=postgres tranches=4
386+
run: scripts/itest_part.sh ${{ matrix.tranche }} 4 0 -dbbackend=postgres --verbose
336387

337388
- name: Zip log files on failure
338389
if: ${{ failure() }}
339-
run: 7z a logs-itest-postgres.zip itest/**/*.log
390+
run: 7z a logs-itest-postgres-${{ matrix.tranche }}.zip itest/**/*.log
340391

341392
- name: Upload log files on failure
342393
uses: actions/upload-artifact@v4
343394
if: ${{ failure() }}
344395
with:
345-
name: logs-itest-postgres
346-
path: logs-itest-postgres.zip
396+
name: logs-itest-postgres-${{ matrix.tranche }}
397+
path: logs-itest-postgres-${{ matrix.tranche }}.zip
347398
retention-days: 5
348399

349400
- name: Send coverage
350401
uses: coverallsapp/github-action@v2
351402
if: ${{ success() }}
352403
continue-on-error: true
353404
with:
354-
file: itest/coverage.txt
355-
flag-name: 'itest'
405+
file: itest/regtest/cover/coverage-tranche${{ matrix.tranche }}.txt
406+
flag-name: 'itest-postgres-${{ matrix.tranche }}'
356407
format: 'golang'
357408
parallel: true
358409

scripts/itest_part.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ SHUFFLE_SEED_PARAM=$3
1111
# the $@ special variable.
1212
shift 3
1313

14+
# Check for --verbose flag in the remaining arguments.
15+
VERBOSE=0
16+
TEST_FLAGS=()
17+
for arg in "$@"; do
18+
if [ "$arg" == "--verbose" ]; then
19+
VERBOSE=1
20+
else
21+
TEST_FLAGS+=("$arg")
22+
fi
23+
done
24+
1425
# Windows insists on having the .exe suffix for an executable, we need to add
1526
# that here if necessary.
1627
EXEC="$WORKDIR"/itest.test
@@ -20,15 +31,21 @@ export GOCOVERDIR="$WORKDIR/regtest/cover"
2031
COVERFILE="$GOCOVERDIR/coverage-tranche$TRANCHE.txt"
2132
mkdir -p "$GOCOVERDIR"
2233
mkdir -p "$LOG_DIR"
23-
echo $EXEC "$@" -test.coverprofile=$COVERFILE -test.gocoverdir=$GOCOVERDIR -logoutput -logdir=$LOG_DIR -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE -shuffleseed=$SHUFFLE_SEED_PARAM
34+
echo $EXEC "${TEST_FLAGS[@]}" -test.coverprofile=$COVERFILE -test.gocoverdir=$GOCOVERDIR -logoutput -logdir=$LOG_DIR -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE -shuffleseed=$SHUFFLE_SEED_PARAM
2435

2536
# Exit code 255 causes the parallel jobs to abort, so if one part fails the
2637
# other is aborted too.
2738
cd "$WORKDIR" || exit 255
28-
$EXEC "$@" -test.coverprofile=$COVERFILE -test.gocoverdir=$GOCOVERDIR -logoutput -logdir=$LOG_DIR -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE -shuffleseed=$SHUFFLE_SEED_PARAM > $LOG_DIR/output.log 2>&1
2939

30-
# Capture the exit code of the test run.
31-
exit_code=$?
40+
if [ $VERBOSE -eq 1 ]; then
41+
$EXEC "${TEST_FLAGS[@]}" -test.coverprofile=$COVERFILE -test.gocoverdir=$GOCOVERDIR -logoutput -logdir=$LOG_DIR -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE -shuffleseed=$SHUFFLE_SEED_PARAM 2>&1 | tee "$LOG_DIR/output.log"
42+
# Capture the exit code of the test run (first command in pipe).
43+
exit_code=${PIPESTATUS[0]}
44+
else
45+
$EXEC "${TEST_FLAGS[@]}" -test.coverprofile=$COVERFILE -test.gocoverdir=$GOCOVERDIR -logoutput -logdir=$LOG_DIR -btcdexec=$BTCD_EXEC -splittranches=$NUM_TRANCHES -runtranche=$TRANCHE -shuffleseed=$SHUFFLE_SEED_PARAM > "$LOG_DIR/output.log" 2>&1
46+
# Capture the exit code of the test run.
47+
exit_code=$?
48+
fi
3249
if [ $exit_code -ne 0 ]; then
3350
echo "Tranche $TRANCHE failed with exit code $exit_code"
3451
tail -n 100 "$LOG_DIR/output.log"

0 commit comments

Comments
 (0)