Merge pull request #429 from hashicorp/b-batch-restart-policy

Fixed validation logic for restart policy when interval is zero
This commit is contained in:
Diptanu Choudhury 2015-11-17 12:09:30 -08:00
commit b31efbfac3
2 changed files with 10 additions and 0 deletions

View File

@ -885,6 +885,9 @@ type RestartPolicy struct {
} }
func (r *RestartPolicy) Validate() error { func (r *RestartPolicy) Validate() error {
if r.Interval == 0 {
return nil
}
if time.Duration(r.Attempts)*r.Delay > r.Interval { 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) 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)
} }

View File

@ -356,3 +356,10 @@ func TestEncodeDecode(t *testing.T) {
t.Fatalf("bad: %#v %#v", arg, out) 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)
}
}