Skip to content

Commit 34df33e

Browse files
authored
test(bench): assert worker arguments at the launch boundary (#133894)
1 parent a50b71e commit 34df33e

2 files changed

Lines changed: 32 additions & 54 deletions

File tree

‎scripts/bench-task-registry-sqlite.ts‎

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ type WorkerLaunchRuntime = {
8787
spawnWorker?: BenchmarkWorkerSpawner;
8888
};
8989

90-
type BenchmarkRuntime = {
91-
runWorker?: typeof runWorker;
92-
writeProgress?: (line: string) => void;
93-
now?: () => number;
94-
};
95-
9690
function usage(): string {
9791
return `OpenClaw durable task registry churn benchmark
9892
@@ -330,23 +324,6 @@ function parseWorkerProcessResult(
330324
});
331325
}
332326

333-
function buildWorkerArgs(options: Options, size: number, stateDir: string): string[] {
334-
return [
335-
"--expose-gc",
336-
"--import",
337-
"tsx",
338-
"scripts/bench-task-registry-sqlite-worker.ts",
339-
"--size",
340-
String(size),
341-
"--cycles",
342-
String(options.cycles),
343-
"--warmup",
344-
String(options.warmup),
345-
"--state-dir",
346-
stateDir,
347-
];
348-
}
349-
350327
function runWorker(
351328
options: Options,
352329
size: number,
@@ -355,7 +332,20 @@ function runWorker(
355332
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-task-registry-bench-"));
356333
try {
357334
return runBenchmarkWorker({
358-
args: buildWorkerArgs(options, size, stateDir),
335+
args: [
336+
"--expose-gc",
337+
"--import",
338+
"tsx",
339+
"scripts/bench-task-registry-sqlite-worker.ts",
340+
"--size",
341+
String(size),
342+
"--cycles",
343+
String(options.cycles),
344+
"--warmup",
345+
String(options.warmup),
346+
"--state-dir",
347+
stateDir,
348+
],
359349
label: `size ${size}`,
360350
sentinel: WORKER_RESULT_SENTINEL,
361351
spawnWorker: runtime.spawnWorker,
@@ -441,14 +431,11 @@ function aggregateWorkerResults(options: Options, workers: WorkerResult[]) {
441431
};
442432
}
443433

444-
function benchmark(options: Options, runtime: BenchmarkRuntime = {}) {
445-
const run = runtime.runWorker ?? runWorker;
434+
function benchmark(options: Options) {
446435
const workers = runBenchmarkJobs(options.sizes, {
447436
prefix: "bench-task-registry-sqlite",
448437
describe: (size) => `size=${size}`,
449-
run: (size) => run(options, size),
450-
now: runtime.now,
451-
writeProgress: runtime.writeProgress,
438+
run: (size) => runWorker(options, size),
452439
});
453440
return aggregateWorkerResults(options, workers);
454441
}
@@ -473,12 +460,9 @@ async function main(argv = process.argv.slice(2)): Promise<void> {
473460

474461
export const testing = {
475462
aggregateWorkerResults,
476-
benchmark,
477-
buildWorkerArgs,
478463
parseOptions,
479464
parseWorkerProcessResult,
480465
runWorker,
481-
summarizeTimings: summarizeBenchmarkTimings,
482466
};
483467

484468
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {

‎test/scripts/bench-task-registry-sqlite.test.ts‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { spawnSync } from "node:child_process";
22
import fs from "node:fs";
3-
import os from "node:os";
43
import path from "node:path";
54
import { describe, expect, it } from "vitest";
65
import {
@@ -148,36 +147,31 @@ describe("durable task registry churn benchmark", () => {
148147
expect(() => testing.parseOptions(["--wat"])).toThrow("Unknown argument: --wat");
149148
});
150149

151-
it("always launches a fresh expose-gc worker for one size", () => {
150+
it("launches an expose-gc worker and removes its state directory after a timeout", () => {
152151
const options = testing.parseOptions(["--sizes", "8", "--cycles", "2", "--warmup", "1"]);
153-
const stateDir = path.join(os.tmpdir(), "benchmark-state");
154-
expect(testing.buildWorkerArgs(options, 8, stateDir)).toEqual([
155-
"--expose-gc",
156-
"--import",
157-
"tsx",
158-
"scripts/bench-task-registry-sqlite-worker.ts",
159-
"--size",
160-
"8",
161-
"--cycles",
162-
"2",
163-
"--warmup",
164-
"1",
165-
"--state-dir",
166-
stateDir,
167-
]);
168-
});
169-
170-
it("removes the parent-owned worker state directory after a timeout", () => {
171-
const options = testing.parseOptions(["--sizes", "2", "--cycles", "1", "--warmup", "0"]);
172152
let stateDir: string | undefined;
173153
expect(() =>
174-
testing.runWorker(options, 2, {
154+
testing.runWorker(options, 8, {
175155
spawnWorker: (_command, args) => {
176156
const stateDirIndex = args.indexOf("--state-dir");
177157
stateDir = args[stateDirIndex + 1];
178158
if (!stateDir) {
179159
throw new Error("missing worker state directory");
180160
}
161+
expect(args).toEqual([
162+
"--expose-gc",
163+
"--import",
164+
"tsx",
165+
"scripts/bench-task-registry-sqlite-worker.ts",
166+
"--size",
167+
"8",
168+
"--cycles",
169+
"2",
170+
"--warmup",
171+
"1",
172+
"--state-dir",
173+
stateDir,
174+
]);
181175
fs.writeFileSync(path.join(stateDir, "openclaw.sqlite"), "timeout fixture");
182176
return {
183177
status: null,

0 commit comments

Comments
 (0)