mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
test: new test, verify task behavior with conditions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ EXTRA_DIST = skel/bin/busybox-x86_64.md5 skel/sbin/service.sh skel/bin/slay \
|
||||
EXTRA_DIST += setup-root.sh
|
||||
EXTRA_DIST += add-remove-dynamic-service.sh
|
||||
EXTRA_DIST += add-remove-dynamic-service-sub-config.sh
|
||||
EXTRA_DIST += cond-start-task.sh
|
||||
EXTRA_DIST += start-stop-service.sh
|
||||
EXTRA_DIST += start-stop-service-sub-config.sh
|
||||
EXTRA_DIST += start-kill-service.sh
|
||||
@@ -41,6 +42,7 @@ TESTS = checkself.sh
|
||||
TESTS += setup-root.sh
|
||||
TESTS += add-remove-dynamic-service.sh
|
||||
TESTS += add-remove-dynamic-service-sub-config.sh
|
||||
TESTS += cond-start-task.sh
|
||||
TESTS += start-stop-service.sh
|
||||
TESTS += start-stop-service-sub-config.sh
|
||||
TESTS += start-kill-service.sh
|
||||
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
# A run/task runs once per runlevel, unless its .conf is touched
|
||||
# then it will run again on initctl reload. This test verifies
|
||||
# this behavior, with the added twist of starting the task by
|
||||
# asserting a condition.
|
||||
set -eu
|
||||
|
||||
TEST_CONF=/etc/finit.d/foo.conf
|
||||
TEST_DIR=$(dirname "$0")
|
||||
|
||||
test_setup()
|
||||
{
|
||||
say "Test start $(date)"
|
||||
}
|
||||
|
||||
test_teardown()
|
||||
{
|
||||
say "Test done $(date)"
|
||||
say "Running test teardown."
|
||||
texec rm -f "$TEST_CONF"
|
||||
}
|
||||
|
||||
test_one()
|
||||
{
|
||||
cond=$1
|
||||
stanza=$2
|
||||
|
||||
say "Add stanza '$stanza' to $TEST_CONF ..."
|
||||
texec sh -c "echo '$stanza' > $TEST_CONF"
|
||||
|
||||
say 'Reload Finit'
|
||||
# texec sh -c "initctl debug"
|
||||
texec sh -c "initctl reload"
|
||||
# texec sh -c "initctl status"
|
||||
# texec sh -c "ps"
|
||||
|
||||
say 'Asserting condition'
|
||||
texec sh -c "initctl cond set $cond"
|
||||
|
||||
# texec sh -c "initctl status"
|
||||
# texec sh -c "ps"
|
||||
# texec sh -c "initctl status task.sh"
|
||||
|
||||
sleep 1
|
||||
assert_file_contains /run/task.state 1
|
||||
|
||||
say 'Reload Finit'
|
||||
texec sh -c "initctl reload"
|
||||
sleep 1
|
||||
say 'Ensure task has not run again ...'
|
||||
assert_file_contains /run/task.state 1
|
||||
|
||||
say 'Switch to another runlevel ...'
|
||||
texec sh -c "initctl runlevel 3"
|
||||
sleep 1
|
||||
say 'Ensure task has run again ...'
|
||||
assert_file_contains /run/task.state 2
|
||||
|
||||
say 'Touch task.sh .conf file and reload Finit ...'
|
||||
texec sh -c "touch $TEST_CONF"
|
||||
texec sh -c "initctl reload"
|
||||
sleep 1
|
||||
# texec sh -c "initctl status task.sh"
|
||||
assert_file_contains /run/task.state 3
|
||||
|
||||
say "Done, drop stanza from $TEST_CONF ..."
|
||||
texec sh -c "rm $TEST_CONF"
|
||||
texec sh -c "initctl reload"
|
||||
}
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
. "$TEST_DIR/tenv/lib.sh"
|
||||
|
||||
test_one "hello" "task <usr/hello> task.sh -- Hello task"
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
num=$(cat /run/task.state)
|
||||
if [ -z "$num" ]; then
|
||||
num=0
|
||||
fi
|
||||
|
||||
num=$((num + 1))
|
||||
echo $num > /run/task.state
|
||||
@@ -21,6 +21,11 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
assert_file_contains()
|
||||
{
|
||||
assert "File $1 contains the string $2" "$(texec grep "$2" "$1")"
|
||||
}
|
||||
|
||||
assert_num_children()
|
||||
{
|
||||
assert "$1 services are running" "$(texec pgrep -P 1 "$2" | wc -l)" -eq "$1"
|
||||
|
||||
Reference in New Issue
Block a user