From 076036327432c6b5db97fd870614bc4f4db946be Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 14 Apr 2021 17:34:25 +0200 Subject: [PATCH] test: add test for OnSuccess= + Uphold= + PropagatesStopTo= + BindsTo= --- test/TEST-57-ONSUCCESS-UPHOLD/Makefile | 1 + test/TEST-57-ONSUCCESS-UPHOLD/test.sh | 7 ++ test/units/testsuite-57-binds-to.service | 8 +++ test/units/testsuite-57-bound-by.service | 5 ++ test/units/testsuite-57-fail.service | 6 ++ test/units/testsuite-57-prop-stop-one.service | 9 +++ test/units/testsuite-57-prop-stop-two.service | 5 ++ test/units/testsuite-57-short-lived.service | 10 +++ test/units/testsuite-57-short-lived.sh | 18 +++++ test/units/testsuite-57-success.service | 6 ++ test/units/testsuite-57-uphold.service | 6 ++ test/units/testsuite-57.service | 7 ++ test/units/testsuite-57.sh | 68 +++++++++++++++++++ 13 files changed, 156 insertions(+) create mode 120000 test/TEST-57-ONSUCCESS-UPHOLD/Makefile create mode 100755 test/TEST-57-ONSUCCESS-UPHOLD/test.sh create mode 100644 test/units/testsuite-57-binds-to.service create mode 100644 test/units/testsuite-57-bound-by.service create mode 100644 test/units/testsuite-57-fail.service create mode 100644 test/units/testsuite-57-prop-stop-one.service create mode 100644 test/units/testsuite-57-prop-stop-two.service create mode 100644 test/units/testsuite-57-short-lived.service create mode 100755 test/units/testsuite-57-short-lived.sh create mode 100644 test/units/testsuite-57-success.service create mode 100644 test/units/testsuite-57-uphold.service create mode 100644 test/units/testsuite-57.service create mode 100755 test/units/testsuite-57.sh diff --git a/test/TEST-57-ONSUCCESS-UPHOLD/Makefile b/test/TEST-57-ONSUCCESS-UPHOLD/Makefile new file mode 120000 index 00000000000..e9f93b1104c --- /dev/null +++ b/test/TEST-57-ONSUCCESS-UPHOLD/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-57-ONSUCCESS-UPHOLD/test.sh b/test/TEST-57-ONSUCCESS-UPHOLD/test.sh new file mode 100755 index 00000000000..145c88fcd8d --- /dev/null +++ b/test/TEST-57-ONSUCCESS-UPHOLD/test.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e + +TEST_DESCRIPTION="test OnSuccess= + Uphold= + PropagatesStopTo= + BindsTo=" +. $TEST_BASE_DIR/test-functions + +do_test "$@" 57 diff --git a/test/units/testsuite-57-binds-to.service b/test/units/testsuite-57-binds-to.service new file mode 100644 index 00000000000..e4b6ee3c299 --- /dev/null +++ b/test/units/testsuite-57-binds-to.service @@ -0,0 +1,8 @@ +[Unit] +Description=Unit with BindsTo= +BindsTo=testsuite-57-bound-by.service +After=testsuite-57-bound-by.service + +[Service] +ExecStart=/bin/sleep infinity +ExecStopPost=systemctl kill --kill-who=main -sRTMIN+1 testsuite-57.service diff --git a/test/units/testsuite-57-bound-by.service b/test/units/testsuite-57-bound-by.service new file mode 100644 index 00000000000..df66a8fe84c --- /dev/null +++ b/test/units/testsuite-57-bound-by.service @@ -0,0 +1,5 @@ +[Unit] +Description=Unit with BoundBy= + +[Service] +ExecStart=/bin/sleep 0.7 diff --git a/test/units/testsuite-57-fail.service b/test/units/testsuite-57-fail.service new file mode 100644 index 00000000000..07d8ddde9d0 --- /dev/null +++ b/test/units/testsuite-57-fail.service @@ -0,0 +1,6 @@ +[Unit] +Description=Failing unit +OnFailure=testsuite-57-uphold.service + +[Service] +ExecStart=/bin/false diff --git a/test/units/testsuite-57-prop-stop-one.service b/test/units/testsuite-57-prop-stop-one.service new file mode 100644 index 00000000000..cdca7d44517 --- /dev/null +++ b/test/units/testsuite-57-prop-stop-one.service @@ -0,0 +1,9 @@ +[Unit] +Description=Stop Propagation Receiver +Wants=testsuite-57-prop-stop-two.service +After=testsuite-57-prop-stop-two.service +StopPropagatedFrom=testsuite-57-prop-stop-two.service + +[Service] +ExecStart=/bin/sleep infinity +ExecStopPost=systemctl kill --kill-who=main -sUSR2 testsuite-57.service diff --git a/test/units/testsuite-57-prop-stop-two.service b/test/units/testsuite-57-prop-stop-two.service new file mode 100644 index 00000000000..a462faf3531 --- /dev/null +++ b/test/units/testsuite-57-prop-stop-two.service @@ -0,0 +1,5 @@ +[Unit] +Description=Stop Propagation Sender + +[Service] +ExecStart=/bin/sleep 1.5 diff --git a/test/units/testsuite-57-short-lived.service b/test/units/testsuite-57-short-lived.service new file mode 100644 index 00000000000..7fa268247f9 --- /dev/null +++ b/test/units/testsuite-57-short-lived.service @@ -0,0 +1,10 @@ +[Unit] +Description=Shortlived Unit +StopWhenUnneeded=yes + +# Bump up the start limit logic, so that we can be restarted frequently enough +StartLimitBurst=15 +StartLimitIntervalSec=1h + +[Service] +ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-57-short-lived.sh diff --git a/test/units/testsuite-57-short-lived.sh b/test/units/testsuite-57-short-lived.sh new file mode 100755 index 00000000000..8c48d3a2d57 --- /dev/null +++ b/test/units/testsuite-57-short-lived.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -ex + +if [ -f /tmp/testsuite-57.counter ] ; then + read -r counter < /tmp/testsuite-57.counter + counter=$(("$counter" + 1)) +else + counter=0 +fi + +echo "$counter" > /tmp/testsuite-57.counter + +if [ "$counter" -eq 5 ] ; then + systemctl kill --kill-who=main -sUSR1 testsuite-57.service +fi + +exec sleep 1.5 diff --git a/test/units/testsuite-57-success.service b/test/units/testsuite-57-success.service new file mode 100644 index 00000000000..ac1071fbba5 --- /dev/null +++ b/test/units/testsuite-57-success.service @@ -0,0 +1,6 @@ +[Unit] +Description=Succeeding unit +OnSuccess=testsuite-57-fail.service + +[Service] +ExecStart=/bin/true diff --git a/test/units/testsuite-57-uphold.service b/test/units/testsuite-57-uphold.service new file mode 100644 index 00000000000..d2b3828375c --- /dev/null +++ b/test/units/testsuite-57-uphold.service @@ -0,0 +1,6 @@ +[Unit] +Description=Upholding Unit +Upholds=testsuite-57-short-lived.service + +[Service] +ExecStart=/bin/sleep infinity diff --git a/test/units/testsuite-57.service b/test/units/testsuite-57.service new file mode 100644 index 00000000000..cab23afb442 --- /dev/null +++ b/test/units/testsuite-57.service @@ -0,0 +1,7 @@ +[Unit] +Description=TEST-57-ONSUCCESS-UPHOLD + +[Service] +ExecStartPre=rm -f /failed /testok +ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh +Type=oneshot diff --git a/test/units/testsuite-57.sh b/test/units/testsuite-57.sh new file mode 100755 index 00000000000..5db82b8437a --- /dev/null +++ b/test/units/testsuite-57.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +set -eux +set -o pipefail + +systemd-analyze log-level debug +systemd-analyze log-target journal + +# Idea is this: +# 1. we start testsuite-57-success.service +# 2. which through OnSuccess= starts testsuite-57-fail.service, +# 3. which through OnFailure= starts testsuite-57-uphold.service, +# 4. which through Uphold= starts/keeps testsuite-57-short-lived.service running, +# 5. which will sleep 1s when invoked, and on the 5th invocation send us a SIGUSR1 +# 6. once we got that we finish cleanly + +sigusr1=0 +trap sigusr1=1 SIGUSR1 + +systemctl start testsuite-57-success.service + +while [ "$sigusr1" -eq 0 ] ; do + sleep .5 +done + +systemctl stop testsuite-57-uphold.service + +# Idea is this: +# 1. we start testsuite-57-prop-stop-one.service +# 2. which through Wants=/After= pulls in testsuite-57-prop-stop-two.service as well +# 3. testsuite-57-prop-stop-one.service then sleeps indefinitely +# 4. testsuite-57-prop-stop-two.service sleeps a short time and exits +# 5. the StopPropagatedFrom= dependency between the two should ensure *both* will exit as result +# 6. an ExecStopPost= line on testsuite-57-prop-stop-one.service will send us a SIGUSR2 +# 7. once we got that we finish cleanly + +sigusr2=0 +trap sigusr2=1 SIGUSR2 + +systemctl start testsuite-57-prop-stop-one.service + +while [ "$sigusr2" -eq 0 ] ; do + sleep .5 +done + + +# Idea is this: +# 1. we start testsuite-57-binds-to.service +# 2. which through BindsTo=/After= pulls in testsuite-57-bound-by.service as well +# 3. testsuite-57-bound-by.service suddenly dies +# 4. testsuite-57-binds-to.service should then also be pulled down (it otherwise just hangs) +# 6. an ExecStopPost= line on testsuite-57-binds-to.service will send us a SIGRTMIN1+1 +# 7. once we got that we finish cleanly + +sigrtmin1=0 +trap sigrtmin1=1 SIGRTMIN+1 + +systemctl start testsuite-57-binds-to.service + +while [ "$sigrtmin1" -eq 0 ] ; do + sleep .5 +done + +systemd-analyze log-level info + +echo OK >/testok + +exit 0 -- 2.47.3