The scheduler was incorrectly calculating min_avail (the amount of needed capacity) for tasks, in two different ways.
In the first task loop, using min instead of max is very wrong and causes the scheduler to miscalculate demand. This won't necessarily lead to obvious problems, but mostly defeats the code's attempt to rank hosts based on demand.
In the second task loop, the calculation is less wrong, but can be negative for tasks with weight less than the overcommit setting. This treats overcommit as "extra capacity" rather than the intention, which was to allow a single task to overshoot the capacity.
The added unit test demonstrates the problem from the second loop, and will fail without this fix.
The scheduler was incorrectly calculating min_avail (the amount of needed capacity) for tasks, in two different ways.
In the first task loop, using min instead of max is very wrong and causes the scheduler to miscalculate demand. This won't necessarily lead to obvious problems, but mostly defeats the code's attempt to rank hosts based on demand.
In the second task loop, the calculation is less wrong, but can be negative for tasks with weight less than the overcommit setting. This treats overcommit as "extra capacity" rather than the intention, which was to allow a single task to overshoot the capacity.
The added unit test demonstrates the problem from the second loop, and will fail without this fix.
Fixes https://pagure.io/koji/issue/4359