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