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:
Joachim Wiberg
2022-02-12 13:30:05 +01:00
parent f567b866a0
commit e9c8d3d740
4 changed files with 45 additions and 0 deletions
+35
View File
@@ -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'