naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
62b62a
From 6ec2c387cd4fe081e6a5561b5c7e66ec0555c353 Mon Sep 17 00:00:00 2001
62b62a
From: Daan De Meyer <daan.j.demeyer@gmail.com>
62b62a
Date: Tue, 24 Aug 2021 16:46:47 +0100
62b62a
Subject: [PATCH] core: Check unit start rate limiting earlier
62b62a
62b62a
[dtardon: This adds the test that's been left out by commit
62b62a
471eda89a25a3ceac91a2d05e39a54aae78038ed]
62b62a
62b62a
(cherry picked from commit 9727f2427ff6b2e1f4ab927cc57ad8e888f04e95)
62b62a
62b62a
Related: #2123801
62b62a
---
62b62a
 test/TEST-10-ISSUE-2467/test.sh            |  3 ++
62b62a
 test/TEST-63-ISSUE-17433/Makefile          |  1 +
62b62a
 test/TEST-63-ISSUE-17433/test.sh           | 42 ++++++++++++++++++++++
62b62a
 test/TEST-63-ISSUE-17433/test63.path       |  2 ++
62b62a
 test/TEST-63-ISSUE-17433/test63.service    |  5 +++
62b62a
 test/TEST-63-ISSUE-17433/testsuite.service | 17 +++++++++
62b62a
 6 files changed, 70 insertions(+)
62b62a
 create mode 120000 test/TEST-63-ISSUE-17433/Makefile
62b62a
 create mode 100755 test/TEST-63-ISSUE-17433/test.sh
62b62a
 create mode 100644 test/TEST-63-ISSUE-17433/test63.path
62b62a
 create mode 100644 test/TEST-63-ISSUE-17433/test63.service
62b62a
 create mode 100644 test/TEST-63-ISSUE-17433/testsuite.service
62b62a
62b62a
diff --git a/test/TEST-10-ISSUE-2467/test.sh b/test/TEST-10-ISSUE-2467/test.sh
62b62a
index 0e61236686..a839ef79de 100755
62b62a
--- a/test/TEST-10-ISSUE-2467/test.sh
62b62a
+++ b/test/TEST-10-ISSUE-2467/test.sh
62b62a
@@ -42,6 +42,9 @@ EOF
62b62a
 [Unit]
62b62a
 Requires=test.socket
62b62a
 ConditionPathExistsGlob=/tmp/nonexistent
62b62a
+# Make sure we hit the socket trigger limit in the test and not the service start limit.
62b62a
+StartLimitInterval=1000
62b62a
+StartLimitBurst=1000
62b62a
 
62b62a
 [Service]
62b62a
 ExecStart=/bin/true
