From: Davin McCall Date: Tue, 23 Jun 2020 09:51:37 +0000 (+1000) Subject: Add integration test for add/rm dep via dinitctl X-Git-Tag: v0.8.2~3 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5469480d65ed56192d1a99da9c752b0d6266e248;p=oweals%2Fdinit.git Add integration test for add/rm dep via dinitctl --- diff --git a/src/igr-tests/add-rm-dep/expected1 b/src/igr-tests/add-rm-dep/expected1 new file mode 100644 index 0000000..bdda757 --- /dev/null +++ b/src/igr-tests/add-rm-dep/expected1 @@ -0,0 +1,2 @@ +[{+} ] main +[{+} ] secondary diff --git a/src/igr-tests/add-rm-dep/expected2 b/src/igr-tests/add-rm-dep/expected2 new file mode 100644 index 0000000..e69de29 diff --git a/src/igr-tests/add-rm-dep/expected3 b/src/igr-tests/add-rm-dep/expected3 new file mode 100644 index 0000000..9418e04 --- /dev/null +++ b/src/igr-tests/add-rm-dep/expected3 @@ -0,0 +1,2 @@ +[{+} ] main +[ {-}] secondary diff --git a/src/igr-tests/add-rm-dep/expected4 b/src/igr-tests/add-rm-dep/expected4 new file mode 100644 index 0000000..e69de29 diff --git a/src/igr-tests/add-rm-dep/expected5 b/src/igr-tests/add-rm-dep/expected5 new file mode 100644 index 0000000..0a32b80 --- /dev/null +++ b/src/igr-tests/add-rm-dep/expected5 @@ -0,0 +1 @@ +Service started. diff --git a/src/igr-tests/add-rm-dep/run-test.sh b/src/igr-tests/add-rm-dep/run-test.sh new file mode 100755 index 0000000..e4f3204 --- /dev/null +++ b/src/igr-tests/add-rm-dep/run-test.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +../../dinit -d sd -u -p socket -q main & +DINITPID=$! + +# give time for socket to open +while [ ! -e socket ]; do + sleep 0.1 +done + +STATUS=FAIL + +DINITCTL="../../dinitctl -p socket" + +while + + out=$($DINITCTL list) + if [ $? != 0 ]; then break; fi + if [ "$out" != "$(cat expected1)" ]; then break; fi + # both "main" and "secondary" should be running + + out=$($DINITCTL rm-dep waits-for main secondary) + if [ $? != 0 ]; then break; fi + if [ "$out" != "$(cat expected2)" ]; then break; fi + # "secondary" should stop + + out=$($DINITCTL list) + if [ $? != 0 ]; then break; fi + if [ "$out" != "$(cat expected3)" ]; then break; fi + + out=$($DINITCTL add-dep waits-for main secondary) + if [ $? != 0 ]; then break; fi + if [ "$out" != "$(cat expected4)" ]; then break; fi + # "secondary" will not automatically start, this is a waits-for dep + + out=$($DINITCTL list) + if [ $? != 0 ]; then break; fi + if [ "$out" != "$(cat expected3)" ]; then break; fi + + out=$($DINITCTL wake secondary) + if [ $? != 0 ]; then break; fi + if [ "$out" != "$(cat expected5)" ]; then break; fi + # if we wake "secondary" it should start and remain started + + out=$($DINITCTL list) + if [ $? != 0 ]; then break; fi + if [ "$out" != "$(cat expected1)" ]; then break; fi + + STATUS=PASS + false + +do :; done + +kill $DINITPID +wait $DINITPID + +if [ $STATUS = PASS ]; then exit 0; fi +exit 1 diff --git a/src/igr-tests/add-rm-dep/sd/main b/src/igr-tests/add-rm-dep/sd/main new file mode 100644 index 0000000..463a032 --- /dev/null +++ b/src/igr-tests/add-rm-dep/sd/main @@ -0,0 +1,2 @@ +type = internal +waits-for = secondary diff --git a/src/igr-tests/add-rm-dep/sd/secondary b/src/igr-tests/add-rm-dep/sd/secondary new file mode 100644 index 0000000..06545a6 --- /dev/null +++ b/src/igr-tests/add-rm-dep/sd/secondary @@ -0,0 +1 @@ +type = internal diff --git a/src/igr-tests/igr-runner.cc b/src/igr-tests/igr-runner.cc index bc26801..c18aeda 100644 --- a/src/igr-tests/igr-runner.cc +++ b/src/igr-tests/igr-runner.cc @@ -13,7 +13,7 @@ extern char **environ; int main(int argc, char **argv) { const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop", "restart", - "check-basic", "check-cycle", "reload1", "reload2", "no-command-error" }; + "check-basic", "check-cycle", "reload1", "reload2", "no-command-error", "add-rm-dep" }; constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]); int passed = 0;