Files
iptvnator/apps/electron-backend-e2e/src/performance/worker-sample-capture-validity.spec.ts
T
4gray bc4e3a2e2c test(performance): bound worker sampling finalization (#1302)
* test(performance): bound worker sampling finalization

* test(performance): reject timed-out worker captures

* test(performance): settle every worker sample
2026-07-28 21:30:35 +02:00

74 lines
2.5 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';
interface WorkerSampleDeadlineModule {
assertWorkerSampleCaptureValid?: (
invalidReasons: readonly string[]
) => void;
}
const modulePromise = import(
new URL('./worker-sample-deadline.ts', import.meta.url).href
).then((module) => module as WorkerSampleDeadlineModule);
test('rejects a timed-out worker sample before returning plain capture metrics', async () => {
const module = await modulePromise;
const assertCaptureValid = module.assertWorkerSampleCaptureValid;
assert.equal(typeof assertCaptureValid, 'function');
assert.doesNotThrow(() => assertCaptureValid?.([]));
assert.throws(
() => assertCaptureValid?.(['worker-sample-timeout']),
/main-capture-worker-sample-timeout/
);
});
test('plain capture stop and rollover both enforce worker sample validity', () => {
const source = readFileSync(
new URL('./m3u-refresh-main-capture.ts', import.meta.url),
'utf8'
);
const rolloverStart = source.indexOf(
'export async function rolloverMainCapture'
);
const stopStart = source.indexOf('export async function stopMainCapture');
const xtreamRolloverStart = source.indexOf(
'export async function rolloverXtreamMainCapture'
);
const rollover = source.slice(rolloverStart, stopStart);
const stop = source.slice(stopStart, xtreamRolloverStart);
assert.match(
rollover,
/assertWorkerSampleCaptureValid\(transport\.xtream\.invalidReasons\)/
);
assert.match(
stop,
/assertWorkerSampleCaptureValid\(transport\.xtream\.invalidReasons\)/
);
});
test('capture stop settles final samples for every current worker', () => {
const source = readFileSync(
new URL('./m3u-refresh-main-capture.ts', import.meta.url),
'utf8'
);
const stopStart = source.indexOf('stop: async (');
const stopEnd = source.indexOf(
'xtreamStatus: (): XtreamMainCaptureStatus',
stopStart
);
const stop = source.slice(stopStart, stopEnd);
assert.match(
stop,
/await Promise\.all\(\s*currentWorkerRecords\.map\(\(record\) =>\s*joinFinalWorkerSample\(record\)/
);
assert.doesNotMatch(
stop,
/currentDatabaseRecords\.map\(\(record\) =>\s*joinFinalWorkerSample\(record\)/
);
});