From 2c4e86c290689a57687bada20234e4db8de1f994 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 11 Aug 2026 14:06:54 +0200 Subject: [PATCH] test: fix & enhance test for RestartMode= Stay `set +e` in the test masked that this test has apparently never worked in the first place: when a unit is killed with a signal, any bound unit is stopped retroactively via retroactively_stop_dependencies() but it's not restarted again, as the restart for the bound unit is queued as TRY_RESTART in a following transaction - but at this point the bound unit is already inactive, so the TRY_RESTART job collapses into a NOP. Let's account for this and also add a couple of test cases for RestartMode= with an explicit restart, which should trigger the bound unit as well (assuming it's active). Follow-up for 9b42c58a2b0f0703ff48cd8e8b37eee1a36c1887. --- test/units/TEST-03-JOBS.sh | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/test/units/TEST-03-JOBS.sh b/test/units/TEST-03-JOBS.sh index d332606ae2..cecd35fa26 100755 --- a/test/units/TEST-03-JOBS.sh +++ b/test/units/TEST-03-JOBS.sh @@ -175,6 +175,7 @@ assert_rc 3 systemctl --quiet is-active sleep-infinity-restart-normal.service assert_rc 3 systemctl --quiet is-active sleep-infinity-restart-direct.service assert_rc 3 systemctl --quiet is-active counter.service echo 0 >"$COUNTER_FILE" +rm -f "$FAILURE_FLAG_FILE" systemctl start counter.service assert_eq "$(cat "$COUNTER_FILE")" "1" @@ -182,15 +183,32 @@ systemctl --quiet is-active sleep-infinity-restart-normal.service systemctl --quiet is-active sleep-infinity-restart-direct.service systemctl --quiet is-active counter.service -systemctl kill --signal=KILL sleep-infinity-restart-direct.service -systemctl --quiet is-active counter.service -assert_eq "$(cat "$COUNTER_FILE")" "1" -[[ ! -f "$FAILURE_FLAG_FILE" ]] - -systemctl kill --signal=KILL sleep-infinity-restart-normal.service -timeout 10 bash -c 'while [[ ! -f $FAILURE_FLAG_FILE ]]; do sleep .5; done' +# RestartMode=direct + restart: explicit restart should get propagated as TRY_RESTART to the still active +# counter.service +systemctl restart sleep-infinity-restart-direct.service timeout 10 bash -c 'while ! systemctl --quiet is-active counter.service; do sleep .5; done' assert_eq "$(cat "$COUNTER_FILE")" "2" +[[ ! -f "$FAILURE_FLAG_FILE" ]] + +# RestartMode=direct + kill: the fail/inactive state shouldn't get propagated to the counter.service +systemctl kill --signal=KILL sleep-infinity-restart-direct.service +systemctl --quiet is-active counter.service +assert_eq "$(cat "$COUNTER_FILE")" "2" +[[ ! -f "$FAILURE_FLAG_FILE" ]] + +# RestartMode=normal + restart: explicit restart should get propagated as TRY_RESTART to the still active +# counter.service +systemctl restart sleep-infinity-restart-normal.service +timeout 10 bash -c 'while ! systemctl --quiet is-active counter.service; do sleep .5; done' +assert_eq "$(cat "$COUNTER_FILE")" "3" +[[ ! -f "$FAILURE_FLAG_FILE" ]] + +# RestartMode=normal + kill: the fail/inactive state should get propagated to the counter.service, which in +# turn should be stopped +systemctl kill --signal=KILL sleep-infinity-restart-normal.service +timeout 10 bash -c 'while [[ ! -f $FAILURE_FLAG_FILE ]]; do sleep .5; done' +timeout 10 bash -c 'while systemctl --quiet is-active counter.service; do sleep .5; done' +assert_eq "$(cat "$COUNTER_FILE")" "3" # Test shortcutting auto restart