teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0783-test-correct-TEST-41-StartLimitBurst-test.patch

62b301
From a7375d12da80d633dfa802f2b66d2361c70c62f5 Mon Sep 17 00:00:00 2001
62b301
From: Dan Streetman <ddstreet@canonical.com>
62b301
Date: Thu, 17 Oct 2019 11:06:18 -0400
62b301
Subject: [PATCH] test: correct TEST-41 StartLimitBurst test
62b301
62b301
TEST-41 verifies that the StartLimitBurst property will correctly
62b301
limit the number of unit restarts, but the test currently doesn't
62b301
adjust the StartLimitIntervalSec which defaults to 10 seconds.
62b301
62b301
On Ubuntu CI, running under un-accelerated qemu, it can take more than
62b301
10 seconds to perform all 3 restarts, which avoids the burst limit,
62b301
and fails the test.
62b301
62b301
Instead, specify a long StartLimitIntervalSec in the test, so we can
62b301
be sure to correctly test StartLimitBurst even on slow testbeds.
62b301
62b301
Fixes #13794.
62b301
62b301
(cherry picked from commit dfec314d41159117c28dffc2b980d3bdd67c3dcb)
62b301
62b301
Related: #2042896
62b301
---
62b301
 test/TEST-41-ONESHOT-RESTART/testsuite.sh | 26 ++++++++++++++++++-----
62b301
 1 file changed, 21 insertions(+), 5 deletions(-)
62b301
62b301
diff --git a/test/TEST-41-ONESHOT-RESTART/testsuite.sh b/test/TEST-41-ONESHOT-RESTART/testsuite.sh
62b301
index f7423dbf9a..4465614ff3 100755
62b301
--- a/test/TEST-41-ONESHOT-RESTART/testsuite.sh
62b301
+++ b/test/TEST-41-ONESHOT-RESTART/testsuite.sh
62b301
@@ -2,14 +2,19 @@
62b301
 set -ex
62b301
 set -o pipefail
62b301
 
62b301
+# wait this many secs for each test service to succeed in what is being tested
62b301
+MAX_SECS=60
62b301
+
62b301
 systemd-analyze log-level debug
62b301
 systemd-analyze log-target console
62b301
 
62b301
-# These three commands should succeed.
62b301
+# test one: Restart=on-failure should restart the service
62b301
 ! systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1"
62b301
 
62b301
-sleep 5
62b301
-
62b301
+for ((secs=0; secs<$MAX_SECS; secs++)); do
62b301
+  [[ "$(systemctl show one.service -p NRestarts --value)" -le 0 ]] || break
62b301
+  sleep 1
62b301
+done
62b301
 if [[ "$(systemctl show one.service -p NRestarts --value)" -le 0 ]]; then
62b301
   exit 1
62b301
 fi
62b301
@@ -18,10 +23,21 @@ TMP_FILE="/test-41-oneshot-restart-test"
62b301
 
62b301
 touch $TMP_FILE
62b301
 
62b301
-! systemd-run --unit=two -p StartLimitBurst=3 -p Type=oneshot -p Restart=on-failure -p ExecStart="/bin/bash -c \"printf a >>  $TMP_FILE\"" /bin/bash -c "exit 1"
62b301
+# test two: make sure StartLimitBurst correctly limits the number of restarts
62b301
+# and restarts execution of the unit from the first ExecStart=
62b301
+! systemd-run --unit=two -p StartLimitIntervalSec=120 -p StartLimitBurst=3 -p Type=oneshot -p Restart=on-failure -p ExecStart="/bin/bash -c \"printf a >>  $TMP_FILE\"" /bin/bash -c "exit 1"
62b301
 
62b301
-sleep 5
62b301
+# wait for at least 3 restarts
62b301
+for ((secs=0; secs<$MAX_SECS; secs++)); do
62b301
+  [[ $(cat $TMP_FILE) != "aaa" ]] || break
62b301
+  sleep 1
62b301
+done
62b301
+if [[ $(cat $TMP_FILE) != "aaa" ]]; then
62b301
+  exit 1
62b301
+fi
62b301
 
62b301
+# wait for 5 more seconds to make sure there aren't excess restarts
62b301
+sleep 5
62b301
 if [[ $(cat $TMP_FILE) != "aaa" ]]; then
62b301
   exit 1
62b301
 fi