Add integration test for add/rm dep via dinitctl
authorDavin McCall <davmac@davmac.org>
Tue, 23 Jun 2020 09:51:37 +0000 (19:51 +1000)
committerDavin McCall <davmac@davmac.org>
Tue, 23 Jun 2020 09:51:37 +0000 (19:51 +1000)
src/igr-tests/add-rm-dep/expected1 [new file with mode: 0644]
src/igr-tests/add-rm-dep/expected2 [new file with mode: 0644]
src/igr-tests/add-rm-dep/expected3 [new file with mode: 0644]
src/igr-tests/add-rm-dep/expected4 [new file with mode: 0644]
src/igr-tests/add-rm-dep/expected5 [new file with mode: 0644]
src/igr-tests/add-rm-dep/run-test.sh [new file with mode: 0755]
src/igr-tests/add-rm-dep/sd/main [new file with mode: 0644]
src/igr-tests/add-rm-dep/sd/secondary [new file with mode: 0644]
src/igr-tests/igr-runner.cc

diff --git a/src/igr-tests/add-rm-dep/expected1 b/src/igr-tests/add-rm-dep/expected1
new file mode 100644 (file)
index 0000000..bdda757
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..9418e04
--- /dev/null
@@ -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 (file)
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 (file)
index 0000000..0a32b80
--- /dev/null
@@ -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 (executable)
index 0000000..e4f3204
--- /dev/null
@@ -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 (file)
index 0000000..463a032
--- /dev/null
@@ -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 (file)
index 0000000..06545a6
--- /dev/null
@@ -0,0 +1 @@
+type = internal
index bc26801c602cfbc039dc04d259d82f205af30492..c18aeda520bafd33895c2a0daad33b9c2f82f2db 100644 (file)
@@ -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;