From a9acc52b4e6eb32ff61036821369eedcb4a58f06 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Tue, 17 Nov 2015 02:56:11 -0500 Subject: [PATCH] Fixed validation logic for restart policy when interval is zero --- nomad/structs/structs.go | 3 +++ nomad/structs/structs_test.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index e73a545d9..746b9b6c8 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -885,6 +885,9 @@ type RestartPolicy struct { } func (r *RestartPolicy) Validate() error { + if r.Interval == 0 { + return nil + } if time.Duration(r.Attempts)*r.Delay > r.Interval { return fmt.Errorf("Nomad can't restart the TaskGroup %v times in an interval of %v with a delay of %v", r.Attempts, r.Interval, r.Delay) } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 61102a4bd..8221c40fd 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -356,3 +356,10 @@ func TestEncodeDecode(t *testing.T) { t.Fatalf("bad: %#v %#v", arg, out) } } + +func TestBatchRestartPolicyValidate(t *testing.T) { + rp := RestartPolicy{Attempts: 10, Delay: 25 * time.Second} + if err := rp.Validate(); err != nil { + t.Fatalf("err: %v", err) + } +}