summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-11-01 17:25:49 +0100
committerGitHub <noreply@github.com>2024-11-01 17:25:49 +0100
commitacc35e51299097cf3f3c466c825a045d0efde0dd (patch)
tree82b0652726d88daed2418ebbcc73a44df7bb16d9 /test
parentresolve: remove always-true superflous check and rename label (diff)
parentTEST-03-JOBS: add test case for #34758 (diff)
downloadsystemd-acc35e51299097cf3f3c466c825a045d0efde0dd.tar.xz
systemd-acc35e51299097cf3f3c466c825a045d0efde0dd.zip
core/service: don't propagate stop jobs if RestartMode=direct (#34768)
Fixes https://github.com/systemd/systemd/issues/34758
Diffstat (limited to 'test')
-rw-r--r--test/TEST-03-JOBS/TEST-03-JOBS.units/counter.service8
-rwxr-xr-xtest/TEST-03-JOBS/TEST-03-JOBS.units/counter.sh13
-rw-r--r--test/TEST-03-JOBS/TEST-03-JOBS.units/restart-on-failure.service4
-rw-r--r--test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-direct.service8
-rw-r--r--test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-normal.service8
-rwxr-xr-xtest/units/TEST-03-JOBS.sh25
6 files changed, 66 insertions, 0 deletions
diff --git a/test/TEST-03-JOBS/TEST-03-JOBS.units/counter.service b/test/TEST-03-JOBS/TEST-03-JOBS.units/counter.service
new file mode 100644
index 0000000000..db2e49404c
--- /dev/null
+++ b/test/TEST-03-JOBS/TEST-03-JOBS.units/counter.service
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+[Unit]
+BindsTo=sleep-infinity-restart-normal.service sleep-infinity-restart-direct.service
+After=sleep-infinity-restart-normal.service sleep-infinity-restart-direct.service
+
+[Service]
+Type=notify
+ExecStart=/usr/lib/systemd/tests/testdata/TEST-03-JOBS.units/counter.sh
diff --git a/test/TEST-03-JOBS/TEST-03-JOBS.units/counter.sh b/test/TEST-03-JOBS/TEST-03-JOBS.units/counter.sh
new file mode 100755
index 0000000000..1d11ca613d
--- /dev/null
+++ b/test/TEST-03-JOBS/TEST-03-JOBS.units/counter.sh
@@ -0,0 +1,13 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+
+COUNTER_FILE=/tmp/test-03-restart-counter
+
+COUNT="$(<"$COUNTER_FILE")"
+: $(( COUNT++ ))
+echo "$COUNT" >"$COUNTER_FILE"
+
+systemd-notify --ready
+
+sleep infinity
diff --git a/test/TEST-03-JOBS/TEST-03-JOBS.units/restart-on-failure.service b/test/TEST-03-JOBS/TEST-03-JOBS.units/restart-on-failure.service
new file mode 100644
index 0000000000..1ec1857e39
--- /dev/null
+++ b/test/TEST-03-JOBS/TEST-03-JOBS.units/restart-on-failure.service
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+[Service]
+Type=oneshot
+ExecStart=touch /tmp/test-03-restart-failure-flag
diff --git a/test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-direct.service b/test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-direct.service
new file mode 100644
index 0000000000..00316db1f1
--- /dev/null
+++ b/test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-direct.service
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+[Unit]
+OnFailure=restart-on-failure.service
+
+[Service]
+ExecStart=/bin/sleep infinity
+Restart=on-failure
+RestartMode=direct
diff --git a/test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-normal.service b/test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-normal.service
new file mode 100644
index 0000000000..dabba4c4f0
--- /dev/null
+++ b/test/TEST-03-JOBS/TEST-03-JOBS.units/sleep-infinity-restart-normal.service
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+[Unit]
+OnFailure=restart-on-failure.service
+
+[Service]
+ExecStart=/bin/sleep infinity
+Restart=on-failure
+RestartMode=normal
diff --git a/test/units/TEST-03-JOBS.sh b/test/units/TEST-03-JOBS.sh
index 067f2ce67d..183439e913 100755
--- a/test/units/TEST-03-JOBS.sh
+++ b/test/units/TEST-03-JOBS.sh
@@ -156,6 +156,7 @@ assert_rc 3 systemctl --quiet is-active propagatestopto-and-pullin.target
assert_rc 3 systemctl --quiet is-active sleep-infinity-simple.service
# Test restart mode direct
+
systemctl start succeeds-on-restart-restartdirect.target
assert_rc 0 systemctl --quiet is-active succeeds-on-restart-restartdirect.target
@@ -168,6 +169,30 @@ assert_rc 3 systemctl --quiet is-active succeeds-on-restart.target
systemctl start fails-on-restart.target || :
assert_rc 3 systemctl --quiet is-active fails-on-restart.target
+COUNTER_FILE=/tmp/test-03-restart-counter
+export FAILURE_FLAG_FILE=/tmp/test-03-restart-failure-flag
+
+assert_rc 3 systemctl --quiet is-active sleep-infinity-restart-normal.service
+assert_rc 3 systemctl --quiet is-active sleep-infinity-restart-direct.service
+assert_rc 3 systemctl --quiet is-active counter.service
+echo 0 >"$COUNTER_FILE"
+
+systemctl start counter.service
+assert_eq "$(cat "$COUNTER_FILE")" "1"
+systemctl --quiet is-active sleep-infinity-restart-normal.service
+systemctl --quiet is-active sleep-infinity-restart-direct.service
+systemctl --quiet is-active counter.service
+
+systemctl kill --signal=KILL sleep-infinity-restart-direct.service
+systemctl --quiet is-active counter.service
+assert_eq "$(cat "$COUNTER_FILE")" "1"
+[[ ! -f "$FAILURE_FLAG_FILE" ]]
+
+systemctl kill --signal=KILL sleep-infinity-restart-normal.service
+timeout 10 bash -c 'while [[ ! -f $FAILURE_FLAG_FILE ]]; do sleep .5; done'
+timeout 10 bash -c 'while ! systemctl --quiet is-active counter.service; do sleep .5; done'
+assert_eq "$(cat "$COUNTER_FILE")" "2"
+
# Test shortcutting auto restart
export UNIT_NAME="TEST-03-JOBS-shortcut-restart.service"