Skip to content

Commit dfec314

Browse files
author
Dan Streetman
committed
test: correct TEST-41 StartLimitBurst test
TEST-41 verifies that the StartLimitBurst property will correctly limit the number of unit restarts, but the test currently doesn't adjust the StartLimitIntervalSec which defaults to 10 seconds. On Ubuntu CI, running under un-accelerated qemu, it can take more than 10 seconds to perform all 3 restarts, which avoids the burst limit, and fails the test. Instead, specify a long StartLimitIntervalSec in the test, so we can be sure to correctly test StartLimitBurst even on slow testbeds. Fixes systemd#13794.
1 parent 02baf23 commit dfec314

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

test/TEST-41-ONESHOT-RESTART/blacklist-ubuntu-ci

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/TEST-41-ONESHOT-RESTART/testsuite.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
set -ex
33
set -o pipefail
44

5+
# wait this many secs for each test service to succeed in what is being tested
6+
MAX_SECS=60
7+
58
systemd-analyze log-level debug
69
systemd-analyze log-target console
710

8-
# These three commands should succeed.
11+
# test one: Restart=on-failure should restart the service
912
! systemd-run --unit=one -p Type=oneshot -p Restart=on-failure /bin/bash -c "exit 1"
1013

11-
sleep 5
12-
14+
for ((secs=0; secs<$MAX_SECS; secs++)); do
15+
[[ "$(systemctl show one.service -p NRestarts --value)" -le 0 ]] || break
16+
sleep 1
17+
done
1318
if [[ "$(systemctl show one.service -p NRestarts --value)" -le 0 ]]; then
1419
exit 1
1520
fi
@@ -18,10 +23,21 @@ TMP_FILE="/test-41-oneshot-restart-test"
1823

1924
touch $TMP_FILE
2025

21-
! 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"
26+
# test two: make sure StartLimitBurst correctly limits the number of restarts
27+
# and restarts execution of the unit from the first ExecStart=
28+
! 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"
2229

23-
sleep 5
30+
# wait for at least 3 restarts
31+
for ((secs=0; secs<$MAX_SECS; secs++)); do
32+
[[ $(cat $TMP_FILE) != "aaa" ]] || break
33+
sleep 1
34+
done
35+
if [[ $(cat $TMP_FILE) != "aaa" ]]; then
36+
exit 1
37+
fi
2438

39+
# wait for 5 more seconds to make sure there aren't excess restarts
40+
sleep 5
2541
if [[ $(cat $TMP_FILE) != "aaa" ]]; then
2642
exit 1
2743
fi

0 commit comments

Comments
 (0)