mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-10 18:36:15 -08:00
* test(performance): bound worker sampling finalization * test(performance): reject timed-out worker captures * test(performance): settle every worker sample
74 lines
2.5 KiB
TypeScript
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\)/
|
|
);
|
|
});
|