-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate harness to the post-#3793 moq API and add a from-dev lane #38
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
Open
kixelated
wants to merge
3
commits into
main
Choose a base branch
from
dev-prepublish-verify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Catalog-only reading: Json.Snapshot.Consumer plus the hang catalog schema. | ||
| // A full snapshot is followed by a merge-patch delta. Parsing every frame as a | ||
| // catalog is the old consumer path and must fail on the delta frame. | ||
| import * as Catalog from "@moq/hang/catalog"; | ||
| import * as Json from "@moq/json"; | ||
| import * as Moq from "@moq/net"; | ||
| import { connected, equal, handle, REPLAY_MS, waitActive, waitAnnounce } from "./lib.ts"; | ||
|
|
||
| const PATH = "dev.catalog"; | ||
|
|
||
| const SNAPSHOT: Catalog.Root = { | ||
| json: { | ||
| tracks: { | ||
| status: { mode: "snapshot" }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const UPDATED: Catalog.Root = { | ||
| json: { | ||
| tracks: { | ||
| extra: { mode: "snapshot" }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export async function catalog(url: URL): Promise<void> { | ||
| const pub = handle(url); | ||
| const sub = handle(url); | ||
| try { | ||
| const pubOrigin = await connected(pub); | ||
| const subOrigin = await connected(sub); | ||
| const announced = sub.announced(); | ||
|
|
||
| const broadcast = pubOrigin.createBroadcast(Moq.Path.from(PATH)); | ||
| const track = broadcast.createTrack(Catalog.TRACK); | ||
| const producer = new Json.Snapshot.Producer<Catalog.Root>({ | ||
| track, | ||
| schema: Catalog.RootSchema, | ||
| deltaRatio: 100, | ||
| }); | ||
| broadcast.announce(); | ||
|
|
||
| await waitAnnounce(announced, PATH, true); | ||
| const request = subOrigin.request(Moq.Path.from(PATH)); | ||
| const consumer = await waitActive(request, "catalog broadcast"); | ||
|
|
||
| const snapshot = new Json.Snapshot.Consumer<Catalog.Root>({ | ||
| track: consumer.track(Catalog.TRACK).subscribe({ | ||
| priority: Catalog.PRIORITY.catalog, | ||
| maxAge: REPLAY_MS, | ||
| }), | ||
| schema: Catalog.RootSchema, | ||
| }); | ||
|
|
||
| producer.update(SNAPSHOT); | ||
| const first = await snapshot.next(); | ||
| if (!first || !equal(first, SNAPSHOT)) { | ||
| throw new Error(`first catalog was ${JSON.stringify(first)}`); | ||
| } | ||
|
|
||
| producer.update(UPDATED); | ||
| const second = await snapshot.next(); | ||
| if (!second || !equal(second, UPDATED)) { | ||
| throw new Error(`delta did not reconstruct ${JSON.stringify(second)}`); | ||
| } | ||
|
|
||
| producer.finish(); | ||
|
|
||
| const raw = consumer | ||
| .track(Catalog.TRACK) | ||
| .subscribe({ priority: Catalog.PRIORITY.catalog, maxAge: REPLAY_MS }) | ||
| .ordered(); | ||
| const group = await raw.nextGroup(); | ||
| if (!group) throw new Error("catalog group missing"); | ||
| const frames: Uint8Array[] = []; | ||
| for (;;) { | ||
| const frame = await group.readFrame(); | ||
| if (!frame) break; | ||
| frames.push(frame.payload); | ||
| } | ||
| if (frames.length < 2) { | ||
| throw new Error(`expected a snapshot frame then a delta, got ${frames.length} frame(s)`); | ||
| } | ||
|
|
||
| const decoder = new TextDecoder(); | ||
| const root = Catalog.RootSchema.parse(JSON.parse(decoder.decode(frames[0]))); | ||
| if (!equal(root, SNAPSHOT)) throw new Error("frame 0 was not the full catalog snapshot"); | ||
|
|
||
| let deltaParsedAsCatalog = false; | ||
| try { | ||
| Catalog.RootSchema.parse(JSON.parse(decoder.decode(frames[1]))); | ||
| deltaParsedAsCatalog = true; | ||
| } catch { | ||
| // The delta is an RFC 7396 merge patch, not a catalog root. | ||
| } | ||
| if (deltaParsedAsCatalog) { | ||
| throw new Error("frame 1 parsed as a full catalog; the consumer is not reconstructing deltas"); | ||
| } | ||
| } finally { | ||
| pub.close(); | ||
| sub.close(); | ||
| } | ||
| console.log(" catalog: ok"); | ||
| } |
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.