Skip to content

Commit febb7a4

Browse files
committed
test: harden webrtc benchmark startup
1 parent 2b722e0 commit febb7a4

2 files changed

Lines changed: 77 additions & 7 deletions

File tree

scripts/e2e-webrtc-reliability.mjs

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,28 @@ try {
492492
15_000,
493493
);
494494

495-
await waitForValue(
496-
cdp,
497-
`
495+
try {
496+
await waitForValue(
497+
cdp,
498+
`
498499
(() => {
499500
const videos = [...document.querySelectorAll("video.stream-video")];
500501
return videos.some((video) => video.readyState >= 2 && video.videoWidth > 0 && video.videoHeight > 0);
501502
})()
502503
`,
503-
Boolean,
504-
streamReadyTimeoutMs,
505-
);
504+
Boolean,
505+
streamReadyTimeoutMs,
506+
);
507+
} catch (error) {
508+
const diagnostics = await collectReadinessDiagnostics(cdp, clientId).catch(
509+
(diagnosticError) => ({
510+
diagnosticError: String(diagnosticError?.message ?? diagnosticError),
511+
}),
512+
);
513+
throw new Error(
514+
`${error?.message ?? error}\nReadiness diagnostics: ${JSON.stringify(diagnostics, null, 2)}`,
515+
);
516+
}
506517

507518
const initialMetrics = await fetchJson(endpoint("/api/metrics"));
508519
const initialStreams = findClientStreams(initialMetrics, clientId);
@@ -840,6 +851,63 @@ async function waitForValue(cdp, expression, predicate, timeoutMs) {
840851
);
841852
}
842853

854+
async function collectReadinessDiagnostics(cdp, clientId) {
855+
const page = await evaluate(
856+
cdp,
857+
`
858+
(() => {
859+
const videos = [...document.querySelectorAll("video.stream-video")].map((video) => ({
860+
height: video.videoHeight || 0,
861+
networkState: video.networkState,
862+
paused: video.paused,
863+
readyState: video.readyState,
864+
width: video.videoWidth || 0,
865+
}));
866+
const peerConnections = (window.__simdeckPeerConnections || []).map((pc) => ({
867+
connectionState: pc.connectionState,
868+
iceConnectionState: pc.iceConnectionState,
869+
iceGatheringState: pc.iceGatheringState,
870+
signalingState: pc.signalingState,
871+
}));
872+
return {
873+
bodyText: (document.body?.innerText || "").slice(0, 1000),
874+
canvases: document.querySelectorAll("canvas.stream-canvas").length,
875+
location: window.location.href,
876+
peerConnections,
877+
sessionClientId: window.sessionStorage.getItem("simdeck.streamClientId") || "",
878+
statusText: document.querySelector("[data-testid='stream-status']")?.textContent || "",
879+
title: document.title,
880+
videos,
881+
};
882+
})()
883+
`,
884+
);
885+
const metrics = await fetchJson(endpoint("/api/metrics")).catch((error) => ({
886+
error: String(error?.message ?? error),
887+
}));
888+
return {
889+
clientId,
890+
page,
891+
streams: Array.isArray(metrics?.client_streams)
892+
? findClientStreams(metrics, clientId).map((stream) => ({
893+
codec: stream.codec,
894+
decodedFrames: stream.decodedFrames,
895+
detail: stream.detail,
896+
droppedFrames: stream.droppedFrames,
897+
height: stream.height,
898+
kind: stream.kind,
899+
latestFrameGapMs: stream.latestFrameGapMs,
900+
receivedPackets: stream.receivedPackets,
901+
reconnects: stream.reconnects,
902+
renderedFrames: stream.renderedFrames,
903+
status: stream.status,
904+
udid: stream.udid,
905+
width: stream.width,
906+
}))
907+
: metrics,
908+
};
909+
}
910+
843911
async function createPageTarget(url) {
844912
const response = await fetch(
845913
`http://127.0.0.1:${debugPort}/json/new?${encodeURIComponent(url)}`,

scripts/integration/webrtc.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ async function main() {
124124
SIMDECK_E2E_MIN_VIDEO_HEIGHT: String(height),
125125
SIMDECK_E2E_MIN_VIDEO_WIDTH: String(width),
126126
SIMDECK_E2E_REQUIRE_VISUAL: "0",
127+
SIMDECK_E2E_STREAM_READY_MS:
128+
process.env.SIMDECK_E2E_STREAM_READY_MS ?? "180000",
127129
SIMDECK_E2E_VISUAL_SAMPLE_INTERVAL_MS: "0",
128130
},
129131
);
@@ -211,7 +213,7 @@ function runNodeScript(script, args, env) {
211213
encoding: "utf8",
212214
env: { ...process.env, ...env },
213215
stdio: "inherit",
214-
timeout: 120_000,
216+
timeout: 300_000,
215217
},
216218
);
217219
if (result.status !== 0) {

0 commit comments

Comments
 (0)