From fa8527af09fccff0d202662056bbb3494b4af1f8 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 24 Feb 2025 18:47:44 +0800 Subject: [PATCH] Makefile+scripts: add unit test flake hunter This commit adds a script to hunt flakes for a specific unit test with trace logs. Also rename the make commands to make them more clear on whether it's a unit test, itest, or paralleled itest. --- Makefile | 16 ++++++++-------- scripts/unit-test-flake-hunter.sh | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100755 scripts/unit-test-flake-hunter.sh diff --git a/Makefile b/Makefile index ebd2b69ec..fc7a04118 100644 --- a/Makefile +++ b/Makefile @@ -276,18 +276,18 @@ unit-bench: $(BTCD_BIN) # FLAKE HUNTING # ============= -#? flakehunter: Run the integration tests continuously until one fails -flakehunter: build-itest +#? flakehunter-itest: Run the integration tests continuously until one fails +flakehunter-itest: build-itest @$(call print, "Flake hunting ${backend} integration tests.") while [ $$? -eq 0 ]; do make itest-only icase='${icase}' backend='${backend}'; done -#? flake-unit: Run the unit tests continuously until one fails -flake-unit: - @$(call print, "Flake hunting unit tests.") - while [ $$? -eq 0 ]; do GOTRACEBACK=all $(UNIT) -count=1; done +#? flakehunter-unit: Run the unit tests continuously until one fails +flakehunter-unit: + @$(call print, "Flake hunting unit test.") + scripts/unit-test-flake-hunter.sh ${pkg} ${case} -#? flakehunter-parallel: Run the integration tests continuously until one fails, running up to ITEST_PARALLELISM test tranches in parallel (default 4) -flakehunter-parallel: +#? flakehunter-itest-parallel: Run the integration tests continuously until one fails, running up to ITEST_PARALLELISM test tranches in parallel (default 4) +flakehunter-itest-parallel: @$(call print, "Flake hunting ${backend} integration tests in parallel.") while [ $$? -eq 0 ]; do make itest-parallel tranches=1 parallel=${ITEST_PARALLELISM} icase='${icase}' backend='${backend}'; done diff --git a/scripts/unit-test-flake-hunter.sh b/scripts/unit-test-flake-hunter.sh new file mode 100755 index 000000000..89406e01a --- /dev/null +++ b/scripts/unit-test-flake-hunter.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Check if pkg and case variables are provided. +if [ $# -lt 2 ] || [ $# -gt 3 ]; then + echo "Usage: $0 [timeout]" + exit 1 +fi + +pkg=$1 +case=$2 +timeout=${3:-30s} # Default to 30s if not provided. + +counter=0 + +# Run the command in a loop until it fails. +while output=$(go clean -testcache && make unit-debug log="stdlog trace" pkg=$pkg case=$case timeout=$timeout 2>&1); do + ((counter++)) + echo "Test $case passed, count: $counter" +done + +# Only log the output when it fails. +echo "Test $case failed. Output:" +echo "$output"