mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Extra test case and better error message for ambiguous config
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user