Extra test case and better error message for ambiguous config

This commit is contained in:
Preetha Appan
2018-03-26 13:30:09 -05:00
parent e8dae69e3a
commit 614d3635c2
2 changed files with 12 additions and 1 deletions

View File

@@ -2904,6 +2904,7 @@ func (r *ReschedulePolicy) Validate() error {
if r.Unlimited {
multierror.Append(&mErr, fmt.Errorf("Reschedule Policy with Attempts = %v, Interval = %v, "+
"and Unlimited = %v is ambiguous", r.Attempts, r.Interval, r.Unlimited))
multierror.Append(&mErr, errors.New("If Attempts >0, Unlimited cannot also be set to true"))
}
}
@@ -5686,6 +5687,7 @@ func (a *Allocation) RescheduleEligible(reschedulePolicy *ReschedulePolicy, fail
if reschedulePolicy.Unlimited {
return true
}
// Early return true if there are no attempts yet and the number of allowed attempts is > 0
if (a.RescheduleTracker == nil || len(a.RescheduleTracker.Events) == 0) && attempts > 0 {
return true
}

View File

@@ -2226,7 +2226,7 @@ func TestReschedulePolicy_Validate(t *testing.T) {
},
},
{
desc: "Ambiguous Unlimited config",
desc: "Ambiguous Unlimited config, has both attempts and unlimited set",
ReschedulePolicy: &ReschedulePolicy{
Attempts: 1,
Unlimited: true,
@@ -2252,6 +2252,15 @@ func TestReschedulePolicy_Validate(t *testing.T) {
fmt.Errorf("Max Delay cannot be less than %v (got %v)", ReschedulePolicyMinDelay, 0*time.Second),
},
},
{
desc: "Valid Unlimited config",
ReschedulePolicy: &ReschedulePolicy{
Unlimited: true,
DelayFunction: "exponential",
Delay: 5 * time.Second,
MaxDelay: 1 * time.Hour,
},
},
}
for _, tc := range testCases {