Re: [PATCH v3] test-lib: run EXPENSIVE tests one at a time
On 11/28/26 02:16, Junio C Hamano wrote:
Show 6 quoted lines
> 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 ;-).
> Ah. Thanks for correcting my grammar. Will fix this too :-)
Show 9 quoted lines
> 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.
>
That's an interesting one. I've defined it above die() per your suggestion.
Show 24 quoted lines
>> +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.
> That's a good point. Will make the fallback paths consistent.Show 19 quoted lines
>> @@ -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.
>Let me give this a shot. I'll keep it in a separate patch so that we could discuss it separately.
> Overall this is clean and well thought out.
> > Very nice.
--
Sivaraam