From 9d8d03d06e0f744960f1f4e30f77e2593469e20b Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Thu, 22 Oct 2026 10:17:15 -0300 Subject: [PATCH] test(xcat-core): the build lock refusal is asserted by a phrase every failure prints Three tests match qr/already holds/ against the refusal that acquire_lock_dir prints. That sentence is printed for every acquire failure, so the checks pass whether the lock is held by a live build or the mkdir failed with ENOENT or EACCES. They cannot tell contention from anything else, which is the one thing the operator reads the message for. Each of the three now asserts the contention report and the pid that holds the lock. build_lock_stale_owner.t adds a lock under a directory that does not exist, and asserts that the refusal carries the real error and claims no concurrent build. release_build_locks has no check at all. It is what a signal handler calls, because DESTROY does not run when a signal ends the process, and it reaches a lock only while that lock is in the registry. One check now takes a lock and frees it through release_build_locks. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT-test/unit/build_lock_stale_owner.t | 37 ++++++++++++++++++-- xCAT-test/unit/builddebs_lock.t | 6 +++- xCAT-test/unit/builddebs_lock_cancellation.t | 8 +++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/xCAT-test/unit/build_lock_stale_owner.t b/xCAT-test/unit/build_lock_stale_owner.t index edb2798485..f45802ee13 100644 --- a/xCAT-test/unit/build_lock_stale_owner.t +++ b/xCAT-test/unit/build_lock_stale_owner.t @@ -6,7 +6,8 @@ # The build lock is an XCAT::NFSLock, whose protocol recovers a lock whose owner is provably # dead. The protocol itself is tested in xcat-dep's t/nfslock_borrow_recovery.t. These checks # cover what xcat-core adds: that the build lock recovers from a killed holder, that a live -# holder is still refused, and that the refusal says which build holds it. +# holder is still refused, and that the refusal says what actually happened -- contention and a +# mkdir that failed outright are different problems and used to print the same sentence. use strict; use warnings; use Test::More; @@ -43,8 +44,26 @@ ok(-d $DIR, 'control: the lock directory exists while that child holds it'); my $blocked = eval { take_build_lock($CKOUT, $TMP) }; ok(!defined $blocked, 'while the holder lives, a second build is refused'); -like($@, qr/already holds/, 'and the refusal is the live-holder message'); -like($@, qr/\Q$CKOUT\E/, 'which names the checkout that is building'); +my $refusal = $@ // ''; +like($refusal, qr/another build still holds/, 'and the refusal reports contention'); +like($refusal, qr/still held after [0-9]+ retr\w+ by pid \Q$holder\E\b/, + 'and names the pid that holds it, so a live holder is told from any other failure'); +like($refusal, qr/\Q$CKOUT\E/, 'which names the checkout that is building'); + +# ---- a lock that cannot be created is not reported as a concurrent build ---------------- +# Every acquire failure used to print "another build already holds", with the contention advice, +# so an ENOENT or an EACCES sent the operator looking for a build that does not exist. +{ + my $advice = "serialize them, or pass a distinct --mock-uniqueext\n"; + my $got = eval { + XCAT::BuildUtils::acquire_lock_dir("$TMP/absent/xcatbld-x.lock.d", 'target zz', $advice); + }; + my $said = $@ // ''; + ok(!defined $got, 'a lock under a directory that does not exist is refused'); + like($said, qr/No such file or directory/, 'and the refusal carries the error that happened'); + unlike($said, qr/another build still holds|\Q$advice\E/, + 'and claims no concurrent build, and prints no advice about one'); +} kill 'KILL', $holder; waitpid($holder, 0); @@ -63,6 +82,18 @@ ok(defined $other, 'a build of a different checkout runs beside it'); undef $after; ok(!-d $DIR, 'releasing the lock removes its directory'); +# ---- a signal handler can release what DESTROY will not --------------------------------- +# DESTROY does not run when a signal ends the process, so cancel_build calls +# release_build_locks instead. That reaches a lock only while the lock is in the registry. +{ + my $signalled = '/opt/builds/signal/xcat-core'; + my $its_dir = XCAT::BuildUtils::lock_path_for($signalled, $TMP) . '.d'; + my $lock = take_build_lock($signalled, $TMP); + ok(-d $its_dir, 'control: the lock directory exists while the guard is held'); + XCAT::BuildUtils::release_build_locks(); + ok(!-d $its_dir, 'release_build_locks frees a lock whose guard is still in scope'); +} + # No lock state may survive, on any path above. undef $other; my @left = glob("$TMP/*.lock.d*"); diff --git a/xCAT-test/unit/builddebs_lock.t b/xCAT-test/unit/builddebs_lock.t index f022fc08cf..1e86e34ba2 100644 --- a/xCAT-test/unit/builddebs_lock.t +++ b/xCAT-test/unit/builddebs_lock.t @@ -38,7 +38,11 @@ ok( $first, 'the first build of a checkout takes the lock' ); my $second = eval { take_build_lock($devel, $lockdir) }; ok( !$second, 'a second build of the SAME checkout is refused' ); -like( $@, qr/already holds/, 'and says which checkout is already building' ); +my $refusal = $@ // ''; +like( $refusal, qr/another build still holds/, 'and reports contention' ); +like( $refusal, qr/still held after [0-9]+ retr\w+ by pid $$\b/, + 'and names the pid holding it, so contention is told from any other failure' ); +like( $refusal, qr/\Q$devel\E/, 'and names the checkout that is already building' ); # Different checkout: must not be blocked by the first. my $stable = eval { take_build_lock('/opt/builds/stable/xcat-core', $lockdir) }; diff --git a/xCAT-test/unit/builddebs_lock_cancellation.t b/xCAT-test/unit/builddebs_lock_cancellation.t index 37d9de5251..ffdd6a98b7 100644 --- a/xCAT-test/unit/builddebs_lock_cancellation.t +++ b/xCAT-test/unit/builddebs_lock_cancellation.t @@ -4,7 +4,8 @@ # The build lock is released in DESTROY, and perl does not run DESTROY when a signal ends the # process. So a cancelled build left its lock directory behind, and the next build of that # checkout died on -# FATAL: another build of already holds (held by [pid=NNNN]) +# FATAL: cannot take the build lock for +# another build still holds # naming a pid that had already exited. One such directory blocked an openSUSE target across # three consecutive runs before anyone looked at it. # @@ -36,7 +37,10 @@ my $ckout = tempdir(CLEANUP => 1); ok(-d $path, 'the lock directory exists while it is held'); my $second = eval { XCAT::BuildUtils::take_build_lock($ckout, $lockdir) }; ok(!$second, 'a second build of the same checkout is refused'); - like($@, qr/already holds/, 'and told which lock is held'); + my $refusal = $@ // ''; + like($refusal, qr/another build still holds/, 'and reported contention'); + like($refusal, qr/still held after [0-9]+ retr\w+ by pid $$\b/, + 'naming the pid that holds it, not the same sentence for every failure'); undef $l; ok(!-d $path, 'releasing it removes the directory'); }