test: make vitest worker caps deterministic

This commit is contained in:
Peter Steinberger
2026-04-05 13:29:28 +01:00
parent c74b222ec1
commit 987f4bba80
2 changed files with 10 additions and 50 deletions

View File

@@ -7,12 +7,6 @@ import baseConfig, {
} from "../../vitest.config.ts";
import { parseVitestProcessStats } from "../../vitest.system-load.ts";
const idleVitestStats = {
otherVitestRootCount: 0,
otherVitestWorkerCount: 0,
otherVitestCpuPercent: 0,
} as const;
describe("resolveLocalVitestMaxWorkers", () => {
it("uses a moderate local worker cap on larger hosts", () => {
expect(
@@ -26,7 +20,6 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 64 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toBe(6);
});
@@ -43,7 +36,6 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 128 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toBe(2);
});
@@ -60,7 +52,6 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 128 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toBe(3);
});
@@ -75,7 +66,6 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 16 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toBe(2);
});
@@ -90,7 +80,6 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 128 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toBe(8);
});
@@ -105,7 +94,6 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 128 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toBe(2);
});
@@ -120,54 +108,43 @@ describe("resolveLocalVitestMaxWorkers", () => {
totalMemoryBytes: 256 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toBe(12);
});
});
describe("resolveLocalVitestScheduling", () => {
it("scales back to half capacity when other Vitest work is already consuming most cores", () => {
it("scales back to half capacity when the host load is already saturated", () => {
expect(
resolveLocalVitestScheduling(
{},
{
cpuCount: 16,
loadAverage1m: 0.5,
loadAverage1m: 16,
totalMemoryBytes: 128 * 1024 ** 3,
},
"threads",
{
otherVitestRootCount: 2,
otherVitestWorkerCount: 12,
otherVitestCpuPercent: 1200,
},
),
).toEqual({
maxWorkers: 4,
maxWorkers: 2,
fileParallelism: true,
throttledBySystem: true,
});
});
it("keeps big hosts parallel under moderate contention", () => {
it("keeps big hosts parallel under moderate host contention", () => {
expect(
resolveLocalVitestScheduling(
{},
{
cpuCount: 16,
loadAverage1m: 0.5,
loadAverage1m: 12,
totalMemoryBytes: 128 * 1024 ** 3,
},
"threads",
{
otherVitestRootCount: 1,
otherVitestWorkerCount: 7,
otherVitestCpuPercent: 700,
},
),
).toEqual({
maxWorkers: 6,
maxWorkers: 5,
fileParallelism: true,
throttledBySystem: true,
});
@@ -185,7 +162,6 @@ describe("resolveLocalVitestScheduling", () => {
totalMemoryBytes: 128 * 1024 ** 3,
},
"threads",
idleVitestStats,
),
).toEqual({
maxWorkers: 8,