mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
client: obey restart policy when attempts == 0
This commit is contained in:
@@ -26,6 +26,11 @@ type RestartTracker struct {
|
||||
}
|
||||
|
||||
func (r *RestartTracker) NextRestart(exitCode int) (bool, time.Duration) {
|
||||
// Hot path if no attempts are expected
|
||||
if r.policy.Attempts == 0 {
|
||||
return false, 0
|
||||
}
|
||||
|
||||
// Check if we have entered a new interval.
|
||||
end := r.startTime.Add(r.policy.Interval)
|
||||
now := time.Now()
|
||||
|
||||
@@ -77,5 +77,14 @@ func TestClient_RestartTracker_NoRestartOnSuccess(t *testing.T) {
|
||||
if shouldRestart, _ := rt.NextRestart(0); shouldRestart {
|
||||
t.Fatalf("NextRestart() returned %v, expected: %v", shouldRestart, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestClient_RestartTracker_ZeroAttempts(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := testPolicy(true, structs.RestartPolicyModeFail)
|
||||
p.Attempts = 0
|
||||
rt := newRestartTracker(p)
|
||||
if actual, when := rt.NextRestart(1); actual {
|
||||
t.Fatalf("expect no restart, got restart/delay: %v", when)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user