mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:30:44 +00:00
feat(test): use host-aware local full-suite defaults (#65264)
* feat(test): use host-aware local full-suite defaults * fix(test): remove undefined local profile host info
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
buildVitestRunPlans,
|
||||
shouldAcquireLocalHeavyCheckLock,
|
||||
resolveChangedTargetArgs,
|
||||
resolveParallelFullSuiteConcurrency,
|
||||
} from "../../scripts/test-projects.test-support.mjs";
|
||||
|
||||
describe("scripts/test-projects changed-target routing", () => {
|
||||
@@ -247,6 +248,52 @@ describe("scripts/test-projects local heavy-check lock", () => {
|
||||
});
|
||||
|
||||
describe("scripts/test-projects full-suite sharding", () => {
|
||||
it("uses the large host-aware local profile on roomy local hosts", () => {
|
||||
expect(
|
||||
resolveParallelFullSuiteConcurrency(
|
||||
61,
|
||||
{},
|
||||
{
|
||||
cpuCount: 14,
|
||||
loadAverage1m: 0,
|
||||
totalMemoryBytes: 48 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(10);
|
||||
});
|
||||
|
||||
it("keeps CI full-suite runs serial even on roomy hosts", () => {
|
||||
expect(
|
||||
resolveParallelFullSuiteConcurrency(
|
||||
61,
|
||||
{
|
||||
CI: "true",
|
||||
},
|
||||
{
|
||||
cpuCount: 14,
|
||||
loadAverage1m: 0,
|
||||
totalMemoryBytes: 48 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(1);
|
||||
});
|
||||
|
||||
it("keeps explicit parallel overrides ahead of the host-aware profile", () => {
|
||||
expect(
|
||||
resolveParallelFullSuiteConcurrency(
|
||||
61,
|
||||
{
|
||||
OPENCLAW_TEST_PROJECTS_PARALLEL: "3",
|
||||
},
|
||||
{
|
||||
cpuCount: 14,
|
||||
loadAverage1m: 0,
|
||||
totalMemoryBytes: 48 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(3);
|
||||
});
|
||||
|
||||
it("splits untargeted runs into fixed core shards and per-extension configs", () => {
|
||||
const previousParallel = process.env.OPENCLAW_TEST_PROJECTS_PARALLEL;
|
||||
const previousSerial = process.env.OPENCLAW_TEST_PROJECTS_SERIAL;
|
||||
|
||||
56
test/scripts/vitest-local-scheduling.test.ts
Normal file
56
test/scripts/vitest-local-scheduling.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
resolveLocalFullSuiteProfile,
|
||||
resolveLocalVitestScheduling,
|
||||
shouldUseLargeLocalFullSuiteProfile,
|
||||
} from "../../scripts/lib/vitest-local-scheduling.mjs";
|
||||
|
||||
describe("vitest local full-suite profile", () => {
|
||||
it("selects the large local profile on roomy hosts that are not throttled", () => {
|
||||
const env = {};
|
||||
const hostInfo = {
|
||||
cpuCount: 14,
|
||||
loadAverage1m: 0,
|
||||
totalMemoryBytes: 48 * 1024 ** 3,
|
||||
};
|
||||
|
||||
expect(resolveLocalVitestScheduling(env, hostInfo, "threads")).toEqual({
|
||||
maxWorkers: 6,
|
||||
fileParallelism: true,
|
||||
throttledBySystem: false,
|
||||
});
|
||||
expect(shouldUseLargeLocalFullSuiteProfile(env, hostInfo)).toBe(true);
|
||||
expect(resolveLocalFullSuiteProfile(env, hostInfo)).toEqual({
|
||||
shardParallelism: 10,
|
||||
vitestMaxWorkers: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the smaller local profile when the host is already throttled", () => {
|
||||
const hostInfo = {
|
||||
cpuCount: 14,
|
||||
loadAverage1m: 14,
|
||||
totalMemoryBytes: 48 * 1024 ** 3,
|
||||
};
|
||||
|
||||
expect(shouldUseLargeLocalFullSuiteProfile({}, hostInfo)).toBe(false);
|
||||
expect(resolveLocalFullSuiteProfile({}, hostInfo)).toEqual({
|
||||
shardParallelism: 4,
|
||||
vitestMaxWorkers: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it("never selects the large local profile in CI", () => {
|
||||
const hostInfo = {
|
||||
cpuCount: 14,
|
||||
loadAverage1m: 0,
|
||||
totalMemoryBytes: 48 * 1024 ** 3,
|
||||
};
|
||||
|
||||
expect(shouldUseLargeLocalFullSuiteProfile({ CI: "true" }, hostInfo)).toBe(false);
|
||||
expect(resolveLocalFullSuiteProfile({ CI: "true" }, hostInfo)).toEqual({
|
||||
shardParallelism: 4,
|
||||
vitestMaxWorkers: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,12 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { pluginSdkSubpaths } from "../../scripts/lib/plugin-sdk-entries.mjs";
|
||||
import {
|
||||
detectVitestHostInfo as detectVitestHostInfoImpl,
|
||||
isCiLikeEnv,
|
||||
resolveLocalVitestMaxWorkers as resolveLocalVitestMaxWorkersImpl,
|
||||
resolveLocalVitestScheduling as resolveLocalVitestSchedulingImpl,
|
||||
} from "../../scripts/lib/vitest-local-scheduling.mjs";
|
||||
import {
|
||||
BUNDLED_PLUGIN_ROOT_DIR,
|
||||
BUNDLED_PLUGIN_TEST_GLOB,
|
||||
@@ -9,18 +14,6 @@ import {
|
||||
import { loadVitestExperimentalConfig } from "./vitest.performance-config.ts";
|
||||
import { shouldPrintVitestThrottle } from "./vitest.system-load.ts";
|
||||
|
||||
const clamp = (value: number, min: number, max: number) => Math.max(min, Math.min(max, value));
|
||||
|
||||
function parsePositiveInt(value: string | undefined): number | null {
|
||||
const parsed = Number.parseInt(value ?? "", 10);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
||||
}
|
||||
|
||||
function isSystemThrottleDisabled(env: Record<string, string | undefined>): boolean {
|
||||
const normalized = env.OPENCLAW_VITEST_DISABLE_SYSTEM_THROTTLE?.trim().toLowerCase();
|
||||
return normalized === "1" || normalized === "true";
|
||||
}
|
||||
|
||||
type VitestHostInfo = {
|
||||
cpuCount?: number;
|
||||
loadAverage1m?: number;
|
||||
@@ -45,12 +38,7 @@ export const jsdomOptimizedDeps = {
|
||||
};
|
||||
|
||||
function detectVitestHostInfo(): Required<VitestHostInfo> {
|
||||
return {
|
||||
cpuCount:
|
||||
typeof os.availableParallelism === "function" ? os.availableParallelism() : os.cpus().length,
|
||||
loadAverage1m: os.loadavg()[0] ?? 0,
|
||||
totalMemoryBytes: os.totalmem(),
|
||||
};
|
||||
return detectVitestHostInfoImpl() as Required<VitestHostInfo>;
|
||||
}
|
||||
|
||||
export function resolveLocalVitestMaxWorkers(
|
||||
@@ -58,7 +46,7 @@ export function resolveLocalVitestMaxWorkers(
|
||||
system: VitestHostInfo = detectVitestHostInfo(),
|
||||
pool: OpenClawVitestPool = resolveDefaultVitestPool(env),
|
||||
): number {
|
||||
return resolveLocalVitestScheduling(env, system, pool).maxWorkers;
|
||||
return resolveLocalVitestMaxWorkersImpl(env, system, pool);
|
||||
}
|
||||
|
||||
export function resolveLocalVitestScheduling(
|
||||
@@ -66,91 +54,7 @@ export function resolveLocalVitestScheduling(
|
||||
system: VitestHostInfo = detectVitestHostInfo(),
|
||||
pool: OpenClawVitestPool = resolveDefaultVitestPool(env),
|
||||
): LocalVitestScheduling {
|
||||
const override = parsePositiveInt(env.OPENCLAW_VITEST_MAX_WORKERS ?? env.OPENCLAW_TEST_WORKERS);
|
||||
if (override !== null) {
|
||||
const maxWorkers = clamp(override, 1, 16);
|
||||
return {
|
||||
maxWorkers,
|
||||
fileParallelism: maxWorkers > 1,
|
||||
throttledBySystem: false,
|
||||
};
|
||||
}
|
||||
|
||||
const cpuCount = Math.max(1, system.cpuCount ?? 1);
|
||||
const loadAverage1m = Math.max(0, system.loadAverage1m ?? 0);
|
||||
const totalMemoryGb = (system.totalMemoryBytes ?? 0) / 1024 ** 3;
|
||||
|
||||
// Keep smaller hosts conservative, but let large local boxes actually use
|
||||
// their cores. Thread workers scale much better than the old fork-first cap.
|
||||
let inferred =
|
||||
cpuCount <= 2
|
||||
? 1
|
||||
: cpuCount <= 4
|
||||
? 2
|
||||
: cpuCount <= 8
|
||||
? 4
|
||||
: Math.max(1, Math.floor(cpuCount * 0.75));
|
||||
|
||||
if (totalMemoryGb <= 16) {
|
||||
inferred = Math.min(inferred, 2);
|
||||
} else if (totalMemoryGb <= 32) {
|
||||
inferred = Math.min(inferred, 4);
|
||||
} else if (totalMemoryGb <= 64) {
|
||||
inferred = Math.min(inferred, 6);
|
||||
} else if (totalMemoryGb <= 128) {
|
||||
inferred = Math.min(inferred, 8);
|
||||
} else if (totalMemoryGb <= 256) {
|
||||
inferred = Math.min(inferred, 12);
|
||||
} else {
|
||||
inferred = Math.min(inferred, 16);
|
||||
}
|
||||
|
||||
const loadRatio = loadAverage1m > 0 ? loadAverage1m / cpuCount : 0;
|
||||
if (loadRatio >= 1) {
|
||||
inferred = Math.max(1, Math.floor(inferred / 2));
|
||||
} else if (loadRatio >= 0.75) {
|
||||
inferred = Math.max(1, inferred - 2);
|
||||
} else if (loadRatio >= 0.5) {
|
||||
inferred = Math.max(1, inferred - 1);
|
||||
}
|
||||
|
||||
if (pool === "forks") {
|
||||
inferred = Math.min(inferred, 8);
|
||||
}
|
||||
|
||||
inferred = clamp(inferred, 1, 16);
|
||||
|
||||
if (isSystemThrottleDisabled(env)) {
|
||||
return {
|
||||
maxWorkers: inferred,
|
||||
fileParallelism: true,
|
||||
throttledBySystem: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (loadRatio >= 1) {
|
||||
const maxWorkers = Math.max(1, Math.floor(inferred / 2));
|
||||
return {
|
||||
maxWorkers,
|
||||
fileParallelism: maxWorkers > 1,
|
||||
throttledBySystem: maxWorkers < inferred,
|
||||
};
|
||||
}
|
||||
|
||||
if (loadRatio >= 0.75) {
|
||||
const maxWorkers = Math.max(2, Math.ceil(inferred * 0.75));
|
||||
return {
|
||||
maxWorkers,
|
||||
fileParallelism: true,
|
||||
throttledBySystem: maxWorkers < inferred,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
maxWorkers: inferred,
|
||||
fileParallelism: true,
|
||||
throttledBySystem: false,
|
||||
};
|
||||
return resolveLocalVitestSchedulingImpl(env, system, pool) as LocalVitestScheduling;
|
||||
}
|
||||
|
||||
export function resolveDefaultVitestPool(
|
||||
@@ -164,7 +68,7 @@ export const nonIsolatedRunnerPath = path.join(repoRoot, "test", "non-isolated-r
|
||||
export function resolveRepoRootPath(value: string): string {
|
||||
return path.isAbsolute(value) ? value : path.join(repoRoot, value);
|
||||
}
|
||||
const isCI = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true";
|
||||
const isCI = isCiLikeEnv(process.env);
|
||||
const isWindows = process.platform === "win32";
|
||||
const defaultPool = resolveDefaultVitestPool();
|
||||
const localScheduling = resolveLocalVitestScheduling(
|
||||
|
||||
Reference in New Issue
Block a user