TEST-35-LOGIN: Handle multiple lock messages per sleep
authorRichard Maw <richard.maw@codethink.co.uk>
Sat, 17 Feb 2024 21:42:45 +0000 (21:42 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 30 Apr 2024 16:17:13 +0000 (18:17 +0200)
If 3 lock messages get sent when going to sleep
then we can falsely assume we have woken up if we only assume we have at least two
so checking we have more than we did before sleeping addresses that issue.

test/units/testsuite-35.sh

index e9af67f358a3a11fa0c2e84a548b5cd9128570ab..4ca312d6bab20949521ebb2742837a2c0ff0ec47 100755 (executable)
@@ -524,11 +524,15 @@ EOF
     # 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"
 
+    # 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.
+    locks="$(journalctl -b -u systemd-logind.service --since="$ts" | grep -c 'Sent message type=signal .* member=Lock')"
+
     # Wakeup
     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 2 ]]; do sleep 1; done"
+    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"
 
     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."