Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Cc: Git mailing list <git@vger.kernel.org>,
	 Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH v3] test-lib: run EXPENSIVE tests one at a time
Date: Fri, 27 Nov 2026 12:46:25 -0800	[thread overview]
Message-ID: <xmqqpkvq6lzy.fsf@gitster.g> (raw)
In-Reply-To: <20261127-ks-ci-long-test-hang-fix-v3-1-91b2aac82a1c@gmail.com> (Kaartic Sivaraam's message of "Fri, 27 Nov 2026 22:53:15 +0530")

Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:

> Recently, we've acquired quite a few expensive tests in our test suite.
> For instance, these commits add several tests that require
> multi-gigabytes of memory:

Either "multi-gigabyte" or "multiple gigabytes"?

> GitHub CI runners are no exception and observe the same behaviour.

Pedantic.  You "observe" that runners "experience/suffer from/trigger".
They do not observe themselves ;-).

> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index c56654b7c5..916ec2d7d1 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -784,6 +784,8 @@ die () {
>  	# test script run with '--immediate' fails, or when the user hits
>  	# ctrl-C, i.e. when 'test_done' is not invoked at all.
>  	test_atexit_handler || code=$?
> +	release_expensive_lock_
> +	test -z "$expensive_lock_" || rm -f "$expensive_lock_.$$"

Minor ordering observation.  Because "trap die EXIT" is registered right
after die(), well before fail_117() where release_expensive_lock_() is
defined, an early failure while sourcing test-lib-functions.sh under set
-e would enter die() while release_expensive_lock_() is still undefined.

I notice that "$expensive_lock_" already has a test -z guard here, and
that would help avoid such issues to some degree.  Defining the lock
variables and helpers above die() (or guarding the call) would close
that small window.

> +acquire_expensive_lock_ () {
> +	local owner waited= tmp="$expensive_lock_.$$" misses=0
> +	mkdir -p "$TEST_RESULTS_DIR" || return 1
> +	# 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"
> +	echo $$ >"$tmp" || return 1

This pre-cleanup and hard-link scheme is neat.  Removing any leftover
"$tmp" before writing "$$" keeps us from truncating the inode of a stale
lock still hard-linked to an old "$tmp" from a recycled PID, and
hard-linking after writing "$$" guarantees $expensive_lock_ never exists
empty.

One minor consistency note.  When ln(1) fails three times with no lock
present, acquire_expensive_lock_() prints "cannot take the EXPENSIVE
lock, running anyway" to FD 3, removes "$tmp", and returns 0.

If mkdir or redirecting to "$tmp" fails instead (say, a read-only
TEST_RESULTS_DIR or a full disk), it returns 1 silently and leaves an
empty "$tmp" behind on write failure until die() runs.  Because
test_run_() ignores the return value, the test still runs anyway as
documented, though sharing the same cleanup, message, and return 0 would
keep all fallback paths consistent.

> @@ -1103,6 +1170,12 @@ test_run_ () {
>  		fi
>  	fi
>  
> +	case ",$test_prereq," in
> +	*,EXPENSIVE,*)
> +		acquire_expensive_lock_
> +		;;
> +	esac

Because test_expect_success() and test_expect_failure() call test_skip()
first, skipped tests never enter test_run_(), and the chainlint dry-run
above this block runs before we take the lock.  Placing the lock around
test_eval_() and outside its set -x block also keeps the polling loop
out of -x trace logs under CI --verbose-log -x, while still releasing
the lock before _error_exit() on --immediate failures.

Optional thought.  A small subtest in t/t0000-basic.sh seeding a stale
expensive.lock with a dead PID or "$$" and checking that it is cleared
and released (including under --immediate) could give quick regression
coverage without any sleep delay.

Overall this is clean and well thought out.

Very nice.

  reply	other threads:[~2026-11-27 20:46 UTC|newest]

Thread overview: 19+ 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 [this message]
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-11-28 14:58   ` [PATCH v4 2/2] t0000: test taking over and releasing the EXPENSIVE lock 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=xmqqpkvq6lzy.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --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