diff --git a/scripts/measure-rpc-rtt.mjs b/scripts/measure-rpc-rtt.mjs index 9a03609b680e..77734fbba2fc 100644 --- a/scripts/measure-rpc-rtt.mjs +++ b/scripts/measure-rpc-rtt.mjs @@ -14,6 +14,7 @@ import { resolveWindowsTaskkillPath } from "./lib/windows-taskkill.mjs"; const DEFAULT_METHODS = ["health", "config.get"]; const DEFAULT_ITERATIONS = 10; +const SINGLE_VALUE_FLAGS = new Set(["--iterations", "--methods", "--output-dir", "--repo-root"]); /** Maximum time to wait for a spawned gateway to become reachable. */ export const READY_TIMEOUT_MS = 120_000; /** Per-probe timeout used while polling gateway readiness endpoints. */ @@ -74,12 +75,19 @@ export function parseArgs(argv) { iterations: DEFAULT_ITERATIONS, methods: DEFAULT_METHODS, }; + const seenSingleValueFlags = new Set(); for (let index = 0; index < argv.length; index += 1) { const arg = argv[index]; if (arg === "--help" || arg === "-h") { args.help = true; continue; } + if (SINGLE_VALUE_FLAGS.has(arg)) { + if (seenSingleValueFlags.has(arg)) { + throw new Error(`${arg} was provided more than once.`); + } + seenSingleValueFlags.add(arg); + } if (arg === "--output-dir") { args.outputDir = readFlagValue(argv, index, arg); index += 1; diff --git a/test/scripts/measure-rpc-rtt.test.ts b/test/scripts/measure-rpc-rtt.test.ts index badd3093aa2a..71375067314f 100644 --- a/test/scripts/measure-rpc-rtt.test.ts +++ b/test/scripts/measure-rpc-rtt.test.ts @@ -182,6 +182,12 @@ describe("scripts/measure-rpc-rtt.mjs", () => { expect(() => parseArgs(["--output-dir", "/tmp/rpc-rtt", "--methods", "health, config.get,health"]), ).toThrow("--methods contains duplicate gateway method: health"); + expect(() => parseArgs(["--output-dir", "/tmp/one", "--output-dir", "/tmp/two"])).toThrow( + "--output-dir was provided more than once.", + ); + expect(() => + parseArgs(["--output-dir", "/tmp/rpc-rtt", "--methods", "health", "--methods", "config.get"]), + ).toThrow("--methods was provided more than once."); for (const value of ["--methods", "-h"]) { for (const flag of ["--output-dir", "--repo-root", "--iterations", "--methods"]) { expect(() => parseArgs([flag, value, "health"])).toThrow(`${flag} requires a value.`);