Commit c2ab4c9c authored by Jasmine Dahilig's avatar Jasmine Dahilig Committed by Mahmood Ali
Browse files

add test for lifecycle coordinator

parent ae2a4bc7
Showing with 49 additions and 0 deletions
+49 -0
...@@ -24,3 +24,34 @@ func TestTaskHookCoordinator_OnlyMainApp(t *testing.T) { ...@@ -24,3 +24,34 @@ func TestTaskHookCoordinator_OnlyMainApp(t *testing.T) {
require.Fail(t, "channel wasn't closed") require.Fail(t, "channel wasn't closed")
} }
} }
func TestTaskHookCoordinator_Prestart(t *testing.T) {
alloc := mock.Alloc()
tasks := alloc.Job.TaskGroups[0].Tasks
logger := testlog.HCLogger(t)
tasks = append(tasks, mock.InitTask())
tasks = append(tasks, mock.SidecarTask())
coord := newTaskHookCoordinator(logger, tasks)
mainCh := coord.startConditionForTask(tasks[0])
initCh := coord.startConditionForTask(tasks[1])
sideCh := coord.startConditionForTask(tasks[2])
select {
case _, ok := <-initCh:
require.False(t, ok)
case _, ok := <-sideCh:
require.False(t, ok)
default:
require.Fail(t, "prestart channels weren't closed")
}
select {
case <-mainCh:
require.Fail(t, "channel was closed, should be open")
default:
// channel for main task is open, which is correct: coordinator should
// block all other tasks until prestart tasks are completed
}
}
...@@ -1013,3 +1013,21 @@ func ACLManagementToken() *structs.ACLToken { ...@@ -1013,3 +1013,21 @@ func ACLManagementToken() *structs.ACLToken {
ModifyIndex: 20, ModifyIndex: 20,
} }
} }
func SidecarTask() *structs.Task {
return &structs.Task{
Lifecycle: &structs.TaskLifecycleConfig{
Hook: structs.TaskLifecycleHookPrestart,
BlockUntil: structs.TaskLifecycleBlockUntilRunning,
},
}
}
func InitTask() *structs.Task {
return &structs.Task{
Lifecycle: &structs.TaskLifecycleConfig{
Hook: structs.TaskLifecycleHookPrestart,
BlockUntil: structs.TaskLifecycleBlockUntilCompleted,
},
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment