Repository navigation
feat(net): follow the aggregate subscriber priority on moq-transport upstreams #5922
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
5 commits
Select commit
Hold shift + click to select a range
a0fe662
quest: claim m1/subscribe-ranges/ietf-update
kixelated 77b3fcb
feat(net): follow the aggregate subscriber priority on moq-transport …
kixelated c3a5cc2
fix(net): finish a JS subscription update before cancelling
kixelated 5c6fa05
fix(net): count an update as unanswered before writing it
kixelated c1b3433
Merge remote-tracking branch 'origin/main' into fix-5922
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
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // One upstream subscription carries the aggregate priority of the subscribers it serves, and | ||
| // follows it as they come and go. The JS origin never serves a received route onward, so the | ||
| // relay case lives with the Rust relay (rs/moq-net/tests/integration/subscribe_priority.rs). | ||
|
|
||
| import { expect, test } from "bun:test"; | ||
| import { accept, connect, type Established } from "./connection/index.ts"; | ||
| import * as Ietf from "./ietf/index.ts"; | ||
| import * as Lite from "./lite/index.ts"; | ||
| import { createMockTransportPair, type MockTransport } from "./mock.ts"; | ||
| import { Producer as OriginProducer } from "./origin.ts"; | ||
| import * as Path from "./path.ts"; | ||
| import { Timescale } from "./time.ts"; | ||
| import type { Producer as TrackProducer } from "./track.ts"; | ||
| import { wireOf } from "./wire.ts"; | ||
|
|
||
| const url = new URL("https://localhost:4443/test"); | ||
| const path = Path.from("test"); | ||
|
|
||
| const LOW = 1; | ||
| const HIGH = 200; | ||
|
|
||
| // Dial a session that consumes what `origin` serves. Draft-14's ALPN is the generic one, so | ||
| // the server is told the version instead. | ||
| async function session(protocol: string, origin: OriginProducer): Promise<[Established, Established]> { | ||
| const draft14 = protocol === Ietf.ALPN.DRAFT_14; | ||
| const pair = createMockTransportPair(draft14 ? "" : protocol); | ||
| lateAcks(pair.client); | ||
| return Promise.all([ | ||
| connect({ url, transport: pair.client }), | ||
| accept({ | ||
| transport: pair.server, | ||
| url, | ||
| publish: origin.consume(), | ||
| version: draft14 ? Ietf.Version.DRAFT_14 : undefined, | ||
| }), | ||
| ]); | ||
| } | ||
|
|
||
| // Acknowledge each write on the client's bidirectional streams a task late, after the peer | ||
| // can already have answered it, as a real send stream may. | ||
| function lateAcks(transport: MockTransport) { | ||
| const create = transport.createBidirectionalStream.bind(transport); | ||
| transport.createBidirectionalStream = async (options) => { | ||
| const stream = await create(options); | ||
| const inner = stream.writable.getWriter(); | ||
| const writable = new WritableStream<Uint8Array>({ | ||
| async write(chunk) { | ||
| await inner.write(chunk); | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); | ||
| }, | ||
| close: () => inner.close(), | ||
| abort: (reason) => inner.abort(reason), | ||
| }); | ||
| return { readable: stream.readable, writable }; | ||
| }; | ||
| } | ||
|
|
||
| // Resolve once the subscription `track` serves asks for `want`. | ||
| async function priority(track: TrackProducer, want: number): Promise<void> { | ||
| while (track.subscription.peek()?.priority !== want) await track.subscription.changed(); | ||
| } | ||
|
|
||
| test.each([Lite.ALPN_07_WIP, ...Object.values(Ietf.ALPN)])( | ||
| "%s follows the aggregate priority upstream", | ||
| async (protocol) => { | ||
| const origin = new OriginProducer(); | ||
| const broadcast = origin.createBroadcast(path); | ||
| broadcast.announce(); | ||
| const video = broadcast.createTrack("video", { timescale: Timescale.MILLI }); | ||
| const [client, server] = await session(protocol, origin); | ||
|
|
||
| const remote = wireOf(client).consume(path); | ||
| const low = remote.track("video").subscribe({ priority: LOW }); | ||
| await priority(video, LOW); | ||
|
|
||
| // A second subscriber at a higher priority raises the one upstream request. | ||
| const high = remote.track("video").subscribe({ priority: HIGH }); | ||
| await priority(video, HIGH); | ||
|
|
||
| // Leaving lowers it again. | ||
| high.close(); | ||
| await priority(video, LOW); | ||
| expect(video.subscription.peek()?.priority).toBe(LOW); | ||
|
|
||
| low.close(); | ||
| remote.close(); | ||
| broadcast.close(); | ||
| client.abort(); | ||
| server.abort(); | ||
| }, | ||
| ); |
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
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.