mirror of
https://github.com/troglobit/finit.git
synced 2026-10-31 13:00:32 +00: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:
1 parent
f567b866a0
commit
e9c8d3d740
4 files changed
+45
No files matched your search
@@ -26,6 +26,7 @@ TESTS += add-remove-dynamic-service.sh
|
|||||||
TESTS += add-remove-dynamic-service-sub-config.sh
|
TESTS += add-remove-dynamic-service-sub-config.sh
|
||||||
TESTS += start-stop-service.sh
|
TESTS += start-stop-service.sh
|
||||||
TESTS += start-stop-service-sub-config.sh
|
TESTS += start-stop-service-sub-config.sh
|
||||||
|
TESTS += start-kill-service.sh
|
||||||
|
|
||||||
clean-local:
|
clean-local:
|
||||||
-rm -rf $(builddir)/tenv-root/
|
-rm -rf $(builddir)/tenv-root/
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
echo $$ > /run/service.pid
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
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 "$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() {
|
texec() {
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
"$TEST_DIR/tenv/exec.sh" "$finit_pid" "$@"
|
"$TEST_DIR/tenv/exec.sh" "$finit_pid" "$@"
|
||||||
|
|||||||
Reference in new issue
Block a user