]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add basic test for timer serialization
authorMatteo Croce <teknoraver@meta.com>
Tue, 24 Jun 2025 12:47:43 +0000 (14:47 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 17 Jul 2025 16:22:32 +0000 (17:22 +0100)
Set an OnCalendar= timer before the downgrade, then test for its
validity after the downgrade and the upgrade.

test/units/TEST-88-UPGRADE.sh

index 61c010e6efc7876999084a2149221664751717a6..9185725b3d674b142cb9b690ef10f5e2b238477d 100755 (executable)
@@ -28,7 +28,7 @@ if [[ $($unitscmd --output json | jq length) -gt 0 ]]; then
 fi
 
 check_sd() {
-    local unit fail=0
+    local unit fail=0 timer1_new timer2_new
     for unit in $($unitscmd --output json | jq -r '.[].unit'); do
         if ! grep -sxqF "$unit" /tmp/failed-units; then
             fail=1
@@ -52,12 +52,33 @@ check_sd() {
         fail=1
     fi
 
+    # ignore the systemctl status error code until we sort out
+    # https://github.com/systemd/systemd/issues/38214
+    systemctl status upgrade_timer_test.{service,timer} || true
+    timer1_new=$(systemctl show -P TimersCalendar upgrade_timer_test.timer)
+    timer2_new=$(systemctl show -P NextElapseUSecRealtime upgrade_timer_test.timer)
+
+    if [[ "$timer1" != "$timer1_new" ]]; then
+        echo "Timer changed unexpectedly: '$timer1' != '$timer1_new'"
+        fail=1
+    fi
+    if [[ "$timer2" != "$timer2_new" ]]; then
+        echo "Timer changed unexpectedly: '$timer2' != '$timer2_new'"
+        fail=1
+    fi
+
     [[ $fail -eq 0 ]]
 }
 
 # Copy the unit in /run so systemd finds it after the downgrade
 cp /usr/lib/systemd/tests/testdata/units/TEST-88-UPGRADE.service /run/systemd/system
 
+now=$(date +%s)
+after_2h=$((now + 3600 * 2))
+systemd-run --on-calendar="@$after_2h" -u upgrade_timer_test date
+timer1=$(systemctl show -P TimersCalendar upgrade_timer_test.timer)
+timer2=$(systemctl show -P NextElapseUSecRealtime upgrade_timer_test.timer)
+
 dnf downgrade -y --allowerasing --disablerepo '*' "$pkgdir"/distro/*.rpm
 
 # Some distros don't ship networkd, so the test will always fail