Fix progressMade in scheduler

This commit is contained in:
Alex Dadgar 2016-02-22 10:38:04 -08:00
parent 64ecbb7cc2
commit e42720c2f5
2 changed files with 22 additions and 2 deletions

View file

@ -238,8 +238,8 @@ func retryMax(max int, cb func() (bool, error), reset func() bool) error {
// progressMade checks to see if the plan result made allocations or updates.
// If the result is nil, false is returned.
func progressMade(result *structs.PlanResult) bool {
return result != nil && len(result.NodeUpdate) != 0 &&
len(result.NodeAllocation) != 0
return result != nil && (len(result.NodeUpdate) != 0 ||
len(result.NodeAllocation) != 0)
}
// taintedNodes is used to scan the allocations and then check if the

View file

@ -736,3 +736,23 @@ func TestInitTaskState(t *testing.T) {
t.Fatal("Expected and actual not equal")
}
}
func TestProgressMade(t *testing.T) {
noopPlan := &structs.PlanResult{}
if progressMade(nil) || progressMade(noopPlan) {
t.Fatal("no progress plan marked as making progress")
}
m := map[string][]*structs.Allocation{
"foo": []*structs.Allocation{mock.Alloc()},
}
both := &structs.PlanResult{
NodeAllocation: m,
NodeUpdate: m,
}
update := &structs.PlanResult{ NodeUpdate: m }
alloc := &structs.PlanResult{ NodeAllocation: m }
if !(progressMade(both) && progressMade(update) && progressMade(alloc)) {
t.Fatal("bad")
}
}