mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 13:16:16 -08:00
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
This commit is contained in:
1 parent
f80eb4d1b9
commit
bc4e3a2e2c
4 files changed
+654
-48
No files matched your search
@@ -0,0 +1,73 @@
|
||||
/* 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\)/
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user