Skip to content

Commit 408e5e7

Browse files
committed
lifecycle: unit test for lifecycle task behavior on restarts
Test the restart behavior of tasks with lifecycles when the allocation or tasks are restarted.
1 parent 4e9ed5f commit 408e5e7

File tree

3 files changed

+474
-175
lines changed

3 files changed

+474
-175
lines changed

client/allochealth/tracker_test.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,30 @@ func TestTracker_Checks_Healthy(t *testing.T) {
9292
func TestTracker_Checks_PendingPostStop_Healthy(t *testing.T) {
9393
t.Parallel()
9494

95-
alloc := mock.LifecycleAllocWithPoststopDeploy()
95+
alloc := mock.LifecycleAllocFromTasks([]mock.LifecycleTaskDef{
96+
{
97+
Name: "web",
98+
RunFor: "1s",
99+
},
100+
{
101+
Name: "side",
102+
RunFor: "1s",
103+
Hook: structs.TaskLifecycleHookPrestart,
104+
IsSidecar: true,
105+
},
106+
{
107+
Name: "post",
108+
RunFor: "1s",
109+
Hook: structs.TaskLifecycleHookPoststop,
110+
},
111+
{
112+
Name: "init",
113+
RunFor: "1s",
114+
Hook: structs.TaskLifecycleHookPrestart,
115+
IsSidecar: false,
116+
},
117+
})
118+
96119
alloc.Job.TaskGroups[0].Migrate.MinHealthyTime = 1 // let's speed things up
97120

98121
// Synthesize running alloc and tasks

0 commit comments

Comments
 (0)