62b62a
diff --git a/test/TEST-63-ISSUE-17433/Makefile b/test/TEST-63-ISSUE-17433/Makefile
62b62a
new file mode 120000
62b62a
index 0000000000..e9f93b1104
62b62a
--- /dev/null
62b62a
+++ b/test/TEST-63-ISSUE-17433/Makefile
62b62a
@@ -0,0 +1 @@
62b62a
+../TEST-01-BASIC/Makefile
62b62a
\ No newline at end of file
62b62a
diff --git a/test/TEST-63-ISSUE-17433/test.sh b/test/TEST-63-ISSUE-17433/test.sh
62b62a
new file mode 100755
62b62a
index 0000000000..406a1e214c
62b62a
--- /dev/null
62b62a
+++ b/test/TEST-63-ISSUE-17433/test.sh
62b62a
@@ -0,0 +1,42 @@
62b62a
+#!/usr/bin/env bash
62b62a
+set -e
62b62a
+
62b62a
+TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/17433"
62b62a
+
62b62a
+# shellcheck source=test/test-functions
62b62a
+. "${TEST_BASE_DIR:?}/test-functions"
62b62a
+
62b62a
+test_setup() {
62b62a
+    create_empty_image
62b62a
+    mkdir -p $TESTDIR/root
62b62a
+    mount ${LOOPDEV}p1 $TESTDIR/root
62b62a
+
62b62a
+    # Create what will eventually be our root filesystem onto an overlay
62b62a
+    (
62b62a
+        LOG_LEVEL=5
62b62a
+        eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
62b62a
+
62b62a
+        setup_basic_environment
62b62a
+
62b62a
+        # setup the testsuite service
62b62a
+        cp testsuite.service $initdir/etc/systemd/system/testsuite.service
62b62a
+
62b62a
+        cp test63.path $initdir/etc/systemd/system/test63.path
62b62a
+        cp test63.service $initdir/etc/systemd/system/test63.service
62b62a
+
62b62a
+        setup_testsuite
62b62a
+    ) || return 1
62b62a
+    setup_nspawn_root
62b62a
+
62b62a
+    # mask some services that we do not want to run in these tests
62b62a
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
62b62a
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
62b62a
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.service
62b62a
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
62b62a
+    ln -s /dev/null $initdir/etc/systemd/system/systemd-resolved.service
62b62a
+
62b62a
+    ddebug "umount $TESTDIR/root"
62b62a
+    umount $TESTDIR/root
62b62a
+}
62b62a
+
62b62a
+do_test "$@"
62b62a
diff --git a/test/TEST-63-ISSUE-17433/test63.path b/test/TEST-63-ISSUE-17433/test63.path
62b62a
new file mode 100644
62b62a
index 0000000000..a6573bda0a
62b62a
--- /dev/null
62b62a
+++ b/test/TEST-63-ISSUE-17433/test63.path
62b62a
@@ -0,0 +1,2 @@
62b62a
+[Path]
62b62a
+PathExists=/tmp/test63
62b62a
diff --git a/test/TEST-63-ISSUE-17433/test63.service b/test/TEST-63-ISSUE-17433/test63.service
62b62a
new file mode 100644
62b62a
index 0000000000..c83801874d
62b62a
--- /dev/null
62b62a
+++ b/test/TEST-63-ISSUE-17433/test63.service
62b62a
@@ -0,0 +1,5 @@
62b62a
+[Unit]
62b62a
+ConditionPathExists=!/tmp/nonexistent
62b62a
+
62b62a
+[Service]
62b62a
+ExecStart=true
62b62a
diff --git a/test/TEST-63-ISSUE-17433/testsuite.service b/test/TEST-63-ISSUE-17433/testsuite.service
62b62a
new file mode 100644
62b62a
index 0000000000..d3ca5b002b
62b62a
--- /dev/null
62b62a
+++ b/test/TEST-63-ISSUE-17433/testsuite.service
62b62a
@@ -0,0 +1,17 @@
62b62a
+[Unit]
62b62a
+Description=TEST-63-ISSUE-17433
62b62a
+
62b62a
+[Service]
62b62a
+ExecStartPre=rm -f /failed /testok
62b62a
+Type=oneshot
62b62a
+ExecStart=rm -f /tmp/nonexistent
62b62a
+ExecStart=systemctl start test63.path
62b62a
+ExecStart=touch /tmp/test63
62b62a
+# Make sure systemd has sufficient time to hit the start limit for test63.service.
62b62a
+ExecStart=sleep 2
62b62a
+ExecStart=sh -x -c 'test "$(systemctl show test63.service --value -p ActiveState)" = failed'
62b62a
+ExecStart=sh -x -c 'test "$(systemctl show test63.service --value -p Result)" = start-limit-hit'
62b62a
+# FIXME: The path remains active, which it should not
62b62a
+# ExecStart=sh -x -c 'test "$(systemctl show test63.path --value -p ActiveState)" = failed'
62b62a
+# ExecStart=sh -x -c 'test "$(systemctl show test63.path --value -p Result)" = unit-start-limit-hit'
62b62a
+ExecStart=sh -x -c 'echo OK >/testok'