machine: resolve race condition in TEST-13-NSPAWN.machinectl.sh
authorIvan Kruglov <mail@ikruglov.com>
Fri, 20 Sep 2024 10:20:53 +0000 (12:20 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 8 Oct 2024 15:39:12 +0000 (16:39 +0100)
I encountered this race condition while working on TEST-13-NSPAWN.varlinkctl.sh.
The long-running machine's init script sometimes does not have time to start and
register signals. As result, occasiounally failed tests.

(cherry picked from commit e826a8bed447f3b3f9ad487f96ab7f8c7620c75b)

test/units/TEST-13-NSPAWN.machinectl.sh

index 462cc6a8c33d55b75f854ac6aae70030ccbf1a21..595809e131fe7591fb75dc8db4deb7ddffc7e769 100755 (executable)
@@ -47,12 +47,21 @@ trap 'kill $PID' EXIT
 # We need to wait for the sleep process asynchronously in order to allow
 # bash to process signals
 sleep infinity &
+
+# notify that the process is ready
+touch /ready
+
 PID=$!
 while :; do
     wait || :
 done
 EOF
+
+rm -f /var/lib/machines/long-running/ready
 machinectl start long-running
+# !!!! DO NOT REMOVE THIS TEST
+# The test makes sure that the long-running's init script has enough time to start and registered signal traps
+timeout 10 bash -c "until test -e /var/lib/machines/long-running/ready; do sleep .5; done"
 
 machinectl
 machinectl --no-pager --help