Skip to content

Commit

Permalink
Add igr test for "before" handling
Browse files Browse the repository at this point in the history
  • Loading branch information
davmac314 committed Jun 7, 2023
1 parent 6b11a6d commit c313f32
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/igr-tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ clean:
rm -f check-basic/output.txt check-lint/output.txt check-cycle/output.txt no-command-error/dinit-run.log
rm -rf reload1/sd
rm -rf reload2/sd
rm -rf pseudo-cycle/output/*
rm -rf before-after/output/*
46 changes: 46 additions & 0 deletions src/igr-tests/before-after/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

set -eu

DINIT_EXEC=${DINIT_EXEC:-../../dinit}
DINITCTL_EXEC=${DINITCTL_EXE:-../../dinitctl}

cd "$(dirname "$0")"

# Tests around before/after link functionality.

mkdir -p output
rm -rf output/*

"$DINIT_EXEC" -q -d sd1 -u -p socket &

# Give some time for startup
sleep 0.2

# start parent; should start service2 and then service1 (due to before= in service2).
"$DINITCTL_EXEC" --quiet -p socket start parent

if [ "$(cat output/script-output)" != "$(printf "two\none\n")" ]; then
"$DINITCTL_EXEC" --quiet -p socket shutdown
return 1
fi

rm output/script-output

# unloading and reloading service1 should not lose the before= relationship
"$DINITCTL_EXEC" --quiet -p socket stop parent
"$DINITCTL_EXEC" --quiet -p socket unload parent
"$DINITCTL_EXEC" --quiet -p socket unload service1

"$DINITCTL_EXEC" --quiet -p socket reload service1
"$DINITCTL_EXEC" --quiet -p socket start parent

if [ "$(cat output/script-output)" != "$(printf "two\none\n")" ]; then
"$DINITCTL_EXEC" --quiet -p socket shutdown
return 1
fi

rm output/script-output

"$DINITCTL_EXEC" --quiet -p socket shutdown
# Success.
6 changes: 6 additions & 0 deletions src/igr-tests/before-after/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" >> output/script-output
2 changes: 2 additions & 0 deletions src/igr-tests/before-after/sd1/boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type = internal
before = service1
3 changes: 3 additions & 0 deletions src/igr-tests/before-after/sd1/parent
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type = internal
depends-on = service1
depends-on = service2
3 changes: 3 additions & 0 deletions src/igr-tests/before-after/sd1/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
2 changes: 2 additions & 0 deletions src/igr-tests/before-after/sd1/service2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type = scripted
command = scripts/service.sh two 0.2
2 changes: 2 additions & 0 deletions src/igr-tests/before-after/sd2/boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type = internal
after = service1
1 change: 1 addition & 0 deletions src/igr-tests/before-after/sd2/service1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type = internal
3 changes: 2 additions & 1 deletion src/igr-tests/igr-runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ 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" };
"no-command-error", "add-rm-dep", "var-subst", "svc-start-fail", "dep-not-found", "pseudo-cycle",
"before-after"};
constexpr int num_tests = sizeof(test_dirs) / sizeof(test_dirs[0]);

int passed = 0;
Expand Down

0 comments on commit c313f32

Please sign in to comment.