From: Patrick Steinhardt <ps@pks.im>
To: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Cc: Git mailing list <git@vger.kernel.org>,
Harald Nordgren <haraldnordgren@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v4 1/2] test-lib: run EXPENSIVE tests one at a time
Date: Tue, 1 Dec 2026 08:22:58 +0100 [thread overview]
Message-ID: <aw51wkqQQ8kgXkzI@pks.im> (raw)
In-Reply-To: <20261128-ks-ci-long-test-hang-fix-v4-1-f117badd2e13@gmail.com>
On Sat, Nov 28, 2026 at 08:27:59PM +0530, Kaartic Sivaraam wrote:
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index c56654b7c5..bfd2fc8374 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1089,6 +1100,71 @@ fail_117 () {
> return 117
> }
>
> +# EXPENSIVE tests may need many gigabytes of memory, so two of them
> +# running at the same time can exhaust the machine.
> +#
> +# Allow only one at a time across all test scripts that share
> +# this TEST_OUTPUT_DIRECTORY.
> +expensive_lock_="$TEST_RESULTS_DIR/expensive.lock"
> +have_expensive_lock_=
> +
> +expensive_lock_unavailable_ () {
> + say >&3 "cannot take the EXPENSIVE lock, running anyway"
> + rm -f "$expensive_lock_.$$"
> +}
> +
> +acquire_expensive_lock_ () {
> + local owner waited= tmp="$expensive_lock_.$$" misses=0
> + mkdir -p "$TEST_RESULTS_DIR" ||
> + { expensive_lock_unavailable_; return 0; }
> + # The lock is a hard link to a file that already holds our PID, so
> + # it never exists without its owner recorded in it. Remove any
> + # $tmp left by a dead process with our PID first: it may still be
> + # linked to that process's lock, which writing to it would empty.
> + rm -f "$tmp"
Nit: it is expected that in most cases this won't do anything, so in the
expected common case we'll see an error message. Do we want to silence
this?
> + echo $$ >"$tmp" ||
> + { expensive_lock_unavailable_; return 0; }
Nit: It would have been nice to maybe have empty lines in this function
to make it easier to follow. Right now the reader is presented one huge
chunk, and they have to figure out by themselves what the logical blocks
are.
> + while ! ln "$tmp" "$expensive_lock_" 2>/dev/null
> + do
> + if ! test -f "$expensive_lock_"
> + then
> + # Nobody holds the lock, yet we cannot create it (no
> + # hard links, disk full, ...). Retry in case it was
> + # just released, then run anyway rather than wait
> + # forever.
> + misses=$((misses + 1))
> + test $misses -lt 3 && continue
> + expensive_lock_unavailable_
> + return 0
> + fi
I was first thinking that this would trigger after three retries
unconditionally, so essentially after three seconds. And that would have
been overly aggressive, as we should expect that expensive tests run
more than 3 seconds.
But this is only detecting the case where we fail to create the lock due
to whatever reason. So it's a rather uncommon case.
> + misses=0
> + owner=$(cat "$expensive_lock_" 2>/dev/null)
> + # A lock carrying our own PID was left by a dead holder whose
> + # PID we were given again; we know we do not hold it.
> + if test -n "$owner" &&
> + { test "$owner" = $$ || ! kill -0 "$owner" 2>/dev/null; }
> + then
> + # The holder was killed without releasing the lock.
> + #
> + # Another waiter may have taken it over since we
> + # looked, so only remove it if it is still the same.
> + if test "$(cat "$expensive_lock_" 2>/dev/null)" = "$owner"
> + then
> + rm -f "$expensive_lock_"
> + fi
I feel like re-checking the lock owner is kind of pointless here. The
check doesn't fix the race, but it suggests it to the reader. And that
is overall fine, because the intent now is to fail in a way that we
prefer to run the test instead of blocking forever.
But it raises the question why we even bother to check again. To me it
only causes puzzlement.
> @@ -1115,6 +1197,7 @@ test_run_ () {
> test_eval_ "$test_cleanup"
> teardown_malloc_check
> fi
> + release_expensive_lock_
In the other block where we call this function we have this one:
> + release_expensive_lock_
> + test -z "$expensive_lock_" || rm -f "$expensive_lock_.$$"
And as far as I can see, `release_expensive_lock_` does not also prune
the PID-file. Do we have to do that here?
Thanks!
Patrick
next prev parent reply other threads:[~2026-12-01 7:23 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 7:40 [PATCH] test-lib: run EXPENSIVE tests one at a time Kaartic Sivaraam
2026-11-19 10:07 ` Patrick Steinhardt
2026-11-19 17:12 ` Kaartic Sivaraam
2026-11-19 17:29 ` [PATCH v2] " Kaartic Sivaraam
2026-11-19 17:33 ` Kaartic Sivaraam
2026-11-20 6:28 ` Junio C Hamano
2026-11-24 13:34 ` Kaartic Sivaraam
2026-11-25 20:21 ` Junio C Hamano
2026-11-27 13:59 ` Kaartic Sivaraam
2026-11-27 18:34 ` Junio C Hamano
2026-11-25 19:09 ` Harald Nordgren
2026-11-27 17:23 ` [PATCH v3] " Kaartic Sivaraam
2026-11-27 20:46 ` Junio C Hamano
2026-11-28 8:06 ` Kaartic Sivaraam
2026-11-28 14:57 ` [PATCH v4 0/2] test-lib: serialize EXPENSIVE tests to avoid OOM in CI Kaartic Sivaraam
2026-11-28 14:57 ` [PATCH v4 1/2] test-lib: run EXPENSIVE tests one at a time Kaartic Sivaraam
2026-11-29 16:55 ` Junio C Hamano
2026-11-30 14:13 ` Christian Couder
2026-12-01 10:14 ` Kaartic Sivaraam
2026-12-01 11:10 ` Christian Couder
2026-12-01 12:34 ` Kaartic Sivaraam
2026-12-01 7:22 ` Patrick Steinhardt [this message]
2026-12-01 8:47 ` Kaartic Sivaraam
2026-12-01 11:07 ` Patrick Steinhardt
2026-12-01 12:50 ` Kaartic Sivaraam
2026-12-01 13:19 ` Patrick Steinhardt
2026-11-28 14:58 ` [PATCH v4 2/2] t0000: test taking over and releasing the EXPENSIVE lock Kaartic Sivaraam
2026-12-01 7:23 ` Patrick Steinhardt
2026-12-01 8:49 ` Kaartic Sivaraam
2026-12-01 19:53 ` [PATCH v5] test-lib: run EXPENSIVE tests one at a time Kaartic Sivaraam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aw51wkqQQ8kgXkzI@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=haraldnordgren@gmail.com \
--cc=kaartic.sivaraam@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox