mirror of https://github.com/openclaw/openclaw.git
fix(test): default local Vitest to one worker (#60281)
This commit is contained in:
parent
69da71c0ce
commit
4e60653959
|
|
@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
|||
import baseConfig, { resolveLocalVitestMaxWorkers } from "../vitest.config.ts";
|
||||
|
||||
describe("resolveLocalVitestMaxWorkers", () => {
|
||||
it("derives a moderate local cap for 64 GiB hosts", () => {
|
||||
it("defaults local runs to a single worker even on larger hosts", () => {
|
||||
expect(
|
||||
resolveLocalVitestMaxWorkers(
|
||||
{
|
||||
|
|
@ -13,7 +13,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
|||
totalMemoryBytes: 64 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(4);
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it("lets OPENCLAW_VITEST_MAX_WORKERS override the inferred cap", () => {
|
||||
|
|
@ -45,7 +45,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
|||
).toBe(3);
|
||||
});
|
||||
|
||||
it("keeps memory-constrained hosts conservative", () => {
|
||||
it("keeps memory-constrained hosts on the same single-worker default", () => {
|
||||
expect(
|
||||
resolveLocalVitestMaxWorkers(
|
||||
{},
|
||||
|
|
@ -54,10 +54,10 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
|||
totalMemoryBytes: 16 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(2);
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it("lets roomy hosts use a higher default cap", () => {
|
||||
it("keeps roomy hosts on the same single-worker default", () => {
|
||||
expect(
|
||||
resolveLocalVitestMaxWorkers(
|
||||
{},
|
||||
|
|
@ -66,7 +66,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
|||
totalMemoryBytes: 128 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(6);
|
||||
).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
|
@ -16,27 +15,12 @@ function parsePositiveInt(value) {
|
|||
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
||||
}
|
||||
|
||||
export function resolveLocalVitestMaxWorkers(
|
||||
env = process.env,
|
||||
system = {
|
||||
cpuCount: os.cpus().length || 1,
|
||||
totalMemoryBytes: os.totalmem(),
|
||||
},
|
||||
) {
|
||||
export function resolveLocalVitestMaxWorkers(env = process.env, _system = undefined) {
|
||||
const override = parsePositiveInt(env.OPENCLAW_VITEST_MAX_WORKERS ?? env.OPENCLAW_TEST_WORKERS);
|
||||
if (override !== null) {
|
||||
return clamp(override, 1, 16);
|
||||
}
|
||||
|
||||
const cpuCount = Math.max(1, system.cpuCount || 1);
|
||||
const memoryGiB = (system.totalMemoryBytes || 0) / 1024 ** 3;
|
||||
let workers = cpuCount >= 16 ? 6 : cpuCount >= 10 ? 4 : cpuCount >= 6 ? 3 : 2;
|
||||
if (memoryGiB < 24) {
|
||||
workers = Math.min(workers, 2);
|
||||
} else if (memoryGiB < 48) {
|
||||
workers = Math.min(workers, 3);
|
||||
}
|
||||
return clamp(workers, 1, 16);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const repoRoot = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
|
|
|||
Loading…
Reference in New Issue