Skip to content

Commit 8e6624c

Browse files
committed
fix(qa): reject duplicate sibling bench cases
1 parent 273eed4 commit 8e6624c

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

scripts/bench-cli-startup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,12 @@ function parsePresets(raw: string | undefined): string[] {
533533
function resolveCases(options: { presets: string[]; caseIds: string[] }): CommandCase[] {
534534
const byId = new Map(COMMAND_CASES.map((commandCase) => [commandCase.id, commandCase]));
535535
if (options.caseIds.length > 0) {
536+
const seenIds = new Set<string>();
536537
return options.caseIds.map((id) => {
538+
if (seenIds.has(id)) {
539+
throw new Error(`Duplicate --case "${id}"`);
540+
}
541+
seenIds.add(id);
537542
const commandCase = byId.get(id);
538543
if (!commandCase) {
539544
throw new Error(`Unknown --case "${id}"`);

scripts/bench-gateway-restart.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,13 @@ function resolveCases(caseIds: string[]): GatewayBenchCase[] {
337337
if (caseIds.length === 0) {
338338
return [GATEWAY_CASES[0]];
339339
}
340+
const seenIds = new Set<string>();
340341
const byId = new Map(GATEWAY_CASES.map((benchCase) => [benchCase.id, benchCase]));
341342
return caseIds.map((id) => {
343+
if (seenIds.has(id)) {
344+
throw new CliArgumentError(`Duplicate --case "${id}"`);
345+
}
346+
seenIds.add(id);
342347
const benchCase = byId.get(id);
343348
if (!benchCase) {
344349
throw new Error(`Unknown --case "${id}"`);

test/scripts/bench-cli-startup.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ describe("bench-cli-startup", () => {
5757
expect(result.stderr).not.toContain("\n at ");
5858
});
5959

60+
it("rejects duplicate benchmark cases before running benchmarks", () => {
61+
const result = spawnSync(
62+
process.execPath,
63+
[
64+
"--import",
65+
"tsx",
66+
"scripts/bench-cli-startup.ts",
67+
"--case",
68+
"version",
69+
"--case",
70+
"version",
71+
],
72+
{
73+
cwd: join(__dirname, "../.."),
74+
encoding: "utf8",
75+
},
76+
);
77+
78+
expect(result.status).toBe(1);
79+
expect(result.stdout).toBe("");
80+
expect(result.stderr.trim()).toBe('Duplicate --case "version"');
81+
expect(result.stderr).not.toContain("Node.js");
82+
expect(result.stderr).not.toContain("\n at ");
83+
});
84+
6085
it.runIf(process.platform !== "win32")(
6186
"cleans timed-out benchmark process groups when the leader exits first",
6287
() => {

test/scripts/bench-gateway-restart.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ describe("gateway restart benchmark script", () => {
9191
"--output requires a value",
9292
);
9393
expect(() => testing.parseOptions(["--case"])).toThrow("--case requires a value");
94+
expect(() =>
95+
testing.parseOptions(["--case", "skipChannels", "--case", "skipChannels"]),
96+
).toThrow('Duplicate --case "skipChannels"');
9497
expect(() => testing.parseOptions(["--restarts", "--runs", "1"])).toThrow(
9598
"--restarts requires a value",
9699
);
@@ -117,6 +120,34 @@ describe("gateway restart benchmark script", () => {
117120
expect(result.stderr).not.toContain("\n at ");
118121
});
119122

123+
it("reports duplicate benchmark cases without a stack trace", () => {
124+
const result = spawnSync(
125+
process.execPath,
126+
[
127+
"--import",
128+
"tsx",
129+
"scripts/bench-gateway-restart.ts",
130+
"--case",
131+
"skipChannels",
132+
"--case",
133+
"skipChannels",
134+
],
135+
{
136+
cwd: process.cwd(),
137+
encoding: "utf8",
138+
env: {
139+
...process.env,
140+
NODE_NO_WARNINGS: "1",
141+
},
142+
},
143+
);
144+
145+
expect(result.status).toBe(1);
146+
expect(result.stdout).toBe("");
147+
expect(result.stderr.trim()).toBe('Duplicate --case "skipChannels"');
148+
expect(result.stderr).not.toContain("\n at ");
149+
});
150+
120151
it("guards the SIGUSR1 restart benchmark on Windows", () => {
121152
expect(() => testing.ensureSupportedRestartPlatform("linux")).not.toThrow();
122153
expect(() => testing.ensureSupportedRestartPlatform("darwin")).not.toThrow();

0 commit comments

Comments
 (0)