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
14 changes: 6 additions & 8 deletions js/net/src/broadcast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Duration, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts";
import * as cache from "./cache.ts";
import { NotFound, StreamCode, toStreamCode } from "./error.ts";
import { NotFound, StreamCode, TooFarBehind, toStreamCode } from "./error.ts";
import { hooks } from "./internal.ts";
import { textFrame } from "./mock.ts";
import { Timescale, Timestamp } from "./time.ts";
Expand Down Expand Up @@ -716,14 +716,13 @@ test("a pending track info query is answered by its request, and closing rejects

// A failed group's consumer settles `closed` with frames still unread; the fetch keeps its mirror
// registered until the caller lets go, so the pool can still reclaim those frames.
test("a fetch of a failed group leaves its unread frames to the pool's eviction", async () => {
test("a fetch of a failed group leaves its unread frames to the pool's expiry", async () => {
const clock = new Manual();
const installed = clock.install();
try {
const broadcast = new BroadcastProducer();
const track = broadcast.createTrack("video", { timescale: Timescale.MILLI });
const pool = new cache.Pool();
hooks.poolTrack(track, pool);
hooks.poolTrack(track, new cache.Pool({ expiry: Duration.millis(1_000) }));

const failed = track.appendGroup();
failed.writeFrame(textFrame("unread"));
Expand All @@ -733,10 +732,9 @@ test("a fetch of a failed group leaves its unread frames to the pool's eviction"
await yieldNow();
expect(group.closed.peek()).toBeInstanceOf(Error);

// Debt reclaims the oldest group, which the caller has not read.
pool.resize(1);
track.writeFrame(textFrame("fresh"));
await expect(group.readFrame()).rejects.toMatchObject({ code: StreamCode.Evicted });
// The idle window reclaims the failed group, which the caller has not read.
await clock.advance(Duration.millis(1_500));
await expect(group.readFrame()).rejects.toBeInstanceOf(TooFarBehind);
broadcast.close();
} finally {
installed.close();
Expand Down
2 changes: 1 addition & 1 deletion js/net/src/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ async function fetchGroup(
// Close the subscription once the caller has read or released the group, not
// now: an in-progress group must keep receiving frames for its lifetime
// (mirrors Rust poll_fetch), and a failed group's unread frames stay in the
// cache's reach, billed and evictable, until the caller lets them go.
// cache's reach, expirable, until the caller lets them go.
void hooks.groupDone(recv.group).then(() => subscriber.close());
return recv.group;
case "drop":
Expand Down
505 changes: 8 additions & 497 deletions js/net/src/cache.test.ts

Large diffs are not rendered by default.

Loading