From 505b20ecddc089780404278333bbdfd6176cb203 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 22 May 2024 12:26:58 +0900 Subject: [PATCH] test: replace journal checkers with journalctl --follow + grep -m Recently, for slow test environments, journalctl --sync was added to the loop in the timeout. However, journalctl --sync may be slow in such systems, and timeout easily triggered during syncing. Hopefully, reading journal with --follow and grep the output with an expected line should be efficient. Hopefully fixes #32712. --- test/units/TEST-17-UDEV.02.sh | 4 +++- test/units/TEST-35-LOGIN.sh | 14 +++++++------- test/units/TEST-50-DISSECT.dissect.sh | 5 +++-- test/units/TEST-60-MOUNT-RATELIMIT.sh | 6 ++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/test/units/TEST-17-UDEV.02.sh b/test/units/TEST-17-UDEV.02.sh index ee1995ad085..96430e64ae9 100755 --- a/test/units/TEST-17-UDEV.02.sh +++ b/test/units/TEST-17-UDEV.02.sh @@ -174,7 +174,9 @@ EOF test -n "$found" journalctl --sync - 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; journalctl --sync; done" + set +o pipefail + timeout -v 30 journalctl _PID=1 _COMM=systemd --since "$since" -n all --follow | grep -m 1 -q -F 'foobar: systemd-udevd failed to process the device, ignoring: File exists' + set -o pipefail # 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" } diff --git a/test/units/TEST-35-LOGIN.sh b/test/units/TEST-35-LOGIN.sh index 890a0290dd3..78e0c1e326b 100755 --- a/test/units/TEST-35-LOGIN.sh +++ b/test/units/TEST-35-LOGIN.sh @@ -524,7 +524,9 @@ EOF # become idle again. 'Lock' signal is sent out for each session, we have at # least one session, so minimum of 2 "Lock" signals must have been sent. journalctl --sync - timeout 35 bash -c "while [[ \"\$(journalctl -b -u systemd-logind.service --since=$ts | grep -c 'Sent message type=signal .* member=Lock')\" -lt 1 ]]; do sleep 1; journalctl --sync; done" + set +o pipefail + timeout -v 35 journalctl -b -u systemd-logind.service --since="$ts" -n all --follow | grep -m 1 -q 'Sent message type=signal .* member=Lock' + set -o pipefail # We need to know that a new message was sent after waking up, # so we must track how many happened before sleeping to check we have extra. @@ -535,12 +537,10 @@ EOF # Wait again journalctl --sync - timeout 35 bash -c "while [[ \"\$(journalctl -b -u systemd-logind.service --since=$ts | grep -c 'Sent message type=signal .* member=Lock')\" -lt $((locks + 1)) ]]; do sleep 1; journalctl --sync; done" - - if [[ "$(journalctl -b -u systemd-logind.service --since="$ts" | grep -c 'System idle. Will be locked now.')" -lt 2 ]]; then - echo >&2 "System haven't entered idle state at least 2 times." - exit 1 - fi + set +o pipefail + timeout -v 35 journalctl -b -u systemd-logind.service --since="$ts" -n all --follow | grep -m "$((locks + 1))" -q 'Sent message type=signal .* member=Lock' + timeout -v 35 journalctl -b -u systemd-logind.service --since="$ts" -n all --follow | grep -m 2 -q -F 'System idle. Will be locked now.' + set -o pipefail } testcase_session_properties() { diff --git a/test/units/TEST-50-DISSECT.dissect.sh b/test/units/TEST-50-DISSECT.dissect.sh index c3260429aba..4eeca3a2676 100755 --- a/test/units/TEST-50-DISSECT.dissect.sh +++ b/test/units/TEST-50-DISSECT.dissect.sh @@ -723,8 +723,9 @@ systemd-sysext merge --no-reload systemd-sysext unmerge --no-reload systemd-sysext merge journalctl --sync -# shellcheck disable=SC2016 -timeout 30s bash -xec 'until [[ $(journalctl -b -u foo.service _TRANSPORT=stdout -o cat) == foo ]]; do sleep 1; journalctl --sync; done' +set +o pipefail +timeout -v 30s journalctl -b -u foo.service _TRANSPORT=stdout -o cat -n all --follow | grep -m 1 -q '^foo$' +set -o pipefail systemd-sysext unmerge --no-reload # Grep on the Warning to find the warning helper mentioning the daemon reload. systemctl status foo.service 2>&1 | grep -q -F "Warning" diff --git a/test/units/TEST-60-MOUNT-RATELIMIT.sh b/test/units/TEST-60-MOUNT-RATELIMIT.sh index 440b8d457d5..a0e99dc40f0 100755 --- a/test/units/TEST-60-MOUNT-RATELIMIT.sh +++ b/test/units/TEST-60-MOUNT-RATELIMIT.sh @@ -294,11 +294,13 @@ 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. +set +o pipefail journalctl --sync -if timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) entered rate limit'; do sleep 1; journalctl --sync; done"; then +if timeout 2m journalctl -u init.scope --since="$TS" -n all --follow | grep -m 1 -q -F '(mount-monitor-dispatch) entered rate limit'; then journalctl --sync - timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) left rate limit'; do sleep 1; journalctl --sync; done" + timeout 2m journalctl -u init.scope --since="$TS" -n all --follow | grep -m 1 -q -F '(mount-monitor-dispatch) left rate limit' fi +set -o pipefail # Verify that the mount units are always cleaned up at the end. # Give some time for units to settle so we don't race between exiting the rate limit state and cleaning up the units. -- 2.47.3