From 123acb25605f904c9a52c67f00dfff2b299a7a58 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 21 May 2024 01:53:02 +0900 Subject: [PATCH 1/2] test: call journalctl --sync just before reading journals Otherwise, journal entries comes during sleep may not be read. Follow-up for c22a112883a46e302dae587b809c459647363ceb. --- test/units/TEST-60-MOUNT-RATELIMIT.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/units/TEST-60-MOUNT-RATELIMIT.sh b/test/units/TEST-60-MOUNT-RATELIMIT.sh index 77663c0fa2..440b8d457d 100755 --- a/test/units/TEST-60-MOUNT-RATELIMIT.sh +++ b/test/units/TEST-60-MOUNT-RATELIMIT.sh @@ -295,9 +295,9 @@ 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. journalctl --sync -if timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) entered rate limit'; do journalctl --sync; sleep 1; done"; then +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 journalctl --sync - timeout 2m bash -c "until journalctl -u init.scope --since=$TS | grep -q '(mount-monitor-dispatch) left rate limit'; do journalctl --sync; sleep 1; done" + 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" fi # Verify that the mount units are always cleaned up at the end. From 702fdd313508354ab7050b6c2b81642d5206a671 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 21 May 2024 01:54:35 +0900 Subject: [PATCH 2/2] test: sync journal before read Similar to recent commits, e.g. f961f0e47c2caf9af735a22e7f23210e746d0c8b. Fixes #32926. --- test/units/TEST-17-UDEV.02.sh | 4 +++- test/units/TEST-35-LOGIN.sh | 10 ++++++++-- test/units/TEST-50-DISSECT.dissect.sh | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/units/TEST-17-UDEV.02.sh b/test/units/TEST-17-UDEV.02.sh index b232fca668..ee1995ad08 100755 --- a/test/units/TEST-17-UDEV.02.sh +++ b/test/units/TEST-17-UDEV.02.sh @@ -145,6 +145,7 @@ EOF # make sure that 'udevadm monitor' actually monitor uevents sleep 1 + journalctl --sync since="$(date '+%H:%M:%S')" # add another interface which will conflict with an existing interface @@ -172,7 +173,8 @@ EOF done test -n "$found" - 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" + 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" # 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 1ad06526e6..890a0290dd 100755 --- a/test/units/TEST-35-LOGIN.sh +++ b/test/units/TEST-35-LOGIN.sh @@ -507,6 +507,7 @@ testcase_lock_idle_action() { create_session + journalctl --sync ts="$(date '+%H:%M:%S')" mkdir -p /run/systemd/logind.conf.d @@ -522,7 +523,8 @@ EOF # session active again and next we slept for another 35s so sessions have # 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. - 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; done" + 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" # 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. @@ -532,7 +534,8 @@ EOF touch /dev/tty2 # Wait again - 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; done" + 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." @@ -620,6 +623,8 @@ testcase_stop_idle_session() { trap teardown_stop_idle_session RETURN id="$(loginctl --no-legend | grep tty | awk '$3 == "logind-test-user" { print $1; }')" + + journalctl --sync ts="$(date '+%H:%M:%S')" mkdir -p /run/systemd/logind.conf.d @@ -630,6 +635,7 @@ EOF systemctl restart systemd-logind.service sleep 5 + journalctl --sync assert_eq "$(journalctl -b -u systemd-logind.service --since="$ts" --grep "Session \"$id\" of user \"logind-test-user\" is idle, stopping." | wc -l)" 1 assert_eq "$(loginctl --no-legend | grep -v manager | grep -c "logind-test-user")" 0 } diff --git a/test/units/TEST-50-DISSECT.dissect.sh b/test/units/TEST-50-DISSECT.dissect.sh index 991346fd6e..c3260429ab 100755 --- a/test/units/TEST-50-DISSECT.dissect.sh +++ b/test/units/TEST-50-DISSECT.dissect.sh @@ -722,8 +722,9 @@ systemd-sysext merge --no-reload (! systemctl --quiet is-active foo.service) 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 .5; done' +timeout 30s bash -xec 'until [[ $(journalctl -b -u foo.service _TRANSPORT=stdout -o cat) == foo ]]; do sleep 1; journalctl --sync; done' 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"