diff --git a/js/net/src/track.ts b/js/net/src/track.ts index 9b48b8041fe..a0f6348170a 100644 --- a/js/net/src/track.ts +++ b/js/net/src/track.ts @@ -3627,11 +3627,13 @@ export class Subscriber { return keys.length === 0 ? "unknown" : "before"; }, nextStart: (from) => keys[keyIndex(keys, from)], - back: (latest, back) => { - // A lite-07 copy holds only part of the track, so it counts back as its publisher did, - // from the latest group the publisher counted from: a newer one moved the live edge. + // A lite-07 copy holds only part of the track, so it starts where its publisher did, + // counting from the same latest group: a newer one moved the live edge. + reportedStart: (latest, back) => { const reported = receivedCopy(producer) ? anchors.relative.get(back) : undefined; - if (reported !== undefined && reported.latest === latest) return reported.start; + return reported !== undefined && reported.latest === latest ? reported.start : undefined; + }, + back: (latest, back) => { if (back === 0n) return latest; // Bounded by the cache: a huge count reaches back to the oldest. const index = BigInt(keyIndex(keys, latest)) - back; diff --git a/js/net/src/window.test.ts b/js/net/src/window.test.ts index 3f938d3a113..438b96d1e9f 100644 --- a/js/net/src/window.test.ts +++ b/js/net/src/window.test.ts @@ -163,6 +163,22 @@ describe("Window", () => { expect(window.missable(0n)[0]).toEqual({ start: 5n, end: UNBOUNDED }); }); + test("a reported start moves a relative start, never a relative end", () => { + const held = new Keys(keys(0n, 10n)); + // The publisher reported starting the range counting back 2 from 9 at 8, past the 7 counted. + const reported: Holdings = { + resolves: () => true, + containing: (at) => held.containing(at), + nextStart: (from) => held.nextStart(from), + back: (latest, back) => held.back(latest, back), + reportedStart: (latest, back) => (latest === 9n && back === 2n ? 8n : undefined), + complete: () => false, + }; + expect(new Window([range(relative(2n))], 9n, reported).start()).toBe(8n); + const ended = new Window([range(time(0n), relative(2n))], 9n, reported); + expect(covered(ended, held.held)).toEqual(keys(0n, 8n)); + }); + test("relative anchors count groups back from the latest", () => { let held = new Keys([0n, 33n, 66n, 99n]); let window = new Window([range(relative(2n), relative(1n))], 99n, held); diff --git a/js/net/src/window.ts b/js/net/src/window.ts index 4e79b598fa6..03596fa4498 100644 --- a/js/net/src/window.ts +++ b/js/net/src/window.ts @@ -333,6 +333,13 @@ export interface Holdings { * undefined once fewer are held than that. */ back(latest: bigint, back: bigint): bigint | undefined; + /** + * Where the publisher reported starting a range counting `back` groups before `latest`, which a + * relative start, but never an end, takes over {@link back}: a delivery start may sit past the + * group counted, such as above groups too stale for the budget. Absent for none. Mirrors the + * Rust `Holdings::reported_start`. + */ + reportedStart?(latest: bigint, back: bigint): bigint | undefined; /** Whether nothing more can arrive here, so a time start nothing contains reaches back to the oldest group rather than wait. */ complete(): boolean; /** @@ -785,7 +792,7 @@ function startOf( if (anchor === undefined) return { group: 0n, floored: false }; if (anchor.relative !== undefined) { if (latest === undefined) return "pending"; - const group = holdings.back(latest, anchor.relative); + const group = holdings.reportedStart?.(latest, anchor.relative) ?? holdings.back(latest, anchor.relative); // Fewer groups are held than it counts back, so reach back to the oldest. return group === undefined ? { group: 0n, floored: false } : { group, floored: true }; } diff --git a/quest/m1/lite07-widened-started.md b/quest/m1/lite07-widened-started.md new file mode 100644 index 00000000000..64421fd705c --- /dev/null +++ b/quest/m1/lite07-widened-started.md @@ -0,0 +1,35 @@ +# [S] The @moq/net widened-range SUBSCRIBE_STARTED test passes again + +## Goal + +`js/net/src/lite/subscriber.test.ts` "a widened range's SUBSCRIBE_STARTED +resolves the feed's start" passes on `main`, with whatever it found fixed +at its root: after an update widens a lite-07 subscription's ranges, the +copy's start (`hooks.sourceStart`) stays pending until the widened range's +SUBSCRIBE_STARTED says where it starts. + +## Plan + +Found by [moq-dev/moq#9132](https://github.com/moq-dev/moq/pull/9132)'s +`just check`. It fails deterministically, with `sourceStart` reading `0n` +right after the update, where the test expects `"pending"`: + +```sh +cd js/net && bun test src/lite/subscriber.test.ts -t "a widened range's SUBSCRIBE_STARTED" +``` + +It passes on 928d337396's parent and fails from +[moq-dev/moq#9045](https://github.com/moq-dev/moq/pull/9045) on, which +changed how a lite-07 relay fits its ranges into one SUBSCRIBE_UPDATE. The +merge queue runs only the tests for changed files, so it landed unseen. + +- Decide whether the update's new range still needs its own + SUBSCRIBE_STARTED under #9045's fitting. If it does, fix `#declare` or + the update path; if a covering superset now legitimately keeps the start, + rewrite the test to that rule, mirrored by the Rust test that covers it. + +Decided 2026-11-19 (coordinator, maintainer away, merge granted): keep this +follow-up while [moq-dev/moq#9147](https://github.com/moq-dev/moq/pull/9147), +which fixes it, is open. #9147 finds #9045 changed only timing (an async encode +before the update's declaration) and fixes the test; it should delete this +quest when it lands. diff --git a/quest/m2/time-addressing/late-relative-join.md b/quest/m2/time-addressing/late-relative-join.md new file mode 100644 index 00000000000..629536f579a --- /dev/null +++ b/quest/m2/time-addressing/late-relative-join.md @@ -0,0 +1,34 @@ +# [M] A later reader's relative start on a partial lite-07 copy reads only its groups + +## Goal + +A reader that joins a lite-07 received copy already holding part of the +track, with a relative start, reads the groups its publisher counts back to +and nothing below them, in Rust and `@moq/net`. Today it resolves the start +against the groups the copy holds before SUBSCRIBE_STARTED can report the +publisher's: over a copy holding groups 1 and 2 of 0..9, a second reader of +`[{relative:2..time:8}]` reads 1, 2, 7, 8, then 3, 4, 5 and on, where it +should read 7 and 8 and end. + +## Plan + +Found by [moq-dev/moq#9132](https://github.com/moq-dev/moq/pull/9132), which +reports each live range's relative start on the copy +(`TrackState::relative_starts` in `rs/moq-net/src/model/track.rs`) but only +helps a reader whose start resolves after the report lands: the first reader, +whose relative start waits on SUBSCRIBE_START. A later reader's window +resolves at once (`Window::new` in `model/subscription/window.rs`), and +`Holdings::back` counts the copy's cache. + +- Reproduce first: the second-reader case above, as a `range_anchors.rs` + integration test, and the same in `js/net/src/integration.test.ts`. +- Decided 2026-11-19 (coordinator, maintainer away, merge granted), taking + the recommendation: on a received copy, count back over the cache only where + the copy holds every group from the counted one to its latest (received + contiguously since it went live), and otherwise leave the relative start + waiting, as a time start waits (`Start::Waiting`), until the range's + SUBSCRIBE_STARTED reports it. Rejected: always waiting on the report, + since an update that coalesces the reader's range into another one + (`fit` in `lite/subscriber/fit.rs`) gets no SUBSCRIBE_STARTED of its own and would hang. +- The waiting reader must still settle when no report can come: the copy + ends, or its feed goes idle. diff --git a/quest/m2/time-addressing/rust-relative-start.md b/quest/m2/time-addressing/rust-relative-start.md deleted file mode 100644 index 349a74e0a93..00000000000 --- a/quest/m2/time-addressing/rust-relative-start.md +++ /dev/null @@ -1,38 +0,0 @@ -# [S] Rust resume copies match @moq/net's relative starts and capped ends - -## Goal - -A Rust reader over a lite-07 received copy resolves a `Relative` range the -way `@moq/net` does: counted back from the start the publisher reported in -SUBSCRIBE_START, not from the groups the copy happens to hold. A sparse -request mixing a time range and a relative one reads every group it names -instead of stalling after the first. A route capped while replaced and then -returned to reads on to the reader's own bounded end. - -## Plan - -Decided 2026-11-17 (maintainer, on -[moq-dev/moq#9027](https://github.com/moq-dev/moq/pull/9027)): ✅ keep the -JS fix and port it here, so the mirror diverges only briefly (rejected: -fixing Rust in that PR; reverting JS to Rust's behavior). - -- Reproduce first: a reader asking `[{time:1..2}, {relative:2..time:8}]` - over a lite-07 copy holding only part of the track. In JS it read group 0 - and stalled, because the copy counted back over only the groups it held. -- `Holdings::back` for a received copy (`rs/moq-net/src/model/track.rs`) - counts the copy's own cache; resolve a relative start from the reported - start instead, as `@moq/net`'s `relativeStarts` hook - (`js/net/src/track.ts`, `js/net/src/internal.ts`) does. -- Scope each range's report to the latest it was counted from, recorded when - its start was answered (SUBSCRIBE_START's Largest, or the copy's latest at - SUBSCRIBE_STARTED), as JS does: once a newer group arrives, a late live - join counts from the copy's own latest instead of replaying from the old - report, and an update that changes no range never re-stamps it. -- `Copy::wire` (`rs/moq-net/src/model/resume.rs`) takes - `sub.resolved_ranges()` for unchanged ranges, which is the resolution of - the copy's clamped wire: a cap while replaced likely becomes the range's - end for good. JS keeps each range's first resolution instead - (`js/net/src/resume.ts` `#wire`, test "a returning route keeps the - reader's bounded end across its cap"); reproduce and port. -- If Rust turns out to handle a case elsewhere, delete this quest with a - test that pins it. diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index e95c831837a..8fac3b43c17 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -3220,6 +3220,7 @@ mod tests { finishing: None, parked: false, starts: Default::default(), + edges: Default::default(), declared: None, end: None, wanted: None, @@ -3381,6 +3382,7 @@ mod tests { finishing: None, parked: false, starts: Default::default(), + edges: Default::default(), declared: None, end: None, wanted: None, @@ -3859,6 +3861,7 @@ mod tests { finishing: None, parked: false, starts: Default::default(), + edges: Default::default(), declared: None, end: Some(lite::SubscribeFinish { group: 10, error: None }), wanted: None, @@ -3975,6 +3978,7 @@ mod tests { finishing: None, parked: false, starts: [(0, Some(4))].into(), + edges: Default::default(), declared: None, end: None, wanted: None, @@ -4043,6 +4047,7 @@ mod tests { finishing: None, parked: false, starts: [(0, Some(4))].into(), + edges: Default::default(), declared: None, end: Some(lite::SubscribeFinish { group: 10, error: None }), wanted: None, @@ -5564,6 +5569,7 @@ mod tests { finishing: None, parked: false, starts: Default::default(), + edges: Default::default(), declared: None, end: None, wanted: None, @@ -10055,6 +10061,10 @@ struct SubStream { /// Where SUBSCRIBE_START or SUBSCRIBE_STARTED says each live range's delivery starts, by /// Range ID, `None` for one with nothing to deliver. starts: std::collections::BTreeMap>, + /// The latest group each live range's start was counted back from, by Range ID: the + /// publisher's Largest when SUBSCRIBE_START answered, or the copy's latest when + /// SUBSCRIBE_STARTED did. Set only with its start, so an update keeping a range keeps it. + edges: std::collections::BTreeMap>, /// What [`Self::declare`] last declared on the copy, so an unchanged one is not declared /// again: each declaration restarts the grace of the gaps above it. declared: Option<(Option, bool)>, @@ -10097,23 +10107,32 @@ impl SubStream { Some((start, self.started.is_none())) } - /// Tell the copy where the publisher started each live range asked from a group's start, - /// which a reader's time start there resolves to when the copy holds no group at it. + /// Tell the copy where the publisher started each live range: one asked from a group's + /// start, which a reader's time start there resolves to when the copy holds no group at + /// it, and one counting back, which the copy, holding only part of the track, can't count. /// Lite-07 only, where each range's start is reported. - fn report_time_starts(&self, serving: &track::Producer) { + fn report_starts(&self, serving: &track::Producer) { if !self.live.reports_starts() { return; } - let starts = self - .live - .iter() - .filter_map(|(id, range)| match (range.start, self.starts.get(&id)) { - (Some(lite::Anchor::Absolute(time)), Some(Some(start))) if time.frame == 0 => { - Some((time.group, *start)) + let mut times = Vec::new(); + let mut relative = Vec::new(); + for (id, range) in self.live.iter() { + let Some(Some(start)) = self.starts.get(&id) else { + continue; + }; + match range.start { + Some(lite::Anchor::Absolute(time)) if time.frame == 0 => times.push((time.group, *start)), + Some(lite::Anchor::Relative(back)) => { + if let Some(Some(latest)) = self.edges.get(&id) { + relative.push((back, *start, *latest)); + } } - _ => None, - }); - serving.time_starts(starts); + _ => {} + } + } + serving.time_starts(times); + serving.relative_starts(relative); } /// Declare on the copy where the live feed starts, by [`Self::feed_start`], so a reader @@ -10244,6 +10263,7 @@ impl SubStream { let changed = !self.live.iter().map(|(id, _)| id).eq(before); let live = &self.live; self.starts.retain(|id, _| live.get(*id).is_some()); + self.edges.retain(|id, _| live.get(*id).is_some()); if self.started.is_some() { self.fill_ids.retain(|id| live.get(*id).is_some()); } @@ -11195,6 +11215,7 @@ impl Establish { finishing: None, parked: self.parked, starts: Default::default(), + edges: Default::default(), declared: None, end: None, wanted: None, @@ -12440,11 +12461,14 @@ impl ServeLoop { // fill's range starting past where it asked skips groups it will not deliver. let now = serve.subscriber.runtime.now(); let mut served: Option = None; + // What each range's relative start counted back from. + let edge = start.largest.map(|largest| largest.position.group); for (id, start) in (0..).zip(&start.starts) { // One an update retired since owes nothing, though before lite-07 its start // still says where the SUBSCRIBE's demand was served from. if active.live.get(id).is_some() { active.starts.insert(id, *start); + active.edges.insert(id, edge); } match active.fill_range(id) { Some(groups) => { @@ -12467,6 +12491,15 @@ impl ServeLoop { } } active.started = Some(served); + // Before the copy goes live, since a reader's relative start resolves only then: + // it counts back from the publisher's Largest, as the publisher did, rather than + // from whichever group landed first. + active.report_starts(&self.serving); + if active.live.reports_starts() + && let Some(largest) = start.largest + { + self.serving.report_edge(largest.position.group); + } // Only a live fill's Range ID matters from here. let live = &active.live; active.fill_ids.retain(|id| live.get(*id).is_some()); @@ -12500,7 +12533,6 @@ impl ServeLoop { // Lite-07 says where every live range starts, so the declaration follows them // whatever an update changed since. if active.live.reports_starts() { - active.report_time_starts(&self.serving); active.declare(&mut self.serving); } else if active.start == active.requested && active.demand.is_some() { let _ = match (serve.subscriber.version.resolves_start(), served) { @@ -12532,6 +12564,7 @@ impl ServeLoop { // One retired since is owed nothing. if active.live.get(id).is_some() { active.starts.insert(id, started.start); + active.edges.insert(id, self.serving.latest_live()); let now = serve.subscriber.runtime.now(); // A fill's range starting past where it asked skips groups it will not deliver. if let Some(groups) = active.fill_range(id) { @@ -12545,7 +12578,7 @@ impl ServeLoop { if let Ok(mut tail) = active.tail.write() { tail.expire(now); } - active.report_time_starts(&self.serving); + active.report_starts(&self.serving); active.declare(&mut self.serving); } } diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index d9bf17d5ef8..39d62c1943d 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -3536,6 +3536,49 @@ mod test { drop(held); } + /// A route capped while replaced and then returned to reads on to the end of the reader's + /// bounded range: the cap never becomes the range's own end. Mirrors the `@moq/net` "a + /// returning route keeps the reader's bounded end across its cap". + #[kio::test] + async fn a_returning_route_keeps_the_readers_bounded_end_across_its_cap() { + let routes = Producer::new(); + let logical = logical(&routes); + let a = copy(); + let mut open = a.create_group(group::Info { start: 0 }).unwrap(); + open.write_frame(ts(0), b"x".as_ref()).unwrap(); + routes.serve(a.consume()); + let subscription = Subscription::default() + .with_delay(Delay::default().with_max(HOUR)) + .with_ranges([track::Range { + start: Anchor::Time(0), + end: Some(Anchor::Time(100)), + }]); + let mut sub = logical + .consume() + .subscribe(subscription.clone()) + .now_or_never() + .unwrap() + .unwrap(); + let held = recv(&mut sub); + assert_eq!(held.start, 0); + + let b = copy(); + routes.serve(b.consume()); + write(&b, 10); + write(&b, 20); + assert_eq!(drain(&mut sub, false), [10, 20]); + + routes.serve(a.consume()); + write(&a, 30); + assert_eq!(drain(&mut sub, false), [30], "past the cap A had while replaced"); + // An update keeping the ranges asks A again with its own resolution of them. + sub.update(subscription.with_priority(1)).unwrap(); + write(&a, 40); + assert_eq!(drain(&mut sub, false), [40], "an update keeps the reader's end"); + open.finish().unwrap(); + drop(held); + } + /// A returning route resumes where a fresh copy would, and what it buffered while /// replaced below what another route already handed out comes through the backfill: /// the late group once, and nothing handed out again. diff --git a/rs/moq-net/src/model/subscription/window.rs b/rs/moq-net/src/model/subscription/window.rs index d168c9815ea..6231a37afc9 100644 --- a/rs/moq-net/src/model/subscription/window.rs +++ b/rs/moq-net/src/model/subscription/window.rs @@ -71,6 +71,14 @@ pub(in crate::model) trait Holdings { /// held: `None` once fewer are held than that. fn back(&self, latest: u64, back: u64) -> Option; + /// Where the publisher reported starting a range counting `back` groups before `latest`, + /// which a relative start, but never an end, takes over [`Self::back`]: a delivery start + /// may sit past the group counted, such as above groups too stale for the budget. + fn reported_start(&self, latest: u64, back: u64) -> Option { + let _ = (latest, back); + None + } + /// Whether nothing more can arrive here, so a time start nothing contains reaches back /// to the oldest group rather than wait. fn complete(&self) -> bool; @@ -690,7 +698,10 @@ fn start(anchor: Anchor, latest: Option, holdings: &impl Holdings) -> Start Anchor::Oldest => Start::At(0, false), Anchor::Relative(back) => match latest { None => Start::Pending, - Some(latest) => match holdings.back(latest, back) { + Some(latest) => match holdings + .reported_start(latest, back) + .or_else(|| holdings.back(latest, back)) + { Some(group) => Start::At(group, true), // Fewer groups are held than it counts back, so reach back to the oldest. None => Start::At(0, false), diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index d30b32c485c..924219ae02f 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -606,6 +606,14 @@ impl Anchors { } } +/// Where a received copy's publisher started a range counting back, and the latest group it +/// counted from. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +struct RelativeStart { + start: u64, + latest: u64, +} + #[derive(Default)] pub(crate) struct TrackState { // Ingress stats scope, inherited from a tagged [`broadcast::Producer`] or [`Request`]. @@ -745,6 +753,11 @@ pub(crate) struct TrackState { // a time it holds no group at, but its publisher reports where it resolved one. Replaced // whole as the ranges change, so it holds at most one entry per live range. time_starts: BTreeMap, + // Where the upstream publisher started each of a lite-07 copy's live wire ranges counting + // back, by how many groups each counted, with the latest group it counted from: the copy + // holds only part of the track, so it can't count back over its own groups. Replaced whole + // as the ranges change, like `time_starts`. + relative_starts: BTreeMap, // Keys the upstream publisher gave up, with why: an incoming SUBSCRIBE_SKIP or // SUBSCRIBE_DROP, or a producer cut. Kept apart from the cache so reclaiming a slot // cannot erase a disposition a relay must forward, and as ranges so a wide one costs @@ -1126,6 +1139,15 @@ impl Holdings for TrackState { self.lookup.range(..latest).rev().nth(back).map(|(&key, _)| key) } + /// A received copy starts where its publisher did, counting from the same latest group: a + /// newer one moved the live edge, which the copy then counts from itself. + fn reported_start(&self, latest: u64, back: u64) -> Option { + self.relative_starts + .get(&back) + .filter(|reported| reported.latest == latest) + .map(|reported| reported.start) + } + fn complete(&self) -> bool { self.outcome.is_final() } @@ -4768,6 +4790,29 @@ impl Producer { } } + /// Record where the upstream publisher started each of this lite-07 copy's live wire + /// ranges counting back, as `(back, start, latest)` triples, replacing the last set. A + /// reader's relative anchor counting back `back` groups from `latest` resolves to `start`. + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub(crate) fn relative_starts(&self, starts: impl IntoIterator) { + let starts: BTreeMap = starts + .into_iter() + .map(|(back, start, latest)| (back, RelativeStart { start, latest })) + .collect(); + if let Ok(mut state) = self.modify() + && state.relative_starts != starts + { + state.relative_starts = starts; + } + } + + /// Where this copy's readers count a relative start back from now (see + /// [`TrackState::latest_live`]). + #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] + pub(crate) fn latest_live(&self) -> Option { + self.state.read().latest_live() + } + /// Have this received copy's readers start a time anchor at the group starting there, /// held or not, for a wire whose publisher starts one at the first group at or after it. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] @@ -15363,6 +15408,57 @@ mod test { assert_eq!(drain(&mut past), vec![1000, 3000]); } + /// A lite-07 copy holds only part of the track, so a relative start counts back as its + /// publisher reported, not over the groups the copy holds, until a group past the latest + /// the publisher counted from moves the live edge. + #[test] + #[cfg(feature = "async")] + fn a_received_copy_counts_a_relative_start_back_as_its_publisher_did() { + let back = |back| { + Subscription::default() + .with_ranges([Range { + start: Anchor::Relative(back), + end: None, + }]) + .with_delay(Delay::default().with_max(None)) + }; + let placed = |subscriber: &mut Subscriber| subscriber.resolved()[0].map(|resolved| resolved.start); + let producer = track_producer("test", Info::timed()); + producer.received(); + producer.anchored(); + for key in [1, 2, 9] { + write_group(&producer, key); + } + producer.report_edge(9); + producer.relative_starts([(2, 7, 9)]); + + let mut reported = producer.subscribe(back(2)); + assert_eq!(placed(&mut reported), Some(7), "the publisher's start, not group 1"); + let mut unreported = producer.subscribe(back(1)); + assert_eq!(placed(&mut unreported), Some(2), "counted over the groups held"); + // A reported start is where delivery began, which may sit past the group counted, so a + // relative end counts over the groups held. + let mut ended = producer.subscribe( + Subscription::default() + .with_ranges([Range { + start: Anchor::Time(0), + end: Some(Anchor::Relative(2)), + }]) + .with_delay(Delay::default().with_max(None)), + ); + assert_eq!(ended.resolved()[0].and_then(|resolved| resolved.end), Some(2)); + + // A newer group moved the live edge, so a later reader counts back from it. + write_group(&producer, 10); + let mut later = producer.subscribe(back(2)); + assert_eq!(placed(&mut later), Some(2)); + assert_eq!( + placed(&mut reported), + Some(7), + "an earlier reader stays where it started" + ); + } + #[test] #[cfg(feature = "async")] fn a_late_lower_group_within_the_budget_is_delivered() { diff --git a/rs/moq-net/tests/integration/range_anchors.rs b/rs/moq-net/tests/integration/range_anchors.rs index c8a245e94c6..fda4f0e6993 100644 --- a/rs/moq-net/tests/integration/range_anchors.rs +++ b/rs/moq-net/tests/integration/range_anchors.rs @@ -241,3 +241,63 @@ async fn a_relative_start_reports_the_publishers_start_over_a_frameless_newest_g assert_eq!(group.map(|group| group.start), Some(5)); let _track = track.finish().unwrap(); } + +/// A lite-07 copy holds only part of the track, so a relative start counts back as its +/// publisher did rather than over the groups the copy holds: a sparse request mixing a time +/// range and a relative one reads every group it names. Mirrors the `@moq/net` +/// `integration: lite-07 serves sparse and relative ranges`. +#[kio::test] +async fn a_sparse_request_counts_its_relative_start_back_as_the_publisher_did() { + let publisher = produce_origin(1); + let broadcast = publisher + .route("room", moq_net::origin::RouteOptions::hidden()) + .unwrap(); + let track = broadcast + .broadcast() + .create_track( + "data", + Info::default().with_timescale(Timescale::MILLI).with_max_age(FOREVER), + ) + .unwrap(); + broadcast.announce().unwrap(); + for key in 0..10 { + let mut group = track.create_group(moq_net::group::Info { start: key }).unwrap(); + group.write_frame(millis(key), &b"x"[..]).unwrap(); + group.finish().unwrap(); + } + + let subscriber = produce_origin(2); + let _pair = peer("moq-lite-07-wip".parse::().unwrap(), &publisher, &subscriber).await; + let remote = kio::clock::timeout(TIMEOUT, subscriber.consume().follow("room", None).unwrap().available()) + .await + .expect("resolve timeout") + .expect("broadcast resolves") + .unwrap(); + let subscription = Subscription::default() + .with_delay(Delay::default().with_max(FOREVER)) + .with_order(Order::Ascending) + .with_ranges([ + range(Anchor::Time(1), Some(Anchor::Time(2))), + range(Anchor::Relative(2), Some(Anchor::Time(8))), + ]); + let mut reader = kio::clock::timeout(TIMEOUT, remote.track("data").unwrap().subscribe(subscription)) + .await + .expect("subscribe timeout") + .unwrap(); + + let mut read = Vec::new(); + for _ in 0..4 { + let group = kio::clock::timeout(TIMEOUT, reader.recv_group()) + .await + .expect("group timeout") + .unwrap(); + read.push(group.map(|group| group.start)); + } + assert_eq!(read, [Some(1), Some(2), Some(7), Some(8)]); + let end = kio::clock::timeout(TIMEOUT, reader.recv_group()) + .await + .expect("end timeout") + .unwrap(); + assert_eq!(end.map(|group| group.start), None, "the ranges are covered"); + let _track = track.finish().unwrap(); +}