mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 05:52:48 +07:00
test: verify finit restarts crashing services & registers new PID
We extend the service.sh to emulate a well behaving service that creates and removes its own PID file. The new test emulates a crash by sending SIGKILL to service.sh. We then verify that Finit restarts it, and eventually registers the new PID when the services recreates the PID file. Issue #226 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -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/
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
set -eu
|
||||
|
||||
echo $$ > /run/service.pid
|
||||
|
||||
while true; do
|
||||
sleep 5
|
||||
done
|
||||
|
||||
rm /run/service.pid
|
||||
|
||||
Executable
+35
@@ -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'
|
||||
@@ -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" "$@"
|
||||
|
||||
Reference in New Issue
Block a user