From: Matteo Croce Date: Tue, 24 Jun 2025 12:47:43 +0000 (+0200) Subject: test: add basic test for timer serialization X-Git-Tag: v258-rc1~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b31b3d5ee7456c6306ebb8924126c1fdda8e63f;p=thirdparty%2Fsystemd.git test: add basic test for timer serialization Set an OnCalendar= timer before the downgrade, then test for its validity after the downgrade and the upgrade. --- diff --git a/test/units/TEST-88-UPGRADE.sh b/test/units/TEST-88-UPGRADE.sh index 61c010e6efc..9185725b3d6 100755 --- a/test/units/TEST-88-UPGRADE.sh +++ b/test/units/TEST-88-UPGRADE.sh @@ -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