Skip to content

Commit

Permalink
Add more tests for before/after service orderings
Browse files Browse the repository at this point in the history
  • Loading branch information
davmac314 committed Jun 28, 2023
1 parent 2660b2e commit 2ba1849
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/igr-tests/before-after/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@ fi
rm "$IGR_OUTPUT"/output/script-output

stop_dinit

spawn_dinit

# load without loading parent: force service2 loaded first

run_dinitctl $QUIET reload service2
run_dinitctl $QUIET reload service1

run_dinitctl $QUIET start --no-wait service1
run_dinitctl $QUIET start service2

if ! compare_text "$IGR_OUTPUT"/output/script-output "$(printf "one\ntwo\n")"; then
error "$IGR_OUTPUT/output/script-output didn't contain expected result!"
fi

stop_dinit

exit 0
33 changes: 33 additions & 0 deletions src/igr-tests/before-after2/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

set -eu
cd "$(dirname "$0")"
. ../igr_functions.sh

# Tests around before/after link functionality.

rm -rf "$IGR_OUTPUT"/output/*

spawn_dinit

# service2 depends on service1, and service1 is "before" service2

run_dinitctl $QUIET reload service2

# however, we'll remove the depends-on dependency before starting both
run_dinitctl $QUIET rm-dep regular service2 service1

run_dinitctl $QUIET start --no-wait service1
run_dinitctl $QUIET start service2


# Note service1 takes longer to start, but has a "before" service2 so should still start first.
if ! compare_text "$IGR_OUTPUT"/output/script-output "$(printf "one\ntwo\n")"; then
error "$IGR_OUTPUT/output/script-output didn't contain expected result!"
fi

rm "$IGR_OUTPUT"/output/script-output

stop_dinit

exit 0
6 changes: 6 additions & 0 deletions src/igr-tests/before-after2/scripts/service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -eu

sleep "$2"
echo "$1" >> "$IGR_OUTPUT"/output/script-output
1 change: 1 addition & 0 deletions src/igr-tests/before-after2/sd/boot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type = internal
3 changes: 3 additions & 0 deletions src/igr-tests/before-after2/sd/service1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type = scripted
command = scripts/service.sh one 0.5
before = service2
3 changes: 3 additions & 0 deletions src/igr-tests/before-after2/sd/service2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type = scripted
command = scripts/service.sh two 0.2
depends-on = service1
2 changes: 1 addition & 1 deletion src/igr-tests/igr-runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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", "pseudo-cycle",
"before-after"};
"before-after", "before-after2" };
constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]);

int passed = 0;
Expand Down

0 comments on commit 2ba1849

Please sign in to comment.