From: Yu Watanabe Date: Tue, 29 Jul 2025 02:07:35 +0000 (+0900) Subject: TEST-03-JOBS: modernize test code and extend timeout X-Git-Tag: v258-rc2~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=065941a92c81dde6706215cb3390b90fc06ff2ce;p=thirdparty%2Fsystemd.git TEST-03-JOBS: modernize test code and extend timeout - use timeout command more, - use `(! cmd)` rather than `cmd && exit 1`, - drop unnecessary `|| exit 1`, - extend timeout to support slow test environment. Fixes #38395. --- diff --git a/test/units/TEST-03-JOBS.sh b/test/units/TEST-03-JOBS.sh index 183439e913b..719c16b986a 100755 --- a/test/units/TEST-03-JOBS.sh +++ b/test/units/TEST-03-JOBS.sh @@ -17,25 +17,16 @@ systemctl daemon-reexec systemctl start --no-block hello-after-sleep.target -systemctl list-jobs >/root/list-jobs.txt -until grep 'sleep\.service.*running' /root/list-jobs.txt; do - systemctl list-jobs >/root/list-jobs.txt -done - +timeout 10 bash -c "until systemctl list-jobs | tee /root/list-jobs.txt | grep 'sleep\.service.*running'; do sleep .1; done" grep 'hello\.service.*waiting' /root/list-jobs.txt # This is supposed to finish quickly, not wait for sleep to finish. -START_SEC=$(date -u '+%s') -systemctl start --job-mode=ignore-dependencies hello -END_SEC=$(date -u '+%s') -ELAPSED=$((END_SEC-START_SEC)) - -test "$ELAPSED" -lt 3 +timeout 10 systemctl start --job-mode=ignore-dependencies hello # sleep should still be running, hello not. systemctl list-jobs >/root/list-jobs.txt grep 'sleep\.service.*running' /root/list-jobs.txt -grep 'hello\.service' /root/list-jobs.txt && exit 1 +(! grep 'hello\.service' /root/list-jobs.txt) systemctl stop sleep.service hello-after-sleep.target # Some basic testing that --show-transaction does something useful @@ -62,13 +53,13 @@ ACTIVATING_ID_PRE=$(systemctl show -P InvocationID always-activating.service) systemctl -T start always-activating.socket # Wait for the socket to come up systemctl -T restart always-activating.socket ACTIVATING_ID_POST=$(systemctl show -P InvocationID always-activating.service) -[ "$ACTIVATING_ID_PRE" != "$ACTIVATING_ID_POST" ] || exit 1 +[[ "$ACTIVATING_ID_PRE" != "$ACTIVATING_ID_POST" ]] # Test for irreversible jobs systemctl start unstoppable.service # This is expected to fail with 'job cancelled' -systemctl stop unstoppable.service && exit 1 +(! systemctl stop unstoppable.service) # But this should succeed systemctl stop --job-mode=replace-irreversibly unstoppable.service @@ -93,27 +84,28 @@ EOF # wait2 succeeds START_SEC=$(date -u '+%s') -systemctl start --wait wait2.service +timeout 10 systemctl start --wait wait2.service END_SEC=$(date -u '+%s') ELAPSED=$((END_SEC-START_SEC)) -[[ "$ELAPSED" -ge 2 ]] && [[ "$ELAPSED" -le 4 ]] || exit 1 +[[ "$ELAPSED" -ge 2 ]] # wait5fail fails, so systemctl should fail START_SEC=$(date -u '+%s') (! systemctl start --wait wait2.service wait5fail.service) END_SEC=$(date -u '+%s') ELAPSED=$((END_SEC-START_SEC)) -[[ "$ELAPSED" -ge 5 ]] && [[ "$ELAPSED" -le 7 ]] || exit 1 +[[ "$ELAPSED" -ge 5 ]] # Test time-limited scopes START_SEC=$(date -u '+%s') set +e -systemd-run --scope --property=RuntimeMaxSec=3s sleep 10 +systemd-run --scope --property=RuntimeMaxSec=3s sleep 30 RESULT=$? END_SEC=$(date -u '+%s') ELAPSED=$((END_SEC-START_SEC)) -[[ "$ELAPSED" -ge 3 ]] && [[ "$ELAPSED" -le 5 ]] || exit 1 -[[ "$RESULT" -ne 0 ]] || exit 1 +[[ "$ELAPSED" -ge 3 ]] +[[ "$ELAPSED" -le 10 ]] +[[ "$RESULT" -ne 0 ]] # Test transactions with cycles # Provides coverage for issues like https://github.com/systemd/systemd/issues/26872