]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: add test for StopIdleSessionSec= option 24242/head
authorMichal Sekletar <msekleta@redhat.com>
Mon, 8 Aug 2022 09:39:52 +0000 (11:39 +0200)
committerMichal Sekletar <msekleta@redhat.com>
Wed, 24 Aug 2022 12:50:52 +0000 (14:50 +0200)
test/units/testsuite-35.sh

index eae2cb801d4c39fffa1029fde4169e15ec0ffc40..4ef0f0c11cc764cefd22c5b96b152e989f0df97a 100755 (executable)
@@ -493,6 +493,42 @@ test_list_users() {
     assert_eq "$(loginctl list-users --no-legend | awk '$2 == "logind-test-user" { print $3 }')" yes
 }
 
+
+teardown_stop_idle_session() (
+    set +eux
+
+    rm -f /run/systemd/logind.conf.d/stop-idle-session.conf
+    systemctl restart systemd-logind.service
+
+    cleanup_session
+)
+
+test_stop_idle_session() {
+    local id ts
+
+    if [[ ! -c /dev/tty2 ]]; then
+        echo "/dev/tty2 does not exist, skipping test ${FUNCNAME[0]}."
+        return
+    fi
+
+    create_session
+    trap teardown_stop_idle_session RETURN
+
+    id="$(loginctl --no-legend | awk '$3 == "logind-test-user" { print $1; }')"
+    ts="$(date '+%H:%M:%S')"
+
+    mkdir -p /run/systemd/logind.conf.d
+    cat >/run/systemd/logind.conf.d/stop-idle-session.conf <<EOF
+[Login]
+StopIdleSessionSec=2s
+EOF
+    systemctl restart systemd-logind.service
+    sleep 5
+
+    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 -c "logind-test-user")" 0
+}
+
 : >/failed
 
 setup_test_user
@@ -505,6 +541,7 @@ test_session
 test_lock_idle_action
 test_session_properties
 test_list_users
+test_stop_idle_session
 
 touch /testok
 rm /failed