From beb8f78fdc38cb091dc5e0511f61e2283ad5fe8e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 03:24:11 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m1/binding-delay-tests.md Quest-Claim: d5c69c4d81979597 From 5f4281a3fcf12aef13e4fef43f0f6f45608691b0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 03:34:21 -0800 Subject: [PATCH 2/2] test(moq-ffi): binding playout-delay tests stop racing the native wall clock The Go, Swift, Kotlin, and Dart audio consumer delay tests pass no max delay, as the Python and Rust ones do, so a read that starts late under load no longer waits out its timeout. Kotlin's retry writer loop is gone. The rule that native timing is asserted once, in moq-ffi's Rust tests, joins its AGENTS.md. Co-Authored-By: Claude Sonnet 5.5 --- dart/moq/test/moq_test.dart | 9 +++- go/wrapper/moq_test.go | 9 +++- .../kotlin/dev/moq/SmokeTest.kt | 48 +++++++------------ quest/m1/binding-delay-tests.md | 34 ------------- rs/moq-ffi/AGENTS.md | 5 ++ swift/Tests/MoqTests/SmokeTests.swift | 6 ++- 6 files changed, 40 insertions(+), 71 deletions(-) delete mode 100644 quest/m1/binding-delay-tests.md diff --git a/dart/moq/test/moq_test.dart b/dart/moq/test/moq_test.dart index f027816482e..904a0b3b159 100644 --- a/dart/moq/test/moq_test.dart +++ b/dart/moq/test/moq_test.dart @@ -1081,9 +1081,11 @@ void main() { ).timeout(timeout); final rendition = (await catalogs.next().timeout(timeout))!.audio['mic']!; + // No max delay: a zero one skips a group once its successor is a warmup old by the + // native wall clock, so a read that starts late under load never returns. final fixedOutput = moq_audio.DecoderOutput( format: moq_audio.SampleFormat.f32, - delay: Delay(min: Duration(milliseconds: 80)), + delay: Delay(min: Duration(milliseconds: 80), max: null), estimate: false, ); final fixed = await moq_audio.Consumer.subscribe( @@ -1096,7 +1098,10 @@ void main() { broadcast: consumer, id: 'mic', catalogAudio: rendition, - output: moq_audio.DecoderOutput(format: moq_audio.SampleFormat.f32), + output: moq_audio.DecoderOutput( + format: moq_audio.SampleFormat.f32, + delay: Delay(max: null), + ), ).timeout(timeout); expect(fixed.delay(), const Duration(milliseconds: 80)); final initial = estimated.delay(); diff --git a/go/wrapper/moq_test.go b/go/wrapper/moq_test.go index 0b05b9da426..5e6ae583f1a 100644 --- a/go/wrapper/moq_test.go +++ b/go/wrapper/moq_test.go @@ -306,18 +306,23 @@ func TestAudioConsumerDelay(t *testing.T) { t.Fatalf("catalog has no %q rendition: %v", track, catalog.Audio) } + // No max delay: a zero one skips a group once its successor is a warmup old by the native + // wall clock, so a read that starts late under load never returns. fixedDelay := 80 * time.Millisecond estimate := false fixed, err := moqaudio.Subscribe(ctx, bc, track, rendition, moqaudio.DecoderOutput{ Format: moq.AudioSampleFormatF32, - Delay: moq.Delay{Min: fixedDelay}, + Delay: moq.Delay{Min: fixedDelay, MaxUnlimited: true}, Estimate: &estimate, }) if err != nil { t.Fatal(err) } defer fixed.Cancel() - estimated, err := moqaudio.Subscribe(ctx, bc, track, rendition, moqaudio.DecoderOutput{Format: moq.AudioSampleFormatF32}) + estimated, err := moqaudio.Subscribe(ctx, bc, track, rendition, moqaudio.DecoderOutput{ + Format: moq.AudioSampleFormatF32, + Delay: moq.Delay{MaxUnlimited: true}, + }) if err != nil { t.Fatal(err) } diff --git a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt index 2ac3e0e2f2e..eeddca403a5 100644 --- a/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt +++ b/kt/moq/src/jvmAndAndroidTest/kotlin/dev/moq/SmokeTest.kt @@ -38,17 +38,12 @@ import kotlin.test.assertTrue import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.nanoseconds import kotlin.time.Duration.Companion.seconds -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async -import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import kotlinx.coroutines.withTimeoutOrNull -import kotlinx.coroutines.yield import kotlinx.serialization.Serializable import uniffi.moq.MoqException @@ -1233,14 +1228,12 @@ class SmokeTest { val catalog = CatalogConsumer.subscribe(consumer).next()!! val rendition = catalog.audio["mic"]!! + // No max delay: a zero one skips a group once its successor is a warmup old by + // the native wall clock, so a read that starts late under load never returns. val fixedOutput = AudioDecoderOutput( format = AudioSampleFormat.F32, - delay = - Delay( - min = java.time.Duration.ofMillis(80), - max = java.time.Duration.ZERO, - ), + delay = Delay(min = java.time.Duration.ofMillis(80), max = null), estimate = false, ) val fixed = AudioConsumer.subscribe(consumer, "mic", rendition, fixedOutput) @@ -1249,33 +1242,26 @@ class SmokeTest { consumer, "mic", rendition, - AudioDecoderOutput(format = AudioSampleFormat.F32), + AudioDecoderOutput( + format = AudioSampleFormat.F32, + delay = Delay(min = java.time.Duration.ZERO, max = null), + ), ) assertEquals(java.time.Duration.ofMillis(80), fixed.delay()) val initial = estimated.delay() - // 20 ms Opus frames of silence at 48 kHz mono, fed until both consumers read - // one. A max delay of zero skips groups by the native wall clock, which the - // test cannot control, so a host stalled under load may skip any fixed set - // of frames; a newer one always follows. - val writer = - launch(Dispatchers.Default) { - var i = 0uL - while (isActive) { - audio.write( - AudioFrame( - timestamp = Timestamp(i++ * 960uL, 48_000uL), - data = ByteArray(960 * 4), - ) - ) - yield() - } - } - // A skipped group reads as a gap before the frame after it. + // Two 20 ms Opus frames of silence at 48 kHz mono. + for (i in 0uL until 2uL) { + audio.write( + AudioFrame( + timestamp = Timestamp(i * 960uL, 48_000uL), + data = ByteArray(960 * 4), + ) + ) + } for (reader in listOf(fixed, estimated)) { - while (assertNotNull(reader.next()) !is AudioReadFrame) {} + assertIs(assertNotNull(reader.next())) } - writer.cancelAndJoin() assertEquals(java.time.Duration.ofMillis(80), fixed.delay()) assertTrue( diff --git a/quest/m1/binding-delay-tests.md b/quest/m1/binding-delay-tests.md deleted file mode 100644 index 682361c4f32..00000000000 --- a/quest/m1/binding-delay-tests.md +++ /dev/null @@ -1,34 +0,0 @@ -# [XS] Binding playout-delay tests stop racing the native wall clock - -## Goal - -The Go, Swift, Kotlin, and Dart "audio consumer reports its playout delay" -tests no longer hang when the host stalls between the writes and the first -read, matching the Python and Rust fixes -([moq-dev/moq#8050](https://github.com/moq-dev/moq/pull/8050), -[moq-dev/moq#8566](https://github.com/moq-dev/moq/pull/8566)). - -## Plan - -Found 2026-11-14 by the [feature review](/quest/m3/release/feature-review.md). -A fixed consumer with `max` zero skips a group by the native wall clock, so a -read that starts more than the 80 ms warmup after group 1 arrives waits out its -timeout (#8566 reproduced it with a 200 ms stall). Still latent in -`go/wrapper/moq_test.go` (`Delay{Min: 80ms}`, zero Max), Swift's -`SmokeTests.swift` (`max: 0`), and Dart's `moq_test.dart` (`max` defaults to -zero); Kotlin's -[moq-dev/moq#8475](https://github.com/moq-dev/moq/pull/8475) kept `max = 0` -and added a writer that loops until a read lands, which is a retry around the -cause. Pass `max: None` (or the language's unset value) to both consumers, and -delete Kotlin's writer loop. - -As a rule for new tests, assert native timing and decoding once, -in moq-ffi's Rust tests, and limit wrapper tests to the code each wrapper -owns (record mapping, cancellation, async adapters, lifetimes). Six copies of -this test took three separate fixes over a week, and three copies were still -unfixed. - -Decided 2026-11-14 (maintainer, pick on [moq-dev/moq#8764](https://github.com/moq-dev/moq/pull/8764)): ✅ (a) fix all four copies, and from now on native timing and decoding are asserted once, in moq-ffi's Rust tests, while wrapper tests cover only the code each wrapper owns; this quest writes that rule into `rs/moq-ffi/AGENTS.md` (rejected: (b) delete the four copies now). - -Public API: none. Wire: none. - diff --git a/rs/moq-ffi/AGENTS.md b/rs/moq-ffi/AGENTS.md index e17c446c5fc..af8e861fe5d 100644 --- a/rs/moq-ffi/AGENTS.md +++ b/rs/moq-ffi/AGENTS.md @@ -10,3 +10,8 @@ The UniFFI core every non-Rust binding is generated from (proc macros, no `.udl` - UniFFI ignores `#[cfg]` inside an export impl; gate at the module. - Default argument values don't reach Go; resolve defaults in Rust. - Go handles must be released from the goroutine that ran the call. + +# Tests + +- Assert native timing and decoding once, in moq-ffi's Rust tests. A wrapper test covers only the code that wrapper owns: record mapping, cancellation, async adapters, and lifetimes. +- A test that reads decoded media passes no max delay (`None`, `max: nil`, `MaxUnlimited`, and so on). A max of zero skips a group by the native wall clock, so a read that starts late under load never returns. diff --git a/swift/Tests/MoqTests/SmokeTests.swift b/swift/Tests/MoqTests/SmokeTests.swift index 60e95245f8e..2f85197c047 100644 --- a/swift/Tests/MoqTests/SmokeTests.swift +++ b/swift/Tests/MoqTests/SmokeTests.swift @@ -941,13 +941,15 @@ final class SmokeTests: XCTestCase { let catalog = try XCTUnwrap(nextCatalog) let rendition = try XCTUnwrap(catalog.audio["mic"]) + // No max delay: a zero one skips a group once its successor is a warmup old by the + // native wall clock, so a read that starts late under load never returns. let fixed = try await Audio.Consumer.subscribe( broadcast: consumer, id: "mic", rendition: rendition, - output: AudioDecoderOutput(format: .f32, delay: Delay(min: 0.08, max: 0), estimate: false) + output: AudioDecoderOutput(format: .f32, delay: Delay(min: 0.08, max: nil), estimate: false) ) let estimated = try await Audio.Consumer.subscribe( broadcast: consumer, id: "mic", rendition: rendition, - output: AudioDecoderOutput(format: .f32) + output: AudioDecoderOutput(format: .f32, delay: Delay(min: 0, max: nil)) ) XCTAssertEqual(fixed.delay, 0.08, accuracy: 1e-9) let initial = estimated.delay