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 9b42c58a2b.
This commit is contained in:
Frantisek Sumsal
2026-08-11 16:11:25 +02:00
parent 2b81535f74
commit 2c4e86c290
+25 -7
View File
@@ -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