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:
commit
b31efbfac3
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue