fix(ci): keep equal-duration shard allocation from leaving jobs empty (#14257)

Co-authored-by: ShuaixinHuang <ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
ShuaixinHuang
2026-11-25 00:48:01 +08:00
committed by GitHub
parent 8a77faf842
commit 5aef49a421
2 changed files with 14 additions and 1 deletions
@@ -235,3 +235,13 @@ describe("duration shard allocation", () => {
).toBe(300);
});
});
it("uses both shards when equal files fit into spare workers in one shard", () => {
const items = ["a", "b"].map((key) => ({
item: key,
key,
duration: 20,
laneWidth: 2,
}));
expect(allocateByDuration(items, 2)).toEqual([["a"], ["b"]]);
});
+4 -1
View File
@@ -181,7 +181,10 @@ export function allocateByDuration<T>(
for (const candidate of shards.slice(1)) {
const phases = place(candidate.phases, entry, duration);
const wall = wallOf(phases);
if (wall < chosenWall) {
if (
wall < chosenWall ||
(wall === chosenWall && candidate.items.length < chosen.items.length)
) {
chosen = candidate;
chosenPhases = phases;
chosenWall = wall;