diff --git a/test/Makefile.am b/test/Makefile.am index 82d224cc..a1885cae 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -26,6 +26,7 @@ TESTS += add-remove-dynamic-service.sh TESTS += add-remove-dynamic-service-sub-config.sh TESTS += start-stop-service.sh TESTS += start-stop-service-sub-config.sh +TESTS += start-kill-service.sh clean-local: -rm -rf $(builddir)/tenv-root/ diff --git a/test/common/service.sh b/test/common/service.sh index 6b267e7f..870a383c 100755 --- a/test/common/service.sh +++ b/test/common/service.sh @@ -2,6 +2,10 @@ set -eu +echo $$ > /run/service.pid + while true; do sleep 5 done + +rm /run/service.pid diff --git a/test/start-kill-service.sh b/test/start-kill-service.sh new file mode 100755 index 00000000..f396857d --- /dev/null +++ b/test/start-kill-service.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -eu + +TEST_DIR=$(dirname "$0") + +# shellcheck source=/dev/null +. "$TEST_DIR/tenv/lib.sh" + +test_teardown() { + say "Test done $(date)" + say "Running test teardown." + + texec rm -f "$FINIT_CONF" + texec rm -f /test_assets/service.sh +} + +say "Test start $(date)" + +cp "$TEST_DIR"/common/service.sh "$TENV_ROOT"/test_assets/ + +say "Add service stanza in $FINIT_CONF" +texec sh -c "echo 'service [2345] kill:20 log /test_assets/service.sh -- Test service' > $FINIT_CONF" + +say 'Reload Finit' +texec sh -c "initctl reload" +#texec sh -c "initctl status" + +retry 'assert_num_children 1 service.sh' + +say 'Simulate service crash (kill -9 ..)' +texec sh -c "kill -9 \$(cat /run/service.pid)" + +retry 'assert_new_pid service.sh /run/service.pid' +retry 'assert_num_children 1 service.sh' diff --git a/test/tenv/lib.sh b/test/tenv/lib.sh index 444cac5a..22e9aaa1 100755 --- a/test/tenv/lib.sh +++ b/test/tenv/lib.sh @@ -25,6 +25,11 @@ assert_num_children() { assert "$1 services are running" "$(texec pgrep -P 1 "$2" | wc -l)" -eq "$1" } +assert_new_pid() { + # shellcheck disable=SC2086 + assert "Finit has registered new PID" "$(texec initctl |grep $1 |awk '{print $1}')" -eq "$(texec cat $2)" +} + texec() { # shellcheck disable=SC2154 "$TEST_DIR/tenv/exec.sh" "$finit_pid" "$@"