From fff1fa7c5bcf1876d96ffd5b590240b24447e790 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 8 Aug 2019 22:18:26 +1000 Subject: [PATCH] Add integration test for service "restart" function. --- src/igr-tests/Makefile | 1 + src/igr-tests/igr-runner.cc | 2 +- src/igr-tests/restart/basic-ran | 1 + src/igr-tests/restart/basic.sh | 8 ++++++ src/igr-tests/restart/run-test.sh | 46 +++++++++++++++++++++++++++++++ src/igr-tests/restart/sd/basic | 2 ++ src/igr-tests/restart/sd/parent | 2 ++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/igr-tests/restart/basic-ran create mode 100755 src/igr-tests/restart/basic.sh create mode 100755 src/igr-tests/restart/run-test.sh create mode 100644 src/igr-tests/restart/sd/basic create mode 100644 src/igr-tests/restart/sd/parent diff --git a/src/igr-tests/Makefile b/src/igr-tests/Makefile index d033d91..ad73728 100644 --- a/src/igr-tests/Makefile +++ b/src/igr-tests/Makefile @@ -8,3 +8,4 @@ igr-runner: igr-runner.cc clean: rm -f igr-runner basic/basic-ran environ/env-record ps-environ/env-record chain-to/recorded-output + rm -f restart/basic-ran diff --git a/src/igr-tests/igr-runner.cc b/src/igr-tests/igr-runner.cc index 879fe7d..7843557 100644 --- a/src/igr-tests/igr-runner.cc +++ b/src/igr-tests/igr-runner.cc @@ -12,7 +12,7 @@ extern char **environ; int main(int argc, char **argv) { - const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop" }; + const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop", "restart" }; constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]); int passed = 0; diff --git a/src/igr-tests/restart/basic-ran b/src/igr-tests/restart/basic-ran new file mode 100644 index 0000000..817c028 --- /dev/null +++ b/src/igr-tests/restart/basic-ran @@ -0,0 +1 @@ +ran diff --git a/src/igr-tests/restart/basic.sh b/src/igr-tests/restart/basic.sh new file mode 100755 index 0000000..398b17d --- /dev/null +++ b/src/igr-tests/restart/basic.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# basic test; record our run + +echo "ran" > ./basic-ran + +while true; do + sleep .2 +done diff --git a/src/igr-tests/restart/run-test.sh b/src/igr-tests/restart/run-test.sh new file mode 100755 index 0000000..75f70b4 --- /dev/null +++ b/src/igr-tests/restart/run-test.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +rm -f ./basic-ran + +../../dinit -d sd -u -p socket -q \ + parent & +DINITPID=$! + +# give time for socket to open +while [ ! -e socket ]; do + sleep 0.1 +done + +# wait until parent (and therefore 'basic') has fully started +../../dinitctl --quiet -p socket start parent + +sleep 0.1 # time for file to be written + +STATUS=FAIL +if [ -e basic-ran ]; then + if [ "$(cat basic-ran)" = "ran" ]; then + STATUS=PASS + fi +fi + +if [ $STATUS != PASS ]; then + ../../dinitctl --quiet -p socket shutdown + exit 1; +fi + +rm basic-ran + +STATUS=FAIL +../../dinitctl --quiet -p socket restart basic +sleep .1 # time for file write +if [ -e basic-ran ]; then + if [ "$(cat basic-ran)" = "ran" ]; then + STATUS=PASS + fi +fi + +../../dinitctl --quiet -p socket shutdown +wait $DINITPID + +if [ $STATUS = PASS ]; then exit 0; fi +exit 1 diff --git a/src/igr-tests/restart/sd/basic b/src/igr-tests/restart/sd/basic new file mode 100644 index 0000000..808dbe3 --- /dev/null +++ b/src/igr-tests/restart/sd/basic @@ -0,0 +1,2 @@ +type = process +command = ./basic.sh diff --git a/src/igr-tests/restart/sd/parent b/src/igr-tests/restart/sd/parent new file mode 100644 index 0000000..f7c6964 --- /dev/null +++ b/src/igr-tests/restart/sd/parent @@ -0,0 +1,2 @@ +type = internal +waits-for = basic -- 2.25.1