]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: several cleanups for DeferReactivation=
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Jul 2025 00:51:55 +0000 (09:51 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 Aug 2025 15:52:18 +0000 (16:52 +0100)
- move to TEST-07-PID1, as it is a timer setting,
- rename the timer and service, to emphasize they are for testing
  DeferReactivation=,
- use timeout command to wait for the timer being triggered several times,
- stop the timer when not necessary,
- accept 9 seconds as delta, as there are fluctuations.

Fixes the following failure:
```
TEST-74-AUX-UTILS.sh[422]: + last=
TEST-74-AUX-UTILS.sh[422]: + read -r time
TEST-74-AUX-UTILS.sh[422]: + '[' -n '' ']'
TEST-74-AUX-UTILS.sh[422]: + last=1753779616
TEST-74-AUX-UTILS.sh[422]: + read -r time
TEST-74-AUX-UTILS.sh[422]: + '[' -n 1753779616 ']'
TEST-74-AUX-UTILS.sh[422]: + delta=9
TEST-74-AUX-UTILS.sh[422]: + '[' 9 -lt 10 ']'
TEST-74-AUX-UTILS.sh[422]: + echo 'Timer fired too early: 9 < 10'
```

Fixes #38403.

(cherry picked from commit 922885e0a5b729a3faaba35676b37013f323d309)

test/integration-tests/TEST-07-PID1/TEST-07-PID1.units/defer-reactivation.service [new file with mode: 0644]
test/integration-tests/TEST-07-PID1/TEST-07-PID1.units/defer-reactivation.timer [new file with mode: 0644]
test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/realtime-test.service [deleted file]
test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/realtime-test.timer [deleted file]
test/meson.build
test/units/TEST-07-PID1.DeferReactivation.sh [new file with mode: 0755]
test/units/TEST-74-AUX-UTILS.defer_reactivation.sh [deleted file]

diff --git a/test/integration-tests/TEST-07-PID1/TEST-07-PID1.units/defer-reactivation.service b/test/integration-tests/TEST-07-PID1/TEST-07-PID1.units/defer-reactivation.service
new file mode 100644 (file)
index 0000000..9c7332d
--- /dev/null
@@ -0,0 +1,6 @@
+[Unit]
+Description=Test for DeferReactivation=yes (service)
+
+[Service]
+Type=simple
+ExecStart=sh -c 'date +%%s >>/tmp/defer-reactivation.log; sleep 5'
diff --git a/test/integration-tests/TEST-07-PID1/TEST-07-PID1.units/defer-reactivation.timer b/test/integration-tests/TEST-07-PID1/TEST-07-PID1.units/defer-reactivation.timer
new file mode 100644 (file)
index 0000000..4fe56b1
--- /dev/null
@@ -0,0 +1,7 @@
+[Unit]
+Description=Test for DeferReactivation=yes (timer)
+
+[Timer]
+OnCalendar=*:*:0/5
+AccuracySec=1us
+DeferReactivation=yes
diff --git a/test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/realtime-test.service b/test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/realtime-test.service
deleted file mode 100644 (file)
index a754626..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-[Unit]
-Description=Testing systemd timers
-
-[Service]
-Type=simple
-ExecStart=sh -c 'date +%%s >>/tmp/realtime-test.log ; sleep 5'
diff --git a/test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/realtime-test.timer b/test/integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units/realtime-test.timer
deleted file mode 100644 (file)
index b870b41..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-[Unit]
-Description=Testing systemd timers
-
-[Timer]
-OnCalendar=*:*:0/5
-AccuracySec=1us
-DeferReactivation=true
-
-[Install]
-WantedBy=timers.target
index e8f2cd78e2f3436c025cbedb8e001534ceb3a1fb..ef748f634a1f57c79efdd7614b8298ba55685a9b 100644 (file)
@@ -335,7 +335,6 @@ if install_tests
                 'integration-tests/TEST-30-ONCLOCKCHANGE/TEST-30-ONCLOCKCHANGE.units',
                 'integration-tests/TEST-52-HONORFIRSTSHUTDOWN/TEST-52-HONORFIRSTSHUTDOWN.units',
                 'integration-tests/TEST-63-PATH/TEST-63-PATH.units',
-                'integration-tests/TEST-74-AUX-UTILS/TEST-74-AUX-UTILS.units',
                 'integration-tests/TEST-80-NOTIFYACCESS/TEST-80-NOTIFYACCESS.units',
         ]
 
diff --git a/test/units/TEST-07-PID1.DeferReactivation.sh b/test/units/TEST-07-PID1.DeferReactivation.sh
new file mode 100755 (executable)
index 0000000..ff795ff
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# shellcheck disable=SC2016
+set -eux
+set -o pipefail
+
+systemctl start defer-reactivation.timer
+
+timeout 20 bash -c 'until [[ -e /tmp/defer-reactivation.log ]]; do sleep .5; done'
+timeout 60 bash -c 'until (( $(cat /tmp/defer-reactivation.log | wc -l) >= 3 )); do sleep 5; done'
+
+systemctl stop defer-reactivation.timer
+
+# If the 'date' command is the service called instantaneously when the timer is triggered, each time delta
+# must be 10 seconds. But in a realistic situation, the command is slightly delayed after the timer is
+# triggered, and the delay has some fluctuations. If a trigger event calls the command at 00:00:01.01, and
+# the next event does at 00:00:10.99, the delta is calculated as 9 seconds. So, let's accept 9 here.
+mindelta=9
+
+last=
+while read -r time; do
+    if [[ -n "$last" ]]; then
+        delta=$(( time - last ))
+        if (( delta < mindelta )); then
+            echo "Timer fired too early: $delta < $mindelta" >/failed
+            exit 1
+        fi
+    fi
+    last=$time
+done </tmp/defer-reactivation.log
diff --git a/test/units/TEST-74-AUX-UTILS.defer_reactivation.sh b/test/units/TEST-74-AUX-UTILS.defer_reactivation.sh
deleted file mode 100755 (executable)
index d1b113d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-# SPDX-License-Identifier: LGPL-2.1-or-later
-set -eux
-set -o pipefail
-
-systemctl start realtime-test.timer
-
-sleep 35
-mindelta=10
-
-last=
-while read -r time; do
-    if [ -n "$last" ]; then
-        delta=$((time - last))
-        if [ "$delta" -lt $mindelta ]; then
-            echo "Timer fired too early: $delta < $mindelta" >/failed
-            break
-        fi
-    fi
-    last=$time
-done </tmp/realtime-test.log
-
-test ! -s /failed