From fd0945fbeb39d12721dc566ebc3ccec3e3eaa493 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 05:38:23 -0700 Subject: [PATCH 1/8] chore(quest): claim quest/m1/interop-finish.md Quest-Claim: f6c2ec75c4873e53 From b74aee6699525bba59e6328494c5c88315da9f6e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 06:03:29 -0700 Subject: [PATCH 2/8] test(interop): verify finite finish in the C subscriber Assert natural media and catalog EOF, exact announcement withdrawal, and continued session use after the finished media lingers. Preflight the reader before publication and keep terminal callbacks owned through teardown. Co-Authored-By: GPT-6 --- test/interop/clients/c/subscribe.c | 270 ++++++++++++++++++++++++++--- 1 file changed, 245 insertions(+), 25 deletions(-) diff --git a/test/interop/clients/c/subscribe.c b/test/interop/clients/c/subscribe.c index 8de8dd52616..fe4cb0ffb24 100644 --- a/test/interop/clients/c/subscribe.c +++ b/test/interop/clients/c/subscribe.c @@ -4,15 +4,18 @@ // moq-c is a handle + callback API: connect, consume a broadcast, get a // catalog snapshot via callback, start the video track, and a frame callback // fires as frames arrive. Once a non-empty frame lands we close and drain every -// registration, then return 0; a timeout exits 1. Publishing isn't wired up: the -// raw-stream importer that the other clients use to publish isn't part of this -// subscribe-only client. +// registration, then return 0; a timeout exits 1. --finish instead verifies the +// complete finite tail, clean media/catalog EOF, withdrawal, and a live session. +// Publishing isn't wired up: the raw-stream importer that the other clients use +// to publish isn't part of this subscribe-only client. // // c-interop subscribe --url http://127.0.0.1:4443 --broadcast b.hang --timeout 20 // // --version offers only that version, through moq_client_config. #include +#include +#include #include #include #include @@ -22,10 +25,20 @@ #include #include +typedef struct { + int enabled, failed, announce_end, done_announce, done_health_wait, done_health; + unsigned expected, frames, health_frames; + int connected; + int32_t frame_end, catalog_end, health_end; + int32_t announcements, health_wait, health_broadcast; + const char *path; +} finish_t; + typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int got; // a non-empty frame arrived + finish_t finish; int32_t origin; int32_t session; int32_t broadcast_wait; @@ -34,7 +47,7 @@ typedef struct { int32_t video_track; // handle from moq_consume_video (0 until on_catalog starts it) // One flag per registration handed &ctx, set by that registration's terminal - // (<= 0) callback. main returns only once all four are set: that terminal is + // (<= 0) callback. main returns only once every registration is done: that terminal is // moq-c's documented last touch of user_data, so it is what makes main's // frame safe to destroy. int done_status, done_broadcast, done_catalog, done_frame; @@ -56,23 +69,40 @@ static void done(ctx_t *c, int *flag) { static void on_status(void *ud, int32_t code) { ctx_t *c = (ctx_t *)ud; fprintf(stderr, "session status: %d\n", code); + if (c->finish.enabled && code > 0) { + pthread_mutex_lock(&c->mu); + c->finish.connected = code; + if (code > 1) c->finish.failed = 1; + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); + } if (code <= 0) done(c, &c->done_status); } static void on_frame(void *ud, int32_t frame) { ctx_t *c = (ctx_t *)ud; if (frame <= 0) { // 0 = ended, negative = error + pthread_mutex_lock(&c->mu); + c->finish.frame_end = frame; + if (c->finish.enabled && frame < 0) { + fprintf(stderr, "finish media error: %d %s\n", frame, moq_error()); + c->finish.failed = 1; + } + pthread_mutex_unlock(&c->mu); done(c, &c->done_frame); return; } moq_frame f; memset(&f, 0, sizeof(f)); - if (moq_consume_frame((uint32_t)frame, &f) == 0 && f.payload_size > 0) { - pthread_mutex_lock(&c->mu); + int32_t read = moq_consume_frame((uint32_t)frame, &f); + pthread_mutex_lock(&c->mu); + if (read < 0 && c->finish.enabled) c->finish.failed = 1; + if (read == 0 && f.payload_size > 0) { c->got = 1; - pthread_cond_broadcast(&c->cv); - pthread_mutex_unlock(&c->mu); + if (c->finish.enabled && ++c->finish.frames > c->finish.expected) c->finish.failed = 1; } + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); moq_consume_frame_free((uint32_t)frame); } @@ -82,6 +112,12 @@ static void on_frame(void *ud, int32_t frame) { static void on_broadcast(void *ud, int32_t broadcast) { ctx_t *c = (ctx_t *)ud; if (broadcast <= 0) { // 0 = ended, negative = error + if (c->finish.enabled) { + if (broadcast < 0) fprintf(stderr, "finish broadcast error: %d %s\n", broadcast, moq_error()); + pthread_mutex_lock(&c->mu); + c->finish.failed = 1; + pthread_mutex_unlock(&c->mu); + } done(c, &c->done_broadcast); return; } @@ -92,12 +128,27 @@ static void on_broadcast(void *ud, int32_t broadcast) { pthread_cond_broadcast(&c->cv); } pthread_mutex_unlock(&c->mu); - if (!first) moq_consume_close((uint32_t)broadcast); + if (!first) { + if (c->finish.enabled) { + pthread_mutex_lock(&c->mu); + c->finish.failed = 1; // A replacement instance cannot finish this fixture. + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); + } + moq_consume_close((uint32_t)broadcast); + } } static void on_catalog(void *ud, int32_t catalog) { ctx_t *c = (ctx_t *)ud; if (catalog <= 0) { + pthread_mutex_lock(&c->mu); + c->finish.catalog_end = catalog; + if (c->finish.enabled && (catalog < 0 || c->video_track <= 0)) { + if (catalog < 0) fprintf(stderr, "finish catalog error: %d %s\n", catalog, moq_error()); + c->finish.failed = 1; + } + pthread_mutex_unlock(&c->mu); done(c, &c->done_catalog); return; } @@ -117,12 +168,95 @@ static void on_catalog(void *ud, int32_t catalog) { pthread_mutex_lock(&c->mu); c->video_track = track; pthread_mutex_unlock(&c->mu); + } else if (c->finish.enabled) { + fprintf(stderr, "finish video registration error: %d %s\n", track, moq_error()); + pthread_mutex_lock(&c->mu); + c->finish.failed = 1; + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); } } } moq_consume_catalog_free((uint32_t)catalog); } +// An END is a route withdrawal, not the terminal of the announcement listener. +static void on_finish_announce(void *ud, int32_t event) { + ctx_t *c = ud; + if (event <= 0) { + if (event < 0) { + fprintf(stderr, "finish announcement error: %d %s\n", event, moq_error()); + pthread_mutex_lock(&c->mu); + c->finish.failed = 1; + pthread_mutex_unlock(&c->mu); + } + done(c, &c->finish.done_announce); + return; + } + moq_announce_event info; + int32_t read = moq_origin_announced_info((uint32_t)event, &info); + pthread_mutex_lock(&c->mu); + if (read < 0) c->finish.failed = 1; + else if (info.prefix_len == strlen(c->finish.path) && + memcmp(info.prefix, c->finish.path, info.prefix_len) == 0 && + info.kind == MOQ_ANNOUNCE_KIND_END) c->finish.announce_end = 1; + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); + moq_origin_announced_free((uint32_t)event); +} + +static void on_finish_health_frame(void *ud, int32_t frame) { + ctx_t *c = ud; + if (frame <= 0) { + pthread_mutex_lock(&c->mu); + c->finish.health_end = frame; + if (frame < 0) { + fprintf(stderr, "finish health error: %d %s\n", frame, moq_error()); + c->finish.failed = 1; + } + pthread_mutex_unlock(&c->mu); + done(c, &c->finish.done_health); + return; + } + moq_frame info; + int32_t read = moq_consume_track_frame((uint32_t)frame, &info); + const char payload[] = "session-alive"; + pthread_mutex_lock(&c->mu); + if (read < 0 || info.payload_size != sizeof(payload) - 1 || + memcmp(info.payload, payload, sizeof(payload) - 1) != 0 || + info.timestamp_present || ++c->finish.health_frames != 1) c->finish.failed = 1; + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); + moq_consume_track_frame_free((uint32_t)frame); +} + +static void on_finish_health(void *ud, int32_t broadcast) { + ctx_t *c = ud; + if (broadcast <= 0) { + if (broadcast < 0) fprintf(stderr, "finish health broadcast error: %d %s\n", broadcast, moq_error()); + pthread_mutex_lock(&c->mu); + c->finish.failed = 1; + pthread_mutex_unlock(&c->mu); + done(c, &c->finish.done_health_wait); + return; + } + pthread_mutex_lock(&c->mu); + int first = c->finish.health_broadcast == 0; + if (first) c->finish.health_broadcast = broadcast; + else c->finish.failed = 1; + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); + if (!first) { + moq_consume_close((uint32_t)broadcast); + return; + } + int32_t track = moq_consume_track((uint32_t)broadcast, "live", 4, NULL, on_finish_health_frame, ud); + pthread_mutex_lock(&c->mu); + if (track <= 0) c->finish.failed = 1; + pthread_cond_broadcast(&c->cv); + pthread_mutex_unlock(&c->mu); +} + // The context whose session a failure closes, once connected. static ctx_t *failing; @@ -155,6 +289,40 @@ static _Noreturn void fail(const char *fmt, ...) { _exit(1); } +// These assertions precede every local cancel, which would also produce terminal 0. +static void finish(ctx_t *c, const struct timespec *deadline) { + pthread_mutex_lock(&c->mu); + while (!c->finish.failed && !c->done_status && !c->finish.done_announce && + !(c->done_frame && c->done_catalog && c->finish.announce_end)) { + if (pthread_cond_timedwait(&c->cv, &c->mu, deadline) != 0) break; + } + int ok = !c->finish.failed && !c->done_status && !c->finish.done_announce && + c->done_frame && c->done_catalog && + c->finish.frame_end == 0 && c->finish.catalog_end == 0 && c->finish.announce_end && + c->finish.frames == c->finish.expected; + unsigned frames = c->finish.frames; + pthread_mutex_unlock(&c->mu); + if (!ok) fail("error: finish did not drain naturally (frames=%u expected=%u)\n", frames, c->finish.expected); + + size_t length = strlen(c->finish.path) + sizeof(".health"); + char *path = malloc(length); + if (!path) fail("error: cannot allocate health path\n"); + snprintf(path, length, "%s.health", c->finish.path); + c->finish.health_wait = moq_origin_announced_broadcast((uint32_t)c->origin, path, strlen(path), on_finish_health, c); + free(path); + if (c->finish.health_wait <= 0) fail("error: health registration failed\n"); + + pthread_mutex_lock(&c->mu); + while (!c->finish.failed && !c->done_status && !c->finish.done_health) { + if (pthread_cond_timedwait(&c->cv, &c->mu, deadline) != 0) break; + } + ok = !c->finish.failed && !c->done_status && c->finish.done_health && + c->finish.health_end == 0 && c->finish.health_frames == 1; + pthread_mutex_unlock(&c->mu); + if (!ok) fail("error: session health failed after broadcast finish\n"); + fprintf(stderr, "finish clean frames=%u catalog=eof announce=end health=ok\n", frames); +} + // Close every registration holding &ctx and wait for each one's terminal // callback. Only then may main return: main's frame is ctx's storage, and // exit()'s own call frames reuse those addresses, so a callback that arrives @@ -168,13 +336,19 @@ static _Noreturn void fail(const char *fmt, ...) { static void drain(ctx_t *c) { pthread_mutex_lock(&c->mu); int32_t track = c->video_track; + int cancel_frame = !c->finish.enabled || !c->done_frame; + int cancel_catalog = !c->finish.enabled || !c->done_catalog; // A video track that was never started registered nothing, so it owes no terminal. if (track <= 0) c->done_frame = 1; pthread_mutex_unlock(&c->mu); - if (track > 0) moq_consume_video_cancel((uint32_t)track); - moq_consume_catalog_cancel((uint32_t)c->catalog); + if (track > 0 && cancel_frame) moq_consume_video_cancel((uint32_t)track); + if (cancel_catalog) moq_consume_catalog_cancel((uint32_t)c->catalog); moq_origin_announced_broadcast_cancel((uint32_t)c->broadcast_wait); + if (c->finish.enabled) { + moq_origin_announced_cancel((uint32_t)c->finish.announcements); + moq_origin_announced_broadcast_cancel((uint32_t)c->finish.health_wait); + } moq_session_close((uint32_t)c->session); struct timespec deadline; @@ -182,10 +356,12 @@ static void drain(ctx_t *c) { deadline.tv_sec += 10; pthread_mutex_lock(&c->mu); - while (!(c->done_frame && c->done_catalog && c->done_broadcast && c->done_status)) { + while (!(c->done_frame && c->done_catalog && c->done_broadcast && c->done_status && + (!c->finish.enabled || (c->finish.done_announce && c->finish.done_health_wait && c->finish.done_health)))) { if (pthread_cond_timedwait(&c->cv, &c->mu, &deadline) != 0) break; // timed out } - int ok = c->done_frame && c->done_catalog && c->done_broadcast && c->done_status; + int ok = c->done_frame && c->done_catalog && c->done_broadcast && c->done_status && + (!c->finish.enabled || (c->finish.done_announce && c->finish.done_health_wait && c->finish.done_health)); int f = c->done_frame, ct = c->done_catalog, b = c->done_broadcast, s = c->done_status; pthread_mutex_unlock(&c->mu); @@ -197,20 +373,33 @@ static void drain(ctx_t *c) { int main(int argc, char **argv) { const char *url = NULL, *broadcast = NULL, *version = NULL; double timeout_s = 20.0; + int finish_mode = 0; + unsigned frames = 0; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "--url") && i + 1 < argc) url = argv[++i]; else if (!strcmp(argv[i], "--broadcast") && i + 1 < argc) broadcast = argv[++i]; else if (!strcmp(argv[i], "--timeout") && i + 1 < argc) timeout_s = atof(argv[++i]); else if (!strcmp(argv[i], "--version") && i + 1 < argc) version = argv[++i]; + else if (!strcmp(argv[i], "--finish")) finish_mode = 1; + else if (!strcmp(argv[i], "--frames") && i + 1 < argc) { + char *end; + errno = 0; + unsigned long value = strtoul(argv[++i], &end, 10); + if (errno || !*argv[i] || argv[i][0] == '-' || *end || value == 0 || value > UINT_MAX) return 2; + frames = (unsigned)value; + } // a leading "subscribe" positional (and anything else) is ignored. } - if (!url || !broadcast) { - fprintf(stderr, "usage: c-interop subscribe --url U --broadcast B [--timeout S] [--version V]\n"); + if (!url || !broadcast || (finish_mode && frames == 0) || (!finish_mode && frames != 0)) { + fprintf(stderr, "usage: c-interop subscribe --url U --broadcast B [--timeout S] [--version V] [--finish --frames N]\n"); return 2; } ctx_t c; memset(&c, 0, sizeof(c)); + c.finish.enabled = finish_mode; + c.finish.expected = frames; + c.finish.path = broadcast; pthread_mutex_init(&c.mu, NULL); pthread_cond_init(&c.cv, NULL); @@ -245,6 +434,33 @@ int main(int argc, char **argv) { clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += (time_t)timeout_s; + if (finish_mode) { + pthread_mutex_lock(&c.mu); + while (!c.finish.connected && !c.done_status && !c.finish.failed) { + if (pthread_cond_timedwait(&c.cv, &c.mu, &deadline) != 0) break; + } + int ready = c.finish.connected == 1 && !c.done_status && !c.finish.failed; + pthread_mutex_unlock(&c.mu); + if (!ready) fail("error: finish reader did not establish its first session\n"); + puts("finish reader ready"); + fflush(stdout); + char command[16]; + if (!fgets(command, sizeof(command), stdin) || strcmp(command, "read\n")) { + fail("error: finish reader expected read command\n"); + } + // Cold reader startup precedes publication; only the released read spends the linger. + clock_gettime(CLOCK_REALTIME, &deadline); + deadline.tv_sec += (time_t)timeout_s; + + moq_announce_config announce; + memset(&announce, 0, sizeof(announce)); + announce.prefix = broadcast; + announce.prefix_len = strlen(broadcast); + announce.filter = ""; // Exact path only, excluding the health sibling. + c.finish.announcements = moq_origin_announced((uint32_t)c.origin, &announce, on_finish_announce, &c); + if (c.finish.announcements <= 0) fail("error: finish announcement registration failed\n"); + } + // The broadcast arrives over the network after connect, so wait for it to be // announced. moq_origin_announced_broadcast resolves via on_broadcast once it's // available; we block on the condvar until then (or the deadline). @@ -269,24 +485,28 @@ int main(int argc, char **argv) { fail("error: moq_consume_catalog failed: %d\n", c.catalog); } - pthread_mutex_lock(&c.mu); - while (!c.got) { - if (pthread_cond_timedwait(&c.cv, &c.mu, &deadline) != 0) break; // timed out - } - int got = c.got; - pthread_mutex_unlock(&c.mu); + if (finish_mode) finish(&c, &deadline); + else { + pthread_mutex_lock(&c.mu); + while (!c.got) { + if (pthread_cond_timedwait(&c.cv, &c.mu, &deadline) != 0) break; // timed out + } + int got = c.got; + pthread_mutex_unlock(&c.mu); - if (!got) { - fail("error: timed out waiting for data\n"); - } + if (!got) { + fail("error: timed out waiting for data\n"); + } - fprintf(stderr, "received a frame from %s\n", broadcast); + fprintf(stderr, "received a frame from %s\n", broadcast); + } // The data path succeeded, which is all this interop client verifies. Returning // (rather than _exit) is the other half of what it verifies: an embedder that // closes and drains gets a clean process exit, with moq-c's runtime thread // still live behind its LazyLock. drain(&c); + if (finish_mode) moq_consume_close((uint32_t)c.finish.health_broadcast); moq_consume_close((uint32_t)bc); moq_origin_close((uint32_t)c.origin); fflush(stderr); From 130041a80b2cecbb984faa0c80582716121a4f00 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 06:06:11 -0700 Subject: [PATCH 3/8] test(interop): verify clean finish with Go and Python clients Add finish-only hooks around the existing finite media publishers, retain media and catalog readers through natural EOF, and require exact announcement END plus a raw health read over the same session. Completion ACK releases teardown only after the actual broadcast linger. Validated all four Go/Python publisher and subscriber combinations with ten nonempty frames and 30s linger. Four wrong-count controls reject eleven expected frames. Go build/vet and Python ruff/pyright pass. Required just ci stops on the unchanged Manual.advanceAsync type error addressed by PR6308. Co-Authored-By: GPT-6 --- test/interop/clients/go/main.go | 219 ++++++++++++++++++++++++- test/interop/clients/python/interop.py | 110 ++++++++++++- 2 files changed, 318 insertions(+), 11 deletions(-) diff --git a/test/interop/clients/go/main.go b/test/interop/clients/go/main.go index f9e89de4089..a3aadde1458 100644 --- a/test/interop/clients/go/main.go +++ b/test/interop/clients/go/main.go @@ -11,11 +11,15 @@ // ffmpeg ... -f h264 - | go-interop publish --url http://localhost:4443 --broadcast b.hang // go-interop subscribe --url http://localhost:4443 --broadcast b.hang --timeout 20 // +// --finish verifies a finite tail, natural media/catalog EOF, announcement END, and +// same-session health; --frames sets its exact size. --finish-ack selects publisher +// finish mode and names the FIFO releasing teardown after the real linger. // --version offers only that version. --grant waits for the grant the relay sends // over AUTH and prints it as an `auth granted` line before the client starts. package main import ( + "bufio" "context" "encoding/binary" "encoding/json" @@ -121,7 +125,7 @@ func patterns(list []string) string { return string(out) } -func publish(ctx context.Context, url, broadcast string, opts dialOptions, timeout time.Duration) error { +func publish(ctx context.Context, url, broadcast string, opts dialOptions, timeout time.Duration, finishAck string) error { client, err := dial(ctx, url, opts, timeout) if err != nil { return err @@ -196,7 +200,57 @@ func publish(ctx context.Context, url, broadcast string, opts dialOptions, timeo if err := audio.Finish(); err != nil { return err } - return media.Finish() + if err := media.Finish(); err != nil { + return err + } + if finishAck == "" { + return nil + } + // Finish also finalizes the catalog. ACK never controls the real linger. + finished, err := producer.Finish() + if err != nil { + return err + } + defer finished.Close() + fmt.Printf("finish ready linger_us=%d\n", finished.Linger().Microseconds()) + if err := finished.Wait(ctx); err != nil { + return err + } + health, err := client.CreateBroadcast(broadcast + ".health") + if err != nil { + return err + } + defer health.Close() + live, err := health.PublishTrack("live", nil) + if err != nil { + return err + } + if err := live.WriteFrame(moq.Frame{Payload: []byte("session-alive")}); err != nil { + return err + } + if err := live.Finish(); err != nil { + return err + } + if err := health.Announce(moq.Route{}); err != nil { + return err + } + ack, err := os.Open(finishAck) + if err != nil { + return err + } + defer ack.Close() + command, err := bufio.NewReader(ack).ReadString('\n') + if err != nil { + return err + } + if command != "complete\n" { + return errors.New("expected finish completion acknowledgement") + } + if client.Session().Connects() != 1 { + return errors.New("publisher reconnected during finish") + } + fmt.Println("finish acknowledged") + return nil } // The catalog is a live track. A lazy publisher (e.g. the browser, which only @@ -223,15 +277,161 @@ func catalogWithVideo(ctx context.Context, consumer *moq.BroadcastConsumer) (*mo } } -func subscribe(ctx context.Context, url, broadcast string, opts dialOptions, timeout time.Duration) error { +// finishSubscribe retains each reader until its natural EOF, then proves the session still serves. +func finishSubscribe(ctx context.Context, client *moq.Client, broadcast string, frames int) error { + announcements, err := client.Announced(moq.AnnounceOptions{Prefix: broadcast}) + if err != nil { + return err + } + defer announcements.Cancel() + announced, err := client.AnnouncedBroadcast(broadcast) + if err != nil { + return err + } + defer announced.Cancel() + consumer, err := announced.Available(ctx) + if err != nil { + return err + } + catalogs, err := moqmedia.NewCatalogConsumer(ctx, consumer) + if err != nil { + return err + } + defer catalogs.Cancel() + var catalog *moqmedia.Catalog + for { + catalog, err = catalogs.Next(ctx) + if err != nil { + return err + } + if catalog == nil { + return errors.New("catalog ended without video") + } + if len(catalog.Video) != 0 { + break + } + } + var id string + var video moqmedia.Video + for id, video = range catalog.Video { + break + } + media, err := moqmedia.NewTrackConsumer(ctx, consumer, moqmedia.TrackConfig{Rendition: moqmedia.VideoRendition(id, video), Subscription: &moq.Subscription{MaxDelay: maxDelay}}) + if err != nil { + return err + } + defer media.Cancel() + count := 0 + for { + frame, err := media.Next(ctx) + if err != nil { + return err + } + if frame == nil { + break + } + // Empty payloads carry endpoint metadata, not codec frames. + if len(frame.Payload) == 0 { + continue + } + count++ + if count > frames { + return fmt.Errorf("expected %d frames, received more", frames) + } + } + if count != frames { + return fmt.Errorf("expected %d frames, received %d", frames, count) + } + for { + catalog, err := catalogs.Next(ctx) + if err != nil { + return err + } + if catalog == nil { + break + } + } + started := false + for { + event, err := announcements.Next(ctx) + if err != nil { + return err + } + if event == nil { + return errors.New("announcement stream ended before broadcast END") + } + if start, ok := event.(moq.AnnounceEventStart); ok && start.Announce.Prefix == broadcast { + started = true + } + if restart, ok := event.(moq.AnnounceEventRestart); ok && restart.Announce.Prefix == broadcast { + return errors.New("broadcast restarted during finish") + } + if end, ok := event.(moq.AnnounceEventEnd); ok && end.Announce.Prefix == broadcast { + if !started { + return errors.New("broadcast ended without announcement") + } + break + } + } + healthAnnounced, err := client.AnnouncedBroadcast(broadcast + ".health") + if err != nil { + return err + } + defer healthAnnounced.Cancel() + health, err := healthAnnounced.Available(ctx) + if err != nil { + return err + } + live, err := health.SubscribeTrack(ctx, "live", nil) + if err != nil { + return err + } + defer live.Cancel() + frame, err := live.ReadFrame(ctx) + if err != nil { + return err + } + if frame == nil || string(frame.Payload) != "session-alive" { + return errors.New("unexpected session health payload") + } + frame, err = live.ReadFrame(ctx) + if err != nil { + return err + } + if frame != nil { + return errors.New("session health track did not end after one frame") + } + if client.Session().Connects() != 1 { + return errors.New("subscriber reconnected during finish") + } + fmt.Printf("finish clean frames=%d catalog=eof announce=end health=ok\n", frames) + return nil +} + +func subscribe(ctx context.Context, url, broadcast string, opts dialOptions, timeout time.Duration, finish bool, frames int) error { + parent := ctx ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - client, err := dial(ctx, url, opts, timeout) if err != nil { return err } defer client.Close() + if finish { + fmt.Println("finish reader ready") + command, err := bufio.NewReader(os.Stdin).ReadString('\n') + if err != nil { + return err + } + if command != "read\n" { + return errors.New("expected finish read command") + } + } + if finish { + readCtx, cancel := context.WithTimeout(parent, timeout) + defer cancel() + return finishSubscribe(readCtx, client, broadcast, frames) + } announced, err := client.AnnouncedBroadcast(broadcast) if err != nil { @@ -291,6 +491,9 @@ func run() error { timeout := flags.Float64("timeout", 20, "seconds to wait for data") version := flags.String("version", "", "offer only this version") grant := flags.Bool("grant", false, "wait for the grant the relay sends over AUTH and print it") + finishAck := flags.String("finish-ack", "", "publisher completion FIFO; enables clean finish") + finish := flags.Bool("finish", false, "verify a late tail and clean broadcast end") + frames := flags.Int("frames", 10, "expected finish video frame count") if err := flags.Parse(os.Args[2:]); err != nil { return err } @@ -298,6 +501,10 @@ func run() error { return errors.New("--url and --broadcast are required") } + if *frames <= 0 || (*finish && role != "subscribe") || (*finishAck != "" && role != "publish") { + return errors.New("finish requires a subscriber, finish-ack a publisher, and frames must be positive") + } + // Warnings and errors from the Rust layer, such as a publication outside the grant. if err := moq.LogLevel("warn"); err != nil { return err @@ -307,9 +514,9 @@ func run() error { opts := dialOptions{version: *version, grant: *grant} switch role { case "publish": - return publish(ctx, *url, *broadcast, opts, wait) + return publish(ctx, *url, *broadcast, opts, wait, *finishAck) case "subscribe": - return subscribe(ctx, *url, *broadcast, opts, wait) + return subscribe(ctx, *url, *broadcast, opts, wait, *finish, *frames) default: return fmt.Errorf("unknown role %q", role) } diff --git a/test/interop/clients/python/interop.py b/test/interop/clients/python/interop.py index 29259f24e50..3c6b50e1e6e 100644 --- a/test/interop/clients/python/interop.py +++ b/test/interop/clients/python/interop.py @@ -7,6 +7,9 @@ subscribe: connect, find the video track in the catalog, and exit 0 as soon as any non-empty frame arrives (exit 1 on timeout / no data). +--finish verifies a finite tail, natural media/catalog EOF, announcement END, and +same-session health; --frames sets its exact size. --finish-ack selects publisher +finish mode and names the FIFO releasing teardown after the real linger. --version offers only that version. --grant waits for the grant the relay sends over AUTH and prints it as an `auth granted` line before the client starts. @@ -81,11 +84,13 @@ async def first() -> moq.Grant: ) -async def publish(url: str, broadcast: str, version: str | None, grant: bool, timeout: float) -> None: +async def publish( + url: str, broadcast: str, version: str | None, grant: bool, timeout: float, finish_ack: str | None +) -> None: async with _client(url, version) as client: if grant: await _print_grant(client, timeout) - # Hold the producer for the lifetime of the publish loop; finish() unpublishes. + # Hold the producer for the lifetime of the publish loop. producer = client.create_broadcast(broadcast) catalog = moq.media.CatalogProducer(producer) media = moq.media.TrackStreamProducer.video( @@ -123,6 +128,26 @@ async def publish(url: str, broadcast: str, version: str | None, grant: bool, ti await tone audio.finish() media.finish() + if finish_ack is not None: + # finish() also finalizes the catalog. ACK never controls the real linger. + finished = producer.finish() + print(f"finish ready linger_us={finished.linger // timedelta(microseconds=1)}", flush=True) + await finished.wait() + health = client.create_broadcast(f"{broadcast}.health") + live = health.publish_track("live") + live.write_frame(b"session-alive") + live.finish() + health.announce() + + def acknowledge() -> None: + with open(finish_ack) as ack: + if ack.readline() != "complete\n": + raise RuntimeError("expected finish completion acknowledgement") + + await loop.run_in_executor(None, acknowledge) + if client.session is None or client.session.connects() != 1: + raise RuntimeError("publisher reconnected during finish") + print("finish acknowledged", flush=True) async def _catalog_with_video(consumer: moq.BroadcastConsumer) -> moq.media.Catalog: @@ -136,10 +161,78 @@ async def _catalog_with_video(consumer: moq.BroadcastConsumer) -> moq.media.Cata raise RuntimeError("catalog stream ended without a video track") -async def subscribe(url: str, broadcast: str, version: str | None, grant: bool, timeout: float) -> None: +async def _finish_subscribe(client: moq.Client, broadcast: str, frames: int) -> None: + # Watch the exact path before resolving it, retaining END while media drains. + async with client.announced(broadcast) as announcements: + async with client.announced_broadcast(broadcast) as announced: + consumer = await announced + async with await moq.media.CatalogConsumer.subscribe(consumer) as catalogs: + async for catalog in catalogs: + if catalog.video: + break + else: + raise RuntimeError("catalog ended without video") + id, video = next(iter(catalog.video.items())) + async with await moq.media.TrackConsumer.subscribe( + consumer, id, video, subscription=moq.Subscription(max_delay=MAX_DELAY) + ) as media: + count = 0 + async for frame in media: + # Empty payloads carry endpoint metadata, not codec frames. + if not frame.payload: + continue + count += 1 + if count > frames: + raise RuntimeError(f"expected {frames} frames, received more") + if count != frames: + raise RuntimeError(f"expected {frames} frames, received {count}") + # Do not cancel the catalog after its first snapshot: EOF is part of the case. + async for _ in catalogs: + pass + + started = False + async for event in announcements: + if isinstance(event, moq.AnnounceEventRestart) and event.announce.prefix == broadcast: + raise RuntimeError("broadcast restarted during finish") + if isinstance(event, moq.AnnounceEventStart) and event.announce.prefix == broadcast: + started = True + if isinstance(event, moq.AnnounceEventEnd) and event.announce.prefix == broadcast: + if not started: + raise RuntimeError("broadcast ended without announcement") + break + else: + raise RuntimeError("announcement stream ended before broadcast END") + + async with client.announced_broadcast(f"{broadcast}.health") as announced_health: + health = await announced_health + async with await health.subscribe_track("live") as live: + seen = False + async for group in live: + async with group: + async for frame in group: + if seen or frame.payload != b"session-alive": + raise RuntimeError("unexpected session health payload") + seen = True + if not seen: + raise RuntimeError("missing session health payload") + if client.session is None or client.session.connects() != 1: + raise RuntimeError("subscriber reconnected during finish") + print(f"finish clean frames={frames} catalog=eof announce=end health=ok", flush=True) + + +async def subscribe( + url: str, broadcast: str, version: str | None, grant: bool, timeout: float, finish: bool, frames: int +) -> None: async with _client(url, version) as client: if grant: await _print_grant(client, timeout) + if finish: + print("finish reader ready", flush=True) + command = await asyncio.wait_for(asyncio.to_thread(sys.stdin.readline), timeout) + if command != "read\n": + raise RuntimeError("expected finish read command") + await asyncio.wait_for(_finish_subscribe(client, broadcast, frames), timeout) + return consumer = await asyncio.wait_for(client.announced_broadcast(broadcast), timeout) catalog = await asyncio.wait_for(_catalog_with_video(consumer), timeout) @@ -173,15 +266,22 @@ def main() -> None: parser.add_argument("--timeout", type=float, default=20.0) parser.add_argument("--version") parser.add_argument("--grant", action="store_true") + parser.add_argument("--finish-ack", help="publisher completion FIFO; enables clean finish") + parser.add_argument("--finish", action="store_true", help="verify a late tail and clean broadcast end") + parser.add_argument("--frames", type=int, default=10, help="expected finish video frame count") args = parser.parse_args() + if args.frames <= 0 or (args.finish and args.role != "subscribe") or (args.finish_ack and args.role != "publish"): + parser.error("finish requires a subscriber, finish-ack a publisher, and frames must be positive") # Warnings and errors from the Rust layer, such as a publication outside the grant. moq.log_level("warn") try: if args.role == "publish": - asyncio.run(publish(args.url, args.broadcast, args.version, args.grant, args.timeout)) + asyncio.run(publish(args.url, args.broadcast, args.version, args.grant, args.timeout, args.finish_ack)) else: - asyncio.run(subscribe(args.url, args.broadcast, args.version, args.grant, args.timeout)) + asyncio.run( + subscribe(args.url, args.broadcast, args.version, args.grant, args.timeout, args.finish, args.frames) + ) except KeyboardInterrupt: pass except (TimeoutError, asyncio.TimeoutError): From bc450717b490368785b96c159142a737d00b6232 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 06:18:22 -0700 Subject: [PATCH 4/8] test(interop): exercise finite media finish across existing clients Co-Authored-By: GPT-6 --- quest/m1/interop-finish.md | 22 +++ rs/moq-cli/Cargo.toml | 4 + test/interop/README.md | 20 +++ test/interop/clients/cpp/main.cpp | 99 +++++++++-- test/interop/clients/js-native/finish.ts | 96 +++++++++++ test/interop/clients/js-native/subscribe.ts | 19 ++- test/interop/clients/js/driver.ts | 61 ++++++- test/interop/clients/js/src/finish.ts | 151 +++++++++++++++++ test/interop/clients/js/src/setup.ts | 5 +- test/interop/clients/rust/finish.rs | 176 ++++++++++++++++++++ test/interop/interop.sh | 164 +++++++++++++++++- 11 files changed, 795 insertions(+), 22 deletions(-) create mode 100644 test/interop/clients/js-native/finish.ts create mode 100644 test/interop/clients/js/src/finish.ts create mode 100644 test/interop/clients/rust/finish.rs diff --git a/quest/m1/interop-finish.md b/quest/m1/interop-finish.md index d10b4c092b9..0a222cb14b3 100644 --- a/quest/m1/interop-finish.md +++ b/quest/m1/interop-finish.md @@ -17,3 +17,25 @@ the late tail arrives and the end is clean. The new case's cells show up in the nightly report at . Public API: none. Wire: none. + +## Progress + +The candidate in [moq-dev/moq#6307](https://github.com/moq-dev/moq/pull/6307) +adds finish-only modes to the existing Rust, browser, native JS, C, C++, Go, +and Python clients and `case=finish` cells in the existing nightly runner. +Preconnected readers begin media demand only after publication is finished; +ten nonempty frames, natural media/catalog EOF, exact announcement END, and a +new untimed health track on the same session are required. The publisher waits +its actual finish linger before health; a separate FIFO only releases teardown. + +## Decisions needed + +The goal includes GStreamer subscribers, whose current documented policy holds +pads across whole-broadcast finish/withdrawal for a later route. Its public +`moqsrc` interface does not expose the connection, natural media/catalog EOF, +or announcement END. Track errors also do not produce a distinct downstream +terminal event. The runner leaves those finish cells red rather than claiming +cancellation, a second health connection, or synthetic EOS proves the goal. +Choose explicit lifecycle observability while preserving persistent watch +(recommended), or a separately selected finite-watch policy. This needs a +maintainer API/behavior decision before completing the quest. diff --git a/rs/moq-cli/Cargo.toml b/rs/moq-cli/Cargo.toml index 2970c6dec35..bb9cfb7e6d5 100644 --- a/rs/moq-cli/Cargo.toml +++ b/rs/moq-cli/Cargo.toml @@ -176,3 +176,7 @@ harness = false [[example]] name = "interop-tail" path = "../../test/interop/clients/rust/tail.rs" + +[[example]] +name = "interop-finish" +path = "../../test/interop/clients/rust/finish.rs" diff --git a/test/interop/README.md b/test/interop/README.md index f53383f9c0b..0b568426122 100644 --- a/test/interop/README.md +++ b/test/interop/README.md @@ -31,6 +31,26 @@ shutdown. No sleep stands in for drain completion. A missing group, error, or stall fails the lane; the timeout only bounds failure. QUIC on localhost rarely reorders, so the ordering race remains covered by transport unit tests. +The in-tree matrix also has a `finish` case. `just test interop --finish --all` +runs it alone. Readers establish their sessions first, then wait on a private +stdin barrier without subscribing to media. Each publisher imports ten nonempty +H.264 frames in one GOP (the browser encodes the same finite fixture), finishes +all media and its catalog, and obtains the normal broadcast finish handle. Only +then does the runner release readers. They require all ten frames, natural media +and catalog EOF, and the exact broadcast's announcement END. After the finish +handle's real linger expires, the publisher announces a separate untimed health +track. Reading its payload and clean EOF on the original session proves that +withdrawal was not a transport shutdown. The final FIFO acknowledgement permits +teardown only; it never ends the linger. These cells use the existing nightly +report records. + +GStreamer's persistent-watch policy keeps pads when a whole broadcast finishes. +Its external client currently cannot distinguish clean media/catalog EOF from a +track error, observe withdrawal, or read health through the same session. The +finish row reports that subscriber as a failure with an explicit diagnostic; +it does not substitute cancellation, a second connection, or artificial EOS. +The lifecycle observability decision remains in `quest/m1/interop-finish.md`. + Every client closes its session on the way out: publishers stop when their input ends (the browser on SIGTERM), and subscribers close once they have their frame. After each publisher's round, the harness waits for the relay to log the close of diff --git a/test/interop/clients/cpp/main.cpp b/test/interop/clients/cpp/main.cpp index 8343138ebc9..38ac7a01591 100644 --- a/test/interop/clients/cpp/main.cpp +++ b/test/interop/clients/cpp/main.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -170,7 +172,7 @@ void publish_tone(const std::shared_ptr &audio, const std::a } } -int publish(const std::string &url, const std::string &path, const Dial &dial) { +int publish(const std::string &url, const std::string &path, const Dial &dial, const std::string &finish_ack) { // No deadline to publish: the harness stops the publisher when the round ends. const auto forever = Clock::now() + std::chrono::hours(24); auto session = connect(url, dial, forever); @@ -218,27 +220,61 @@ int publish(const std::string &url, const std::string &path, const Dial &dial) { tone.join(); ok(audio->finish(), "audio finish"); ok(media->finish(), "video finish"); - ok(broadcast->close(), "broadcast close"); + if (!finish_ack.empty()) { + auto finish = ok(broadcast->finish(), "broadcast finish"); + std::printf("finish ready linger_us=%llu\n", static_cast(finish->linger_us())); + std::fflush(stdout); + ok(finish->wait().get(), "finish linger"); + std::puts("finish ended"); + std::fflush(stdout); + auto health = ok(session->publish()->create_broadcast(path + ".health"), "health broadcast"); + auto track = ok(health->publish_track("live", std::nullopt), "health track"); + const std::string payload = "session-alive"; + ok(track->write_frame({std::vector(payload.begin(), payload.end()), std::nullopt}), "health write"); + ok(track->finish(), "health finish"); + ok(health->announce({}), "health announce"); + // Only teardown waits on the FIFO; linger has already completed on its own clock. + std::ifstream ack(finish_ack); + std::string line; + if (!std::getline(ack, line) || line != "complete" || session->connects() != 1) { + fail("finish acknowledgement or session continuity failed"); + } + ok(health->close(), "health close"); + std::puts("finish acknowledged"); + } else { + ok(broadcast->close(), "broadcast close"); + } close_session(session); moq::shutdown(); return 0; } -int subscribe(const std::string &url, const std::string &path, const Dial &dial, double timeout) { +int subscribe(const std::string &url, const std::string &path, const Dial &dial, double timeout, bool finish, size_t expected_frames) { const auto deadline = Clock::now() + std::chrono::duration_cast(std::chrono::duration(timeout)); auto session = connect(url, dial, deadline); + std::shared_ptr routes; + if (finish) { + std::puts("finish reader ready"); + std::fflush(stdout); + std::string line; + if (!std::getline(std::cin, line) || line != "read") fail("finish read phase was not released"); + routes = ok(session->consume()->announced({}), "finish announcements"); + } + const auto read_deadline = finish + ? Clock::now() + std::chrono::duration_cast(std::chrono::duration(timeout)) + : deadline; auto announced = ok(session->consume()->announced_broadcast(path), "announced_broadcast"); - auto consumer = until(announced->available(), deadline, "available"); + auto consumer = until(announced->available(), read_deadline, "available"); // The catalog is a live track. A lazy publisher (e.g. the browser, which only encodes on // demand) may announce video in a later update rather than the first snapshot, so wait // for a catalog that actually has a video track. - auto catalogs = until(moq::MediaCatalogConsumer::subscribe(consumer), deadline, "catalog consumer"); + auto catalogs = until(moq::MediaCatalogConsumer::subscribe(consumer), read_deadline, "catalog consumer"); std::optional catalog; while (!catalog || catalog->video.empty()) { - catalog = until(catalogs->next(), deadline, "catalog"); + catalog = until(catalogs->next(), read_deadline, "catalog"); if (!catalog) { fail("catalog stream ended without a video track"); } @@ -246,24 +282,49 @@ int subscribe(const std::string &url, const std::string &path, const Dial &dial, const auto &[id, video] = *catalog->video.begin(); moq::Subscription subscription; - subscription.max_delay_us = MAX_DELAY_US; + subscription.max_delay_us = finish ? static_cast(timeout * 1e6) : MAX_DELAY_US; auto media = until( - moq::MediaTrackConsumer::subscribe(consumer, {moq::Rendition::kVideo{id, video}, subscription}), deadline, + moq::MediaTrackConsumer::subscribe(consumer, {moq::Rendition::kVideo{id, video}, subscription}), read_deadline, "container consumer" ); - size_t total = 0; - while (total == 0) { - auto frame = until(media->next(), deadline, "next frame"); + size_t total = 0, frames = 0; + while (finish || total == 0) { + auto frame = until(media->next(), read_deadline, "next frame"); if (!frame) { break; } total += frame->payload.size(); + if (!frame->payload.empty()) ++frames; } if (total == 0) { fail("no frame data received"); } std::printf("received %zu bytes from \"%s\"\n", total, path.c_str()); + if (finish) { + if (frames != expected_frames) fail("wrong finished media frame count"); + while (until(catalogs->next(), read_deadline, "catalog EOF")) {} + for (;;) { + auto event = until(routes->next(), read_deadline, "announcement END"); + if (!event) fail("origin ended before broadcast withdrawal"); + const auto *end = std::get_if(&event->get_variant()); + if (end && end->announce.prefix == path) break; + } + auto watch = ok(session->consume()->announced_broadcast(path + ".health"), "health watch"); + auto health = until(watch->available(), read_deadline, "health available"); + auto track = until(health->subscribe_track("live", std::nullopt), read_deadline, "health subscribe"); + auto group = until(track->next_group(), read_deadline, "health group"); + if (!group) fail("missing health group"); + auto frame = until(group->read_frame(), read_deadline, "health frame"); + if (!frame || std::string(frame->payload.begin(), frame->payload.end()) != "session-alive" || frame->timestamp_us) { + fail("health payload or timestamp"); + } + if (until(group->read_frame(), read_deadline, "health group EOF") || + until(track->next_group(), read_deadline, "health track EOF") || session->connects() != 1) { + fail("health EOF or session continuity"); + } + std::printf("finish clean frames=%zu catalog=eof announce=end health=ok\n", frames); + } close_session(session); moq::shutdown(); return 0; @@ -279,9 +340,16 @@ int main(int argc, char **argv) { std::string url; std::string broadcast; Dial dial; + bool finish = false; + std::string finish_ack; + size_t frames = 10; double timeout = 20; for (int i = 2; i < argc; i++) { const std::string flag = argv[i]; + if (flag == "--finish") { + finish = true; + continue; + } if (flag == "--grant") { dial.grant = true; continue; @@ -296,6 +364,11 @@ int main(int argc, char **argv) { broadcast = value; } else if (flag == "--timeout") { timeout = std::atof(value.c_str()); + } else if (flag == "--finish-ack") { + finish_ack = value; + } else if (flag == "--frames") { + frames = std::strtoull(value.c_str(), nullptr, 10); + if (frames == 0) fail("frames must be positive"); } else if (flag == "--version") { dial.version = value; } else { @@ -309,10 +382,10 @@ int main(int argc, char **argv) { ok(moq::moq_log_level("warn"), "log level"); if (role == "publish") { - return publish(url, broadcast, dial); + return publish(url, broadcast, dial, finish_ack); } if (role == "subscribe") { - return subscribe(url, broadcast, dial, timeout); + return subscribe(url, broadcast, dial, timeout, finish, frames); } fail(("unknown role " + role).c_str()); } diff --git a/test/interop/clients/js-native/finish.ts b/test/interop/clients/js-native/finish.ts new file mode 100644 index 00000000000..9410e834946 --- /dev/null +++ b/test/interop/clients/js-native/finish.ts @@ -0,0 +1,96 @@ +/** Shared finish assertions for native JS and the existing browser client. @module */ +import type { Milli } from "@moq/clock"; +import * as Catalog from "@moq/hang/catalog"; +import * as Container from "@moq/hang/container"; +import * as Moq from "@moq/net"; + +/** Drain a finished media tail, then prove the same one-shot session can still receive. */ +export async function readFinish( + origin: Moq.Origin.Producer, + path: string, + frames: number, + maxDelay: Milli, +): Promise { + const source = origin.consume(); + const routes = source.announced(); + const request = origin.request(Moq.Path.from(path), { announced: true }); + const healthRequest = origin.request(Moq.Path.from(`${path}.health`), { announced: true }); + try { + let broadcast = request.active.peek(); + while (!broadcast) { + await request.active.changed(); + broadcast = request.active.peek(); + } + const catalogs = Catalog.watch(broadcast)[Symbol.asyncIterator](); + try { + let catalog = await catalogs.next(); + while (!catalog.done && !Object.keys(catalog.value.video?.renditions ?? {}).length) + catalog = await catalogs.next(); + if (catalog.done) throw new Error("finished catalog had no video"); + const [name, config] = Object.entries(catalog.value.video?.renditions ?? {})[0]; + const format = + config.container.kind === "legacy" + ? new Container.Legacy.Format(config) + : config.container.kind === "loc" + ? new Container.Loc.Format("video") + : undefined; + if (!format) throw new Error("unsupported finish media container"); + const subscription = broadcast + .track(Catalog.track(name, config)) + .subscribe({ maxDelay, groups: { start: { included: 0 } } }); + const media = new Container.Consumer(subscription, { format, maxDelay }); + let count = 0; + try { + for (;;) { + const item = await media.next(); + if (!item) break; + if (item.kind === "gap") throw new Error("gap in finished tail"); + if (item.kind === "frame" && item.frame.payload.byteLength) count++; + } + if ((await subscription.closed) !== null) throw new Error("media did not end cleanly"); + if (count !== frames) throw new Error(`wrong finished tail: ${count} frames, expected ${frames}`); + } finally { + media.close(); + } + while (!(await catalogs.next()).done) {} + for (;;) { + const event = await routes.next(); + if (!event) throw new Error("origin ended before broadcast withdrawal"); + if (event.kind === "end" && event.prefix === path) break; + } + let health = healthRequest.active.peek(); + while (!health) { + await healthRequest.active.changed(); + health = healthRequest.active.peek(); + } + const track = health.track("live").subscribe(); + try { + const group = await track.recvGroup(); + if (!group) throw new Error("no health group"); + try { + const frame = await group.readFrame(); + if ( + !frame || + new TextDecoder().decode(frame.payload) !== "session-alive" || + frame.timestamp !== undefined + ) + throw new Error("health frame"); + if ((await group.readFrame()) !== undefined || (await track.recvGroup()) !== undefined) + throw new Error("health EOF"); + } finally { + group.close(); + } + if ((await track.closed) !== null) throw new Error("health did not end cleanly"); + } finally { + track.close(); + } + return `finish clean frames=${count} catalog=eof announce=end health=ok`; + } finally { + await catalogs.return?.(); + } + } finally { + routes.close(); + request.close(); + healthRequest.close(); + } +} diff --git a/test/interop/clients/js-native/subscribe.ts b/test/interop/clients/js-native/subscribe.ts index b06b151c77e..8955e468ab1 100644 --- a/test/interop/clients/js-native/subscribe.ts +++ b/test/interop/clients/js-native/subscribe.ts @@ -15,6 +15,7 @@ * * @module */ +import { createInterface } from "node:readline/promises"; import { parseArgs } from "node:util"; import { Milli } from "@moq/clock"; import * as Catalog from "@moq/hang/catalog"; @@ -22,6 +23,7 @@ import * as Container from "@moq/hang/container"; import * as Json from "@moq/json"; import * as Moq from "@moq/net"; import { install } from "@moq/web-transport"; +import { readFinish } from "./finish"; // globalThis.WebTransport = the polyfill (no-op if a native one already exists). // @moq/net's connect() reads globalThis.WebTransport at call time, so this just @@ -41,12 +43,16 @@ const { positionals, values } = parseArgs({ broadcast: { type: "string" }, timeout: { type: "string", default: "20" }, version: { type: "string" }, + finish: { type: "boolean", default: false }, + frames: { type: "string", default: "10" }, }, }); const role = positionals[0]; const url = values.url; const broadcast = values.broadcast; +const frames = Number(values.frames); +if (!Number.isSafeInteger(frames) || frames <= 0) throw new Error("frames must be a positive integer"); const timeoutMs = Number.parseFloat(values.timeout ?? "20") * 1000; if (role !== "subscribe" || !url || !broadcast || !Number.isFinite(timeoutMs) || timeoutMs <= 0) { console.error("usage: subscribe.ts subscribe --url U --broadcast B [--timeout S>0] [--version V]"); @@ -87,6 +93,17 @@ async function run(): Promise { const unwatch = connection.auth.grant.subscribe(printGrant); let requested: Moq.Origin.Requesting | undefined; try { + if (values.finish) { + console.error("finish reader ready"); + const input = createInterface({ input: process.stdin }); + try { + if ((await input.question("")) !== "read") throw new Error("expected finish read release"); + } finally { + input.close(); + } + console.error(await readFinish(origin, broadcast as string, frames, Milli(timeoutMs))); + return; + } const path = Moq.Path.from(broadcast as string); requested = origin.request(path, { announced: true }); let bc = requested.active.peek(); @@ -137,7 +154,7 @@ async function run(): Promise { } const timeout = new Promise((_, reject) => - setTimeout(() => reject(new Error("timed out waiting for data")), timeoutMs), + setTimeout(() => reject(new Error("timed out waiting for data")), timeoutMs * (values.finish ? 2 : 1)), ); try { diff --git a/test/interop/clients/js/driver.ts b/test/interop/clients/js/driver.ts index b2f2030d690..4d3beeb2a70 100644 --- a/test/interop/clients/js/driver.ts +++ b/test/interop/clients/js/driver.ts @@ -14,6 +14,8 @@ * * @module */ +import { createReadStream } from "node:fs"; +import { createInterface } from "node:readline/promises"; import { parseArgs } from "node:util"; import type { Page } from "playwright"; import { @@ -57,6 +59,9 @@ const { positionals, values } = parseArgs({ url: { type: "string" }, broadcast: { type: "string" }, version: { type: "string" }, + finish: { type: "boolean", default: false }, + "finish-ack": { type: "string" }, + frames: { type: "string", default: "10" }, timeout: { type: "string", default: "20" }, "expect-audio": { type: "boolean", default: false }, }, @@ -66,6 +71,7 @@ const role = positionals[0]; const url = values.url; const broadcast = values.broadcast; const timeoutMs = Number.parseFloat(values.timeout ?? "20") * 1000; +const finishing = values.finish || values["finish-ack"] !== undefined; const expectAudio = values["expect-audio"] ?? false; if ( (role !== "publish" && role !== "subscribe") || @@ -113,13 +119,61 @@ let code = 1; try { const [page, errors] = await open( browser, - pageUrl(server.origin, role, { url, broadcast, ...(values.version ? { versions: values.version } : {}) }), + pageUrl(server.origin, finishing ? `finish-${role}` : role, { + url, + broadcast, + frames: values.frames ?? "10", + timeout: String(timeoutMs), + ...(values.version ? { versions: values.version } : {}), + }), role, role === "subscribe", ); - if (role === "subscribe") await waitForWatch(page); + if (!finishing && role === "subscribe") await waitForWatch(page); - if (role === "publish") { + if (finishing) { + const wait = async (field: "ready" | "ended" | "result") => { + const deadline = Date.now() + timeoutMs; + while (Date.now() < deadline) { + throwPageErrors(errors); + const state = await page.evaluate(() => { + const s = window.interopFinish; + return ( + s && { ready: s.ready, ended: s.ended, result: s.result, error: s.error, lingerUs: s.lingerUs } + ); + }); + if (state?.error) throw new Error(state.error); + if (state?.[field]) return state; + await sleep(POLL_INTERVAL_MS); + } + throw new Error(`finish ${field} timed out`); + }; + const ready = await wait("ready"); + if (role === "subscribe") { + console.error("finish reader ready"); + const input = createInterface({ input: process.stdin }); + try { + if ((await input.question("")) !== "read") throw new Error("expected finish read release"); + } finally { + input.close(); + } + await page.evaluate(() => window.interopFinish?.read()); + } else { + console.error(`finish ready linger_us=${ready.lingerUs}`); + await wait("ended"); + console.error("finish ended"); + const input = createInterface({ input: createReadStream(values["finish-ack"] as string) }); + try { + if ((await input[Symbol.asyncIterator]().next()).value !== "complete") + throw new Error("expected finish acknowledgement"); + } finally { + input.close(); + } + await page.evaluate(() => window.interopFinish?.acknowledge()); + } + console.error((await wait("result")).result); + code = 0; + } else if (role === "publish") { console.error(`publishing ${broadcast} (fake camera + microphone) to ${url}`); // Stream until the orchestrator stops us. await new Promise((resolve) => process.once("SIGTERM", resolve)); @@ -197,6 +251,7 @@ try { // Close every session before the browser: closing it, or even the page, can end them without // a close, leaving the relay to time them out. for (const page of browser.contexts().flatMap((context) => context.pages())) { + await page.evaluate(() => window.interopFinish?.close()).catch(() => {}); await closeSessions(page); await page.close().catch(() => {}); } diff --git a/test/interop/clients/js/src/finish.ts b/test/interop/clients/js/src/finish.ts new file mode 100644 index 00000000000..e56f97ff7a3 --- /dev/null +++ b/test/interop/clients/js/src/finish.ts @@ -0,0 +1,151 @@ +// Finite media fixture and finish observations for the existing browser client. +import { Micro, Milli } from "@moq/clock"; +import * as Catalog from "@moq/hang/catalog"; +import * as Container from "@moq/hang/container"; +import * as Moq from "@moq/net"; +import { CatalogProducer } from "@moq/publish"; +import { Effect } from "@moq/signals"; +import { readFinish } from "../../js-native/finish"; + +interface State { + ready: boolean; + ended: boolean; + lingerUs?: number; + result?: string; + error?: string; + read(): void; + acknowledge(): void; + close(): void; +} + +declare global { + interface Window { + interopFinish?: State; + } +} + +export function finish( + role: string, + url: string, + path: string, + version: string | null, + frames: number, + timeout: number, +): void { + let releaseRead = () => {}; + let releaseAck = () => {}; + const read = new Promise((resolve) => { + releaseRead = resolve; + }); + const ack = new Promise((resolve) => { + releaseAck = resolve; + }); + const origin = new Moq.Origin.Producer(); + let connection: Moq.Connection.Established | undefined; + const state: State = { + ready: false, + ended: false, + read: () => releaseRead(), + acknowledge: () => releaseAck(), + close: () => { + connection?.close(); + origin.close(); + }, + }; + window.interopFinish = state; + void (async () => { + connection = await Moq.Connection.connect({ + url: new URL(url), + consume: origin, + publish: origin.consume(), + websocket: { enabled: false }, + ...(version ? { versions: [version] } : {}), + }); + if (role === "finish-subscribe") { + state.ready = true; + await read; + state.result = await readFinish(origin, path, frames, Milli(timeout)); + return; + } + const broadcast = origin.createBroadcast(Moq.Path.from(path)); + const config: Catalog.VideoConfig = { + codec: "avc1.42001e", + codedWidth: Catalog.u53(320), + codedHeight: Catalog.u53(240), + container: { kind: "legacy" }, + }; + const track = broadcast.createTrack("video", { + timescale: Moq.Time.Timescale.MICRO, + maxAge: Milli(Number.MAX_SAFE_INTEGER), + priority: Catalog.PRIORITY.video, + }); + const media = new Container.Legacy.Producer(track, new Container.Legacy.Format(config)); + let encodingError: Error | undefined; + const encoder = new VideoEncoder({ + output: (chunk) => media.encode(chunk, Micro(chunk.timestamp), chunk.type === "key"), + error: (error) => { + encodingError = error; + }, + }); + try { + encoder.configure({ + codec: config.codec, + width: 320, + height: 240, + bitrate: 300_000, + framerate: 30, + avc: { format: "annexb" }, + }); + const canvas = new OffscreenCanvas(320, 240); + const context = canvas.getContext("2d"); + if (!context) throw new Error("no fixture canvas"); + for (let index = 0; index < frames; index++) { + context.fillStyle = `rgb(${index * 20},80,160)`; + context.fillRect(0, 0, 320, 240); + const frame = new VideoFrame(canvas, { timestamp: Math.round((index * 1_000_000) / 30) }); + try { + encoder.encode(frame, { keyFrame: index === 0 }); + } finally { + frame.close(); + } + } + await encoder.flush(); + if (encodingError) throw encodingError; + } finally { + encoder.close(); + } + media.close(); + const catalog = new CatalogProducer(); + catalog.mutate((root) => { + root.video = { renditions: { video: config } }; + }); + const serving = new Effect(); + catalog.serve( + broadcast.createTrack(Catalog.TRACK, { + timescale: Moq.Time.Timescale.MILLI, + maxAge: Milli(Number.MAX_SAFE_INTEGER), + priority: Catalog.PRIORITY.catalog, + }), + serving, + ); + serving.close(); + broadcast.announce(); + const finishing = broadcast.finish(); + state.lingerUs = finishing.linger * 1000; + state.ready = true; + await finishing.wait(); + const health = origin.createBroadcast(Moq.Path.from(`${path}.health`)); + const healthTrack = health.createTrack("live"); + const group = healthTrack.appendGroup(); + group.writeFrame({ payload: new TextEncoder().encode("session-alive") }); + group.close(); + healthTrack.close(); + health.announce(); + state.ended = true; + await ack; + health.close(); + state.result = "finish acknowledged"; + })().catch((error) => { + state.error = error instanceof Error ? error.message : String(error); + }); +} diff --git a/test/interop/clients/js/src/setup.ts b/test/interop/clients/js/src/setup.ts index b01321c739f..ba3926c0db6 100644 --- a/test/interop/clients/js/src/setup.ts +++ b/test/interop/clients/js/src/setup.ts @@ -6,6 +6,7 @@ import type MoqPublish from "@moq/publish/element"; import type MoqWatch from "@moq/watch/element"; import { refused, refusedWebSocket } from "./close"; import { type CaptureState, FAULTS, type Fault, publish, SAMPLE_MS } from "./contract"; +import { finish } from "./finish"; import { Fixture } from "./fixture"; import { attach, watchResources } from "./probe"; @@ -23,7 +24,9 @@ function parseFault(value: string | null): Fault { return fault; } -if (role === "publish") { +if (role === "finish-publish" || role === "finish-subscribe") { + finish(role, url, broadcast, versions, Number(params.get("frames") ?? 10), Number(params.get("timeout") ?? 60_000)); +} else if (role === "publish") { const el = document.createElement("moq-publish") as MoqPublish; el.setAttribute("url", url); if (versions) el.setAttribute("versions", versions); diff --git a/test/interop/clients/rust/finish.rs b/test/interop/clients/rust/finish.rs new file mode 100644 index 00000000000..a91134b18ad --- /dev/null +++ b/test/interop/clients/rust/finish.rs @@ -0,0 +1,176 @@ +//! Finite media finish case in the existing interop runner. +use std::path::PathBuf; +use std::time::Duration; + +use anyhow::{Context, ensure}; +use moq_mux::catalog::Stream; +use moq_tokio::moq_net; +use tokio::io::{AsyncBufReadExt, AsyncReadExt}; + +struct Args { + role: String, + url: url::Url, + broadcast: String, + version: Option, + timeout: u64, + frames: usize, + finish: bool, + finish_ack: Option, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let mut input = std::env::args().skip(1); + let role = input.next().context("missing role")?; + let mut options = std::collections::HashMap::new(); + let mut finish = false; + while let Some(flag) = input.next() { + if flag == "--finish" { + finish = true; + continue; + } + ensure!( + [ + "--url", + "--broadcast", + "--version", + "--timeout", + "--frames", + "--finish-ack" + ] + .contains(&flag.as_str()), + "unknown flag: {flag}" + ); + options.insert(flag, input.next().context("missing flag value")?); + } + let args = Args { + role, + finish, + url: options.remove("--url").context("missing --url")?.parse()?, + broadcast: options.remove("--broadcast").context("missing --broadcast")?, + version: options.remove("--version"), + timeout: options.remove("--timeout").unwrap_or_else(|| "60".into()).parse()?, + frames: options.remove("--frames").unwrap_or_else(|| "10".into()).parse()?, + finish_ack: options.remove("--finish-ack").map(PathBuf::from), + }; + let mut config = moq_tokio::connect::Config::default(); + if let Some(version) = &args.version { + config.version.push(version.parse().map_err(anyhow::Error::msg)?); + } + config.websocket.enabled = Some(false); + let client = config.init(Default::default())?.with_reconnect(false); + let origin = moq_tokio::origin::spawn(); + let consumer = origin.consume(); + let session = client + .clone() + .with_publisher(&origin) + .with_subscriber(origin.clone()) + .connect(args.url) + .established() + .await?; + let mut stdin = tokio::io::BufReader::new(tokio::io::stdin()); + if args.role == "publish" { + let mut broadcast = origin.create_broadcast(&args.broadcast)?; + let mut catalog = moq_mux::catalog::Producer::<()>::new(&mut broadcast, Default::default())?; + let mut media = moq_mux::import::TrackStream::video( + broadcast.reserve_track("video")?, + catalog.reserve(), + moq_mux::import::VideoInit::new(moq_mux::import::VideoFormat::Avc3, Vec::new()), + )?; + let mut data = Vec::new(); + stdin.read_to_end(&mut data).await?; + media.decode(&data)?; + media.finish()?; + catalog.finish()?; + broadcast.announce(Default::default())?; + let finish = broadcast.finish(); + println!("finish ready linger_us={}", finish.linger().as_micros()); + finish.wait().await; + println!("finish ended"); + let health = origin.create_broadcast(format!("{}.health", args.broadcast))?; + let mut track = health.create_track("live", moq_net::track::Info::default())?; + track.write_frame(None, b"session-alive".to_vec())?; + track.finish()?; + health.announce(Default::default())?; + let ack = args.finish_ack.context("publisher needs --finish-ack")?; + let mut complete = String::new(); + tokio::io::BufReader::new(tokio::fs::File::open(ack).await?) + .read_line(&mut complete) + .await?; + ensure!(complete == "complete\n", "finish acknowledgement was not complete"); + health.close(); + println!("finish acknowledged"); + } else { + ensure!(args.role == "subscribe" && args.finish, "expected finish subscriber"); + println!("finish reader ready"); + let mut command = String::new(); + stdin.read_line(&mut command).await?; + ensure!(command == "read\n", "finish read phase was not released"); + tokio::time::timeout(Duration::from_secs(args.timeout), async { + let mut routes = consumer.announced(); + let broadcast = consumer.routed_broadcast(&args.broadcast).await?; + let mut catalogs = + moq_mux::catalog::Consumer::<()>::new(&broadcast, moq_mux::catalog::CatalogFormat::Hang).await?; + let catalog = loop { + let catalog = catalogs.next().await?.context("finished catalog had no video")?; + if !catalog.video.renditions.is_empty() { + break catalog; + } + }; + let (name, config) = catalog.video.renditions.iter().next().context("no video")?; + let track = broadcast + .track(name)? + .subscribe(Some( + moq_net::track::Subscription::default() + .with_max_delay(Duration::from_secs(args.timeout)) + .with_groups(0..), + )) + .await?; + let format = moq_mux::catalog::hang::Container::try_from(config)?; + let mut media = moq_mux::container::Consumer::new(track, format); + let mut count = 0; + while let Some(item) = media.read().await? { + match item { + moq_mux::container::Read::Frame { frame, .. } => { + if !frame.payload.is_empty() { + count += 1; + } + } + moq_mux::container::Read::Gap { .. } => anyhow::bail!("gap in finished tail"), + moq_mux::container::Read::End { .. } => {} + } + } + ensure!(count == args.frames, "wrong finished tail: {count} frames"); + while catalogs.next().await?.is_some() {} + loop { + let event = routes + .next() + .await + .context("origin ended before broadcast withdrawal")?; + if let moq_net::announce::Event::End(announce) = event { + if announce.prefix.as_str() == args.broadcast { + break; + } + } + } + let health = consumer.routed_broadcast(format!("{}.health", args.broadcast)).await?; + let mut track = health.track("live")?.subscribe(None).await?; + let mut group = track.recv_group().await?.context("no health group")?; + let frame = group.read_frame().await?.context("no health frame")?; + ensure!( + frame.payload.as_ref() == b"session-alive" && frame.timestamp.is_none(), + "health payload or timestamp" + ); + ensure!( + group.read_frame().await?.is_none() && track.recv_group().await?.is_none(), + "health EOF" + ); + println!("finish clean frames={count} catalog=eof announce=end health=ok"); + Ok::<_, anyhow::Error>(()) + }) + .await??; + } + session.close().await?; + client.close().await; + Ok(()) +} diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 25d2402af71..8c7eae11b50 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -66,6 +66,7 @@ MEDIA=0 MEDIA_CASES="" MEDIA_ENGINES="chromium" TAIL_ONLY=0 +FINISH_ONLY=0 # The versions the matrix runs on, one pass each. `auto` leaves every client its defaults, # except the clients the harness reads a grant from, which offer $AUTH_VERSION alone. Any other # entry pins every client in its pass to that version, and `ietf` expands to IETF_VERSIONS. @@ -111,6 +112,10 @@ while [[ $# -gt 0 ]]; do NEGATIVE=1 shift ;; + --finish) + FINISH_ONLY=1 + shift + ;; --tail) TAIL_ONLY=1 shift @@ -166,6 +171,13 @@ fi exit 2 } +if [[ "$FINISH_ONLY" -eq 1 ]]; then + if [[ "$NEGATIVE" -eq 1 || "$MEDIA" -eq 1 || "$TAIL_ONLY" -eq 1 || "$IN_TREE" -eq 0 ]]; then + echo "error: --finish requires in-tree clients and is separate from --tail, --media, and --negative" >&2 + exit 2 + fi +fi + if [[ "$TAIL_ONLY" -eq 1 ]]; then if [[ "$NEGATIVE" -eq 1 || "$MEDIA" -eq 1 ]]; then echo "error: --tail, --media, and --negative are separate runs" >&2 @@ -351,7 +363,7 @@ plan_cases() { # One version's share of plan_cases. plan_pass() { local pub sub runtime version - if [[ "$TAIL_ONLY" -eq 0 ]]; then + if [[ "$TAIL_ONLY" -eq 0 && "$FINISH_ONLY" -eq 0 ]]; then for pub in "${PUB_LIST[@]}"; do for sub in "${SUB_LIST[@]}"; do record "not run" case=media publisher="$pub" subscriber="$sub"; done [[ "$IN_TREE" -eq 0 ]] || record "not run" case="relay close" publisher="$pub" @@ -366,6 +378,12 @@ plan_pass() { [[ "$VERSION" != auto ]] || ! needs js || record "not run" case="refused session" subscriber=js fi [[ "$IN_TREE" -eq 1 ]] || return 0 + if [[ "$TAIL_ONLY" -eq 0 ]]; then + for pub in "${PUB_LIST[@]}"; do + for sub in "${SUB_LIST[@]}"; do record "not run" case=finish publisher="$pub" subscriber="$sub"; done + done + fi + [[ "$FINISH_ONLY" -eq 0 ]] || return 0 record "not run" case="CLI FETCH" publisher=rust subscriber=rust record "not run" case=tail publisher=rust subscriber=rust for runtime in js-native-node js-native-bun; do @@ -457,7 +475,7 @@ build_relay_cli() { exit 1 } if [[ "$NEGATIVE" -eq 0 && "$MEDIA" -eq 0 ]]; then - (cd "$WORKSPACE" && cargo build --locked ${flag[@]+"${flag[@]}"} -p moq-cli --example interop-tail) + (cd "$WORKSPACE" && cargo build --locked ${flag[@]+"${flag[@]}"} -p moq-cli --example interop-tail --example interop-finish) fi [[ -n "$RELAY" ]] || RELAY="$TARGET_BASE/$PROFILE/moq-relay" # The `moq-cli` crate ships its binary as `moq` (a `[[bin]]` override). @@ -1174,6 +1192,141 @@ run_round() { fi } +# Finish readers connect before publication, but make no media request until finish is fixed. +# shellcheck disable=SC2329 # invoked indirectly via harness_spawn +run_finish_client() { + local lang="$1" role="$2" broadcast="$3" url="$4" ack="${5:-}" version limit read_limit + version=$(cell_version "$lang") + # Setup and the read phase each have a deadline. The latter includes the real media linger. + read_limit=$(awk -v t="$TIMEOUT" 'BEGIN { print t * 2 }') + limit=$(awk -v t="$TIMEOUT" 'BEGIN { print t * 4 }') + local args=("$role" --url "$url" --broadcast "$broadcast" --timeout "$read_limit") + [[ -z "$version" ]] || args+=(--version "$version") + if [[ "$role" == publish ]]; then args+=(--finish-ack "$ack"); else args+=(--finish --frames 10); fi + case "$lang" in + rust) timeout -k 3 "$limit" "$TARGET_BASE/$PROFILE/examples/interop-finish" "${args[@]}" ;; + python) timeout -k 3 "$limit" "$PY" "$CLIENTS/python/interop.py" "${args[@]}" ;; + go) timeout -k 3 "$limit" "$GO_INTEROP" "${args[@]}" ;; + cpp) timeout -k 3 "$limit" "$CPP_INTEROP" "${args[@]}" ;; + c) timeout -k 3 "$limit" "$C_INTEROP" "${args[@]}" ;; + js) (cd "$CLIENTS/js" && timeout -k 3 "$limit" bun driver.ts "${args[@]}") ;; + js-native-node) (cd "$CLIENTS/js-native" && timeout -k 3 "$limit" node --import tsx subscribe.ts "${args[@]}") ;; + js-native-bun) (cd "$CLIENTS/js-native" && timeout -k 3 "$limit" bun subscribe.ts "${args[@]}") ;; + *) + echo "finish assertions unavailable for $lang" >&2 + return 1 + ;; + esac +} + +# shellcheck disable=SC2329 # invoked indirectly via harness_spawn +run_finish_publisher() { + local lang="$1" broadcast="$2" url="$3" ack="$4" + if [[ "$lang" == js ]]; then + run_finish_client "$lang" publish "$broadcast" "$url" "$ack" + else + ffmpeg -hide_banner -loglevel error -f lavfi -i "testsrc2=size=$SIZE:rate=$FPS" \ + -frames:v 10 -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p \ + -g 10 -keyint_min 10 -sc_threshold 0 -f h264 - | run_finish_client "$lang" publish "$broadcast" "$url" "$ack" + fi +} + +finish_ready() { + local pid="$1" log="$2" marker="$3" deadline + deadline=$(awk -v now="$SECONDS" -v t="$TIMEOUT" 'BEGIN { print int(now + t + 1) }') + while ((SECONDS < deadline)); do + grep -q "$marker" "$log" && return 0 + harness_exited "$pid" && return 1 + sleep 0.05 + done + return 1 +} + +# shellcheck disable=SC2329 # invoked indirectly via harness_spawn +run_finish_reader() { + local fifo="$1" + shift + run_finish_client "$@" <"$fifo" +} + +run_finishes() { + local pub sub name broadcast pid ack ack_fd reader_fd i started + for pub in "${PUB_LIST[@]}"; do + name="finish-$pub" + broadcast="$name-$$-$RANDOM.hang" + ack="$LOGS/$name-ack" + local pids=() fds=() names=() all_ready=1 all_clean=1 publisher_ok=1 + started=$SECONDS + echo "=== finished media: $pub ===" + if is_broken "$pub"; then + for sub in "${SUB_LIST[@]}"; do record fail case=finish publisher="$pub" subscriber="$sub" detail="publisher unavailable"; done + overall=1 + continue + fi + mkfifo "$ack" + exec {ack_fd}<>"$ack" + for sub in "${SUB_LIST[@]}"; do + if is_broken "$sub" || [[ "$sub" == gst ]]; then + record fail case=finish publisher="$pub" subscriber="$sub" detail="finish assertions unavailable for $sub" + echo " FAIL finish $pub -> $sub (finish assertions unavailable)" + overall=1 + continue + fi + local fifo="$LOGS/$name-$sub-read" + mkfifo "$fifo" + exec {reader_fd}<>"$fifo" + harness_spawn "$name-$sub" "$LOGS/$name-$sub.log" run_finish_reader "$fifo" "$sub" subscribe "$broadcast" "$(token_url --subscribe "$broadcast*")" + pids+=("$HARNESS_PID") + fds+=("$reader_fd") + names+=("$sub") + done + for i in "${!pids[@]}"; do + if ! finish_ready "${pids[$i]}" "$LOGS/$name-${names[$i]}.log" '^finish reader ready$'; then all_ready=0; fi + done + if [[ "$all_ready" -eq 1 ]]; then + harness_spawn "$name-pub" "$LOGS/$name-pub.log" run_finish_publisher "$pub" "$broadcast" "$(token_url --publish "$broadcast*")" "$ack" + pid="$HARNESS_PID" + if ! finish_ready "$pid" "$LOGS/$name-pub.log" '^finish ready linger_us='; then all_ready=0; fi + else pid=""; fi + if [[ "$all_ready" -eq 1 ]]; then + for reader_fd in "${fds[@]}"; do printf 'read\n' >&"$reader_fd"; done + for i in "${!pids[@]}"; do + harness_wait "${pids[$i]}" || all_clean=0 + if ! grep -qx 'finish clean frames=10 catalog=eof announce=end health=ok' "$LOGS/$name-${names[$i]}.log"; then all_clean=0; fi + done + else all_clean=0; fi + if [[ "$all_clean" -eq 1 ]]; then + printf 'complete\n' >&"$ack_fd" + # FIFO readers use EOF to finish reading the acknowledgement. + exec {ack_fd}>&- + harness_wait "$pid" || publisher_ok=0 + grep -qx 'finish acknowledged' "$LOGS/$name-pub.log" || publisher_ok=0 + else + publisher_ok=0 + [[ -z "$pid" ]] || harness_reap "$pid" + exec {ack_fd}>&- + fi + for i in "${!pids[@]}"; do + sub="${names[$i]}" + local cell=(case=finish publisher="$pub" subscriber="$sub" seconds=$((SECONDS - started)) log="$LOGS/$name-$sub.log") + if [[ "$all_ready" -eq 1 && "$publisher_ok" -eq 1 ]] && grep -qx 'finish clean frames=10 catalog=eof announce=end health=ok' "$LOGS/$name-$sub.log"; then + echo " PASS finish $pub -> $sub (late tail, EOF, END, live session)" + record pass "${cell[@]}" + else + record fail "${cell[@]}" detail="missing finish tail/EOF/withdrawal/health or acknowledgement" + echo " FAIL finish $pub -> $sub" + overall=1 + cat "$LOGS/$name-$sub.log" "$LOGS/$name-pub.log" 2>/dev/null || true + harness_reap "${pids[$i]}" + fi + reader_fd="${fds[$i]}" + exec {reader_fd}>&- + rm "$LOGS/$name-$sub-read" + done + rm "$ack" + done +} + # Raw-track clients have no codecs: every byte, group, and the declared end is checked. # shellcheck disable=SC2329 # invoked indirectly via harness_spawn run_tail_client() { @@ -1531,8 +1684,11 @@ else LOGS="$HARNESS_RUN/$VERSION" mkdir -p "$LOGS" fi - [[ "$TAIL_ONLY" -eq 1 ]] || run_matrix - [[ "$IN_TREE" -eq 0 ]] || run_tails + [[ "$TAIL_ONLY" -eq 1 || "$FINISH_ONLY" -eq 1 ]] || run_matrix + if [[ "$IN_TREE" -eq 1 ]]; then + [[ "$TAIL_ONLY" -eq 1 ]] || run_finishes + [[ "$FINISH_ONLY" -eq 1 ]] || run_tails + fi done fi From 18f7cd85348fbe73fec9bf1677c39b9b34eeb6d6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 06:19:33 -0700 Subject: [PATCH 5/8] test(interop): drain the complete Go session health group Require an untimed health payload, natural group EOF, and then track EOF. Track.ReadFrame only reads the first frame per group, so it cannot establish the group end or reject an extra frame in that group. Go build and vet pass against the current staged bindings without rebuilding FFI. Required just ci remains blocked by the unchanged Manual.advanceAsync type error covered by PR6308. Co-Authored-By: GPT-6 --- test/interop/clients/go/main.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/test/interop/clients/go/main.go b/test/interop/clients/go/main.go index a3aadde1458..3089258a15b 100644 --- a/test/interop/clients/go/main.go +++ b/test/interop/clients/go/main.go @@ -387,19 +387,35 @@ func finishSubscribe(ctx context.Context, client *moq.Client, broadcast string, return err } defer live.Cancel() - frame, err := live.ReadFrame(ctx) + group, err := live.NextGroup(ctx) if err != nil { return err } - if frame == nil || string(frame.Payload) != "session-alive" { - return errors.New("unexpected session health payload") + if group == nil { + return errors.New("missing session health group") } - frame, err = live.ReadFrame(ctx) + defer group.Cancel() + frame, err := group.ReadFrame(ctx) + if err != nil { + return err + } + if frame == nil || string(frame.Payload) != "session-alive" || frame.Timestamp != nil { + return errors.New("unexpected session health payload or timestamp") + } + frame, err = group.ReadFrame(ctx) if err != nil { return err } if frame != nil { - return errors.New("session health track did not end after one frame") + return errors.New("session health group did not end after one frame") + } + next, err := live.NextGroup(ctx) + if err != nil { + return err + } + if next != nil { + next.Cancel() + return errors.New("session health track did not end after one group") } if client.Session().Connects() != 1 { return errors.New("subscriber reconnected during finish") From 2e3981df2cc85ad3b1348964a254e9b7892b3cbd Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 06:20:34 -0700 Subject: [PATCH 6/8] test(interop): require untimed Python session health Match the other finish readers by refusing a timestamp on the raw session health frame. Ruff, formatting and pyright pass; required just ci still stops on the existing Manual.advanceAsync error covered by PR6308. Co-Authored-By: GPT-6 --- test/interop/clients/python/interop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/interop/clients/python/interop.py b/test/interop/clients/python/interop.py index 3c6b50e1e6e..f348ad0f713 100644 --- a/test/interop/clients/python/interop.py +++ b/test/interop/clients/python/interop.py @@ -210,8 +210,8 @@ async def _finish_subscribe(client: moq.Client, broadcast: str, frames: int) -> async for group in live: async with group: async for frame in group: - if seen or frame.payload != b"session-alive": - raise RuntimeError("unexpected session health payload") + if seen or frame.payload != b"session-alive" or frame.timestamp is not None: + raise RuntimeError("unexpected session health payload or timestamp") seen = True if not seen: raise RuntimeError("missing session health payload") From 6830230fac12e87cf3eb42a6dca3d0948d122eda Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 06:40:29 -0700 Subject: [PATCH 7/8] test(interop): require each finish wait to cover its linger Co-Authored-By: GPT-6 --- quest/m1/interop-finish.md | 6 ++++-- test/interop/README.md | 5 ++++- test/interop/clients/cpp/main.cpp | 4 ++++ test/interop/clients/go/main.go | 10 +++++++++- test/interop/clients/js/src/finish.ts | 6 +++++- test/interop/clients/python/interop.py | 9 ++++++++- test/interop/clients/rust/finish.rs | 24 ++++++++++++++++-------- test/interop/interop.sh | 1 - 8 files changed, 50 insertions(+), 15 deletions(-) diff --git a/quest/m1/interop-finish.md b/quest/m1/interop-finish.md index 0a222cb14b3..7127bd0f670 100644 --- a/quest/m1/interop-finish.md +++ b/quest/m1/interop-finish.md @@ -18,7 +18,7 @@ in the nightly report at . Public API: none. Wire: none. -## Progress +**Candidate:** The candidate in [moq-dev/moq#6307](https://github.com/moq-dev/moq/pull/6307) adds finish-only modes to the existing Rust, browser, native JS, C, C++, Go, @@ -27,8 +27,10 @@ Preconnected readers begin media demand only after publication is finished; ten nonempty frames, natural media/catalog EOF, exact announcement END, and a new untimed health track on the same session are required. The publisher waits its actual finish linger before health; a separate FIFO only releases teardown. +Publisher monotonic checks require a nonzero returned linger and a wait at least +that long, measured from before handle creation. -## Decisions needed +**Remaining decision:** The goal includes GStreamer subscribers, whose current documented policy holds pads across whole-broadcast finish/withdrawal for a later route. Its public diff --git a/test/interop/README.md b/test/interop/README.md index 0b568426122..1ab7f083729 100644 --- a/test/interop/README.md +++ b/test/interop/README.md @@ -41,7 +41,10 @@ and catalog EOF, and the exact broadcast's announcement END. After the finish handle's real linger expires, the publisher announces a separate untimed health track. Reading its payload and clean EOF on the original session proves that withdrawal was not a transport shutdown. The final FIFO acknowledgement permits -teardown only; it never ends the linger. These cells use the existing nightly +teardown only; it never ends the linger. Each publisher also measures monotonic +time from before creating its finish handle and refuses a zero linger or a wait +shorter than that handle promises, without a fixed duration or tolerance. +These cells use the existing nightly report records. GStreamer's persistent-watch policy keeps pads when a whole broadcast finishes. diff --git a/test/interop/clients/cpp/main.cpp b/test/interop/clients/cpp/main.cpp index 38ac7a01591..4215bf26702 100644 --- a/test/interop/clients/cpp/main.cpp +++ b/test/interop/clients/cpp/main.cpp @@ -221,10 +221,14 @@ int publish(const std::string &url, const std::string &path, const Dial &dial, c ok(audio->finish(), "audio finish"); ok(media->finish(), "video finish"); if (!finish_ack.empty()) { + const auto started = Clock::now(); auto finish = ok(broadcast->finish(), "broadcast finish"); + const auto linger = std::chrono::microseconds(finish->linger_us()); + if (linger.count() <= 0) fail("finished media has no linger"); std::printf("finish ready linger_us=%llu\n", static_cast(finish->linger_us())); std::fflush(stdout); ok(finish->wait().get(), "finish linger"); + if (Clock::now() - started < linger) fail("finish wait ended before its linger"); std::puts("finish ended"); std::fflush(stdout); auto health = ok(session->publish()->create_broadcast(path + ".health"), "health broadcast"); diff --git a/test/interop/clients/go/main.go b/test/interop/clients/go/main.go index 3089258a15b..4a2fc278267 100644 --- a/test/interop/clients/go/main.go +++ b/test/interop/clients/go/main.go @@ -207,15 +207,23 @@ func publish(ctx context.Context, url, broadcast string, opts dialOptions, timeo return nil } // Finish also finalizes the catalog. ACK never controls the real linger. + started := time.Now() finished, err := producer.Finish() if err != nil { return err } defer finished.Close() - fmt.Printf("finish ready linger_us=%d\n", finished.Linger().Microseconds()) + linger := finished.Linger() + if linger <= 0 { + return errors.New("finished media has no linger") + } + fmt.Printf("finish ready linger_us=%d\n", linger.Microseconds()) if err := finished.Wait(ctx); err != nil { return err } + if time.Since(started) < linger { + return errors.New("finish wait ended before its linger") + } health, err := client.CreateBroadcast(broadcast + ".health") if err != nil { return err diff --git a/test/interop/clients/js/src/finish.ts b/test/interop/clients/js/src/finish.ts index e56f97ff7a3..b80fa18e03a 100644 --- a/test/interop/clients/js/src/finish.ts +++ b/test/interop/clients/js/src/finish.ts @@ -1,5 +1,5 @@ // Finite media fixture and finish observations for the existing browser client. -import { Micro, Milli } from "@moq/clock"; +import { Instant, Micro, Milli, Nano, now } from "@moq/clock"; import * as Catalog from "@moq/hang/catalog"; import * as Container from "@moq/hang/container"; import * as Moq from "@moq/net"; @@ -130,10 +130,14 @@ export function finish( ); serving.close(); broadcast.announce(); + const started = now(); const finishing = broadcast.finish(); + const linger = Nano.fromMilli(finishing.linger); + if (linger <= 0) throw new Error("finished media has no linger"); state.lingerUs = finishing.linger * 1000; state.ready = true; await finishing.wait(); + if (Instant.durationSince(now(), started) < linger) throw new Error("finish wait ended before its linger"); const health = origin.createBroadcast(Moq.Path.from(`${path}.health`)); const healthTrack = health.createTrack("live"); const group = healthTrack.appendGroup(); diff --git a/test/interop/clients/python/interop.py b/test/interop/clients/python/interop.py index f348ad0f713..838fd917e75 100644 --- a/test/interop/clients/python/interop.py +++ b/test/interop/clients/python/interop.py @@ -24,6 +24,7 @@ import math import struct import sys +import time from datetime import timedelta import moq @@ -130,9 +131,15 @@ async def publish( media.finish() if finish_ack is not None: # finish() also finalizes the catalog. ACK never controls the real linger. + started = time.monotonic_ns() finished = producer.finish() - print(f"finish ready linger_us={finished.linger // timedelta(microseconds=1)}", flush=True) + linger_us = finished.linger // timedelta(microseconds=1) + if linger_us <= 0: + raise RuntimeError("finished media has no linger") + print(f"finish ready linger_us={linger_us}", flush=True) await finished.wait() + if time.monotonic_ns() - started < linger_us * 1000: + raise RuntimeError("finish wait ended before its linger") health = client.create_broadcast(f"{broadcast}.health") live = health.publish_track("live") live.write_frame(b"session-alive") diff --git a/test/interop/clients/rust/finish.rs b/test/interop/clients/rust/finish.rs index a91134b18ad..4fdd6b69ff6 100644 --- a/test/interop/clients/rust/finish.rs +++ b/test/interop/clients/rust/finish.rs @@ -12,7 +12,7 @@ struct Args { url: url::Url, broadcast: String, version: Option, - timeout: u64, + timeout: Duration, frames: usize, finish: bool, finish_ack: Option, @@ -49,10 +49,14 @@ async fn main() -> anyhow::Result<()> { url: options.remove("--url").context("missing --url")?.parse()?, broadcast: options.remove("--broadcast").context("missing --broadcast")?, version: options.remove("--version"), - timeout: options.remove("--timeout").unwrap_or_else(|| "60".into()).parse()?, + timeout: Duration::try_from_secs_f64(options.remove("--timeout").unwrap_or_else(|| "60".into()).parse()?)?, frames: options.remove("--frames").unwrap_or_else(|| "10".into()).parse()?, finish_ack: options.remove("--finish-ack").map(PathBuf::from), }; + ensure!( + !args.timeout.is_zero() && args.frames > 0, + "timeout and frames must be positive" + ); let mut config = moq_tokio::connect::Config::default(); if let Some(version) = &args.version { config.version.push(version.parse().map_err(anyhow::Error::msg)?); @@ -83,9 +87,13 @@ async fn main() -> anyhow::Result<()> { media.finish()?; catalog.finish()?; broadcast.announce(Default::default())?; + let started = moq_clock::now(); let finish = broadcast.finish(); + let linger = finish.linger(); + ensure!(!linger.is_zero(), "finished media has no linger"); println!("finish ready linger_us={}", finish.linger().as_micros()); finish.wait().await; + ensure!(started.elapsed() >= linger, "finish wait ended before its linger"); println!("finish ended"); let health = origin.create_broadcast(format!("{}.health", args.broadcast))?; let mut track = health.create_track("live", moq_net::track::Info::default())?; @@ -106,7 +114,7 @@ async fn main() -> anyhow::Result<()> { let mut command = String::new(); stdin.read_line(&mut command).await?; ensure!(command == "read\n", "finish read phase was not released"); - tokio::time::timeout(Duration::from_secs(args.timeout), async { + moq_clock::timeout(args.timeout, async { let mut routes = consumer.announced(); let broadcast = consumer.routed_broadcast(&args.broadcast).await?; let mut catalogs = @@ -122,7 +130,7 @@ async fn main() -> anyhow::Result<()> { .track(name)? .subscribe(Some( moq_net::track::Subscription::default() - .with_max_delay(Duration::from_secs(args.timeout)) + .with_max_delay(args.timeout) .with_groups(0..), )) .await?; @@ -147,10 +155,10 @@ async fn main() -> anyhow::Result<()> { .next() .await .context("origin ended before broadcast withdrawal")?; - if let moq_net::announce::Event::End(announce) = event { - if announce.prefix.as_str() == args.broadcast { - break; - } + if let moq_net::announce::Event::End(announce) = event + && announce.prefix.as_str() == args.broadcast + { + break; } } let health = consumer.routed_broadcast(format!("{}.health", args.broadcast)).await?; diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 8c7eae11b50..4a691553659 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -1297,7 +1297,6 @@ run_finishes() { else all_clean=0; fi if [[ "$all_clean" -eq 1 ]]; then printf 'complete\n' >&"$ack_fd" - # FIFO readers use EOF to finish reading the acknowledgement. exec {ack_fd}>&- harness_wait "$pid" || publisher_ok=0 grep -qx 'finish acknowledged' "$LOGS/$name-pub.log" || publisher_ok=0 From 169fba4d407e642de8af21917b641b94f7087107 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 15:37:32 -0700 Subject: [PATCH 8/8] test(interop): skip moq-transport finish cells and grant the fixture by prefix moq-transport's AUTH extension carries prefixes alone, so the finish fixture and its health sibling share a parent path. Late join, withdrawal, and same-session health after a finish do not yet interoperate on moq-transport; pinned passes record the case as skipped, tracked by quest/m2/ietf-finish.md. Co-Authored-By: Claude Opus 5.5 --- quest/m2/README.md | 1 + quest/m2/ietf-finish.md | 35 +++++++++++++++++++++ test/interop/README.md | 3 +- test/interop/clients/js-native/subscribe.ts | 3 +- test/interop/interop.sh | 24 +++++++++++--- 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 quest/m2/ietf-finish.md diff --git a/quest/m2/README.md b/quest/m2/README.md index 9bda980032d..1f88d59e25a 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -210,6 +210,7 @@ ranked just below deterministic TS legs, which it requires. - [Relay metrics through prometheus-client](/quest/m2/relay-prometheus-client.md) - `/metrics` renders through the maintained client with the same series - [IETF request order](/quest/m2/ietf-request-order.md) - d14/15 requests take their ID after opening, legacy `control.sending()` races are gone, and SUBSCRIBE_NAMESPACE never closes over its own close - [JS IETF request streams](/quest/m2/js-request-stream.md) - `RequestStream` owns deadlines and cancellation, and TRACK trailing bytes close the session like Rust +- [moq-transport finish interop](/quest/m2/ietf-finish.md) - the interop `finish` case runs on every even moq-transport draft instead of being skipped - [Join after a quick finish](/quest/m2/ietf-join-after-finish.md) - a pre-draft-20 joining FETCH that arrives after its subscription finished is still answered, within a bound the peer already negotiates - [ashpd uses maintained D-Bus crates](/quest/m2/ashpd-maintained.md) - wait for a stable zbus 6 port, then remove the portal dependency exceptions - [Askama uses a maintained TOML parser](/quest/m2/askama-maintained.md) - wait for a stable parser migration, then remove the generator dependency exception diff --git a/quest/m2/ietf-finish.md b/quest/m2/ietf-finish.md new file mode 100644 index 00000000000..8a3eb7c7d3f --- /dev/null +++ b/quest/m2/ietf-finish.md @@ -0,0 +1,35 @@ +# [M] moq-transport finish interop + +## Goal + +The interop `finish` case passes on every even moq-transport draft, not only +moq-lite: each reader that joins a finished broadcast during its linger gets +the whole ten-frame tail, natural media and catalog EOF, the exact broadcast's +withdrawal, and the publisher's later health broadcast through the same +session. Until then `interop.sh` records those cells as skipped; delete that +skip in `run_finishes` and its README note. + +## Plan + +Observed on 2026-10-22 with `just test interop --finish --all --versions ietf` +(lite passes 45/45): + +- Drafts 14 to 19: late readers see the finished catalog end empty, a short + tail, or a refused joining FETCH (`publish done: internal error`). This is + the pre-draft-20 join after a finish, which + [join after a quick finish](/quest/m2/ietf-join-after-finish.md) fixes; rerun + these drafts once it lands. +- Drafts 20 and 22: several readers time out after the withdrawal (C and C++ + on the health broadcast), JS readers see `publish done: internal error`, and + native JS refuses a "malformed request stream message" from the relay. + Reproduce each between two clients before fixing; they may be separate bugs. + +A failing reader fails its whole publisher row, since the publisher waits for +every reader's acknowledgement, so judge each cell from its reader's log. + +Public API: none. Wire: none expected; any fix that changes framing updates +its draft. + +## Related + +- [Join after a quick finish](/quest/m2/ietf-join-after-finish.md) - the pre-draft-20 half of this diff --git a/test/interop/README.md b/test/interop/README.md index effac6e5119..ef8fc451977 100644 --- a/test/interop/README.md +++ b/test/interop/README.md @@ -64,7 +64,8 @@ GStreamer checks the late tail alone. `moqsrc` keeps watching a finished broadcast, since an announcement means online/offline, so it has no end, withdrawal, or session to report. It joins once the broadcast has finished and requires exactly ten nonempty video buffers; its cell passes with the end check -marked N/A. +marked N/A. A pinned moq-transport pass records the case as skipped until +[`quest/m2/ietf-finish.md`](../../quest/m2/ietf-finish.md) makes it pass. Every client closes its session on the way out: publishers stop when their input ends (the browser on SIGTERM), and subscribers close once they have their frame. diff --git a/test/interop/clients/js-native/subscribe.ts b/test/interop/clients/js-native/subscribe.ts index 5410ea06147..74248b158ee 100644 --- a/test/interop/clients/js-native/subscribe.ts +++ b/test/interop/clients/js-native/subscribe.ts @@ -19,8 +19,9 @@ * * @module */ -import { createInterface } from "node:readline/promises"; + import { writeFileSync } from "node:fs"; +import { createInterface } from "node:readline/promises"; import { parseArgs } from "node:util"; import { Milli } from "@moq/clock"; import * as Catalog from "@moq/hang/catalog"; diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 80ee5a086e0..6743d6950b0 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -1487,10 +1487,24 @@ finish_marker() { } run_finishes() { - local pub sub name broadcast pid ack ack_fd reader_fd i started late + local pub sub name broadcast grant pid ack ack_fd reader_fd i started late + # moq-transport does not yet deliver a finished broadcast's late tail, withdrawal, and + # same-session health across clients, so a pinned moq-transport pass records the case as + # skipped rather than red. + if [[ "$VERSION" == moq-transport-* ]]; then + for pub in "${PUB_LIST[@]}"; do + for sub in "${SUB_LIST[@]}"; do + record skip case=finish publisher="$pub" subscriber="$sub" detail="moq-transport finish: quest/m2/ietf-finish.md" + done + done + return + fi for pub in "${PUB_LIST[@]}"; do name="finish-$pub" - broadcast="$name-$$-$RANDOM.hang" + # The fixture and its .health sibling share a parent, so one prefix grant covers both: + # moq-transport's AUTH extension carries prefixes alone. + broadcast="$name-$$-$RANDOM/fixture.hang" + grant="${broadcast%/*}/**" ack="$LOGS/$name-ack" local pids=() fds=() names=() all_ready=1 all_clean=1 publisher_ok=1 late=0 @@ -1518,7 +1532,7 @@ run_finishes() { local fifo="$LOGS/$name-$sub-read" mkfifo "$fifo" exec {reader_fd}<>"$fifo" - harness_spawn "$name-$sub" "$LOGS/$name-$sub.log" run_finish_reader "$fifo" "$sub" subscribe "$broadcast" "$(token_url --subscribe "$broadcast*")" + harness_spawn "$name-$sub" "$LOGS/$name-$sub.log" run_finish_reader "$fifo" "$sub" subscribe "$broadcast" "$(token_url --subscribe "$grant")" pids+=("$HARNESS_PID") fds+=("$reader_fd") names+=("$sub") @@ -1527,14 +1541,14 @@ run_finishes() { if ! finish_ready "${pids[$i]}" "$LOGS/$name-${names[$i]}.log" '^finish reader ready$'; then all_ready=0; fi done if [[ "$all_ready" -eq 1 ]]; then - harness_spawn "$name-pub" "$LOGS/$name-pub.log" run_finish_publisher "$pub" "$broadcast" "$(token_url --publish "$broadcast*")" "$ack" + harness_spawn "$name-pub" "$LOGS/$name-pub.log" run_finish_publisher "$pub" "$broadcast" "$(token_url --publish "$grant")" "$ack" pid="$HARNESS_PID" if ! finish_ready "$pid" "$LOGS/$name-pub.log" '^finish ready linger_us='; then all_ready=0; fi else pid=""; fi if [[ "$all_ready" -eq 1 ]]; then for reader_fd in "${fds[@]}"; do printf 'read\n' >&"$reader_fd"; done if [[ "$late" -eq 1 ]]; then - harness_spawn "$name-gst" "$LOGS/$name-gst.log" run_finish_gst "$broadcast" "$(token_url --subscribe "$broadcast*")" "$LOGS/$name-gst.out" + harness_spawn "$name-gst" "$LOGS/$name-gst.log" run_finish_gst "$broadcast" "$(token_url --subscribe "$grant")" "$LOGS/$name-gst.out" pids+=("$HARNESS_PID") fds+=("") names+=(gst)