diff --git a/js/publish/src/audio/encoder.test.ts b/js/publish/src/audio/encoder.test.ts index bf4a47b968..1abb22aa67 100644 --- a/js/publish/src/audio/encoder.test.ts +++ b/js/publish/src/audio/encoder.test.ts @@ -305,24 +305,33 @@ test("a push completing several frames keeps the encoder running", async () => { // it, which the catalog advertises as `delay`. test("a rendition trailing the broadcast's earliest advertises delay", async () => { using _webcodecs = installFakeWebCodecs(); - const baseline = new Baseline(); - using env = await setup(baseline); - const { encoder, feed } = env; + const clock = spyOn(performance, "now").mockReturnValue(200); - expect(encoder.out.catalog.peek()?.delay).toBeUndefined(); + try { + const baseline = new Baseline(); + using env = await setup(baseline); + const { encoder, feed } = env; - // A sibling that flushes each frame the instant it is captured. - baseline.observe(0, performance.now() * 1000); + expect(encoder.out.catalog.peek()?.delay).toBeUndefined(); - // Captured 100ms ago, so this rendition flushes at least that late. - const start = performance.now() * 1000 - 100_000; - for (let index = 0; index < 4; index++) { - await feed.push({ timestamp: Time.Micro(start + index * 20_000), channels: [new Float32Array(960)] }); - } - await feed.drain(); + // A sibling that flushes each frame the instant it is captured. + baseline.observe(0, performance.now() * 1000); + + // Captured 100ms ago, with a clock origin that keeps timestamps nonnegative. + const start = performance.now() * 1000 - 100_000; + for (let index = 0; index < 4; index++) { + await feed.push({ timestamp: Time.Micro(start + index * 20_000), channels: [new Float32Array(960)] }); + } + await feed.drain(); - expect(env.written.length).toBe(2); - expect(encoder.out.catalog.peek()?.delay).toBeGreaterThanOrEqual(100); + expect(env.written).toEqual([ + [100_000, 1], + [120_000, 1], + ]); + expect(encoder.out.catalog.peek()).toMatchObject({ delay: 100 }); + } finally { + clock.mockRestore(); + } }); // Regression: codec settings that can't resolve left the encoder unsettled, so `` never diff --git a/quest/m1/test-flakes-2/README.md b/quest/m1/test-flakes-2/README.md index 0472cfb295..2d41c024a0 100644 --- a/quest/m1/test-flakes-2/README.md +++ b/quest/m1/test-flakes-2/README.md @@ -33,7 +33,6 @@ Public API: none. Wire: none. - [moq-cli tests on a paused clock](/quest/m1/test-flakes-2/cli-paused-clock.md) - the fetch timeout and completion tests stop racing wall-clock budgets - [Subscription cut by disconnect](/quest/m1/test-flakes-2/subscription-cut.md) - a publisher disconnect never ends a subscription clean - [Media late join](/quest/m1/test-flakes-2/media-late-join.md) - `just test media` late join stays within one GOP, or the regression is fixed -- [js/publish audio clock](/quest/m1/test-flakes-2/publish-audio-clock.md) - the audio encoder delay test runs on mock time - [moq-mux live import clock](/quest/m1/test-flakes-2/mux-live-import-clock.md) - the live import restart tests advance a paused clock instead of sleeping ## Related diff --git a/quest/m1/test-flakes-2/publish-audio-clock.md b/quest/m1/test-flakes-2/publish-audio-clock.md deleted file mode 100644 index ccc4becaad..0000000000 --- a/quest/m1/test-flakes-2/publish-audio-clock.md +++ /dev/null @@ -1,11 +0,0 @@ -# [XS] js/publish audio delay test on mock time - -## Goal - -The js/publish audio encoder test "a rendition trailing the broadcast's -earliest advertises delay" passes when its file runs alone. - -## Plan - -It reads the real clock, so timestamps go negative early in the process and -it fails when run alone (#4414). Run it on mock time.