1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00
systemd/test/units/testsuite-11.sh

14 lines
538 B
Bash
Raw Normal View History

#!/usr/bin/env bash
set -eux
set -o pipefail
systemctl --no-block start fail-on-restart.service
active_state=$(systemctl show --value --property ActiveState fail-on-restart.service)
test: wait until the unit leaves the 'inactive' state as well In many CI runs I noticed a race where we check the "active" state a bit too early where the unit is still in the "inactive" state, causing the `is-failed` check to fail. Mitigate this by waiting even if the unit is in the inactive state and introduce a "safe net" which checks whether the unit is not restarting indefinitely or more than it should (as described in the original issue #3166). Example: ``` [ 5.757784] testsuite-11.sh[216]: + systemctl --no-block start fail-on-restart.service [ 5.853657] testsuite-11.sh[222]: ++ systemctl show --value --property ActiveState fail-on-restart.service [ 5.946044] testsuite-11.sh[216]: + active_state=inactive [ 5.946044] testsuite-11.sh[216]: + [[ inactive == \a\c\t\i\v\a\t\i\n\g ]] [ 5.946044] testsuite-11.sh[216]: + [[ inactive == \a\c\t\i\v\e ]] [ 5.946044] testsuite-11.sh[216]: + systemctl is-failed fail-on-restart.service [ 5.946816] systemd[1]: fail-on-restart.service: Passing 0 fds to service [ 5.946913] systemd[1]: fail-on-restart.service: About to execute false [ 5.947011] systemd[1]: fail-on-restart.service: Forked false as 228 [ 5.947093] systemd[1]: fail-on-restart.service: Changed dead -> start [ 5.947172] systemd[1]: Starting Fail on restart... [ 5.947272] systemd[228]: fail-on-restart.service: Executing: false [ 5.960553] testsuite-11.sh[227]: activating [ 5.965188] testsuite-11.sh[216]: + exit 1 [ 6.011838] systemd[1]: Received SIGCHLD from PID 228 (4). [ 6.012510] systemd[1]: fail-on-restart.service: Main process exited, code=exited, status=1/FAILURE [ 6.012638] systemd[1]: fail-on-restart.service: Failed with result 'exit-code'. [ 6.012834] systemd[1]: fail-on-restart.service: Service will restart (restart setting) [ 6.012963] systemd[1]: fail-on-restart.service: Changed running -> failed [ 6.013081] systemd[1]: fail-on-restart.service: Unit entered failed state. ```
2021-06-17 21:17:25 +03:00
while [[ "$active_state" == "activating" || "$active_state" =~ ^(in)?active$ ]]; do
sleep .5
active_state=$(systemctl show --value --property ActiveState fail-on-restart.service)
done
systemctl is-failed fail-on-restart.service || exit 1
test: wait until the unit leaves the 'inactive' state as well In many CI runs I noticed a race where we check the "active" state a bit too early where the unit is still in the "inactive" state, causing the `is-failed` check to fail. Mitigate this by waiting even if the unit is in the inactive state and introduce a "safe net" which checks whether the unit is not restarting indefinitely or more than it should (as described in the original issue #3166). Example: ``` [ 5.757784] testsuite-11.sh[216]: + systemctl --no-block start fail-on-restart.service [ 5.853657] testsuite-11.sh[222]: ++ systemctl show --value --property ActiveState fail-on-restart.service [ 5.946044] testsuite-11.sh[216]: + active_state=inactive [ 5.946044] testsuite-11.sh[216]: + [[ inactive == \a\c\t\i\v\a\t\i\n\g ]] [ 5.946044] testsuite-11.sh[216]: + [[ inactive == \a\c\t\i\v\e ]] [ 5.946044] testsuite-11.sh[216]: + systemctl is-failed fail-on-restart.service [ 5.946816] systemd[1]: fail-on-restart.service: Passing 0 fds to service [ 5.946913] systemd[1]: fail-on-restart.service: About to execute false [ 5.947011] systemd[1]: fail-on-restart.service: Forked false as 228 [ 5.947093] systemd[1]: fail-on-restart.service: Changed dead -> start [ 5.947172] systemd[1]: Starting Fail on restart... [ 5.947272] systemd[228]: fail-on-restart.service: Executing: false [ 5.960553] testsuite-11.sh[227]: activating [ 5.965188] testsuite-11.sh[216]: + exit 1 [ 6.011838] systemd[1]: Received SIGCHLD from PID 228 (4). [ 6.012510] systemd[1]: fail-on-restart.service: Main process exited, code=exited, status=1/FAILURE [ 6.012638] systemd[1]: fail-on-restart.service: Failed with result 'exit-code'. [ 6.012834] systemd[1]: fail-on-restart.service: Service will restart (restart setting) [ 6.012963] systemd[1]: fail-on-restart.service: Changed running -> failed [ 6.013081] systemd[1]: fail-on-restart.service: Unit entered failed state. ```
2021-06-17 21:17:25 +03:00
[[ "$(systemctl show --value --property NRestarts fail-on-restart.service)" -le 3 ]] || exit 1
touch /testok