git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 1/2] test-lib: run EXPENSIVE tests one at a time

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 29, 2026, 16:55 UTC
Message-ID
<xmqqa4mro9ur.fsf@gitster.g>
In-Reply-To
<20261128-ks-ci-long-test-hang-fix-v4-1-f117badd2e13@gmail.com>
Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:
Show 13 quoted lines
> +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"
> +	echo $$ >"$tmp" ||
> +	{ expensive_lock_unavailable_; return 0; }
> +	while ! ln "$tmp" "$expensive_lock_" 2>/dev/null
> +	do

Neat-o. We can try to hardlink ours, fail, notice the owner is gone, unlink it, and try again. Another waiter may interfere while we are doing so and take the lock, in which case we will fail to hardlink and wait one more time, which isn't too bad.

Show 38 quoted lines
> +		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
> +		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
> +			continue
> +		fi
> +		if test -z "$waited"
> +		then
> +			say >&3 "waiting for another EXPENSIVE test to finish"
> +			waited=t
> +		fi
> +		sleep 1
> +	done
> +	have_expensive_lock_=t
> +	rm -f "$tmp"
> +}
Very nicely done.
Previous: Kaartic SivaraamNext: Christian Couder
Message 17 of 32 in “test-lib: run EXPENSIVE tests one at a time”
  1. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 19, 2026
  2. Patrick SteinhardtNov 19, 2026
  3. Kaartic SivaraamNov 19, 2026
  4. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 19, 2026
  5. Kaartic SivaraamNov 19, 2026
  6. Junio C HamanoNov 20, 2026
  7. Kaartic SivaraamNov 24, 2026
  8. Junio C HamanoNov 25, 2026
  9. Kaartic SivaraamNov 27, 2026
  10. Junio C HamanoNov 27, 2026
  11. Harald NordgrenNov 25, 2026
  12. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 27, 2026
  13. Junio C HamanoNov 27, 2026
  14. Kaartic SivaraamNov 28, 2026
  15. 0/2 test-lib: serialize EXPENSIVE tests to avoid OOM in CIKaartic Sivaraam, Nov 28, 2026
  16. 1/2 test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Nov 28, 2026
  17. Junio C HamanoNov 29, 2026
  18. Christian CouderNov 30, 2026
  19. Kaartic SivaraamDec 1, 2026
  20. Christian CouderDec 1, 2026
  21. Kaartic SivaraamDec 1, 2026
  22. Patrick SteinhardtDec 1, 2026
  23. Kaartic SivaraamDec 1, 2026
  24. Patrick SteinhardtDec 1, 2026
  25. Kaartic SivaraamDec 1, 2026
  26. Patrick SteinhardtDec 1, 2026
  27. 2/2 t0000: test taking over and releasing the EXPENSIVE lockKaartic Sivaraam, Nov 28, 2026
  28. Patrick SteinhardtDec 1, 2026
  29. Kaartic SivaraamDec 1, 2026
  30. test-lib: run EXPENSIVE tests one at a timeKaartic Sivaraam, Dec 1, 2026
  31. Patrick SteinhardtDec 3, 2026
  32. Kaartic SivaraamDec 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.