[PATCH v4 2/2] t0000: test taking over and releasing the EXPENSIVE lock
- From
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
- Date
- Nov 28, 2026, 14:58 UTC
- Message-ID
- <20261128-ks-ci-long-test-hang-fix-v4-2-f117badd2e13@gmail.com>
- In-Reply-To
- <20261128-ks-ci-long-test-hang-fix-v4-0-f117badd2e13@gmail.com>
The previous commit serializes EXPENSIVE tests with a lock that a waiter takes over when its holder was killed, and that the EXIT trap releases when a script dies while holding it.
Add subtests checking that:
- a lock left by a dead process is taken over, held while the test
runs, and released afterwards; - a lock carrying the script's own PID, which can only be left by a
dead holder whose PID was reused, is taken over; - a script exiting in the middle of an EXPENSIVE test does not leave
the lock behind.None of them has to wait, as a stale lock is cleared without polling.
Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com> --- t/t0000-basic.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 7bd1f4e7b7..1535b7aa7e 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -746,6 +746,54 @@ test_expect_success 'subtest: lazy prereqs do not turn off tracing' ' test_grep "echo trace" lazy-prereq-and-tracing/err ' +test_expect_success 'subtest: EXPENSIVE lock of a dead holder is taken over' ' + write_sub_test_lib_test expensive-lock-dead <<-\EOF && + test_expect_success EXPENSIVE "holds the lock" " + echo $$ >expect && + test_cmp expect \"$TEST_RESULTS_DIR/expensive.lock\" + " + test_done + EOF + mkdir expensive-lock-dead/test-results && + sh -c "echo \$\$" >expensive-lock-dead/test-results/expensive.lock && + run_sub_test_lib_test expensive-lock-dead --long && + check_sub_test_lib_test expensive-lock-dead <<-\EOF && + > ok 1 - holds the lock + > # passed all 1 test(s) + > 1..1 + EOF + test_path_is_missing expensive-lock-dead/test-results/expensive.lock +' + +test_expect_success 'subtest: EXPENSIVE lock carrying our own PID is taken over' ' + write_sub_test_lib_test expensive-lock-own-pid <<-\EOF && + mkdir -p "$TEST_RESULTS_DIR" && + echo $$ >"$TEST_RESULTS_DIR/expensive.lock" + test_expect_success EXPENSIVE "takes the lock" "true" + test_done + EOF + run_sub_test_lib_test expensive-lock-own-pid --long && + check_sub_test_lib_test expensive-lock-own-pid <<-\EOF && + > ok 1 - takes the lock + > # passed all 1 test(s) + > 1..1 + EOF + test_path_is_missing expensive-lock-own-pid/test-results/expensive.lock +' + +test_expect_success 'subtest: EXPENSIVE lock is released when exiting mid-test' ' + write_sub_test_lib_test expensive-lock-exit <<-\EOF && + test_expect_success EXPENSIVE "exits holding the lock" " + test_path_is_file \"$TEST_RESULTS_DIR/expensive.lock\" && + exit 1 + " + test_done + EOF + run_sub_test_lib_test_err expensive-lock-exit --long && + test_grep "FATAL: Unexpected exit" expensive-lock-exit/out && + test_path_is_missing expensive-lock-exit/test-results/expensive.lock +' + test_expect_success 'subtest: tests clean up after themselves' ' write_and_run_sub_test_lib_test cleanup <<-\EOF && clean=no
-- 2.56.1.911.g883d8bcb20