From: Frantisek Sumsal Date: Thu, 17 Jun 2021 18:17:25 +0000 (+0200) Subject: test: wait until the unit leaves the 'inactive' state as well X-Git-Tag: v249-rc2~42 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5384e84c466bac6cacf29cbdcb3b6ef1b928d683;p=thirdparty%2Fsystemd.git 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. ``` --- diff --git a/test/units/testsuite-11.sh b/test/units/testsuite-11.sh index 97ab8be7574..d05f6098777 100755 --- a/test/units/testsuite-11.sh +++ b/test/units/testsuite-11.sh @@ -4,9 +4,10 @@ set -o pipefail systemctl --no-block start fail-on-restart.service active_state=$(systemctl show --value --property ActiveState fail-on-restart.service) -while [[ "$active_state" == "activating" || "$active_state" == "active" ]]; do - sleep 1 +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 +[[ "$(systemctl show --value --property NRestarts fail-on-restart.service)" -le 3 ]] || exit 1 touch /testok