Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m1/test-flakes-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Public API: none. Wire: none.
## Required

- [Media resource instrumentation](/quest/m1/test-flakes-2/resource-instrumentation.md) - the media test stops seeing a playing player report nothing to release
- [Tone check grace](/quest/m1/test-flakes-2/tone-grace.md) - the interop tone check charges its grace only for audible playback, so a refilling ring under CPU starvation is not a failure
- [IETF22 fallback](/quest/m1/test-flakes-2/ietf22-fallback.md) - an IETF22 browser viewer follows a fallback within the media lane's bound, keeping its session and its audio
- [macOS receive credit](/quest/m1/test-flakes-2/macos-receive-credit.md) - `partial_control_requests_give_way` passes on the macOS lane, after checking for a shared platform cause
- [moq-mux missing sequence](/quest/m1/test-flakes-2/mux-missing-sequence.md) - `missing_sequence_skips_on_live_track` runs on a paused clock
Expand Down
23 changes: 0 additions & 23 deletions quest/m1/test-flakes-2/tone-grace.md

This file was deleted.

41 changes: 14 additions & 27 deletions test/interop/clients/js/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
waitForWatch,
} from "./harness";
import { type Sample, TONE_CHECK } from "./src/contract";
import { ToneCheck } from "./tone";

/** Remove the page's players, which closes their sessions, and wait until every transport has. */
async function closeSessions(page: Page): Promise<void> {
Expand Down Expand Up @@ -96,25 +97,8 @@ if (
process.exit(2);
}

/**
* Whether every channel the player outputs carries its own tone, judged as tone.py judges a native
* subscriber, from the `codec` rendition.
*/
function toneHeard(state: Sample, codec: string): boolean {
return (
state.audioCodec?.split(".")[0] === codec &&
state.audioContext === "running" &&
state.audioChannels === tones.length &&
state.tones?.length === tones.length &&
state.tones.every(({ rms, share }) => rms >= TONE_CHECK.minRms && share >= TONE_CHECK.minShare)
);
}

const PAUSE_STABILITY_MS = 750;

/** How long audible audio may play before it has to carry the tone: the analyser's window, several times over. */
const TONE_GRACE_MS = 3000;

async function waitForStablePause(page: Page, errors: BrowserErrors, deadline: number): Promise<Sample> {
let previous = await readPlayerState(page);
let stableSince = Date.now();
Expand Down Expand Up @@ -184,29 +168,32 @@ async function watch(codec: string): Promise<boolean> {
}

const interactionDeadline = Date.now() + timeoutMs;
const tone = new ToneCheck({ codec, channels: tones.length });
let failedAudio: Sample | undefined;
try {
// Once audio plays, the tone gets a bounded grace rather than the whole timeout, so a
// wrong tone fails as fast as it does in the native subscribers.
await waitForState(page, errors, {
deadline: interactionDeadline,
description: "audible audio",
predicate: (state) => state.audioContext === "running" && (state.rms ?? 0) >= TONE_CHECK.minRms,
});
playing = await waitForState(page, errors, {
deadline: Math.min(interactionDeadline, Date.now() + TONE_GRACE_MS),
deadline: interactionDeadline,
description: "the audio tone",
predicate: (state) => toneHeard(state, codec),
predicate: (state) => {
const result = tone.read(state);
if (result === "failed") {
failedAudio = state;
throw new Failure("audio tone", `after 3 s of playback: ${JSON.stringify(state)}`);
}
return result === "heard";
},
});
} catch (err) {
// Only a tone wait that ran out is an audio check failure; a page error reports as itself.
if (!(err instanceof Failure)) throw err;
// `wrong tone` is the marker the harness's control requires: audible audio from the pinned
// rendition, in the publisher's layout, that does not carry its tones. Anything else failing is
// a plain audio failure.
const state = await readPlayerState(page);
const state = failedAudio ?? (await readPlayerState(page));
const wrongTone =
state.audioCodec?.split(".")[0] === codec &&
state.audioContext === "running" &&
!state.audioStalled &&
state.audioChannels === tones.length &&
state.tones?.length === tones.length &&
state.tones.every(({ rms }) => rms >= TONE_CHECK.minRms);
Expand Down
64 changes: 64 additions & 0 deletions test/interop/clients/js/tone.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { expect, test } from "bun:test";
import { ToneCheck } from "./tone";

const wrong = {
at: 0,
audioContext: "running",
audioStalled: false,
audioCodec: "opus",
audioChannels: 2,
tones: [
{ rms: 0.35, share: 0 },
{ rms: 0.35, share: 0 },
],
};
const expected = { codec: "opus", channels: 2 };
const correct = wrong.tones.map(() => ({ rms: 0.35, share: 1 }));

test("a refill pauses rather than resets or consumes the tone grace", () => {
const check = new ToneCheck(expected);
expect(check.read(wrong)).toBe("waiting");
expect(check.read({ ...wrong, at: 1000 })).toBe("waiting");
expect(check.read({ ...wrong, at: 1100, audioStalled: true })).toBe("waiting");
expect(check.read({ ...wrong, at: 6100, audioStalled: true })).toBe("waiting");
expect(check.read({ ...wrong, at: 6200 })).toBe("waiting");
expect(check.read({ ...wrong, at: 8199 })).toBe("waiting");
expect(check.read({ ...wrong, at: 8200 })).toBe("failed");
});

test("repeated observations cannot spend playback grace while the page is starved", () => {
const check = new ToneCheck(expected);
for (let poll = 0; poll < 100; poll++) expect(check.read(wrong)).toBe("waiting");
expect(check.read({ ...wrong, at: 2999 })).toBe("waiting");
expect(check.read({ ...wrong, at: 3000 })).toBe("failed");
});

test("suspension and startup buffering contribute no playback time", () => {
const check = new ToneCheck(expected);
expect(check.read({ ...wrong, audioStalled: true })).toBe("waiting");
expect(check.read({ ...wrong, at: 5000 })).toBe("waiting");
expect(check.read({ ...wrong, at: 6000 })).toBe("waiting");
expect(check.read({ ...wrong, at: 6100, audioContext: "suspended" })).toBe("waiting");
expect(check.read({ ...wrong, at: 16100, audioContext: "suspended" })).toBe("waiting");
expect(check.read({ ...wrong, at: 16200 })).toBe("waiting");
expect(check.read({ ...wrong, at: 18200 })).toBe("failed");
});

test("analyser residue while stalled cannot satisfy the tone check", () => {
const check = new ToneCheck(expected);
expect(check.read({ ...wrong, audioStalled: true, tones: correct })).toBe("waiting");
expect(check.read({ ...wrong, at: 10000, tones: correct })).toBe("heard");
});

for (const bad of [
{ tones: wrong.tones.map(() => ({ rms: 0, share: 1 })) },
{ audioCodec: "mp4a.40.2", tones: correct },
{ audioChannels: 1, tones: correct },
{ tones: correct.slice(0, 1) },
]) {
test(`playing invalid audio still fails: ${JSON.stringify(bad)}`, () => {
const check = new ToneCheck(expected);
expect(check.read({ ...wrong, ...bad })).toBe("waiting");
expect(check.read({ ...wrong, ...bad, at: 3000 })).toBe("failed");
});
}
37 changes: 37 additions & 0 deletions test/interop/clients/js/tone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { type Sample, TONE_CHECK } from "./src/contract";

/** How long rendered audio may play before it has to carry the tone: several analyser windows. */
const GRACE_MS = 3000;

type Observation = Pick<Sample, "at" | "audioContext" | "audioStalled" | "audioCodec" | "audioChannels" | "tones">;

/** Judge the expected tones after giving the running player a bounded grace to fill its analyser. */
export class ToneCheck {
#expected: { codec: string; channels: number };
#previous?: { at: number; playing: boolean };
#played = 0;

constructor(expected: { codec: string; channels: number }) {
this.#expected = expected;
}

/** Wait through buffering, accept the tone, or fail after enough audio has played to judge it. */
read(state: Observation): "waiting" | "heard" | "failed" {
const playing = state.audioContext === "running" && !state.audioStalled;
// Samples use the page's clock, so polling the same observation cannot spend the grace.
// Both ends must be playing: a refill or suspension contributes no playback time.
if (playing && this.#previous?.playing) this.#played += state.at - this.#previous.at;
this.#previous = { at: state.at, playing };
if (!playing) return "waiting";

if (
state.audioCodec?.split(".")[0] === this.#expected.codec &&
state.audioChannels === this.#expected.channels &&
state.tones?.length === this.#expected.channels &&
state.tones.every(({ rms, share }) => rms >= TONE_CHECK.minRms && share >= TONE_CHECK.minShare)
) {
return "heard";
}
return this.#played >= GRACE_MS ? "failed" : "waiting";
}
}
1 change: 1 addition & 0 deletions test/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ harness_browser_tests := '''
./open-gop.browser.ts
./publish-ui.browser.ts
./signals-dom.browser.ts
./tone.test.ts
./src/contract.test.ts
./src/resume.test.ts
'''
Expand Down
Loading