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
4 changes: 4 additions & 0 deletions js/net/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ How to update your code for each breaking change, newest first.

## Unreleased

### Past group ranges work over moq-transport ([#7793](https://github.com/moq-dev/moq/pull/7793))

`track.Consumer.fetchGroup()` and subscriptions to past group ranges now use standalone FETCH on drafts 18, 20, and 22. No API migration is needed. First-party publishers serve one group per FETCH; multi-group ranges require a publisher that serves them.

### IETF FETCH serves on-demand history ([#7794](https://github.com/moq-dev/moq/pull/7794))

A single-group IETF FETCH now asks `track.requests()` for groups the publisher's cache no longer holds, or never held, using the same `Track.Fill` responder as moq-lite. Existing responders need no changes. Multi-group IETF FETCH remains unsupported.
Expand Down
7 changes: 7 additions & 0 deletions js/net/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ function subtract(gap: Run, run: Run): Run[] {
].filter((part) => part.start < part.end);
}

/** The still-wanted runs of a fill, in ascending order. @internal */
export let wantedRuns: (fill: Fill) => Run[];
/** Wait for a change to the groups or readers of a fill. @internal */
export let fillChanged: (fill: Fill) => Promise<unknown>;

// Constructs the public handles from within this module; assigned in their static blocks.
let makeFill: (state: FillState, pending: Pending) => Fill;
let makeRequests: (state: FillState) => Requests;
Expand Down Expand Up @@ -443,6 +448,8 @@ export class Fill {

static {
makeFill = (state, pending) => new Fill(state, pending);
wantedRuns = (fill) => fill.#pending.owed();
fillChanged = (fill) => Promise.resolve(fill.#pending.revision.changed());
}

/** The most urgent delivery priority among the readers waiting on it now. */
Expand Down
5 changes: 3 additions & 2 deletions js/net/src/goaway-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ async function handover(kind: "lite" | "ietf"): Promise<void> {

// A fresh consumer caches nothing, so the publisher's answer proves the FETCH reached the wire.
const fetched = wireOf(client).consume(Path.from("room")).track("video").fetchGroup(0n);
if (kind === "lite") expect(await (await fetched).readString()).toBe("one");
else await expect(fetched).rejects.toThrow(/not supported/);
const group = await fetched;
expect(await group.readString()).toBe("one");
group.close();

// A new announce-interest opens too, and sees the route at the drain cost.
const interest = client.announced();
Expand Down
42 changes: 40 additions & 2 deletions js/net/src/ietf/join.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect, jest, onTestFinished, test } from "bun:test";
import { Elapsed, Instant, Milli, Nano, now, timeout } from "@moq/clock";
import { Elapsed, Instant, Manual, Milli, Nano, now, timeout } from "@moq/clock";
import * as Connection from "../connection/index.ts";
import { StreamCode } from "../error.ts";
import { hooks } from "../internal.ts";
import { GRACE } from "../ledger.ts";
import { createMockTransportPair, textFrame } from "../mock.ts";
import { Producer as OriginProducer } from "../origin.ts";
Expand Down Expand Up @@ -61,7 +62,10 @@ async function subscribed(version: IetfVersion = VERSION) {
const pair = createMockTransportPair(ALPNS[version]);
const session = new NativeSession(pair.server, version, true);
const subscriber = new Subscriber({ session });
const consumer = subscriber.consume(Path.from("room")).track("video").subscribe();
const consumer = subscriber
.consume(Path.from("room"))
.track("video")
.subscribe({ ...track.Subscription.default(), ranges: [{ start: { relative: 0 } }] });
onTestFinished(() => {
consumer.close();
session.close();
Expand Down Expand Up @@ -617,3 +621,37 @@ for (const version of VERSIONS) {
expect(sent.mock.calls).toHaveLength(version === VERSION ? 2 : 0);
});
}

// A completed join must not remain a gate on the group's later cache misses.
test("an evicted joined group is fetched again as standalone history", async () => {
const clock = new Manual();
const installed = clock.install();
onTestFinished(() => installed.close());
const { subscriber, consumer, fetching, fetch, client } = await join();
if (!fetch) throw new Error("no joining FETCH");
await accept(fetching);
await subscriber.handleFetch(await head(fetch.requestId, ["h0", "h1"]));
await subscriber.handleGroup(...liveStream(GROUP, 2, ["t2"]));
const first = await consumer.recvGroup();
expect(await frames(first)).toEqual(["h0", "h1", "t2"]);
first?.close();
await subscriber.handleGroup(...liveStream(GROUP + 1n, 0, ["new"]));
// Twice the model's 30-second idle cache window, with deterministic time.
await clock.advance(Nano.fromMilli(Milli(60_000)));
expect(hooks.cachedGroup(consumer, GROUP)).toBeUndefined();
const broadcast = subscriber.consume(Path.from("room"));
onTestFinished(() => broadcast.close());
const pending = broadcast.track("video").fetchGroup(GROUP);
const stream = await nextStream(client);
if (!stream) throw new Error("no standalone FETCH");
expect(await stream.reader.u53()).toBe(Fetch.id);
const standalone = await Fetch.decode(stream.reader, VERSION);
expect(standalone.type.kind).toBe("standalone");
await stream.writer.u53(FetchOk.id);
await new FetchOk({ endOfTrack: false, endLocation: { group: GROUP, object: 3n } }).encode(stream.writer, VERSION);
await subscriber.handleFetch(await head(standalone.requestId, ["h0", "h1", "t2"]));
const group = await pending;
expect(await frames(group)).toEqual(["h0", "h1", "t2"]);
group.close();
consumer.close();
});
Loading
Loading