From 594dfe75b1ea310ca5e06a140ed13c1c2d444ea7 Mon Sep 17 00:00:00 2001 From: Steven L Date: Thu, 9 Oct 2025 20:02:41 -0500 Subject: [PATCH] script to split apart tests in a target and run them as separate executions, rather than one bulk job --- Makefile | 10 ++++++++-- scripts/run_tests_separately.sh | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 scripts/run_tests_separately.sh diff --git a/Makefile b/Makefile index a722efd313c..1c37b2167b5 100644 --- a/Makefile +++ b/Makefile @@ -660,6 +660,12 @@ $Q FAIL=""; for dir in $1; do \ done; test -z "$$FAIL" || (echo "Failed packages; $$FAIL"; exit 1) endef +define individual_looptest +$Q FAIL=""; for dir in $1; do \ + ./scripts/run_tests_separately.sh "$$dir" $(TEST_ARG) -coverprofile=$@ $(TEST_TAG) -exec /usr/bin/true | tee -a test.log || FAIL="$$FAIL $$dir"; \ +done; test -z "$$FAIL" || (echo "Failed packages; $$FAIL"; exit 1) +endef + test: ## Build and run all tests locally $Q rm -f test $Q rm -f test.log @@ -673,13 +679,13 @@ test_dirs: test_e2e: $Q rm -f test $Q rm -f test.log - $Q $(call looptest,$(INTEG_TEST_ROOT)) + $Q $(call individual_looptest,$(INTEG_TEST_ROOT)) # need to run end-to-end xdc tests with race detector off because of ringpop bug causing data race issue test_e2e_xdc: $Q rm -f test $Q rm -f test.log - $Q $(call looptest,$(INTEG_TEST_XDC_ROOT)) + $Q $(call individual_looptest,$(INTEG_TEST_XDC_ROOT)) cover_profile: $Q mkdir -p $(BUILD) diff --git a/scripts/run_tests_separately.sh b/scripts/run_tests_separately.sh new file mode 100755 index 00000000000..6c6a5837d1c --- /dev/null +++ b/scripts/run_tests_separately.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -eou pipefail + +# basic idea: +# - `go test -list` to print all the test names +# - janky `jq` to filter that output, because -json doesn't differentiate +# between "what you asked for" vs "the package's results" +# vs "random in-test output" which is absolutely ridiculous imo +# - iterate through that output and execute it, so we can tell which test +# produced what output / failed / etc + +target="$1" +shift + +test_names_orig="$(go test -list '.' -json "$target")" +test_name_lines="$( + echo "$test_names_orig" \ + | jq 'select(.Action == "output") | select(.Output | startswith("Test"))' --compact-output --raw-output +)" +test_names_and_args="$( + echo "$test_name_lines" \ + | jq '{"package":(.Package | ltrimstr("github.com/uber/cadence/")), "name":(.Output | rtrimstr("\n"))}' --compact-output --raw-output +)" + +while read -r each_test; do + pkg="$(echo "$each_test" | jq .package --raw-output)" + tst="'^$(echo "$each_test" | jq .name --raw-output)\$'" + cmd="go test ${*@Q} -run ${tst} ./${pkg}" + echo "----------------------------------------------" + echo "$cmd" + eval "$cmd" + echo "----------------------------------------------" +done < <(echo "$test_names_and_args")