mirror of
https://github.com/systemd/systemd
synced 2025-10-06 00:13:24 +02:00
test: use 'until' instead of 'while !'
In general, it's better to avoid a negation. And "!" is special, because it is
used for history expansion, i.e. the same command would behave differently if
pasted on the command line.
Inspired by 4a899c5a23
.
This commit is contained in:
committed by
Luca Boccassi
parent
8b7f0eb6a8
commit
1c5d54b2df
@@ -30,7 +30,7 @@ create_container() {
|
||||
sudo lxc-attach -n "$CONTAINER" -- sh -ex <<EOF
|
||||
sed 's/^deb/deb-src/' /etc/apt/sources.list >>/etc/apt/sources.list.d/sources.list
|
||||
# We might attach the console too soon
|
||||
while ! systemctl --quiet --wait is-system-running; do sleep 1; done
|
||||
until systemctl --quiet --wait is-system-running; do sleep 1; done
|
||||
# Manpages database trigger takes a lot of time and is not useful in a CI
|
||||
echo 'man-db man-db/auto-update boolean false' | debconf-set-selections
|
||||
# Speed up dpkg, image is thrown away after the test
|
||||
|
@@ -10,4 +10,4 @@ PrivateTmp=yes
|
||||
BindPaths=/run/testsuite-23-marker-fixed:/tmp/testfile-marker-fixed
|
||||
InaccessiblePaths=/run/inaccessible
|
||||
ExecStartPre=grep -q -F MARKER_FIXED /tmp/testfile-marker-fixed
|
||||
ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile-marker-fixed'
|
||||
ExecStart=/bin/sh -c 'systemd-notify --ready; until grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; test ! -f /run/inaccessible/testfile-marker-fixed'
|
||||
|
@@ -3,4 +3,4 @@
|
||||
RuntimeMaxSec=5
|
||||
Type=notify
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/bin/sh -c 'systemd-notify --ready; while ! grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; exit 0'
|
||||
ExecStart=/bin/sh -c 'systemd-notify --ready; until grep -q -F MARKER_RUNTIME /tmp/testfile-marker-runtime; do sleep 0.1; done; exit 0'
|
||||
|
@@ -16,7 +16,7 @@ systemctl daemon-reexec
|
||||
systemctl start --no-block hello-after-sleep.target
|
||||
|
||||
systemctl list-jobs >/root/list-jobs.txt
|
||||
while ! grep 'sleep\.service.*running' /root/list-jobs.txt; do
|
||||
until grep 'sleep\.service.*running' /root/list-jobs.txt; do
|
||||
systemctl list-jobs >/root/list-jobs.txt
|
||||
done
|
||||
|
||||
|
@@ -19,7 +19,7 @@ EOF
|
||||
ID="$(systemd-id128 new)"
|
||||
systemd-cat -t "$ID" /bin/bash -c "for ((i=0;i<100;i++)); do echo -n hoge with ${c}; done; echo"
|
||||
journalctl --sync
|
||||
timeout 10 bash -c "while ! SYSTEMD_LOG_LEVEL=debug journalctl --verify --quiet --file /var/log/journal/$MACHINE_ID/system.journal 2>&1 | grep -q -F 'compress=${c}'; do sleep .5; done"
|
||||
timeout 10 bash -c "until SYSTEMD_LOG_LEVEL=debug journalctl --verify --quiet --file /var/log/journal/$MACHINE_ID/system.journal 2>&1 | grep -q -F 'compress=${c}'; do sleep .5; done"
|
||||
|
||||
# $SYSTEMD_JOURNAL_COMPRESS= also works for journal-remote
|
||||
if [[ -x /usr/lib/systemd/systemd-journal-remote ]]; then
|
||||
|
@@ -81,11 +81,11 @@ systemd-analyze cat-config systemd/journal-upload.conf
|
||||
|
||||
systemctl restart systemd-journal-remote.socket
|
||||
systemctl restart systemd-journal-upload
|
||||
timeout 15 bash -xec 'while ! systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
|
||||
timeout 15 bash -xec 'until systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
|
||||
systemctl status systemd-journal-{remote,upload}
|
||||
|
||||
# It may take a bit until the whole journal is transferred
|
||||
timeout 30 bash -xec "while ! journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
|
||||
timeout 30 bash -xec "until journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
|
||||
|
||||
systemctl stop systemd-journal-upload
|
||||
systemctl stop systemd-journal-remote.{socket,service}
|
||||
@@ -184,11 +184,11 @@ systemd-analyze cat-config systemd/journal-upload.conf
|
||||
|
||||
systemctl restart systemd-journal-remote.socket
|
||||
systemctl restart systemd-journal-upload
|
||||
timeout 15 bash -xec 'while ! systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
|
||||
timeout 15 bash -xec 'until systemctl -q is-active systemd-journal-remote.service; do sleep 1; done'
|
||||
systemctl status systemd-journal-{remote,upload}
|
||||
|
||||
# It may take a bit until the whole journal is transferred
|
||||
timeout 30 bash -xec "while ! journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
|
||||
timeout 30 bash -xec "until journalctl --directory=/var/log/journal/remote --identifier='$TEST_TAG' --grep='$TEST_MESSAGE'; do sleep 1; done"
|
||||
|
||||
systemctl stop systemd-journal-upload
|
||||
systemctl stop systemd-journal-remote.{socket,service}
|
||||
|
@@ -207,9 +207,9 @@ ID="$(systemd-id128 new)"
|
||||
journalctl -t "$ID" --follow --cursor-file=/tmp/issue-26746-cursor | tee /tmp/issue-26746-log &
|
||||
systemd-cat -t "$ID" /bin/sh -c 'echo hogehoge'
|
||||
# shellcheck disable=SC2016
|
||||
timeout 10 bash -c 'while ! [[ -f /tmp/issue-26746-log && "$(cat /tmp/issue-26746-log)" =~ hogehoge ]]; do sleep .5; done'
|
||||
timeout 10 bash -c 'until [[ -f /tmp/issue-26746-log && "$(cat /tmp/issue-26746-log)" =~ hogehoge ]]; do sleep .5; done'
|
||||
pkill -TERM journalctl
|
||||
timeout 10 bash -c 'while ! test -f /tmp/issue-26746-cursor; do sleep .5; done'
|
||||
timeout 10 bash -c 'until test -f /tmp/issue-26746-cursor; do sleep .5; done'
|
||||
CURSOR_FROM_FILE="$(cat /tmp/issue-26746-cursor)"
|
||||
CURSOR_FROM_JOURNAL="$(journalctl -t "$ID" --output=export MESSAGE=hogehoge | sed -n -e '/__CURSOR=/ { s/__CURSOR=//; p }')"
|
||||
test "$CURSOR_FROM_FILE" = "$CURSOR_FROM_JOURNAL"
|
||||
|
@@ -13,5 +13,5 @@ nc -i20 -w20 -U /run/test.ctl || :
|
||||
# TriggerLimitIntervalSec= by default is set to 2s. A "sleep 10" should give
|
||||
# systemd enough time even on slower machines, to reach the trigger limit.
|
||||
# shellcheck disable=SC2016
|
||||
timeout 10 bash -c 'while ! [[ "$(systemctl show issue2467.socket -P ActiveState)" == failed ]]; do sleep .5; done'
|
||||
timeout 10 bash -c 'until [[ "$(systemctl show issue2467.socket -P ActiveState)" == failed ]]; do sleep .5; done'
|
||||
[[ "$(systemctl show issue2467.socket -P Result)" == trigger-limit-hit ]]
|
||||
|
@@ -13,7 +13,7 @@ at_exit() {
|
||||
set +e
|
||||
|
||||
machinectl status long-running >/dev/null && machinectl kill --signal=KILL long-running
|
||||
mountpoint -q /var/lib/machines && timeout 10 sh -c "while ! umount /var/lib/machines; do sleep .5; done"
|
||||
mountpoint -q /var/lib/machines && timeout 10 sh -c "until umount /var/lib/machines; do sleep .5; done"
|
||||
[[ -n "${NSPAWN_FRAGMENT:-}" ]] && rm -f "/etc/systemd/nspawn/$NSPAWN_FRAGMENT" "/var/lib/machines/$NSPAWN_FRAGMENT"
|
||||
rm -f /run/systemd/nspawn/*.nspawn
|
||||
}
|
||||
@@ -90,15 +90,15 @@ machinectl disable long-running long-running long-running container1
|
||||
# Equivalent to machinectl kill --signal=SIGRTMIN+4 --kill-whom=leader
|
||||
rm -f /var/lib/machines/long-running/poweroff
|
||||
machinectl poweroff long-running
|
||||
timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/poweroff; do sleep .5; done"
|
||||
timeout 10 bash -c "until test -e /var/lib/machines/long-running/poweroff; do sleep .5; done"
|
||||
# Equivalent to machinectl kill --signal=SIGINT --kill-whom=leader
|
||||
rm -f /var/lib/machines/long-running/reboot
|
||||
machinectl reboot long-running
|
||||
timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/reboot; do sleep .5; done"
|
||||
timeout 10 bash -c "until test -e /var/lib/machines/long-running/reboot; do sleep .5; done"
|
||||
# Skip machinectl terminate for now, as it doesn't play well with our "init"
|
||||
rm -f /var/lib/machines/long-running/trap
|
||||
machinectl kill --signal=SIGTRAP --kill-whom=leader long-running
|
||||
timeout 10 bash -c "while ! test -e /var/lib/machines/long-running/trap; do sleep .5; done"
|
||||
timeout 10 bash -c "until test -e /var/lib/machines/long-running/trap; do sleep .5; done"
|
||||
# Multiple machines at once
|
||||
machinectl poweroff long-running long-running long-running
|
||||
machinectl reboot long-running long-running long-running
|
||||
@@ -183,7 +183,7 @@ machinectl import-fs /tmp/container.dir container-dir
|
||||
machinectl start container-dir
|
||||
rm -fr /tmp/container.dir
|
||||
|
||||
timeout 10 bash -c "while ! machinectl clean --all; do sleep .5; done"
|
||||
timeout 10 bash -c "until machinectl clean --all; do sleep .5; done"
|
||||
|
||||
NSPAWN_FRAGMENT="machinectl-test-$RANDOM.nspawn"
|
||||
cat >"/var/lib/machines/$NSPAWN_FRAGMENT" <<EOF
|
||||
|
@@ -11,7 +11,7 @@ at_exit() {
|
||||
set +e
|
||||
|
||||
machinectl kill --signal=KILL nss-mymachines-{noip,singleip,manyips}
|
||||
mountpoint -q /var/lib/machines && timeout 10 sh -c "while ! umount /var/lib/machines; do sleep .5; done"
|
||||
mountpoint -q /var/lib/machines && timeout 10 sh -c "until umount /var/lib/machines; do sleep .5; done"
|
||||
rm -f /run/systemd/nspawn/*.nspawn
|
||||
}
|
||||
|
||||
|
@@ -172,7 +172,7 @@ EOF
|
||||
done
|
||||
test -n "$found"
|
||||
|
||||
timeout 30 bash -c "while ! journalctl _PID=1 _COMM=systemd --since $since | grep -q 'foobar: systemd-udevd failed to process the device, ignoring: File exists'; do sleep 1; done"
|
||||
timeout 30 bash -c "until journalctl _PID=1 _COMM=systemd --since $since | grep -q 'foobar: systemd-udevd failed to process the device, ignoring: File exists'; do sleep 1; done"
|
||||
# check if the invalid SYSTEMD_ALIAS property for the interface foobar is ignored by PID1
|
||||
assert_eq "$(systemctl show --property=SysFSPath --value /sys/subsystem/net/devices/hoge)" "/sys/devices/virtual/net/hoge"
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ rm -f /tmp/testsuite-23-retry-fail
|
||||
systemctl start testsuite-23-retry-uphold.service
|
||||
systemctl is-active testsuite-23-upheldby-install.service
|
||||
|
||||
while ! systemctl is-failed testsuite-23-retry-fail.service ; do
|
||||
until systemctl is-failed testsuite-23-retry-fail.service ; do
|
||||
sleep .5
|
||||
done
|
||||
|
||||
@@ -54,7 +54,7 @@ done
|
||||
|
||||
touch /tmp/testsuite-23-retry-fail
|
||||
|
||||
while ! systemctl is-active testsuite-23-retry-upheld.service ; do
|
||||
until systemctl is-active testsuite-23-retry-upheld.service ; do
|
||||
sleep .5
|
||||
done
|
||||
|
||||
|
@@ -171,7 +171,7 @@ EOF
|
||||
|
||||
evemu-device /run/lidswitch.evemu &
|
||||
|
||||
timeout 20 bash -c 'while ! grep "^Fake Lid Switch" /sys/class/input/*/device/name; do sleep .5; done'
|
||||
timeout 20 bash -c 'until grep "^Fake Lid Switch" /sys/class/input/*/device/name; do sleep .5; done'
|
||||
input_name=$(grep -l '^Fake Lid Switch' /sys/class/input/*/device/name || :)
|
||||
if [[ -z "$input_name" ]]; then
|
||||
echo "cannot find fake lid switch." >&2
|
||||
@@ -418,7 +418,7 @@ EOF
|
||||
# coldplug: logind started with existing device
|
||||
systemctl stop systemd-logind.service
|
||||
modprobe scsi_debug
|
||||
timeout 30 bash -c 'while ! ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
|
||||
timeout 30 bash -c 'until ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
|
||||
dev=/dev/$(ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null)
|
||||
if [[ ! -b "$dev" ]]; then
|
||||
echo "cannot find suitable scsi block device" >&2
|
||||
@@ -437,7 +437,7 @@ EOF
|
||||
# hotplug: new device appears while logind is running
|
||||
rmmod scsi_debug
|
||||
modprobe scsi_debug
|
||||
timeout 30 bash -c 'while ! ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
|
||||
timeout 30 bash -c 'until ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null; do sleep 1; done'
|
||||
dev=/dev/$(ls /sys/bus/pseudo/drivers/scsi_debug/adapter*/host*/target*/*:*/block 2>/dev/null)
|
||||
if [[ ! -b "$dev" ]]; then
|
||||
echo "cannot find suitable scsi block device" >&2
|
||||
|
@@ -38,7 +38,7 @@ startStrace() {
|
||||
coproc strace -qq -p 1 -o "$straceLog" -e set_mempolicy -s 1024 ${1:+"$1"}
|
||||
# Wait for strace to properly "initialize", i.e. until PID 1 has the TracerPid
|
||||
# field set to the current strace's PID
|
||||
while ! awk -v spid="$COPROC_PID" '/^TracerPid:/ {exit !($2 == spid);}' /proc/1/status; do sleep 0.1; done
|
||||
until awk -v spid="$COPROC_PID" '/^TracerPid:/ {exit !($2 == spid);}' /proc/1/status; do sleep 0.1; done
|
||||
}
|
||||
|
||||
stopStrace() {
|
||||
|
@@ -549,7 +549,7 @@ systemd-run --unit=test-root-ephemeral \
|
||||
test -n "$(ls -A /var/lib/systemd/ephemeral-trees)"
|
||||
systemctl stop test-root-ephemeral
|
||||
# shellcheck disable=SC2016
|
||||
timeout 10 bash -c 'while ! test -z "$(ls -A /var/lib/systemd/ephemeral-trees)"; do sleep .5; done'
|
||||
timeout 10 bash -c 'until test -z "$(ls -A /var/lib/systemd/ephemeral-trees)"; do sleep .5; done'
|
||||
test ! -f /tmp/img/abc
|
||||
|
||||
systemd-dissect --mtree /tmp/img
|
||||
|
@@ -286,8 +286,8 @@ done
|
||||
|
||||
# Figure out if we have entered the rate limit state.
|
||||
# If the infra is slow we might not enter the rate limit state; in that case skip the exit check.
|
||||
if timeout 2m bash -c "while ! journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) entered rate limit'; do sleep 1; done"; then
|
||||
timeout 2m bash -c "while ! journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) left rate limit'; do sleep 1; done"
|
||||
if timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) entered rate limit'; do sleep 1; done"; then
|
||||
timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) left rate limit'; do sleep 1; done"
|
||||
fi
|
||||
|
||||
# Verify that the mount units are always cleaned up at the end.
|
||||
|
@@ -16,7 +16,7 @@ touch /tmp/test63
|
||||
|
||||
# Make sure systemd has sufficient time to hit the trigger limit for test63.path.
|
||||
# shellcheck disable=SC2016
|
||||
timeout 30 bash -c 'while ! test "$(systemctl show test63.path -P ActiveState)" = failed; do sleep .2; done'
|
||||
timeout 30 bash -c 'until test "$(systemctl show test63.path -P ActiveState)" = failed; do sleep .2; done'
|
||||
test "$(systemctl show test63.service -P ActiveState)" = inactive
|
||||
test "$(systemctl show test63.service -P Result)" = success
|
||||
test "$(systemctl show test63.path -P Result)" = trigger-limit-hit
|
||||
@@ -34,7 +34,7 @@ test "$(systemctl show test63.path -P Result)" = success
|
||||
# Test that glob matching works too, with $TRIGGER_PATH
|
||||
systemctl start test63-glob.path
|
||||
touch /tmp/test63-glob-foo
|
||||
timeout 60 bash -c 'while ! systemctl -q is-active test63-glob.service; do sleep .2; done'
|
||||
timeout 60 bash -c 'until systemctl -q is-active test63-glob.service; do sleep .2; done'
|
||||
test "$(systemctl show test63-glob.service -P ActiveState)" = active
|
||||
test "$(systemctl show test63-glob.service -P Result)" = success
|
||||
|
||||
|
@@ -546,7 +546,7 @@ testcase_lvm_basic() {
|
||||
# Mount mypart1 through by-label devlink
|
||||
mkdir -p /tmp/mypart1-mount-point
|
||||
mount /dev/disk/by-label/mylvpart1 /tmp/mypart1-mount-point
|
||||
timeout 30 bash -c "while ! systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
|
||||
timeout 30 bash -c "until systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
|
||||
# Extend the partition and check if the device and mount units are still active.
|
||||
# See https://bugzilla.redhat.com/show_bug.cgi?id=2158628
|
||||
# Note, the test below may be unstable with LVM2 without the following patch:
|
||||
@@ -556,8 +556,8 @@ testcase_lvm_basic() {
|
||||
# is hopefully fast.
|
||||
lvm lvextend -y --size 8M "/dev/$vgroup/mypart1"
|
||||
udevadm wait --settle --timeout="$timeout" "/dev/disk/by-label/mylvpart1"
|
||||
timeout 30 bash -c "while ! systemctl -q is-active '/dev/$vgroup/mypart1'; do sleep .2; done"
|
||||
timeout 30 bash -c "while ! systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
|
||||
timeout 30 bash -c "until systemctl -q is-active '/dev/$vgroup/mypart1'; do sleep .2; done"
|
||||
timeout 30 bash -c "until systemctl -q is-active /tmp/mypart1-mount-point; do sleep .2; done"
|
||||
# Umount the partition, otherwise the underlying device unit will stay in
|
||||
# the inactive state and not be collected, and helper_check_device_units() will fail.
|
||||
systemctl show /tmp/mypart1-mount-point
|
||||
@@ -956,7 +956,7 @@ testcase_long_sysfs_path() {
|
||||
echo "UUID=deadbeef-dead-dead-beef-222222222222 $mpoint ext4 defaults 0 0" >>/etc/fstab
|
||||
systemctl daemon-reload
|
||||
mount "$mpoint"
|
||||
timeout 30 bash -c "while ! systemctl -q is-active '$mpoint'; do sleep .2; done"
|
||||
timeout 30 bash -c "until systemctl -q is-active '$mpoint'; do sleep .2; done"
|
||||
test -e "$mpoint/test"
|
||||
umount "$mpoint"
|
||||
|
||||
|
Reference in New Issue
Block a user