Repository navigation
fix(mux): bound sequence hole waits by max delay #5999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8afb3ed
chore: claim sequence hole budget quest
kixelated 5eac5b3
fix(mux): bound sequence hole waits by max delay
kixelated 11a02e2
fix(hang): keep sequence-hole skip diagnostics
kixelated 68e199a
Merge remote-tracking branch 'origin/main' into quest/m1/ts-reliabili…
kixelated 4aefbce
Merge remote-tracking branch 'origin/main' into quest/m1/ts-reliabili…
kixelated 38a1062
Merge remote-tracking branch 'origin/main' into quest/m1/ts-reliabili…
kixelated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { Manual, Micro, Milli, Nano } from "@moq/clock"; | ||
| import { Group, Time, Track } from "@moq/net"; | ||
| import { Consumer, type Read } from "./consumer.ts"; | ||
| import { encodeFrame, Format } from "./legacy.ts"; | ||
|
|
||
| const flush = () => new Promise<void>((resolve) => setImmediate(resolve)); | ||
|
|
||
| test.each([0, 100])("a sequence hole before a paused data marker expires at %sms", async (budget) => { | ||
| const clock = new Manual(); | ||
| const restore = clock.install(); | ||
| const track = new Track.Producer("data"); | ||
| const consumer = new Consumer(track.subscribe({ maxDelay: Milli(30_000) }), { | ||
| format: new Format("data"), | ||
| maxDelay: Milli(budget), | ||
| }); | ||
| const results: Read[] = []; | ||
| const reading = (async () => { | ||
| for (;;) { | ||
| const read = await consumer.next(); | ||
| if (!read) return; | ||
| results.push(read); | ||
| } | ||
| })(); | ||
| try { | ||
| const first = new Group.Producer(0); | ||
| track.writeGroup(first); | ||
| first.writeFrame({ payload: encodeFrame(new Uint8Array([1]), Micro(10_000)), timestamp: Time.Timestamp.now() }); | ||
| first.close(); | ||
| await flush(); | ||
| expect(results).toHaveLength(1); | ||
| const marker = new Group.Producer(2); | ||
| track.writeGroup(marker); | ||
| marker.writeFrame({ payload: new Uint8Array(), timestamp: Time.Timestamp.now() }); | ||
| marker.close(); | ||
| await flush(); | ||
| if (budget > 0) { | ||
| expect(results).toHaveLength(1); | ||
| await clock.advanceAsync(Nano.fromMilli(Milli(budget - 1))); | ||
| expect(results).toHaveLength(1); | ||
| await clock.advanceAsync(Nano.fromMilli(Milli(1))); | ||
| } | ||
| expect(results.slice(1)).toEqual([ | ||
| { kind: "gap", timestamp: Micro(10_000), duration: Micro.zero }, | ||
| { kind: "end", group: 2, end: Micro(10_000) }, | ||
| ]); | ||
| } finally { | ||
| consumer.close(); | ||
| track.close(); | ||
| await reading; | ||
| restore(); | ||
| } | ||
| }); | ||
|
|
||
| test("a filled hole cancels its timer and the next hole gets a fresh budget", async () => { | ||
| const clock = new Manual(); | ||
| const restore = clock.install(); | ||
| const track = new Track.Producer("data"); | ||
| const consumer = new Consumer(track.subscribe({ maxDelay: Milli(30_000) }), { | ||
| format: new Format("data"), | ||
| maxDelay: Milli(100), | ||
| }); | ||
| const results: Read[] = []; | ||
| const reading = (async () => { | ||
| for (;;) { | ||
| const read = await consumer.next(); | ||
| if (!read) return; | ||
| results.push(read); | ||
| } | ||
| })(); | ||
| const write = (sequence: number, timestamp?: number) => { | ||
| const group = new Group.Producer(sequence); | ||
| track.writeGroup(group); | ||
| group.writeFrame({ | ||
| payload: timestamp === undefined ? new Uint8Array() : encodeFrame(new Uint8Array([1]), Micro(timestamp)), | ||
| timestamp: Time.Timestamp.fromMicros(timestamp ?? 20_000), | ||
| }); | ||
| group.close(); | ||
| }; | ||
| try { | ||
| write(0, 0); | ||
| await flush(); | ||
| write(2, 20_000); | ||
| await flush(); | ||
| await clock.advanceAsync(Nano.fromMilli(Milli(50))); | ||
| write(1, 10_000); | ||
| await flush(); | ||
| expect(results.map((read) => read.kind)).toEqual(["frame", "frame", "frame"]); | ||
| write(4); | ||
| await flush(); | ||
| await clock.advanceAsync(Nano.fromMilli(Milli(99))); | ||
| expect(results).toHaveLength(3); | ||
| await clock.advanceAsync(Nano.fromMilli(Milli(1))); | ||
| expect(results.slice(3)).toEqual([ | ||
| { kind: "gap", timestamp: Micro(20_000), duration: Micro.zero }, | ||
| { kind: "end", group: 4, end: Micro(20_000) }, | ||
| ]); | ||
| } finally { | ||
| consumer.close(); | ||
| track.close(); | ||
| await reading; | ||
| restore(); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.