test policy delay for startup error

This commit is contained in:
Cameron Davison 2016-07-11 20:54:36 -05:00
parent dd314ea06e
commit d7fe56ecf3
1 changed files with 27 additions and 2 deletions

View File

@ -94,9 +94,9 @@ func TestClient_RestartTracker_ZeroAttempts(t *testing.T) {
} }
} }
func TestClient_RestartTracker_StartError_Recoverable(t *testing.T) { func TestClient_RestartTracker_StartError_Recoverable_Fail(t *testing.T) {
t.Parallel() t.Parallel()
p := testPolicy(true, structs.RestartPolicyModeDelay) p := testPolicy(true, structs.RestartPolicyModeFail)
rt := newRestartTracker(p, structs.JobTypeSystem) rt := newRestartTracker(p, structs.JobTypeSystem)
recErr := cstructs.NewRecoverableError(fmt.Errorf("foo"), true) recErr := cstructs.NewRecoverableError(fmt.Errorf("foo"), true)
for i := 0; i < p.Attempts; i++ { for i := 0; i < p.Attempts; i++ {
@ -114,3 +114,28 @@ func TestClient_RestartTracker_StartError_Recoverable(t *testing.T) {
t.Fatalf("NextRestart() returned %v; want %v", state, structs.TaskNotRestarting) t.Fatalf("NextRestart() returned %v; want %v", state, structs.TaskNotRestarting)
} }
} }
func TestClient_RestartTracker_StartError_Recoverable_Delay(t *testing.T) {
t.Parallel()
p := testPolicy(true, structs.RestartPolicyModeDelay)
rt := newRestartTracker(p, structs.JobTypeSystem)
recErr := cstructs.NewRecoverableError(fmt.Errorf("foo"), true)
for i := 0; i < p.Attempts; i++ {
state, when := rt.SetStartError(recErr).GetState()
if state != structs.TaskRestarting {
t.Fatalf("NextRestart() returned %v, want %v", state, structs.TaskRestarting)
}
if !withinJitter(p.Delay, when) {
t.Fatalf("NextRestart() returned %v; want %v+jitter", when, p.Delay)
}
}
// Next restart should cause delay
state, when := rt.SetStartError(recErr).GetState()
if state != structs.TaskRestarting {
t.Fatalf("NextRestart() returned %v; want %v", state, structs.TaskRestarting)
}
if !(when > p.Delay && when <= p.Interval) {
t.Fatalf("NextRestart() returned %v; want > %v and <= %v", when, p.Delay, p.Interval)
}
}