|
| 1 | +import { describe, expect, it } from 'bun:test' |
| 2 | +import { parseArgs } from './run' |
| 3 | +import { DEFAULT_TARGETS } from './targets' |
| 4 | + |
| 5 | +describe('routing benchmark options', () => { |
| 6 | + it('preserves the default matrix and accepts fractional timing windows', () => { |
| 7 | + expect(parseArgs([])).toMatchObject({ |
| 8 | + targets: DEFAULT_TARGETS.map(target => target.id), |
| 9 | + connections: 50, |
| 10 | + warmupSeconds: 5, |
| 11 | + durationSeconds: 30, |
| 12 | + runs: 3, |
| 13 | + db: true, |
| 14 | + }) |
| 15 | + expect(parseArgs(['-c', '2', '-d', '0.5', '--warmup', '0.25', '--runs', '1'])).toMatchObject({ |
| 16 | + connections: 2, durationSeconds: 0.5, warmupSeconds: 0.25, runs: 1, |
| 17 | + }) |
| 18 | + expect(parseArgs(['--warmup', '0']).warmupSeconds).toBe(0) |
| 19 | + }) |
| 20 | + |
| 21 | + it.each(['--connections', '--runs'])('requires a positive safe integer for %s', (flag) => { |
| 22 | + for (const value of ['0', '-1', '1.5', 'NaN', 'Infinity', '9007199254740992', '']) |
| 23 | + expect(() => parseArgs([flag, value]), `${flag} ${value}`).toThrow() |
| 24 | + }) |
| 25 | + |
| 26 | + it.each(['0', '-1', 'NaN', 'Infinity', ''])('rejects invalid measured duration %s', (value) => { |
| 27 | + expect(() => parseArgs(['--duration', value])).toThrow() |
| 28 | + }) |
| 29 | + |
| 30 | + it.each(['-1', 'NaN', 'Infinity', ''])('rejects invalid warmup %s', (value) => { |
| 31 | + expect(() => parseArgs(['--warmup', value])).toThrow() |
| 32 | + }) |
| 33 | + |
| 34 | + it.each(['missing', 'stacks,missing', '', 'stacks,'])('rejects unknown or empty target selections: %s', (value) => { |
| 35 | + expect(() => parseArgs(['--targets', value])).toThrow() |
| 36 | + }) |
| 37 | + |
| 38 | + it.each(['missing', 'static-json,missing', '', 'static-json,'])('rejects unknown or empty scenario selections: %s', (value) => { |
| 39 | + expect(() => parseArgs(['--scenarios', value])).toThrow() |
| 40 | + }) |
| 41 | + |
| 42 | + it('rejects a matrix emptied by --no-db', () => { |
| 43 | + expect(() => parseArgs(['--scenarios', 'db-roundtrip', '--no-db'])).toThrow('No scenarios') |
| 44 | + }) |
| 45 | + |
| 46 | + it('accepts explicit tuned targets and a mixed matrix with --no-db', () => { |
| 47 | + expect(parseArgs(['--targets', 'stacks-wal-full,bun-raw', '--scenarios', 'static-json,db-roundtrip', '--no-db'])).toMatchObject({ |
| 48 | + targets: ['stacks-wal-full', 'bun-raw'], scenarios: ['static-json', 'db-roundtrip'], db: false, |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + it('rejects missing values and unknown flags', () => { |
| 53 | + expect(() => parseArgs(['--runs'])).toThrow('--runs needs a value') |
| 54 | + expect(() => parseArgs(['--mystery'])).toThrow('Unknown flag') |
| 55 | + }) |
| 56 | +}) |
0 commit comments