Files
iptvnator/apps/electron-backend-e2e/src/performance/main-capture-sampling-scheduler.spec.ts
T
4gray a2fafcfc08 test(performance): add end-to-end Xtream benchmark harness (#1300)
* docs(performance): plan Xtream benchmark

* feat(xtream-mock-server): add deterministic 100k fixture

* style(xtream-mock-server): apply repository formatting

* fix(xtream-mock-server): harden performance fixture data

* feat(xtream-mock-server): add performance control plane

* docs(performance): correct Xtream capture plan

* fix(xtream-mock-server): harden performance controls

* fix(xtream-mock-server): harden control lifecycle

* feat(performance): add Xtream preload markers

* feat(performance): trace Xtream main phases

* feat(performance): mark Xtream store publications

* feat(performance): trace Xtream database phases

* feat(performance): trace Xtream delete cancellation

* feat(performance): capture Xtream phase attribution

* feat(performance): mark Sources Xtream refresh

* test(performance): define Xtream benchmark evidence contracts

* test(performance): add Xtream benchmark runner

* test(performance): surface failure evidence writes

* test(performance): align database read clock

* test(performance): preserve capture failure contracts
2026-07-28 08:08:07 +02:00

82 lines
2.9 KiB
TypeScript

/* eslint-disable playwright/expect-expect -- This is a Node assertion-based performance contract test. */
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
const source = readFileSync(
new URL('./m3u-refresh-main-capture.ts', import.meta.url),
'utf8'
);
function section(startMarker: string, endMarker: string): string {
const start = source.indexOf(startMarker);
const end = source.indexOf(endMarker, start);
assert.ok(start >= 0, `missing start marker: ${startMarker}`);
assert.ok(end > start, `missing end marker: ${endMarker}`);
return source.slice(start, end);
}
test('samples main and worker memory from one shared interval scheduler', () => {
const workerRecord = section(
'interface WorkerRecord',
'interface TimelineRecord'
);
const resetWorker = section(
'const resetWorkerForCapture',
'const startWorker'
);
const startWorker = section(
'const startWorker',
'const stopWorkerSampling'
);
const stopWorker = section(
'const stopWorkerSampling',
'const joinFinalWorkerSample'
);
const joinFinalWorker = section(
'const joinFinalWorkerSample',
'const stopWorkerProfile'
);
const sampleMain = section('const sampleMain', 'const startCapture');
const beginMeasurement = section(
'const beginMeasurement = async',
'const startCapture'
);
const armCapture = section('const startCapture', 'const api =');
const stopCapture = section(
'stop: async (',
'xtreamStatus: (): XtreamMainCaptureStatus'
);
assert.match(workerRecord, /samplingStarted: boolean/);
assert.doesNotMatch(workerRecord, /sampleTimer/);
assert.match(resetWorker, /record\.samplingStarted = false/);
assert.match(startWorker, /if \(record\.samplingStarted\)/);
assert.match(
startWorker,
/record\.samplingStarted = true[\s\S]*const initialSample = sampleWorker\(record\)/
);
assert.doesNotMatch(startWorker, /setInterval/);
assert.match(stopWorker, /record\.samplingStarted = false/);
assert.match(joinFinalWorker, /await sampleWorker\(record\)/);
assert.match(
sampleMain,
/for \(const record of records\.values\(\)\)[\s\S]*record\.samplingStarted &&[\s\S]*isCurrentCaptureRecord\(record\)[\s\S]*void sampleWorker\(record\)/
);
assert.match(
beginMeasurement,
/sampleMain\(\)[\s\S]*state\.sampleTimer = setInterval\(sampleMain, 20\)/
);
assert.doesNotMatch(armCapture, /setInterval\(sampleMain/);
assert.match(
stopCapture,
/clearInterval\(state\.sampleTimer\)[\s\S]*state\.sampleTimer = null[\s\S]*await startCapture\(nextOptions\)/
);
assert.equal(
source.match(/\bsetInterval\s*\(/g)?.length,
1,
'the injected main capture must own exactly one interval timer'
);
});