From 094e00d4053aeb65f7f5951b33f7ebb05c5778f6 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 23 Mar 2022 07:02:10 +0100 Subject: [PATCH] test: update test to use kill(1) replacement slay.sh The slay script checks for common errors and gives some logs and status of Finit when something goes wrong. Helps detect issue #226 when the start-kill-service.sh test runs at 100000 laps. Signed-off-by: Joachim Wiberg --- test/common/slay.sh | 47 ++++++++++++++++++++++++++++++++++++++ test/start-kill-service.sh | 7 +++--- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100755 test/common/slay.sh diff --git a/test/common/slay.sh b/test/common/slay.sh new file mode 100755 index 00000000..5f2cae6d --- /dev/null +++ b/test/common/slay.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +nm=$1 + +# shellcheck disable=SC2046 +getpid() +{ + initctl status "$1" |awk '/PID :/{ print $3; }' +} + +pid=$(getpid "$nm") +if [ -f oldpid ]; then + oldpid=$(cat oldpid) + if [ "$oldpid" = "$pid" ]; then + echo "Looks bad, wait for it ..." + sleep 3 + pid=$(getpid "$nm") + if [ "$oldpid" = "$pid" ]; then + echo "Finit did not deregister old PID $oldpid vs $pid" + initctl status "$nm" + ps + echo "Reloading finit ..." + initctl reload + sleep 1 + initctl status "$nm" + exit 1 + fi + fi +fi + +if [ "$pid" -le 1 ]; then + sleep 3 + pid=$(getpid "$nm") + if [ "$pid" -le 1 ]; then + echo "Got a bad PID: $pid, aborting ..." + ps + sleep 1 + initctl status "$nm" + ps + exit 1 + fi +fi + +echo "$pid" > oldpid + +#echo "PID $pid, kill -9 ..." +kill -9 "$pid" diff --git a/test/start-kill-service.sh b/test/start-kill-service.sh index 16457d29..f028ecf9 100755 --- a/test/start-kill-service.sh +++ b/test/start-kill-service.sh @@ -19,7 +19,9 @@ test_teardown() { say "Test start $(date)" +cp "$TEST_DIR"/common/slay.sh "$TENV_ROOT"/test_assets/ cp "$TEST_DIR"/common/service.sh "$TENV_ROOT"/test_assets/ +rm "$TENV_ROOT"/oldpid say "Add service stanza in $FINIT_CONF" texec sh -c "echo 'service [2345] respawn log /test_assets/service.sh -- Test service' > $FINIT_CONF" @@ -37,10 +39,7 @@ laps=1000 while [ $i -lt $laps ]; do i=$((i + 1)) say "Lap $i/$laps, killing service ..." # we have this, no sleep needed - # texec sh -c "echo \"PID is \$(initctl status service.sh |awk '/PID : /{ print \$3; }')\"; echo \"PID file says \$(cat /run/service.pid)\"; kill -9 \$(cat /run/service.pid)" - #texec sh -c "initctl status service.sh" - #texec sh -c "initctl signal service.sh KILL" - texec sh -c "kill -9 \$(cat /run/service.pid)" + texec sh -c "/test_assets/slay.sh service.sh" done retry 'assert_new_pid service.sh /run/service.pid'