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
29 changes: 29 additions & 0 deletions js/net/src/fill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,35 @@ async function failedAnswerHoldsTheEnd(error: Error) {
broadcast.close();
}

// A reader whose range lowers the copy's floor asks the live feed for those groups, as the update
// it sends does, so none is asked of a fill too, even before the session declares the new floor:
// the START answered the old floor, so it no longer bounds what the feed owes.
test("fill: a group a lowered floor asks the feed for is not asked of a fill", async () => {
const broadcast = new BroadcastProducer();
const track = broadcast.createTrack("video", { maxAge: null });
hooks.receiveTrack(track);
const live = track.subscribe({ ranges: [{ start: { relative: 0n } }], delay: { max: null } });
hooks.startTrack(track, { start: 1n });
hooks.receiveGroup(track, { sequence: 1n, start: 0 }).finish();
expect((await live.recvGroup())?.sequence).toBe(1n);
const requests = track.requests();
const asked = requests.requestedFill();

const history = track.subscribe({
ranges: [{ start: { absolute: 0n }, end: { absolute: 1n } }],
delay: { max: null },
});
const next = history.recvGroup();
expect(await Promise.race([asked.then(() => "asked"), yieldNow().then(() => "waiting")])).toBe("waiting");
hooks.receiveGroup(track, { sequence: 0n, start: 0 }).finish();
expect((await next)?.sequence).toBe(0n);

live.close();
history.close();
requests.close();
broadcast.close();
});

// Withheld as it fails, so a read in the same turn cannot take it either.
test("fill: a failed answer is withheld from a subscribed reader that reads at once", async () => {
for (const dispositions of [false, true]) {
Expand Down
6 changes: 5 additions & 1 deletion js/net/src/lite/copy_fill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ test("copy fill: a yielded group the fill's drop names ends", async () => {
const remote = wireOf(client).consume(Path.from("room"));
try {
const reader = remote.track("video").subscribe({ ranges: [{ start: { relative: 0n } }] });
expect((await reader.ordered().nextGroup())?.sequence).toBe(1n);
const live = await reader.ordered().nextGroup();
expect(live?.sequence).toBe(1n);
expect(dec.decode((await live?.readFrame())?.payload)).toBe("live 1");
expect(await live?.readFrame()).toBeUndefined();
live?.close();
const history = remote
.track("video")
.subscribe({ ...WIDE, ranges: [{ start: { absolute: 0n }, end: { absolute: 1n } }] });
Expand Down
5 changes: 4 additions & 1 deletion js/net/src/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,10 @@ export class Producer {
if (first === undefined) return;
start = max(start, first);
}
start = max(start, this.#wire?.served?.start ?? 0n);
// A START bounds the feed only while the demand keeps the floor it answered: a lowered floor
// asks the feed for the groups below it, which a fill must not duplicate.
const feed = this.#feedStart();
if (typeof feed === "bigint") start = max(start, feed);
const declared = this.#state.end.peek()?.at;
const end = declared === undefined ? land.end : min(land.end, finalSequence(declared));
const at = now();
Expand Down