Add integration test for gentle stop/force stop.
authorDavin McCall <davmac@davmac.org>
Sat, 27 Jul 2019 06:03:21 +0000 (16:03 +1000)
committerDavin McCall <davmac@davmac.org>
Sat, 27 Jul 2019 06:03:21 +0000 (16:03 +1000)
src/igr-tests/force-stop/expected-1 [new file with mode: 0644]
src/igr-tests/force-stop/expected-2.err [new file with mode: 0644]
src/igr-tests/force-stop/expected-3 [new file with mode: 0644]
src/igr-tests/force-stop/run-test.sh [new file with mode: 0755]
src/igr-tests/force-stop/sd/boot [new file with mode: 0644]
src/igr-tests/force-stop/sd/critical [new file with mode: 0644]
src/igr-tests/force-stop/sd/intermediary [new file with mode: 0644]
src/igr-tests/igr-runner.cc

diff --git a/src/igr-tests/force-stop/expected-1 b/src/igr-tests/force-stop/expected-1
new file mode 100644 (file)
index 0000000..6737262
--- /dev/null
@@ -0,0 +1,3 @@
+[{+}     ] boot
+[{+}     ] critical
+[{+}     ] intermediary
diff --git a/src/igr-tests/force-stop/expected-2.err b/src/igr-tests/force-stop/expected-2.err
new file mode 100644 (file)
index 0000000..561b7d2
--- /dev/null
@@ -0,0 +1,3 @@
+dinitctl: Cannot stop service due to the following dependents:
+(Only direct dependents are listed. Exercise caution before using '--force' !!)
+  intermediary boot
diff --git a/src/igr-tests/force-stop/expected-3 b/src/igr-tests/force-stop/expected-3
new file mode 100644 (file)
index 0000000..d081f7a
--- /dev/null
@@ -0,0 +1 @@
+Service stopped.
diff --git a/src/igr-tests/force-stop/run-test.sh b/src/igr-tests/force-stop/run-test.sh
new file mode 100755 (executable)
index 0000000..44d52b5
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+../../dinit -d sd -u -p socket -q &
+DINITPID=$!
+
+# give time for socket to open
+while [ ! -e socket ]; do
+    sleep 0.1
+done
+
+DINITCTLOUT="$(../../dinitctl -p socket list)"
+if [ "$DINITCTLOUT" != "$(cat expected-1)" ]; then
+    kill $DINITPID; wait $DINITPID
+    exit 1
+fi
+
+DINITCTLOUT="$(../../dinitctl -p socket stop critical 2>&1)"
+if [ "$DINITCTLOUT" != "$(cat expected-2.err)" ]; then
+    kill $DINITPID; wait $DINITPID
+    exit 1
+fi
+
+DINITCTLOUT="$(../../dinitctl -p socket stop --force critical 2>&1)"
+if [ "$DINITCTLOUT" != "$(cat expected-3)" ]; then
+    kill $DINITPID; wait $DINITPID
+    exit 1;
+fi
+
+# Note dinit should shutdown since all services stopped.
+wait $DINITPID
+
+# Passed:
+exit 0
diff --git a/src/igr-tests/force-stop/sd/boot b/src/igr-tests/force-stop/sd/boot
new file mode 100644 (file)
index 0000000..b55189a
--- /dev/null
@@ -0,0 +1,3 @@
+type = internal
+depends-on = critical
+depends-on = intermediary
diff --git a/src/igr-tests/force-stop/sd/critical b/src/igr-tests/force-stop/sd/critical
new file mode 100644 (file)
index 0000000..06545a6
--- /dev/null
@@ -0,0 +1 @@
+type = internal
diff --git a/src/igr-tests/force-stop/sd/intermediary b/src/igr-tests/force-stop/sd/intermediary
new file mode 100644 (file)
index 0000000..187d6af
--- /dev/null
@@ -0,0 +1,2 @@
+type = internal
+depends-on = critical
index e8a906be138c9ab2a620a53d038482f88d460377..879fe7d6df5207660d724a70a307e27205ff1dcf 100644 (file)
@@ -12,7 +12,7 @@ extern char **environ;
 
 int main(int argc, char **argv)
 {
-    const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to" };
+    const char * const test_dirs[] = { "basic", "environ", "ps-environ", "chain-to", "force-stop" };
     constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]);
 
     int passed = 0;