Browse Source

Test we can load services where "before" link refers to dependent

A "before" link is a kind-of reverse dependency. It needs special
handling to check for cycles. If service (A) depends on (B) then it is
allowed for (B) to have a "before =" for (A).
Davin McCall 10 months ago
parent
commit
8ee65e1b3c

+ 1 - 0
.gitignore

@@ -20,6 +20,7 @@
 /build/tools/mconfig-gen
 
 # Integration test output:
+/src/igr-tests/*/output/**
 /src/igr-tests/basic/basic-ran
 /src/igr-tests/environ/env-record
 /src/igr-tests/environ2/env-record

+ 1 - 1
src/igr-tests/igr-runner.cc

@@ -14,7 +14,7 @@ int main(int argc, char **argv)
 {
     const char * const test_dirs[] = { "basic", "environ", "environ2", "ps-environ", "chain-to", "force-stop",
             "restart", "check-basic", "check-cycle", "check-cycle2", "check-lint", "reload1", "reload2",
-			"no-command-error", "add-rm-dep", "var-subst", "svc-start-fail", "dep-not-found" };
+			"no-command-error", "add-rm-dep", "var-subst", "svc-start-fail", "dep-not-found", "pseudo-cycle" };
     constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]);
 
     int passed = 0;

+ 10 - 0
src/igr-tests/pseudo-cycle/README

@@ -0,0 +1,10 @@
+This test has three services, which have no cycle but do have a "before" relationship:
+
+boot
+   depends-on -->
+middle
+   depends-on -->
+service
+   before = boot
+
+This should not be considered a cyclic dependency. The service script should run.

+ 19 - 0
src/igr-tests/pseudo-cycle/run-test.sh

@@ -0,0 +1,19 @@
+#!/bin/sh
+
+cd "$(dirname "$0")"
+
+mkdir -p output
+rm -rf output/*
+
+"$DINIT_EXEC" -d sd -u -p socket -q \
+	boot
+
+STATUS=FAIL
+if [ -e output/svc-script ]; then
+   if [ "$(cat output/svc-script)" = "ran" ]; then
+       STATUS=PASS
+   fi
+fi
+
+if [ $STATUS = PASS ]; then exit 0; fi
+exit 1

+ 3 - 0
src/igr-tests/pseudo-cycle/sd/boot

@@ -0,0 +1,3 @@
+type = internal
+depends-on = middle
+restart = no

+ 2 - 0
src/igr-tests/pseudo-cycle/sd/middle

@@ -0,0 +1,2 @@
+type = internal
+depends-on = service

+ 4 - 0
src/igr-tests/pseudo-cycle/sd/service

@@ -0,0 +1,4 @@
+type = process
+command = ./svc-script.sh
+restart = false
+before = boot

+ 5 - 0
src/igr-tests/pseudo-cycle/svc-script.sh

@@ -0,0 +1,5 @@
+#!/bin/sh
+# record our run
+
+mkdir -p output
+echo "ran" > ./output/svc-script