feat(research): run durable backtests in a bounded worker pool
This commit is contained in:
parent
bbf0dd4453
commit
26b97265c6
15 changed files with 1730 additions and 129 deletions
62
scripts/test/benchmark-research-pool.test.ts
Normal file
62
scripts/test/benchmark-research-pool.test.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { describe, expect, test } from 'bun:test';
|
||||
import {
|
||||
efficiency,
|
||||
parsePoolArguments,
|
||||
percentile,
|
||||
sampleProcessTree,
|
||||
verifyHashParity,
|
||||
} from '../benchmark-research-pool';
|
||||
|
||||
describe('bounded pool measurement integrity', () => {
|
||||
test('nearest-rank tails preserve zero and reject incomplete/nonfinite samples', () => {
|
||||
expect(percentile([0, 4, 2, 1, 3], 0.5)).toBe(2);
|
||||
expect(
|
||||
percentile(
|
||||
Array.from({ length: 24 }, (_, i) => i),
|
||||
0.95
|
||||
)
|
||||
).toBe(22);
|
||||
for (const values of [[], [NaN], [Infinity], [-1]]) {
|
||||
expect(() => percentile(values, 0.95)).toThrow();
|
||||
}
|
||||
});
|
||||
test('paired efficiency uses full serial duration divided by slots times parallel duration', () => {
|
||||
expect(efficiency(100, 60, 2)).toBeCloseTo(0.83333333);
|
||||
expect(efficiency(100, 100, 1)).toBe(1);
|
||||
expect(efficiency(100, 120, 4)).toBeCloseTo(0.20833333);
|
||||
expect(() => efficiency(100, 0, 2)).toThrow();
|
||||
});
|
||||
test('parity is per candidate index, never sorted by result or completion order', () => {
|
||||
const a = 'a'.repeat(64),
|
||||
b = 'b'.repeat(64);
|
||||
verifyHashParity(undefined, [a, b]);
|
||||
verifyHashParity([a, b], [a, b]);
|
||||
for (const hashes of [[b, a], [a], [], [a, 'invalid']]) {
|
||||
expect(() => verifyHashParity([a, b], hashes)).toThrow();
|
||||
}
|
||||
});
|
||||
test('measurement execution is explicit and malformed options cannot silently run', () => {
|
||||
expect(parsePoolArguments(['--measure', '--smoke', '--output', '/tmp/report.json'])).toEqual({
|
||||
smoke: true,
|
||||
output: '/tmp/report.json',
|
||||
});
|
||||
for (const args of [
|
||||
[],
|
||||
['--smoke'],
|
||||
['unknown', '--measure'],
|
||||
['--measure', '--output'],
|
||||
['--measure', '--output', '--smoke'],
|
||||
['--measure', '--measure'],
|
||||
]) {
|
||||
expect(() => parsePoolArguments(args)).toThrow();
|
||||
}
|
||||
});
|
||||
test('RSS includes the actual driver and records process identities', () => {
|
||||
const sample = sampleProcessTree();
|
||||
expect(sample.processes.some(processInfo => processInfo.pid === process.pid)).toBe(true);
|
||||
expect(sample.rssBytes).toBeGreaterThan(0);
|
||||
expect(sample.rssBytes).toBe(
|
||||
sample.processes.reduce((total, processInfo) => total + processInfo.rssBytes, 0)
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue