Skip to content

Commit 505b20e

Browse files
yuwatabluca
authored andcommitted
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.
1 parent ce2aade commit 505b20e

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

test/units/TEST-17-UDEV.02.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ EOF
174174
test -n "$found"
175175

176176
journalctl --sync
177-
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"
177+
set +o pipefail
178+
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'
179+
set -o pipefail
178180
# check if the invalid SYSTEMD_ALIAS property for the interface foobar is ignored by PID1
179181
assert_eq "$(systemctl show --property=SysFSPath --value /sys/subsystem/net/devices/hoge)" "/sys/devices/virtual/net/hoge"
180182
}

test/units/TEST-35-LOGIN.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ EOF
524524
# become idle again. 'Lock' signal is sent out for each session, we have at
525525
# least one session, so minimum of 2 "Lock" signals must have been sent.
526526
journalctl --sync
527-
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"
527+
set +o pipefail
528+
timeout -v 35 journalctl -b -u systemd-logind.service --since="$ts" -n all --follow | grep -m 1 -q 'Sent message type=signal .* member=Lock'
529+
set -o pipefail
528530

529531
# We need to know that a new message was sent after waking up,
530532
# so we must track how many happened before sleeping to check we have extra.
@@ -535,12 +537,10 @@ EOF
535537

536538
# Wait again
537539
journalctl --sync
538-
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"
539-
540-
if [[ "$(journalctl -b -u systemd-logind.service --since="$ts" | grep -c 'System idle. Will be locked now.')" -lt 2 ]]; then
541-
echo >&2 "System haven't entered idle state at least 2 times."
542-
exit 1
543-
fi
540+
set +o pipefail
541+
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'
542+
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.'
543+
set -o pipefail
544544
}
545545

546546
testcase_session_properties() {

test/units/TEST-50-DISSECT.dissect.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,9 @@ systemd-sysext merge --no-reload
723723
systemd-sysext unmerge --no-reload
724724
systemd-sysext merge
725725
journalctl --sync
726-
# shellcheck disable=SC2016
727-
timeout 30s bash -xec 'until [[ $(journalctl -b -u foo.service _TRANSPORT=stdout -o cat) == foo ]]; do sleep 1; journalctl --sync; done'
726+
set +o pipefail
727+
timeout -v 30s journalctl -b -u foo.service _TRANSPORT=stdout -o cat -n all --follow | grep -m 1 -q '^foo$'
728+
set -o pipefail
728729
systemd-sysext unmerge --no-reload
729730
# Grep on the Warning to find the warning helper mentioning the daemon reload.
730731
systemctl status foo.service 2>&1 | grep -q -F "Warning"

test/units/TEST-60-MOUNT-RATELIMIT.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ done
294294

295295
# Figure out if we have entered the rate limit state.
296296
# If the infra is slow we might not enter the rate limit state; in that case skip the exit check.
297+
set +o pipefail
297298
journalctl --sync
298-
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
299+
if timeout 2m journalctl -u init.scope --since="$TS" -n all --follow | grep -m 1 -q -F '(mount-monitor-dispatch) entered rate limit'; then
299300
journalctl --sync
300-
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"
301+
timeout 2m journalctl -u init.scope --since="$TS" -n all --follow | grep -m 1 -q -F '(mount-monitor-dispatch) left rate limit'
301302
fi
303+
set -o pipefail
302304

303305
# Verify that the mount units are always cleaned up at the end.
304306
# Give some time for units to settle so we don't race between exiting the rate limit state and cleaning up the units.

0 commit comments

Comments
 (0)