]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
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)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 25 Sep 2024 10:23:12 +0000 (12:23 +0200)
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.

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

index 7ff953bae9e78a4a7d3e823ad23710c7b62de04e..0b0f90fb8fdbb6be21dbf2f09054944736371e5b 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