Skip to content

Commit

Permalink
Merge pull request #32942 from yuwata/test-journal-sync-more
Browse files Browse the repository at this point in the history
test: sync journal before read
  • Loading branch information
bluca committed May 20, 2024
2 parents f8ef1df + 702fdd3 commit 1bfa83e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion test/units/TEST-17-UDEV.02.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand Down
10 changes: 8 additions & 2 deletions test/units/TEST-35-LOGIN.sh
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ testcase_lock_idle_action() {

create_session

journalctl --sync
ts="$(date '+%H:%M:%S')"

mkdir -p /run/systemd/logind.conf.d
Expand All @@ -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.
Expand All @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion test/units/TEST-50-DISSECT.dissect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/units/TEST-60-MOUNT-RATELIMIT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1bfa83e

Please sign in to comment.