Skip to content

Commit

Permalink
test: shutdown in order
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Mar 2, 2024
1 parent 8a6e33b commit 1cc0938
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
31 changes: 31 additions & 0 deletions fixtures-code/process-compose-shutdown-inorder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "0.5"

log_level: debug
log_length: 1000

processes:
procA:
command: |
echo "A: starting"
procB:
command: |
echo "B: starting"
is_daemon: true
shutdown:
command: |
echo "B: exiting"
depends_on:
procA:
condition: process_started

procC:
command: |
echo "C: starting"
isDaemon: true
shutdown:
command: |
echo "C: exiting"
depends_on:
procB:
condition: process_started
66 changes: 66 additions & 0 deletions src/app/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,69 @@ func TestSystem_TestProcListToRun(t *testing.T) {
}
})
}

func TestSystem_TestProcListShutsDownInOrder(t *testing.T) {
fixture1 := filepath.Join("..", "..", "fixtures-code", "process-compose-shutdown-inorder.yaml")
t.Run("Single Proc with deps", func(t *testing.T) {
project, err := loader.Load(&loader.LoaderOptions{
FileNames: []string{fixture1},
})
if err != nil {
t.Errorf(err.Error())
return
}
numProc := len(project.Processes)
runner, err := NewProjectRunner(&ProjectOpts{
project: project,
processesToRun: []string{},
mainProcessArgs: []string{},
isOrderedShutDown: true,
})
if err != nil {
t.Errorf(err.Error())
return
}
if len(runner.project.Processes) != numProc {
t.Errorf("should have %d processes", numProc)
}
for name, proc := range runner.project.Processes {
if proc.Disabled {
t.Errorf("process %s is disabled", name)
}
}

go runner.Run()
time.Sleep(10 * time.Millisecond)
states, err := runner.GetProcessesState()
if err != nil {
t.Errorf(err.Error())
return
}
want := 3
if len(states.States) != want {
t.Errorf("len(states.States) = %d, want %d", len(states.States), want)
}

time.Sleep(10 * time.Millisecond)
err = runner.ShutDownProject()
if err != nil {
t.Errorf(err.Error())
return
}
runningProcesses := 0
for _, proc := range runner.runningProcesses {
processState, err := runner.GetProcessState(proc.getName())
if err != nil {
t.Errorf(err.Error())
return
}
if processState.IsRunning {
runningProcesses++
}
}
want = 0
if runningProcesses != want {
t.Errorf("len(runner.runningProcesses) = %d, want %d", len(runner.runningProcesses), want)
}
})
}

0 comments on commit 1cc0938

Please sign in to comment.