Files
NODEDC_MISSION_CORE/apps/control-station/test/streamDiagnostics.test.mjs
T

30 lines
2.3 KiB
JavaScript

import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import {test} from 'node:test';
import ts from 'typescript';
const code=ts.transpileModule(readFileSync(new URL('../src/core/simulation/streamDiagnostics.ts',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext}}).outputText;
const {StreamDiagnostics}=await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
test('network round trip, decode and estimated presentation delay retain separate units',()=>{
const d=new StreamDiagnostics();d.observeNative(100,{fps:8,rtd:42,avgDecodeTime:3,currentBitrate:9,codec:'H264'});
d.observeFrame(105,{expectedDisplayTime:106,captureTime:40,receiveTime:96,processingDuration:.003});
const s=d.snapshot(110,7.8);assert.equal(s.native.round_trip_ms,42);assert.equal(s.native.decode_ms,3);
assert.equal(s.presentation.estimated_capture_to_present_ms,66);assert.equal(s.presentation.receive_to_present_ms,10);
assert.equal(s.presentation.frame_decode_ms,3);assert.equal(s.decoded_fps,7.8);
});
test('missing remote clock estimates and invalid SDK fields remain unknown, not zero latency',()=>{
const d=new StreamDiagnostics();d.observeNative(0,{rtd:NaN,avgDecodeTime:-1,fps:0,codec:'secret://endpoint',extra:'ignored'});
d.observeFrame(1,{expectedDisplayTime:2});const s=d.snapshot(2,0);
assert.equal(s.native.fps,0);assert.equal(s.native.round_trip_ms,null);assert.equal(s.native.decode_ms,null);
assert.equal(s.native.codec,null);assert.equal(s.native.extra,undefined);assert.equal(s.presentation.estimated_capture_to_present_ms,null);
});
test('stalled native and presentation samples expire independently after three seconds',()=>{
const d=new StreamDiagnostics();d.observeNative(0,{fps:8});d.observeFrame(2500,{expectedDisplayTime:2501});
assert.equal(d.snapshot(3001,0).native,null);assert.ok(d.snapshot(3001,0).presentation);
assert.equal(d.snapshot(5501,0).presentation,null);
});
test('invalid clock order cannot become a claimed end-to-end measurement',()=>{
const d=new StreamDiagnostics();d.observeFrame(100,{expectedDisplayTime:100,captureTime:110,receiveTime:-1});
assert.equal(d.snapshot(100,8).presentation.estimated_capture_to_present_ms,null);
assert.equal(d.snapshot(100,8).presentation.receive_to_present_ms,null);
});