test: new regression test for bug #313

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-11-11 15:53:48 +01:00
parent 61dab8bd75
commit 726f7ba229
5 changed files with 80 additions and 2 deletions
+2
View File
@@ -33,6 +33,7 @@ EXTRA_DIST += runlevel.sh
EXTRA_DIST += start-stop-service.sh
EXTRA_DIST += start-stop-service-sub-config.sh
EXTRA_DIST += start-kill-service.sh
EXTRA_DIST += start-kill-stop.sh
EXTRA_DIST += start-stop-sysv.sh
EXTRA_DIST += start-stop-serv.sh
EXTRA_DIST += signal-service.sh
@@ -65,6 +66,7 @@ TESTS += runlevel.sh
TESTS += start-stop-service.sh
TESTS += start-stop-service-sub-config.sh
TESTS += start-kill-service.sh
TESTS += start-kill-stop.sh
TESTS += start-stop-sysv.sh
TESTS += start-stop-serv.sh
TESTS += signal-service.sh
+66
View File
@@ -0,0 +1,66 @@
#!/bin/sh
# Regression test for Finit bug #313:
# - services get the 'forking' flag on initctl reload
# - stopping a crashing task while its restart callback is pending
# causes state 'running' with pid:0 (i.e., not running at all.)
#
set -eu
TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/tenv/lib.sh"
test_teardown()
{
# texec sh -c "initctl status -j serv"
say "Test done $(date)"
say "Running test teardown."
texec rm -f "$FINIT_CONF"
}
say "Check deps ..."
check_dep jq
check_dep fozza
say "Test start $(date)"
rm -f "$TENV_ROOT"/oldpid
say "Add service stanza in $FINIT_CONF"
texec sh -c "echo 'service [2345] log:stderr serv -np -- Test service' > $FINIT_CONF"
say 'Reload Finit'
texec sh -c "initctl reload"
say 'Verify serv is running ...'
retry 'assert_num_children 1 serv'
say 'Verify reload does not change forking type of service'
#texec sh -c "initctl status -j serv"
texec sh -c "initctl reload"
#texec sh -c "initctl status -j serv"
assert_forking serv false
say 'Simulate service crash (kill -9 ..)'
texec sh -c "initctl debug"
i=0
laps=7
while [ $i -lt $laps ]; do
i=$((i + 1))
say "Lap $i/$laps, killing service ..." # we have this, no sleep needed
texec sh -c "slay serv"
done
say 'Verify stopping service actually stops it'
sleep 1
texec sh -c "initctl stop serv"
sleep 5
#texec sh -c "initctl status serv"
assert_status serv stopped
say 'Verify restarting service actually starts it'
texec sh -c "initctl start serv"
retry 'assert_num_children 1 serv'
+10
View File
@@ -36,6 +36,16 @@ assert_num_services()
assert "$1 services are loaded" "$(texec initctl -t status "$2" | wc -l)" -eq "$1"
}
assert_forking()
{
assert "service $1 forking:$2" "$(texec initctl -j status "$1" | jq -M .forking)" = "$2"
}
assert_nopid()
{
assert "service $1 pid:0" "$(texec initctl -j status "$1" | jq -M .pid)" -eq 0
}
# shellcheck disable=SC2086
assert_new_pid()
{