Skip to content

Commit 8d7d806

Browse files
committed
test: make TEST-35-LOGIN stable again
Let's add a couple of synchronization points and reduce the amount of sleeps to make the test, hopefully, stable again. Follow-up to 638c241. Related: #2179309 rhel-only
1 parent 05a06e3 commit 8d7d806

2 files changed

Lines changed: 29 additions & 22 deletions

File tree

test/TEST-35-LOGIN/testsuite.sh

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ EOF
2424

2525
teardown_idle_action_lock() {(
2626
set +ex
27+
[[ -e dbus.log ]] && cat dbus.log
28+
[[ -e logind.log ]] && cat logind.log
2729
rm -f /run/systemd/logind.conf.d/idle-action-lock.conf
2830
rm -f /run/systemd/systemd-logind.service.d/debug.conf
2931
pkill -9 -u "$(id -u testuser)"
@@ -37,56 +39,61 @@ test_lock_idle_action() {
3739
return 0
3840
fi
3941

42+
local busctl_pid expect_pid ts
43+
4044
setup_idle_action_lock
4145
trap teardown_idle_action_lock RETURN
4246

4347
if loginctl --no-legend | awk '{ print $3; }' | sort -u | grep -q testuser ; then
44-
echo >&2 "Session of the \'testuser\' is already present."
48+
echo >&2 "Session of the 'testuser' is already present."
4549
return 1
4650
fi
4751

48-
# IdleActionSec is set 1s but the accuracy of associated timer is 30s so we
52+
rm -f /tmp/expect-sync
53+
54+
# IdleActionSec= is set 1s but the accuracy of associated timer is 30s so we
4955
# need to sleep in worst case for 31s to make sure timer elapsed. We sleep
50-
# here for 35s to accomodate for any possible scheudling delays.
51-
cat > /tmp/test.exp <<EOF
56+
# here for 35s to accommodate for any possible scheduling delays.
57+
cat >/tmp/test.exp <<EOF
5258
spawn systemd-run -G -t -p PAMName=login -p User=testuser bash
53-
send "sleep 35\r"
59+
expect "three times"
60+
send "touch /tmp/expect-sync\r"
61+
sleep 35
5462
send "echo foobar\r"
55-
send "sleep 35\r"
63+
sleep 35
5664
send "exit\r"
5765
interact
5866
wait
5967
EOF
6068

6169
ts="$(date '+%H:%M:%S')"
62-
busctl --match "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='Lock'" monitor > dbus.log &
70+
busctl --match "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='Lock'" monitor &>dbus.log &
71+
busctl_pid=$!
72+
timeout 15 bash -c 'while ! grep -q "Monitoring bus" dbus.log; do sleep .5; done'
6373

64-
expect /tmp/test.exp &
74+
expect -d /tmp/test.exp &
75+
expect_pid=$!
6576

66-
# Sleep a bit to give expect time to spawn systemd-run before we check for
77+
# Wait a bit to give expect time to spawn systemd-run before we check for
6778
# the presence of resulting session.
68-
sleep 2
69-
if [ "$(loginctl --no-legend | awk '{ print $3; }' | sort -u | grep -c testuser)" != 1 ] ; then
70-
echo >&2 "\'testuser\' is expected to have exactly one session running."
79+
timeout 15 bash -c "while [[ ! -e /tmp/expect-sync ]]; do sleep .5; done"
80+
if [[ "$(loginctl --no-legend | awk '{ print $3; }' | grep -c testuser)" -ne 1 ]] ; then
81+
echo >&2 "'testuser' is expected to have exactly one session running."
7182
return 1
7283
fi
7384

74-
wait %2
75-
sleep 20
76-
kill %1
85+
wait "$expect_pid"
7786

7887
# We slept for 35s , in that interval all sessions should have become idle
7988
# and "Lock" signal should have been sent out. Then we wrote to tty to make
8089
# session active again and next we slept for another 35s so sessions have
8190
# become idle again. 'Lock' signal is sent out for each session, we have at
8291
# least one session, so minimum of 2 "Lock" signals must have been sent.
83-
if [ "$(grep -c Member=Lock dbus.log)" -lt 2 ]; then
84-
echo >&2 "Too few 'Lock' D-Bus signal sent, expected at least 2."
85-
return 1
86-
fi
92+
timeout 30 bash -c 'while [[ $(grep -c Member=Lock dbus.log) -lt 2 ]]; do sleep .5; done'
93+
kill "$busctl_pid"
8794

88-
journalctl -b -u systemd-logind.service --since="$ts" > logind.log
89-
if [ "$(grep -c 'System idle. Doing lock operation.' logind.log)" -lt 2 ]; then
95+
journalctl -b -u systemd-logind.service --since="$ts" >logind.log
96+
if [[ "$(grep -c 'System idle. Doing lock operation.' logind.log)" -lt 2 ]]; then
9097
echo >&2 "System haven't entered idle state at least 2 times."
9198
return 1
9299
fi

test/test-functions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fi
2323

2424
PATH_TO_INIT=$ROOTLIBDIR/systemd
2525

26-
BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs env mktemp mountpoint useradd userdel"
26+
BASICTOOLS="test sh bash setsid loadkeys setfont login sulogin gzip sleep echo mount umount cryptsetup date dmsetup modprobe sed cmp tee rm true false chmod chown ln xargs env mktemp mountpoint useradd userdel timeout"
2727
DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort hostname find"
2828

2929
STATEDIR="${BUILD_DIR:-.}/test/$(basename $(dirname $(realpath $0)))"

0 commit comments

Comments
 (0)