From 08c7abf3e2485ae56ca568d7dad3238e3e3b6ecc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 23:36:15 -0700 Subject: [PATCH 1/5] chore(quest): claim quest/m1/kio-clock.md Quest-Claim: 9740628bbb362c46 From e6c2c444789e676e60b5fb6017bb7456eb252b90 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 23:44:50 -0700 Subject: [PATCH 2/5] refactor(kio)!: move moq-clock into kio::clock moq-clock and moq-clock-macros become kio::clock and #[kio::test], behind kio's runtime, sim, manual, and serde features. kio's private _sim feature is gone, and every dependent imports kio::clock. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 78 +-- Cargo.toml | 8 +- doc/.vitepress/config.ts | 2 +- doc/lib/rs/index.md | 2 +- doc/lib/rs/{moq-clock.md => kio.md} | 35 +- doc/setup/repository.md | 2 +- doc/setup/upgrade.md | 2 +- js/clock/src/index.ts | 2 +- rs/AGENTS.md | 2 +- rs/hang/Cargo.toml | 3 +- rs/hang/clippy.toml | 28 +- rs/hang/examples/video.rs | 6 +- rs/hang/src/catalog/clock.rs | 10 +- rs/hang/src/catalog/root.rs | 2 +- rs/hang/src/echo.rs | 4 +- rs/hang/src/snapshot.rs | 14 +- rs/justfile | 16 +- rs/kio/Cargo.toml | 52 +- rs/kio/README.md | 13 + rs/kio/benches/contended.rs | 1 + rs/{moq-clock => kio}/clippy.toml | 20 +- rs/kio/macros/Cargo.toml | 21 + rs/{moq-clock => kio}/macros/MIGRATE.md | 2 +- rs/{moq-clock => kio}/macros/src/lib.rs | 16 +- .../src => kio/src/clock}/deadline.rs | 91 +-- .../src => kio/src/clock}/installed.rs | 42 +- .../src => kio/src/clock}/instant.rs | 6 +- rs/{moq-clock/src => kio/src/clock}/manual.rs | 2 +- .../src/lib.rs => kio/src/clock/mod.rs} | 18 +- .../src => kio/src/clock}/runtime.rs | 113 ++-- rs/{moq-clock/src => kio/src/clock}/serde.rs | 2 +- rs/{moq-clock/src => kio/src/clock}/sim.rs | 192 +++--- rs/{moq-clock/src => kio/src/clock}/timer.rs | 39 +- rs/{moq-clock/src => kio/src/clock}/wall.rs | 4 +- rs/kio/src/consumer.rs | 4 +- rs/kio/src/coop.rs | 18 +- rs/kio/src/lib.rs | 15 +- rs/kio/src/producer.rs | 10 +- rs/kio/src/queue.rs | 4 +- rs/kio/src/shared.rs | 2 +- rs/kio/src/task.rs | 4 +- rs/kio/src/waiter.rs | 2 +- rs/kio/src/weak.rs | 10 +- rs/libmoq/clippy.toml | 28 +- rs/moq-archive/Cargo.toml | 3 +- rs/moq-archive/clippy.toml | 28 +- rs/moq-archive/src/consumer/mod.rs | 2 +- rs/moq-archive/src/consumer/tests.rs | 2 +- rs/moq-archive/src/producer/backends.rs | 8 +- rs/moq-archive/src/producer/ordered.rs | 18 +- rs/moq-archive/src/producer/tests.rs | 6 +- rs/moq-archive/src/producer/track.rs | 18 +- rs/moq-audio/Cargo.toml | 6 +- rs/moq-audio/clippy.toml | 28 +- rs/moq-audio/src/capture.rs | 2 +- rs/moq-audio/src/capture/channel.rs | 2 +- rs/moq-audio/src/capture/permission.rs | 2 +- rs/moq-audio/src/capture/screencapture.rs | 6 +- rs/moq-audio/src/decode/consumer.rs | 2 +- rs/moq-audio/src/encode/capture.rs | 26 +- rs/moq-audio/src/playback/driver.rs | 2 +- rs/moq-audio/src/resample.rs | 2 +- rs/moq-auth/Cargo.toml | 7 +- rs/moq-auth/MIGRATE.md | 6 +- rs/moq-auth/clippy.toml | 28 +- rs/moq-auth/examples/asymmetric.rs | 4 +- rs/moq-auth/examples/basic.rs | 4 +- rs/moq-auth/src/claims.rs | 14 +- rs/moq-auth/src/client.rs | 14 +- rs/moq-auth/src/grant.rs | 28 +- rs/moq-auth/src/key.rs | 30 +- rs/moq-auth/src/lease.rs | 20 +- rs/moq-auth/src/request.rs | 4 +- rs/moq-auth/src/serve.rs | 40 +- rs/moq-auth/src/set.rs | 10 +- rs/moq-auth/src/wire.rs | 12 +- rs/moq-bench/Cargo.toml | 2 +- rs/moq-bench/clippy.toml | 28 +- rs/moq-bench/src/config.rs | 4 +- rs/moq-bench/src/connection.rs | 10 +- rs/moq-bench/src/host.rs | 6 +- rs/moq-bench/src/main.rs | 4 +- rs/moq-bench/src/stats.rs | 8 +- rs/moq-boy/Cargo.toml | 2 +- rs/moq-boy/clippy.toml | 28 +- rs/moq-boy/src/main.rs | 2 +- rs/moq-boy/src/stats.rs | 2 +- rs/moq-boy/src/video.rs | 2 +- rs/moq-c/Cargo.toml | 2 +- rs/moq-c/clippy.toml | 28 +- rs/moq-c/src/publish.rs | 6 +- rs/moq-c/src/video.rs | 4 +- rs/moq-cli/Cargo.toml | 2 +- rs/moq-cli/clippy.toml | 28 +- rs/moq-cli/src/auth.rs | 10 +- rs/moq-cli/src/complete.rs | 4 +- rs/moq-cli/src/fetch.rs | 4 +- rs/moq-cli/src/hls.rs | 2 +- rs/moq-cli/src/hls/record.rs | 18 +- rs/moq-cli/src/play/fake.rs | 6 +- rs/moq-cli/src/play/media.rs | 16 +- rs/moq-cli/src/play/metrics.rs | 10 +- rs/moq-cli/src/play/timeline.rs | 44 +- rs/moq-cli/src/play/video.rs | 4 +- rs/moq-cli/src/play/window.rs | 4 +- rs/moq-cli/src/publish.rs | 8 +- rs/moq-cli/src/report.rs | 6 +- rs/moq-cli/src/rtsp.rs | 2 +- rs/moq-cli/src/subscribe.rs | 8 +- rs/moq-cli/src/transcode.rs | 4 +- rs/moq-clock/CHANGELOG.md | 14 - rs/moq-clock/Cargo.toml | 68 --- rs/moq-clock/MIGRATE.md | 15 - rs/moq-clock/README.md | 28 - rs/moq-clock/macros/Cargo.toml | 21 - rs/moq-congestion/Cargo.toml | 4 +- rs/moq-congestion/README.md | 2 +- rs/moq-congestion/clippy.toml | 28 +- rs/moq-congestion/src/lib.rs | 2 +- rs/moq-congestion/src/pacer.rs | 2 +- rs/moq-congestion/src/rate.rs | 2 +- rs/moq-e2ee/clippy.toml | 28 +- rs/moq-ffi/Cargo.toml | 5 +- rs/moq-ffi/clippy.toml | 16 +- rs/moq-ffi/src/ffi.rs | 8 +- rs/moq-ffi/src/lib.rs | 2 +- rs/moq-ffi/src/media.rs | 2 +- rs/moq-ffi/src/session/dial.rs | 2 +- rs/moq-ffi/src/test.rs | 10 +- rs/moq-ffi/src/video.rs | 4 +- rs/moq-flate/clippy.toml | 28 +- rs/moq-gst/Cargo.toml | 2 +- rs/moq-gst/clippy.toml | 28 +- rs/moq-gst/src/sink/imp.rs | 10 +- rs/moq-gst/src/sink/wall.rs | 12 +- rs/moq-hls/Cargo.toml | 3 +- rs/moq-hls/clippy.toml | 28 +- rs/moq-hls/src/export/mod.rs | 12 +- rs/moq-hls/src/export/mpd.rs | 2 +- rs/moq-hls/src/export/playlist.rs | 2 +- rs/moq-hls/src/export/rendition.rs | 6 +- rs/moq-hls/src/export/renditions.rs | 4 +- rs/moq-hls/src/export/segments.rs | 2 +- rs/moq-hls/src/import.rs | 10 +- rs/moq-hls/src/server/mod.rs | 8 +- rs/moq-hls/src/server/routes.rs | 12 +- rs/moq-hls/tests/integration/disconnect.rs | 4 +- rs/moq-hls/tests/integration/finish.rs | 10 +- rs/moq-hls/tests/integration/restart.rs | 12 +- rs/moq-hls/tests/integration/server.rs | 30 +- rs/moq-hls/tests/integration/support.rs | 16 +- rs/moq-ice/Cargo.toml | 2 +- rs/moq-ice/clippy.toml | 28 +- rs/moq-ice/src/agent.rs | 4 +- rs/moq-json/clippy.toml | 28 +- rs/moq-loc/clippy.toml | 28 +- rs/moq-msf/clippy.toml | 28 +- rs/moq-mux/Cargo.toml | 5 +- rs/moq-mux/benches/decode_clock.rs | 2 +- rs/moq-mux/benches/jitter.rs | 8 +- rs/moq-mux/clippy.toml | 16 +- rs/moq-mux/src/binary.rs | 6 +- rs/moq-mux/src/catalog/producer.rs | 40 +- rs/moq-mux/src/catalog/timebase.rs | 2 +- rs/moq-mux/src/clock.rs | 46 +- rs/moq-mux/src/codec/av1/split.rs | 4 +- rs/moq-mux/src/codec/h264/split.rs | 4 +- rs/moq-mux/src/codec/h265/split.rs | 4 +- rs/moq-mux/src/container/consumer.rs | 16 +- rs/moq-mux/src/container/decode.rs | 2 +- rs/moq-mux/src/container/flv/export.rs | 18 +- rs/moq-mux/src/container/flv/export_test.rs | 6 +- rs/moq-mux/src/container/flv/import_test.rs | 6 +- rs/moq-mux/src/container/fmp4/import_test.rs | 8 +- rs/moq-mux/src/container/mkv/export.rs | 14 +- rs/moq-mux/src/container/mkv/export_test.rs | 6 +- rs/moq-mux/src/container/mkv/import_test.rs | 6 +- rs/moq-mux/src/container/ts/damage.rs | 6 +- rs/moq-mux/src/container/ts/export.rs | 60 +- rs/moq-mux/src/container/ts/export_test.rs | 4 +- .../src/container/ts/export_timing_test.rs | 24 +- rs/moq-mux/src/container/ts/follower.rs | 12 +- rs/moq-mux/src/container/ts/import.rs | 6 +- rs/moq-mux/src/container/ts/import_test.rs | 6 +- rs/moq-mux/src/container/ts/programs.rs | 4 +- rs/moq-mux/src/container/ts/release.rs | 8 +- rs/moq-mux/src/container/ts/si.rs | 20 +- rs/moq-mux/src/jitter.rs | 152 ++--- rs/moq-mux/src/json.rs | 4 +- rs/moq-mux/src/linger.rs | 20 +- rs/moq-mux/src/pace.rs | 24 +- rs/moq-mux/src/rate.rs | 94 +-- rs/moq-mux/src/stats.rs | 2 +- rs/moq-native/clippy.toml | 28 +- rs/moq-net-tests/Cargo.toml | 2 +- .../tests/integration/ietf_conformance.rs | 6 +- rs/moq-net-tests/tests/integration/refresh.rs | 12 +- rs/moq-net-tests/tests/integration/restart.rs | 58 +- rs/moq-net/AGENTS.md | 2 +- rs/moq-net/Cargo.toml | 5 +- rs/moq-net/benches/memory.rs | 2 +- rs/moq-net/benches/origin.rs | 12 +- rs/moq-net/benches/session/mod.rs | 6 +- rs/moq-net/clippy.toml | 16 +- rs/moq-net/src/auth.rs | 44 +- rs/moq-net/src/client.rs | 58 +- rs/moq-net/src/coding/stream.rs | 4 +- rs/moq-net/src/coding/writer.rs | 2 +- rs/moq-net/src/ietf/auth.rs | 2 +- rs/moq-net/src/ietf/peer.rs | 4 +- rs/moq-net/src/ietf/publisher.rs | 508 ++++++++-------- rs/moq-net/src/ietf/publisher/tracks.rs | 94 +-- rs/moq-net/src/ietf/request_stream.rs | 6 +- rs/moq-net/src/ietf/session.rs | 166 ++--- rs/moq-net/src/ietf/subscriber.rs | 490 +++++++-------- rs/moq-net/src/ietf/subscriber/tracks.rs | 68 +-- rs/moq-net/src/lite/ietf.rs | 56 +- rs/moq-net/src/lite/publisher.rs | 280 ++++----- rs/moq-net/src/lite/session.rs | 44 +- rs/moq-net/src/lite/subscriber.rs | 210 +++---- rs/moq-net/src/model/bandwidth.rs | 18 +- rs/moq-net/src/model/broadcast.rs | 48 +- rs/moq-net/src/model/cache.rs | 6 +- rs/moq-net/src/model/clock.rs | 32 +- rs/moq-net/src/model/follow.rs | 38 +- rs/moq-net/src/model/group.rs | 22 +- rs/moq-net/src/model/origin.rs | 566 +++++++++--------- rs/moq-net/src/model/resume.rs | 40 +- rs/moq-net/src/model/track.rs | 248 ++++---- rs/moq-net/src/model/track/miss.rs | 6 +- rs/moq-net/src/priority.rs | 24 +- rs/moq-net/src/server.rs | 96 +-- rs/moq-net/src/tail.rs | 10 +- rs/moq-net/src/time.rs | 10 +- .../integration/announce_covering_route.rs | 12 +- .../tests/integration/announce_to_serve.rs | 22 +- rs/moq-net/tests/integration/auth.rs | 96 +-- .../tests/integration/broadcast_close.rs | 10 +- .../tests/integration/catalog_acquisition.rs | 4 +- rs/moq-net/tests/integration/catalog_churn.rs | 24 +- .../tests/integration/catalog_handover.rs | 60 +- rs/moq-net/tests/integration/compress.rs | 24 +- rs/moq-net/tests/integration/control_stats.rs | 6 +- rs/moq-net/tests/integration/datagram.rs | 16 +- .../tests/integration/dial_split_horizon.rs | 14 +- rs/moq-net/tests/integration/drained_claim.rs | 14 +- rs/moq-net/tests/integration/empty_group.rs | 12 +- rs/moq-net/tests/integration/extensions.rs | 16 +- rs/moq-net/tests/integration/fetch_cancel.rs | 28 +- rs/moq-net/tests/integration/fetch_fanout.rs | 4 +- .../tests/integration/fetch_from_feed.rs | 32 +- rs/moq-net/tests/integration/fetch_only.rs | 22 +- .../integration/finished_broadcast_mock.rs | 14 +- rs/moq-net/tests/integration/finite_relay.rs | 30 +- rs/moq-net/tests/integration/goaway.rs | 54 +- rs/moq-net/tests/integration/group_order.rs | 26 +- .../tests/integration/history_groups.rs | 30 +- .../tests/integration/idle_cancel_refetch.rs | 18 +- rs/moq-net/tests/integration/idle_session.rs | 32 +- .../tests/integration/implementation.rs | 12 +- .../tests/integration/late_lower_group.rs | 46 +- .../tests/integration/lazy_discovery.rs | 86 +-- rs/moq-net/tests/integration/mesh_withdraw.rs | 70 +-- rs/moq-net/tests/integration/multi_cdn.rs | 16 +- rs/moq-net/tests/integration/partial_group.rs | 22 +- rs/moq-net/tests/integration/quiet_catalog.rs | 22 +- rs/moq-net/tests/integration/range_anchors.rs | 14 +- .../tests/integration/received_rewind.rs | 32 +- rs/moq-net/tests/integration/rejoin.rs | 58 +- .../tests/integration/relay_upstream_close.rs | 20 +- rs/moq-net/tests/integration/replacement.rs | 50 +- rs/moq-net/tests/integration/request_caps.rs | 22 +- rs/moq-net/tests/integration/route_change.rs | 96 +-- .../tests/integration/segmented_frame.rs | 6 +- rs/moq-net/tests/integration/session_close.rs | 92 +-- rs/moq-net/tests/integration/session_panic.rs | 12 +- .../integration/settled_end_survives_abort.rs | 6 +- .../tests/integration/setup_negotiation.rs | 4 +- rs/moq-net/tests/integration/source_errors.rs | 34 +- rs/moq-net/tests/integration/stream_credit.rs | 4 +- .../tests/integration/subscribe_priority.rs | 10 +- .../tests/integration/subscribe_ranges.rs | 82 +-- .../tests/integration/subscribe_tracks.rs | 16 +- .../tests/integration/subscriber_max_age.rs | 6 +- .../integration/subscription_end_integrity.rs | 28 +- .../tests/integration/support/harness.rs | 8 +- rs/moq-net/tests/integration/support/mock.rs | 8 +- rs/moq-net/tests/integration/synced.rs | 12 +- .../integration/track_abort_over_session.rs | 10 +- .../tests/integration/track_info_cancel.rs | 14 +- .../tests/integration/track_stream_demand.rs | 48 +- rs/moq-net/tests/integration/track_tail.rs | 62 +- rs/moq-net/tests/integration/tracks.rs | 24 +- rs/moq-net/tests/integration/tracks_ietf.rs | 62 +- .../tests/integration/unannounce_release.rs | 6 +- rs/moq-net/tests/integration/untimed.rs | 30 +- rs/moq-net/tests/integration/wide_hop.rs | 4 +- rs/moq-net/tests/integration/wide_sequence.rs | 12 +- .../tests/integration/widened_max_age.rs | 40 +- rs/moq-net/tests/integration/zero_copy.rs | 8 +- rs/moq-nvenc/clippy.toml | 28 +- rs/moq-pattern/clippy.toml | 28 +- rs/moq-quic/Cargo.toml | 4 +- rs/moq-quic/MIGRATE.md | 2 +- rs/moq-quic/README.md | 2 +- rs/moq-quic/benches/common/mod.rs | 2 +- rs/moq-quic/clippy.toml | 28 +- rs/moq-quic/src/config/transport.rs | 2 +- rs/moq-quic/src/connection/mod.rs | 2 +- rs/moq-quic/src/endpoint.rs | 2 +- rs/moq-quic/src/lib.rs | 4 +- rs/moq-quic/src/tests/token.rs | 8 +- rs/moq-quic/src/token.rs | 4 +- rs/moq-relay/Cargo.toml | 7 +- rs/moq-relay/clippy.toml | 28 +- rs/moq-relay/src/acme/client.rs | 22 +- rs/moq-relay/src/acme/tests.rs | 14 +- rs/moq-relay/src/auth.rs | 26 +- rs/moq-relay/src/auth/refresh.rs | 26 +- rs/moq-relay/src/cache.rs | 4 +- rs/moq-relay/src/cluster.rs | 8 +- rs/moq-relay/src/listener.rs | 2 +- rs/moq-relay/src/listener/idle.rs | 6 +- rs/moq-relay/src/session.rs | 6 +- rs/moq-relay/src/shutdown.rs | 6 +- rs/moq-relay/src/stun.rs | 2 +- rs/moq-relay/src/web.rs | 12 +- .../tests/integration/auth_lifetime.rs | 14 +- .../tests/integration/cluster_drain.rs | 4 +- rs/moq-relay/tests/integration/refusals.rs | 2 +- .../tests/integration/runtime_uring.rs | 2 +- .../tests/integration/session_revalidate.rs | 2 +- rs/moq-room/Cargo.toml | 3 +- rs/moq-room/clippy.toml | 16 +- rs/moq-room/src/chat.rs | 12 +- rs/moq-rtc/Cargo.toml | 2 +- rs/moq-rtc/clippy.toml | 26 +- rs/moq-rtc/src/client/whep.rs | 2 +- rs/moq-rtc/src/egress.rs | 2 +- rs/moq-rtc/src/server/whep.rs | 12 +- rs/moq-rtc/src/server/whip.rs | 2 +- rs/moq-rtc/src/session.rs | 10 +- rs/moq-rtmp/Cargo.toml | 4 +- rs/moq-rtmp/clippy.toml | 28 +- rs/moq-rtmp/src/rml/sessions/client/mod.rs | 10 +- rs/moq-rtmp/src/rml/sessions/server/mod.rs | 10 +- rs/moq-rtmp/src/server.rs | 26 +- rs/moq-rtsp/Cargo.toml | 4 +- rs/moq-rtsp/clippy.toml | 28 +- rs/moq-rtsp/src/client.rs | 24 +- rs/moq-scene/Cargo.toml | 3 +- rs/moq-scene/src/compositor.rs | 2 +- rs/moq-shaper/Cargo.toml | 2 +- rs/moq-shaper/clippy.toml | 28 +- rs/moq-shaper/src/lib.rs | 4 +- rs/moq-shaper/src/main.rs | 4 +- rs/moq-sock/clippy.toml | 28 +- rs/moq-srt/clippy.toml | 28 +- rs/moq-stats/Cargo.toml | 2 +- rs/moq-stats/clippy.toml | 16 +- rs/moq-stats/src/aggregate.rs | 10 +- rs/moq-stats/src/produce.rs | 30 +- rs/moq-stats/src/produce_bench.rs | 4 +- rs/moq-studio/Cargo.toml | 2 +- rs/moq-studio/src/engine.rs | 10 +- rs/moq-studio/src/ui.rs | 2 +- rs/moq-tokio/Cargo.toml | 7 +- rs/moq-tokio/clippy.toml | 28 +- rs/moq-tokio/examples/chat.rs | 4 +- rs/moq-tokio/examples/clock.rs | 4 +- rs/moq-tokio/src/accept.rs | 6 +- rs/moq-tokio/src/client.rs | 4 +- rs/moq-tokio/src/connection.rs | 24 +- rs/moq-tokio/src/failover.rs | 10 +- rs/moq-tokio/src/listen.rs | 2 +- rs/moq-tokio/src/mdns.rs | 4 +- rs/moq-tokio/src/quic/backend.rs | 2 +- rs/moq-tokio/src/quic/driver/connection.rs | 4 +- rs/moq-tokio/src/quic/driver/mod.rs | 2 +- rs/moq-tokio/src/quic/web/session.rs | 2 +- rs/moq-tokio/src/resolve.rs | 4 +- rs/moq-tokio/src/server.rs | 24 +- rs/moq-tokio/src/tcp.rs | 2 +- rs/moq-tokio/src/tls.rs | 10 +- rs/moq-tokio/src/unix.rs | 2 +- rs/moq-tokio/src/webrtc.rs | 2 +- rs/moq-tokio/src/webrtc/resolver.rs | 8 +- rs/moq-tokio/src/websocket.rs | 6 +- rs/moq-transcode/Cargo.toml | 2 +- rs/moq-transcode/clippy.toml | 28 +- rs/moq-transcode/src/catalog.rs | 2 +- rs/moq-uring/Cargo.toml | 9 +- rs/moq-uring/MIGRATE.md | 8 +- rs/moq-uring/README.md | 4 +- rs/moq-uring/benches/timers.rs | 2 +- rs/moq-uring/clippy.toml | 22 +- rs/moq-uring/src/clock.rs | 28 +- rs/moq-uring/src/quic/driver/connection.rs | 2 +- rs/moq-uring/src/quic/handshake.rs | 2 +- rs/moq-uring/src/quic/qlog.rs | 4 +- rs/moq-uring/src/shared.rs | 4 +- rs/moq-uring/src/timer.rs | 4 +- rs/moq-uring/src/udp.rs | 4 +- rs/moq-uring/src/worker.rs | 38 +- rs/moq-uring/tests/integration/endpoint.rs | 4 +- rs/moq-uring/tests/integration/local_addr.rs | 2 +- rs/moq-v4l/clippy.toml | 28 +- rs/moq-video/Cargo.toml | 6 +- rs/moq-video/clippy.toml | 28 +- rs/moq-video/src/capture/avfoundation.rs | 4 +- rs/moq-video/src/capture/channel.rs | 2 +- rs/moq-video/src/capture/mod.rs | 2 +- rs/moq-video/src/capture/pipewire.rs | 4 +- rs/moq-video/src/capture/screencapture.rs | 6 +- rs/moq-video/src/capture/settle.rs | 2 +- rs/moq-video/src/capture/wgc.rs | 2 +- rs/moq-video/src/capture/wgc/native.rs | 2 +- rs/moq-video/src/capture/x11.rs | 2 +- rs/moq-video/src/decode/backend/v4l2.rs | 2 +- rs/moq-video/src/decode/consumer.rs | 6 +- rs/moq-video/src/decode/select.rs | 2 +- rs/moq-video/src/encode/backend/v4l2.rs | 2 +- rs/moq-video/src/encode/producer.rs | 18 +- rs/moq-video/src/frame.rs | 4 +- rs/moq-wasm/README.md | 4 +- rs/moq-wasm/clippy.toml | 28 +- rs/qmux/Cargo.toml | 3 +- rs/qmux/clippy.toml | 28 +- rs/qmux/examples/common/mod.rs | 4 +- rs/qmux/examples/interop-client.rs | 10 +- rs/qmux/examples/interop-server.rs | 10 +- rs/qmux/src/session.rs | 20 +- rs/qmux/src/session/tests.rs | 20 +- rs/qmux/src/socket.rs | 22 +- rs/qmux/src/transport.rs | 14 +- rs/qmux/src/ws.rs | 2 +- rs/uniffi-bindgen/clippy.toml | 28 +- sh/dispatch-query.test.py | 4 +- sh/rs/select.sh | 6 +- test/interop/clients/rust/finish.rs | 2 +- test/wasm/README.md | 2 +- test/wasm/generator.md | 2 +- 442 files changed, 4703 insertions(+), 4782 deletions(-) rename doc/lib/rs/{moq-clock.md => kio.md} (76%) rename rs/{moq-clock => kio}/clippy.toml (64%) create mode 100644 rs/kio/macros/Cargo.toml rename rs/{moq-clock => kio}/macros/MIGRATE.md (73%) rename rs/{moq-clock => kio}/macros/src/lib.rs (69%) rename rs/{moq-clock/src => kio/src/clock}/deadline.rs (89%) rename rs/{moq-clock/src => kio/src/clock}/installed.rs (89%) rename rs/{moq-clock/src => kio/src/clock}/instant.rs (97%) rename rs/{moq-clock/src => kio/src/clock}/manual.rs (98%) rename rs/{moq-clock/src/lib.rs => kio/src/clock/mod.rs} (90%) rename rs/{moq-clock/src => kio/src/clock}/runtime.rs (84%) rename rs/{moq-clock/src => kio/src/clock}/serde.rs (99%) rename rs/{moq-clock/src => kio/src/clock}/sim.rs (83%) rename rs/{moq-clock/src => kio/src/clock}/timer.rs (88%) rename rs/{moq-clock/src => kio/src/clock}/wall.rs (97%) delete mode 100644 rs/moq-clock/CHANGELOG.md delete mode 100644 rs/moq-clock/Cargo.toml delete mode 100644 rs/moq-clock/MIGRATE.md delete mode 100644 rs/moq-clock/README.md delete mode 100644 rs/moq-clock/macros/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index d43faae9d44..2c177a748f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3567,7 +3567,6 @@ dependencies = [ "derive_more 2.1.1", "hex", "kio 0.6.2", - "moq-clock", "moq-json", "moq-mux", "moq-net", @@ -4601,11 +4600,23 @@ dependencies = [ "criterion", "crossbeam-epoch", "futures", + "kio 0.6.2", + "kio-macros", "loom", + "serde", + "serde_json", + "serde_with", "smallvec", "tokio", + "wasm-bindgen", + "wasm-bindgen-test", + "web-async", ] +[[package]] +name = "kio-macros" +version = "0.1.0" + [[package]] name = "kqueue" version = "1.2.1" @@ -5005,7 +5016,6 @@ dependencies = [ "criterion", "futures", "kio 0.6.2", - "moq-clock", "moq-net", "object_store", "percent-encoding", @@ -5031,7 +5041,6 @@ dependencies = [ "dispatch2", "hang", "kio 0.6.2", - "moq-clock", "moq-mux", "moq-net", "objc2 0.6.5", @@ -5066,7 +5075,6 @@ dependencies = [ "kio 0.6.2", "moq-auth 0.2.1", "moq-auth 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "moq-clock", "moq-pattern 0.1.2", "moq-token", "p256", @@ -5114,7 +5122,7 @@ version = "0.0.1" dependencies = [ "anyhow", "humantime", - "moq-clock", + "kio 0.6.2", "moq-net", "moq-tokio", "moq-uring", @@ -5137,8 +5145,8 @@ dependencies = [ "boytacean", "bytes", "hang", + "kio 0.6.2", "moq-audio", - "moq-clock", "moq-json", "moq-mux", "moq-net", @@ -5160,7 +5168,6 @@ dependencies = [ "hang", "kio 0.6.2", "moq-audio", - "moq-clock", "moq-json", "moq-loc", "moq-mux", @@ -5203,11 +5210,11 @@ dependencies = [ "futures", "hang", "humantime", + "kio 0.6.2", "libc", "moq-archive", "moq-audio", "moq-auth 0.2.1", - "moq-clock", "moq-hls", "moq-json", "moq-mux", @@ -5241,33 +5248,12 @@ dependencies = [ "winit", ] -[[package]] -name = "moq-clock" -version = "0.11.0" -dependencies = [ - "futures", - "kio 0.6.2", - "moq-clock", - "moq-clock-macros", - "serde", - "serde_json", - "serde_with", - "tokio", - "wasm-bindgen", - "wasm-bindgen-test", - "web-async", -] - -[[package]] -name = "moq-clock-macros" -version = "0.1.0" - [[package]] name = "moq-congestion" version = "0.1.0" dependencies = [ "cpu-time", - "moq-clock", + "kio 0.6.2", "rand 0.10.3", "rand_pcg", "stats_alloc", @@ -5300,7 +5286,6 @@ dependencies = [ "kio 0.6.2", "libc", "moq-audio", - "moq-clock", "moq-json", "moq-mux", "moq-net", @@ -5344,8 +5329,8 @@ dependencies = [ "gstreamer", "gstreamer-audio", "hang", + "kio 0.6.2", "moq-audio", - "moq-clock", "moq-mux", "moq-net", "moq-tokio", @@ -5369,7 +5354,6 @@ dependencies = [ "kio 0.6.2", "m3u8-rs", "moq-archive", - "moq-clock", "moq-json", "moq-mux", "moq-net", @@ -5392,7 +5376,7 @@ dependencies = [ name = "moq-ice" version = "0.1.0" dependencies = [ - "moq-clock", + "kio 0.6.2", "str0m", "stun-types", "thiserror 2.0.21", @@ -5454,7 +5438,6 @@ dependencies = [ "kio 0.6.2", "libc", "memchr", - "moq-clock", "moq-flate", "moq-json", "moq-loc", @@ -5498,7 +5481,6 @@ dependencies = [ "kio 0.6.2", "libc", "loom", - "moq-clock", "moq-pattern 0.1.2", "num_enum", "rand 0.10.3", @@ -5527,7 +5509,7 @@ name = "moq-net-tests" version = "0.0.0" dependencies = [ "futures", - "moq-clock", + "kio 0.6.2", "moq-json", "moq-net", "serde_json", @@ -5576,8 +5558,8 @@ dependencies = [ "getrandom 0.4.3", "hex-literal", "indexmap 2.14.2", + "kio 0.6.2", "lru-slab", - "moq-clock", "moq-congestion", "moq-quic", "proptest", @@ -5627,7 +5609,6 @@ dependencies = [ "kio 0.6.2", "libc", "moq-auth 0.2.1", - "moq-clock", "moq-congestion", "moq-net", "moq-quic", @@ -5672,7 +5653,6 @@ version = "0.2.11" dependencies = [ "kio 0.6.2", "moq-auth 0.2.1", - "moq-clock", "moq-json", "moq-net", "moq-tokio", @@ -5688,7 +5668,7 @@ dependencies = [ "axum", "bytes", "hang", - "moq-clock", + "kio 0.6.2", "moq-ice", "moq-mux", "moq-net", @@ -5714,7 +5694,7 @@ dependencies = [ "futures", "hang", "hmac 0.13.0", - "moq-clock", + "kio 0.6.2", "moq-mux", "moq-net", "moq-tokio", @@ -5736,7 +5716,7 @@ dependencies = [ "base64 0.23.1", "futures", "hang", - "moq-clock", + "kio 0.6.2", "moq-mux", "moq-net", "moq-tokio", @@ -5759,7 +5739,6 @@ dependencies = [ "image", "kio 0.6.2", "moq-audio", - "moq-clock", "moq-mux", "moq-net", "moq-video", @@ -5780,7 +5759,7 @@ dependencies = [ "clap", "humantime", "humantime-serde", - "moq-clock", + "kio 0.6.2", "rand 0.10.3", "serde", "serde_json", @@ -5826,7 +5805,7 @@ version = "0.2.12" dependencies = [ "criterion", "futures", - "moq-clock", + "kio 0.6.2", "moq-json", "moq-net", "serde", @@ -5847,8 +5826,8 @@ dependencies = [ "eframe", "egui", "egui_dock", + "kio 0.6.2", "moq-audio", - "moq-clock", "moq-mux", "moq-net", "moq-relay", @@ -5901,7 +5880,6 @@ dependencies = [ "kio 0.6.2", "libc", "mdns-sd", - "moq-clock", "moq-congestion", "moq-ice", "moq-net", @@ -5956,7 +5934,6 @@ dependencies = [ "bytes", "hang", "kio 0.6.2", - "moq-clock", "moq-mux", "moq-net", "moq-tokio", @@ -5979,7 +5956,6 @@ dependencies = [ "io-uring", "kio 0.6.2", "libc", - "moq-clock", "moq-congestion", "moq-net", "moq-quic", @@ -6048,7 +6024,6 @@ dependencies = [ "libloading 0.9.0", "libvpx-native-sys", "linux-raw-sys 0.12.1", - "moq-clock", "moq-mux", "moq-net", "moq-nvenc", @@ -8225,7 +8200,6 @@ dependencies = [ "futures", "kio 0.6.2", "libc", - "moq-clock", "moq-net", "moq-quic", "qmux 0.6.5", diff --git a/Cargo.toml b/Cargo.toml index c96c253118d..3edd4ef35a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,12 @@ [workspace] # Keep source-only members discoverable in Maturin's dependency-pruned archive, # including the separately packaged UniFFI generator. -members = ["demo/carla/bridge", "rs/*", "rs/moq-clock/macros", "rs/moq-net/fuzz", "rs/moq-quic/fuzz"] +members = ["demo/carla/bridge", "rs/*", "rs/kio/macros", "rs/moq-net/fuzz", "rs/moq-quic/fuzz"] default-members = [ "rs/kio", + "rs/kio/macros", "rs/hang", # "rs/moq-c", # requires C toolchain - "rs/moq-clock", - "rs/moq-clock/macros", "rs/moq-congestion", "rs/moq-archive", "rs/moq-auth", @@ -127,6 +126,7 @@ indexmap = "2.14.2" io-uring = "0.7.15" jsonwebtoken = "11" kio = { version = "0.6.2", path = "rs/kio" } +kio-macros = { version = "0.1.0", path = "rs/kio/macros" } libc = "0.2" libloading = "0.9" linux-raw-sys = { version = "0.12.1", features = ["ioctl"] } @@ -139,8 +139,6 @@ mdns-sd = { version = "0.21", features = ["async"] } moq-archive = { version = "0.0.11", path = "rs/moq-archive" } moq-audio = { version = "0.1.10", path = "rs/moq-audio", default-features = false } moq-auth = { version = "0.2.1", path = "rs/moq-auth" } -moq-clock = { version = "0.11.0", path = "rs/moq-clock" } -moq-clock-macros = { version = "0.1.0", path = "rs/moq-clock/macros" } moq-congestion = { version = "0.1.0", path = "rs/moq-congestion" } moq-flate = { version = "0.2.0", path = "rs/moq-flate" } moq-hls = { version = "0.5.11", path = "rs/moq-hls", default-features = false } diff --git a/doc/.vitepress/config.ts b/doc/.vitepress/config.ts index 54eb955d650..0f94fdcc1a5 100644 --- a/doc/.vitepress/config.ts +++ b/doc/.vitepress/config.ts @@ -207,7 +207,7 @@ export default defineConfig({ { text: "moq-room", link: "/lib/rs/moq-room" }, { text: "moq-json", link: "/lib/rs/moq-json" }, { text: "moq-flate", link: "/lib/rs/moq-flate" }, - { text: "moq-clock", link: "/lib/rs/moq-clock" }, + { text: "kio", link: "/lib/rs/kio" }, ], }, { diff --git a/doc/lib/rs/index.md b/doc/lib/rs/index.md index ba5dbdab825..73d6e8225aa 100644 --- a/doc/lib/rs/index.md +++ b/doc/lib/rs/index.md @@ -39,7 +39,7 @@ see [Applications](/bin/). [Examples](/setup/examples) links runnable consumers; | [moq-e2ee](https://github.com/moq-dev/moq/tree/main/rs/moq-e2ee) | Workspace-only end-to-end encryption of groups, datagrams, and track names, scoped to a publisher epoch. | | [moq-loc](https://docs.rs/moq-loc), [moq-msf](https://docs.rs/moq-msf) | The IETF LOC container and MSF catalog. | | [moq-stats](https://docs.rs/moq-stats) | Publish and consume relay traffic counters as tracks. | -| [moq-clock](/lib/rs/moq-clock) | One clock for time and timers on tokio, the browser, and a deterministic test simulator. | +| [kio](/lib/rs/kio) | The async primitives everything polls through, and one clock for time and timers on tokio, the browser, and a deterministic test simulator. | | [moq-hls](https://docs.rs/moq-hls), [moq-rtmp](https://docs.rs/moq-rtmp), [moq-srt](https://docs.rs/moq-srt), [moq-rtsp](https://github.com/moq-dev/moq/tree/main/rs/moq-rtsp), [moq-rtc](https://docs.rs/moq-rtc) | The [gateways](/bin/), as libraries you can embed with your own auth. | | [moq-ffi](https://docs.rs/moq-ffi), [moq-c](/lib/c/) | The UniFFI core behind the language bindings, and the C ABI. | | [moq-relay](/bin/relay/), [moq-cli](/bin/cli) | The binaries, also usable as crates. | diff --git a/doc/lib/rs/moq-clock.md b/doc/lib/rs/kio.md similarity index 76% rename from doc/lib/rs/moq-clock.md rename to doc/lib/rs/kio.md index 24841d6e246..77bec2bb37f 100644 --- a/doc/lib/rs/moq-clock.md +++ b/doc/lib/rs/kio.md @@ -1,19 +1,20 @@ --- -title: moq-clock -description: One clock for time, timers, and deterministic tests +title: kio +description: Async primitives, and one clock for time, timers, and deterministic tests --- -# moq-clock +# kio -[![crates.io](https://img.shields.io/crates/v/moq-clock)](https://crates.io/crates/moq-clock) -[![docs.rs](https://docs.rs/moq-clock/badge.svg)](https://docs.rs/moq-clock) +[![crates.io](https://img.shields.io/crates/v/kio)](https://crates.io/crates/kio) +[![docs.rs](https://docs.rs/kio/badge.svg)](https://docs.rs/kio) -One clock for reading time and arming timers, so the same code runs on tokio, +The "easy async" primitives the other crates poll through, and `kio::clock`: +one clock for reading time and arming timers, so the same code runs on tokio, in the browser, and in a simulator that tests drive. ## The clock -`moq_clock::Instant` is a monotonic instant, counted in nanoseconds from the +`kio::clock::Instant` is a monotonic instant, counted in nanoseconds from the clock's origin, with the methods of `std::time::Instant`. `Wall` is wall time from the same clock. It is a separate type because wall time can step forward or back without any time passing, so it never measures elapsed time. @@ -28,6 +29,14 @@ and it pauses the instant but not wall time. The simulator is its own clock too. A runtime that reads the time itself, like a moq-uring worker, enters a `Deadlines` queue on its thread, and the ambient clock is that queue. +Host timers need the `runtime` feature, which is off by default so a kio user +that never waits on the host clock compiles no runtime backend: + +```toml +[dependencies] +kio = { version = "0.6", features = ["runtime"] } +``` + Instants from different clocks don't compare. On native, `Instant::into_std()` and `Instant::from_std()` convert at a third-party API that takes `std::time::Instant`, through the runtime clock's origin. That is exact on a @@ -51,19 +60,19 @@ for dev-dependencies only: ```toml [dev-dependencies] -moq-clock = { version = "0.11", features = ["sim"] } +kio = { version = "0.6", features = ["sim"] } ``` ```rust use std::time::Duration; -#[moq_clock::test] +#[kio::test] async fn gives_up_after_five_seconds() { - let task = moq_clock::sim::spawn(async { - moq_clock::timeout(Duration::from_secs(5), std::future::pending::<()>()).await + let task = kio::clock::sim::spawn(async { + kio::clock::timeout(Duration::from_secs(5), std::future::pending::<()>()).await }); assert!(task.await.unwrap().is_err()); - assert_eq!(moq_clock::now(), moq_clock::Instant::ZERO + Duration::from_secs(5)); + assert_eq!(kio::clock::now(), kio::clock::Instant::ZERO + Duration::from_secs(5)); } ``` @@ -88,4 +97,4 @@ reaches them, and other runtimes and threads keep the host clock. Python's Tests that do real I/O (sockets, browsers, codecs) can't use the simulator. They wait on events and use the host clock only for a watchdog. -API: [docs.rs/moq-clock](https://docs.rs/moq-clock). +API: [docs.rs/kio](https://docs.rs/kio). diff --git a/doc/setup/repository.md b/doc/setup/repository.md index fa64a993050..43d8e82db5e 100644 --- a/doc/setup/repository.md +++ b/doc/setup/repository.md @@ -32,7 +32,7 @@ wrap the Rust core. [Layers](/lib/layers) maps the binding namespaces. | Language bindings | [`rs/moq-ffi`](https://github.com/moq-dev/moq/tree/main/rs/moq-ffi), [`rs/moq-c`](https://github.com/moq-dev/moq/tree/main/rs/moq-c), then `py/`, `swift/`, `kt/`, `go/`, `dart/`, or `cpp/moq/` | [Binding layers](/lib/layers) | | Rooms, chat, and application data | [`rs/moq-room`](https://github.com/moq-dev/moq/tree/main/rs/moq-room), [`js/room`](https://github.com/moq-dev/moq/tree/main/js/room), `rs/moq-json`, `js/json` | [Rooms](/lib/js/room), [JSON tracks](/lib/js/json) | | End-to-end encryption | [`rs/moq-e2ee`](https://github.com/moq-dev/moq/tree/main/rs/moq-e2ee), [`js/e2ee`](https://github.com/moq-dev/moq/tree/main/js/e2ee) | [Media encryption](/concept/hang), [E2EE draft](/draft/moq-e2ee) | -| Async primitives and deterministic time | [`rs/kio`](https://github.com/moq-dev/moq/tree/main/rs/kio), [`rs/moq-clock`](https://github.com/moq-dev/moq/tree/main/rs/moq-clock), [`js/clock`](https://github.com/moq-dev/moq/tree/main/js/clock) | [Rust conventions](/lib/rs/#conventions), [clock](/lib/js/clock) | +| Async primitives and deterministic time | [`rs/kio`](https://github.com/moq-dev/moq/tree/main/rs/kio), [`js/clock`](https://github.com/moq-dev/moq/tree/main/js/clock) | [Rust conventions](/lib/rs/#conventions), [clock](/lib/js/clock) | ## Find the surrounding work diff --git a/doc/setup/upgrade.md b/doc/setup/upgrade.md index ee1ecd9583b..81694b87350 100644 --- a/doc/setup/upgrade.md +++ b/doc/setup/upgrade.md @@ -27,7 +27,7 @@ replaces it. - **Binaries:** [moq-relay](https://github.com/moq-dev/moq/blob/main/rs/moq-relay/MIGRATE.md), [moq-cli (`moq`)](https://github.com/moq-dev/moq/blob/main/rs/moq-cli/MIGRATE.md), [moq-gst](https://github.com/moq-dev/moq/blob/main/rs/moq-gst/MIGRATE.md), [obs-moq](https://github.com/moq-dev/moq/blob/main/cpp/obs/MIGRATE.md) - **Bindings:** [moq-ffi (UniFFI)](https://github.com/moq-dev/moq/blob/main/rs/moq-ffi/MIGRATE.md), [moq-c (C)](https://github.com/moq-dev/moq/blob/main/rs/moq-c/MIGRATE.md), [Python](https://github.com/moq-dev/moq/blob/main/py/moq-rs/MIGRATE.md), [Go](https://github.com/moq-dev/moq/blob/main/go/wrapper/MIGRATE.md), [Swift](https://github.com/moq-dev/moq/blob/main/swift/MIGRATE.md), [Kotlin](https://github.com/moq-dev/moq/blob/main/kt/moq/MIGRATE.md), [Dart](https://github.com/moq-dev/moq/blob/main/dart/moq/MIGRATE.md), [C++](https://github.com/moq-dev/moq/blob/main/cpp/moq/MIGRATE.md) -- **Rust:** [hang](https://github.com/moq-dev/moq/blob/main/rs/hang/MIGRATE.md), [kio](https://github.com/moq-dev/moq/blob/main/rs/kio/MIGRATE.md), [moq-archive](https://github.com/moq-dev/moq/blob/main/rs/moq-archive/MIGRATE.md), [moq-audio](https://github.com/moq-dev/moq/blob/main/rs/moq-audio/MIGRATE.md), [moq-auth](https://github.com/moq-dev/moq/blob/main/rs/moq-auth/MIGRATE.md), [moq-boy](https://github.com/moq-dev/moq/blob/main/rs/moq-boy/MIGRATE.md), [moq-clock](https://github.com/moq-dev/moq/blob/main/rs/moq-clock/MIGRATE.md), [moq-clock-macros](https://github.com/moq-dev/moq/blob/main/rs/moq-clock/macros/MIGRATE.md), [moq-e2ee](https://github.com/moq-dev/moq/blob/main/rs/moq-e2ee/MIGRATE.md), [moq-flate](https://github.com/moq-dev/moq/blob/main/rs/moq-flate/MIGRATE.md), [moq-hls](https://github.com/moq-dev/moq/blob/main/rs/moq-hls/MIGRATE.md), [moq-ice](https://github.com/moq-dev/moq/blob/main/rs/moq-ice/MIGRATE.md), [moq-json](https://github.com/moq-dev/moq/blob/main/rs/moq-json/MIGRATE.md), [moq-loc](https://github.com/moq-dev/moq/blob/main/rs/moq-loc/MIGRATE.md), [moq-msf](https://github.com/moq-dev/moq/blob/main/rs/moq-msf/MIGRATE.md), [moq-mux](https://github.com/moq-dev/moq/blob/main/rs/moq-mux/MIGRATE.md), [moq-net](https://github.com/moq-dev/moq/blob/main/rs/moq-net/MIGRATE.md), [moq-nvenc](https://github.com/moq-dev/moq/blob/main/rs/moq-nvenc/MIGRATE.md), [moq-pattern](https://github.com/moq-dev/moq/blob/main/rs/moq-pattern/MIGRATE.md), [moq-quic](https://github.com/moq-dev/moq/blob/main/rs/moq-quic/MIGRATE.md), [moq-room](https://github.com/moq-dev/moq/blob/main/rs/moq-room/MIGRATE.md), [moq-rtc](https://github.com/moq-dev/moq/blob/main/rs/moq-rtc/MIGRATE.md), [moq-rtmp](https://github.com/moq-dev/moq/blob/main/rs/moq-rtmp/MIGRATE.md), [moq-sock](https://github.com/moq-dev/moq/blob/main/rs/moq-sock/MIGRATE.md), [moq-srt](https://github.com/moq-dev/moq/blob/main/rs/moq-srt/MIGRATE.md), [moq-stats](https://github.com/moq-dev/moq/blob/main/rs/moq-stats/MIGRATE.md), [moq-tokio](https://github.com/moq-dev/moq/blob/main/rs/moq-tokio/MIGRATE.md), [moq-transcode](https://github.com/moq-dev/moq/blob/main/rs/moq-transcode/MIGRATE.md), [moq-uring](https://github.com/moq-dev/moq/blob/main/rs/moq-uring/MIGRATE.md), [moq-v4l](https://github.com/moq-dev/moq/blob/main/rs/moq-v4l/MIGRATE.md), [moq-video](https://github.com/moq-dev/moq/blob/main/rs/moq-video/MIGRATE.md), [qmux](https://github.com/moq-dev/moq/blob/main/rs/qmux/MIGRATE.md) +- **Rust:** [hang](https://github.com/moq-dev/moq/blob/main/rs/hang/MIGRATE.md), [kio](https://github.com/moq-dev/moq/blob/main/rs/kio/MIGRATE.md), [kio-macros](https://github.com/moq-dev/moq/blob/main/rs/kio/macros/MIGRATE.md), [moq-archive](https://github.com/moq-dev/moq/blob/main/rs/moq-archive/MIGRATE.md), [moq-audio](https://github.com/moq-dev/moq/blob/main/rs/moq-audio/MIGRATE.md), [moq-auth](https://github.com/moq-dev/moq/blob/main/rs/moq-auth/MIGRATE.md), [moq-boy](https://github.com/moq-dev/moq/blob/main/rs/moq-boy/MIGRATE.md), [moq-e2ee](https://github.com/moq-dev/moq/blob/main/rs/moq-e2ee/MIGRATE.md), [moq-flate](https://github.com/moq-dev/moq/blob/main/rs/moq-flate/MIGRATE.md), [moq-hls](https://github.com/moq-dev/moq/blob/main/rs/moq-hls/MIGRATE.md), [moq-ice](https://github.com/moq-dev/moq/blob/main/rs/moq-ice/MIGRATE.md), [moq-json](https://github.com/moq-dev/moq/blob/main/rs/moq-json/MIGRATE.md), [moq-loc](https://github.com/moq-dev/moq/blob/main/rs/moq-loc/MIGRATE.md), [moq-msf](https://github.com/moq-dev/moq/blob/main/rs/moq-msf/MIGRATE.md), [moq-mux](https://github.com/moq-dev/moq/blob/main/rs/moq-mux/MIGRATE.md), [moq-net](https://github.com/moq-dev/moq/blob/main/rs/moq-net/MIGRATE.md), [moq-nvenc](https://github.com/moq-dev/moq/blob/main/rs/moq-nvenc/MIGRATE.md), [moq-pattern](https://github.com/moq-dev/moq/blob/main/rs/moq-pattern/MIGRATE.md), [moq-quic](https://github.com/moq-dev/moq/blob/main/rs/moq-quic/MIGRATE.md), [moq-room](https://github.com/moq-dev/moq/blob/main/rs/moq-room/MIGRATE.md), [moq-rtc](https://github.com/moq-dev/moq/blob/main/rs/moq-rtc/MIGRATE.md), [moq-rtmp](https://github.com/moq-dev/moq/blob/main/rs/moq-rtmp/MIGRATE.md), [moq-sock](https://github.com/moq-dev/moq/blob/main/rs/moq-sock/MIGRATE.md), [moq-srt](https://github.com/moq-dev/moq/blob/main/rs/moq-srt/MIGRATE.md), [moq-stats](https://github.com/moq-dev/moq/blob/main/rs/moq-stats/MIGRATE.md), [moq-tokio](https://github.com/moq-dev/moq/blob/main/rs/moq-tokio/MIGRATE.md), [moq-transcode](https://github.com/moq-dev/moq/blob/main/rs/moq-transcode/MIGRATE.md), [moq-uring](https://github.com/moq-dev/moq/blob/main/rs/moq-uring/MIGRATE.md), [moq-v4l](https://github.com/moq-dev/moq/blob/main/rs/moq-v4l/MIGRATE.md), [moq-video](https://github.com/moq-dev/moq/blob/main/rs/moq-video/MIGRATE.md), [qmux](https://github.com/moq-dev/moq/blob/main/rs/qmux/MIGRATE.md) - **JavaScript:** [`@moq/auth`](https://github.com/moq-dev/moq/blob/main/js/auth/MIGRATE.md), [`@moq/boy`](https://github.com/moq-dev/moq/blob/main/js/moq-boy/MIGRATE.md), [`@moq/clock`](https://github.com/moq-dev/moq/blob/main/js/clock/MIGRATE.md), [`@moq/flate`](https://github.com/moq-dev/moq/blob/main/js/flate/MIGRATE.md), [`@moq/hang`](https://github.com/moq-dev/moq/blob/main/js/hang/MIGRATE.md), [`@moq/json`](https://github.com/moq-dev/moq/blob/main/js/json/MIGRATE.md), [`@moq/loc`](https://github.com/moq-dev/moq/blob/main/js/loc/MIGRATE.md), [`@moq/msf`](https://github.com/moq-dev/moq/blob/main/js/msf/MIGRATE.md), [`@moq/net`](https://github.com/moq-dev/moq/blob/main/js/net/MIGRATE.md), [`@moq/p2p`](https://github.com/moq-dev/moq/blob/main/js/p2p/MIGRATE.md), [`@moq/pattern`](https://github.com/moq-dev/moq/blob/main/js/pattern/MIGRATE.md), [`@moq/publish`](https://github.com/moq-dev/moq/blob/main/js/publish/MIGRATE.md), [`@moq/qmux`](https://github.com/moq-dev/moq/blob/main/js/qmux/MIGRATE.md), [`@moq/room`](https://github.com/moq-dev/moq/blob/main/js/room/MIGRATE.md), [`@moq/signals`](https://github.com/moq-dev/moq/blob/main/js/signals/MIGRATE.md), [`@moq/ui`](https://github.com/moq-dev/moq/blob/main/js/ui/MIGRATE.md), [`@moq/video`](https://github.com/moq-dev/moq/blob/main/js/video/MIGRATE.md), [`@moq/watch`](https://github.com/moq-dev/moq/blob/main/js/watch/MIGRATE.md) ## Unreleased diff --git a/js/clock/src/index.ts b/js/clock/src/index.ts index 47f93c41334..4ce8c6e9dac 100644 --- a/js/clock/src/index.ts +++ b/js/clock/src/index.ts @@ -20,7 +20,7 @@ export function wall(): Wall { /** * Read the installed clock's wall time at instant zero, in Unix milliseconds. - * Rust's `moq_clock::origin()` pairs a nanosecond `Wall` with an instant instead. + * Rust's `kio::clock::origin()` pairs a nanosecond `Wall` with an instant instead. */ export function origin(): Wall { return Wall(backend().origin()); diff --git a/rs/AGENTS.md b/rs/AGENTS.md index b0ee466bad2..6946ae96a0f 100644 --- a/rs/AGENTS.md +++ b/rs/AGENTS.md @@ -56,7 +56,7 @@ Prefer poll. New logic is a `poll_*` with an `async` helper, not the other way a # Testing -- Tests are inline `#[cfg(test)] mod tests`, except full Client/Server session tests over a crate's shared mock harness, which go in its `tests/integration/` module. Time-dependent async tests call `tokio::time::pause()` first (moq-net uses `#[moq_clock::test]` instead), unless they cross real networking that can't be mocked (sockets, smoke tests); those run on the wall clock and assert lower bounds. +- Tests are inline `#[cfg(test)] mod tests`, except full Client/Server session tests over a crate's shared mock harness, which go in its `tests/integration/` module. Time-dependent async tests call `tokio::time::pause()` first (moq-net uses `#[kio::test]` instead), unless they cross real networking that can't be mocked (sockets, smoke tests); those run on the wall clock and assert lower bounds. - Run tests through `just` (nextest), not `cargo test`: nextest kills a wedged test as TIMEOUT, cargo hangs forever. A test flagged SLOW is a bug to fix, not a threshold to raise. - `just check` and CI compile the selected crates at default and extreme feature sets, with isolated boundary checks. `just rs features` (nightly) covers the full matrix. Keep a feature gate around the dependency, not the logic, so the logic's tests stay in the merge gate. - Local checks compile only the host platform; Nightly and release PRs run `just rs windows` / `macos` on those hosts, and `just rs wasm` covers `moq-wasm`. diff --git a/rs/hang/Cargo.toml b/rs/hang/Cargo.toml index 3c59a1a0ddb..3370a7768dc 100644 --- a/rs/hang/Cargo.toml +++ b/rs/hang/Cargo.toml @@ -15,8 +15,7 @@ categories = ["multimedia", "network-programming", "web-programming"] [dependencies] bytes = { workspace = true } hex = { workspace = true } -kio = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-json = { workspace = true } moq-net = { workspace = true } regex = "1" diff --git a/rs/hang/clippy.toml b/rs/hang/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/hang/clippy.toml +++ b/rs/hang/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/hang/examples/video.rs b/rs/hang/examples/video.rs index d61cfc54022..899b59c8807 100644 --- a/rs/hang/examples/video.rs +++ b/rs/hang/examples/video.rs @@ -103,7 +103,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()> }; producer.write(frame)?; - moq_clock::sleep(tokio::time::Duration::from_secs(1)).await; + kio::clock::sleep(tokio::time::Duration::from_secs(1)).await; let frame = moq_mux::container::Frame { timestamp: moq_net::Timestamp::from_secs(2).unwrap(), @@ -113,7 +113,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()> }; producer.write(frame)?; - moq_clock::sleep(tokio::time::Duration::from_secs(1)).await; + kio::clock::sleep(tokio::time::Duration::from_secs(1)).await; // Marking this frame as a keyframe closes the current group and starts a new one. let frame = moq_mux::container::Frame { @@ -125,7 +125,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()> producer.write(frame)?; // Sleep before exiting and closing the broadcast. - moq_clock::sleep(tokio::time::Duration::from_secs(10)).await; + kio::clock::sleep(tokio::time::Duration::from_secs(10)).await; Ok(()) } diff --git a/rs/hang/src/catalog/clock.rs b/rs/hang/src/catalog/clock.rs index 0f39b6118d3..85c0fafb266 100644 --- a/rs/hang/src/catalog/clock.rs +++ b/rs/hang/src/catalog/clock.rs @@ -67,7 +67,7 @@ impl Clock { /// /// Exact down to the nanosecond; an instant finer than that (a 90 kHz tick) is floored. /// Refuses a result past the JSON-safe range or the wall clock's 1970-2554 range. - pub fn wall_clock(&self, pts: moq_net::Timestamp) -> Result { + pub fn wall_clock(&self, pts: moq_net::Timestamp) -> Result { let overflow = || crate::Error::TimestampOverflow(moq_net::TimeOverflow); let wall_scale = self.wall.scale().as_u64() as u128; let pts_scale = pts.scale().as_u64() as u128; @@ -90,7 +90,7 @@ impl Clock { let nanos = (num % den).checked_mul(1_000_000_000).ok_or_else(overflow)? / den; let since_moq_epoch = std::time::Duration::new(secs, nanos as u32); // A catalog can name a wall beyond the clock's nanosecond range. - moq_clock::Wall::UNIX_EPOCH + kio::clock::Wall::UNIX_EPOCH .checked_add(std::time::Duration::from_millis(MOQ_EPOCH_UNIX_MILLIS)) .and_then(|moq_epoch| moq_epoch.checked_add(since_moq_epoch)) .ok_or_else(overflow) @@ -187,13 +187,13 @@ mod test { #[test] fn wall_clock_converts_across_timescales() { let clock = Clock::new(moq_net::Timestamp::from_micros(1_000_000).unwrap()).unwrap(); - let epoch = moq_clock::Wall::UNIX_EPOCH + std::time::Duration::from_millis(MOQ_EPOCH_UNIX_MILLIS + 1_000); + let epoch = kio::clock::Wall::UNIX_EPOCH + std::time::Duration::from_millis(MOQ_EPOCH_UNIX_MILLIS + 1_000); assert_eq!( clock.wall_clock(moq_net::Timestamp::from_millis(0).unwrap()).unwrap(), epoch ); - let second = moq_clock::Wall::UNIX_EPOCH + std::time::Duration::from_millis(MOQ_EPOCH_UNIX_MILLIS + 2_000); + let second = kio::clock::Wall::UNIX_EPOCH + std::time::Duration::from_millis(MOQ_EPOCH_UNIX_MILLIS + 2_000); assert_eq!( clock .wall_clock(moq_net::Timestamp::from_millis(1000).unwrap()) @@ -217,7 +217,7 @@ mod test { /// Regression: the result was floored to the millisecond, dropping the sub-millisecond part. #[test] fn wall_clock_keeps_sub_millisecond_precision() { - let moq_epoch = moq_clock::Wall::UNIX_EPOCH + std::time::Duration::from_millis(MOQ_EPOCH_UNIX_MILLIS); + let moq_epoch = kio::clock::Wall::UNIX_EPOCH + std::time::Duration::from_millis(MOQ_EPOCH_UNIX_MILLIS); let micros = |v| moq_net::Timestamp::from_micros(v).unwrap(); let nanos = std::time::Duration::from_nanos; diff --git a/rs/hang/src/catalog/root.rs b/rs/hang/src/catalog/root.rs index 0c90a55b35a..1f6446f0d77 100644 --- a/rs/hang/src/catalog/root.rs +++ b/rs/hang/src/catalog/root.rs @@ -1074,7 +1074,7 @@ mod test { ); // Record PTS 2000 (ms) lands 2s after the wall epoch, whatever the track timescale. - let expected = moq_clock::Wall::UNIX_EPOCH + let expected = kio::clock::Wall::UNIX_EPOCH + std::time::Duration::from_millis(crate::catalog::MOQ_EPOCH_UNIX_MILLIS + 1_751_846_402_000); assert_eq!( clock diff --git a/rs/hang/src/echo.rs b/rs/hang/src/echo.rs index afd380bb0fe..db483066af0 100644 --- a/rs/hang/src/echo.rs +++ b/rs/hang/src/echo.rs @@ -77,12 +77,12 @@ pub struct Arrival { pub timestamp: moq_net::Timestamp, /// The arrival wall time, encoded in milliseconds since the MoQ epoch. #[serde_as(as = "crate::snapshot::Wall")] - pub wall: moq_clock::Wall, + pub wall: kio::clock::Wall, } impl Arrival { /// Pair a received media timestamp with the wall time it arrived. - pub fn new(timestamp: moq_net::Timestamp, wall: moq_clock::Wall) -> Self { + pub fn new(timestamp: moq_net::Timestamp, wall: kio::clock::Wall) -> Self { Self { timestamp, wall } } } diff --git a/rs/hang/src/snapshot.rs b/rs/hang/src/snapshot.rs index 9f9ba99637f..d3df579aa3c 100644 --- a/rs/hang/src/snapshot.rs +++ b/rs/hang/src/snapshot.rs @@ -50,19 +50,19 @@ impl<'de> DeserializeAs<'de, moq_net::Timestamp> for Millis { } pub(crate) struct Wall; -fn epoch() -> moq_clock::Wall { - moq_clock::Wall::UNIX_EPOCH + Duration::from_millis(crate::catalog::MOQ_EPOCH_UNIX_MILLIS) +fn epoch() -> kio::clock::Wall { + kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(crate::catalog::MOQ_EPOCH_UNIX_MILLIS) } -impl SerializeAs for Wall { - fn serialize_as(value: &moq_clock::Wall, serializer: S) -> Result { +impl SerializeAs for Wall { + fn serialize_as(value: &kio::clock::Wall, serializer: S) -> Result { let duration = value .checked_duration_since(epoch()) .ok_or_else(|| serde::ser::Error::custom("snapshot wall is before the MoQ epoch"))?; Millis::serialize_as(&duration, serializer) } } -impl<'de> DeserializeAs<'de, moq_clock::Wall> for Wall { - fn deserialize_as>(deserializer: D) -> Result { +impl<'de> DeserializeAs<'de, kio::clock::Wall> for Wall { + fn deserialize_as>(deserializer: D) -> Result { epoch() .checked_add(Millis::deserialize_as(deserializer)?) .ok_or_else(|| serde::de::Error::custom("snapshot wall clock overflow")) @@ -90,7 +90,7 @@ mod tests { #[derive(Debug, Serialize, Deserialize)] struct Value { #[serde_as(as = "Wall")] - wall: moq_clock::Wall, + wall: kio::clock::Wall, } let last_millis = (u64::MAX / 1_000_000) - crate::catalog::MOQ_EPOCH_UNIX_MILLIS; let last = format!(r#"{{"wall":{last_millis}}}"#); diff --git a/rs/justfile b/rs/justfile index 437114da920..022ec56bb20 100644 --- a/rs/justfile +++ b/rs/justfile @@ -197,25 +197,25 @@ android *args: # build sees the code. Not to be confused with `just js wasm`, which builds the # shippable `@moq/wasm` package. `moq-mux` and `moq-ffi` share the invocation # because moq-mux needs the getrandom backend only its siblings declare, and -# features unify only within one cargo invocation. `moq-clock` rides along to -# compile its browser clock backend. +# features unify only within one cargo invocation. `kio` rides along to +# lint its browser clock backend. # Compile and lint the browser/WASM bindings, which the host-target check skips. [positional-arguments] wasm *args: - bash sh/local.sh cargo clippy --locked -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock --target wasm32-unknown-unknown --lib "$@" -- -D warnings + bash sh/local.sh cargo clippy --locked -p moq-wasm -p moq-mux -p moq-ffi -p kio --target wasm32-unknown-unknown --lib "$@" -- -D warnings # Run the browser clock backend on the root devShell's Playwright Chromium, # with the runtime and with reads alone. wasm-test: - CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" bash sh/local.sh cargo test --locked -p moq-clock --lib --target wasm32-unknown-unknown - CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" bash sh/local.sh cargo test --locked -p moq-clock --lib --target wasm32-unknown-unknown --no-default-features + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" bash sh/local.sh cargo test --locked -p kio --lib --target wasm32-unknown-unknown --features runtime -- clock:: + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER="bun {{ justfile_directory() }}/test/wasm/rust.ts" bash sh/local.sh cargo test --locked -p kio --lib --target wasm32-unknown-unknown -- clock:: # Auto-fix the browser/WASM bindings. [positional-arguments] wasm-fix *args: - bash sh/local.sh cargo clippy --locked --fix --allow-staged --allow-dirty -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock --target wasm32-unknown-unknown --lib "$@" - cargo fmt -p moq-wasm -p moq-mux -p moq-ffi -p moq-clock + bash sh/local.sh cargo clippy --locked --fix --allow-staged --allow-dirty -p moq-wasm -p moq-mux -p moq-ffi -p kio --target wasm32-unknown-unknown --lib "$@" + cargo fmt -p moq-wasm -p moq-mux -p moq-ffi -p kio # Audit dependencies against deny.toml. Nightly: advisories land without a diff. audit: @@ -265,7 +265,7 @@ features: net-features *args: bash sh/rs/net-features.sh "$@" -# Prove moq-quic leaves moq-clock's dev-only runtime to its consumers, and lints without its default features; a workspace build unifies both back in. +# Prove moq-quic leaves kio's dev-only clock runtime to its consumers, and lints without its default features; a workspace build unifies both back in. [positional-arguments] quic-features *args: #!/usr/bin/env bash diff --git a/rs/kio/Cargo.toml b/rs/kio/Cargo.toml index deb8af47795..fd5af944545 100644 --- a/rs/kio/Cargo.toml +++ b/rs/kio/Cargo.toml @@ -9,17 +9,47 @@ version = "0.6.2" edition = "2024" rust-version.workspace = true -keywords = ["async", "producer", "consumer", "state", "sync"] -categories = ["asynchronous", "concurrency"] +keywords = ["async", "producer", "consumer", "clock", "simulation"] +categories = ["asynchronous", "concurrency", "date-and-time", "development-tools::testing"] + +[package.metadata.docs.rs] +features = ["runtime", "manual", "sim", "serde"] + +# The self dev-dependency below only enables features; no code names it. +[package.metadata.cargo-shear] +ignored = ["kio"] [features] -# Per-task Ready poll accounting for deterministic simulators, never production. -_sim = [] +# Lean by default: without `runtime`, the clock compiles no host timer backend. +default = [] +# Host timers: tokio's clock on native, `setTimeout` in the browser. +runtime = ["dep:tokio", "dep:web-async"] +# The deterministic single-threaded executor, `#[kio::test]`, and per-task Ready +# poll accounting. Meant for dev-dependencies, so production builds never compile it. +sim = ["dep:futures", "dep:kio-macros"] +# `clock::Manual::install`: a clock that only a test moves, as one tokio runtime's +# ambient clock. Native only. Meant for test builds, so production builds never compile it. +manual = ["runtime"] +# Numeric Unix-second JSON adapters for public wall times. +serde = ["dep:serde", "dep:serde_with"] [dependencies] # Frees a log's evicted segments once no read that could reach them is running. crossbeam-epoch = "0.9.21" +futures = { workspace = true, optional = true } +kio-macros = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +serde_with = { workspace = true, optional = true } smallvec = { version = "1.15", features = ["union"] } +web-async = { workspace = true, optional = true } + +# The browser's only clocks, read with or without the runtime's timers. +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] +web-async = { workspace = true } + +# The runtime handle, to keep a paused runtime's clock on its own origin. +[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies] +tokio = { workspace = true, features = ["rt", "time"], optional = true } # Loom swaps in its own Arc/Mutex/atomics so it can permute every interleaving. # It's a normal (not dev) dependency because `sync.rs` re-exports it from the @@ -33,8 +63,22 @@ loom = { workspace = true } # Bench-only: the FuturesUnordered comparison in benches/tasks.rs. criterion = { workspace = true } futures = "0.3" +# Enable the simulator so the clock's tests run in the merge gate. The browser +# leaves the runtime to `--features runtime`, so it tests the clock both ways. +kio = { path = ".", features = ["sim", "serde"] } +serde_json = { workspace = true } tokio = { workspace = true, features = ["macros", "rt", "test-util", "time"] } +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies] +# Match the wasm-bindgen CLI schema used by the browser runner. +wasm-bindgen = "=0.2.129" +wasm-bindgen-test = "=0.3.79" + +[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dev-dependencies] +# Test the installed manual clock, which needs tokio's runtime and so is native only. +kio = { path = ".", features = ["manual", "sim", "serde"] } +tokio = { workspace = true, features = ["rt-multi-thread"] } + [[bench]] name = "tasks" harness = false diff --git a/rs/kio/README.md b/rs/kio/README.md index 5118e15effc..1479dbb0c58 100644 --- a/rs/kio/README.md +++ b/rs/kio/README.md @@ -23,6 +23,19 @@ work ready still yields to the rest of its runtime. `log::Writer` is an append-o log whose `log::Reader`s read committed entries by index without a lock, paired with a channel that parks them; evicted entries are freed by epoch-based reclamation. +`clock` is the time those waits run on: logical instants, wall time, deadlines, and +timers on tokio or the browser (the `runtime` feature). The `sim` feature adds a +deterministic executor and `#[kio::test]`, which runs an `async fn` test on it: + +```rust +#[kio::test] +async fn retries_after_a_second() { + let start = kio::clock::now(); // Instant::ZERO + kio::clock::sleep(std::time::Duration::from_secs(1)).await; // returns at once + assert_eq!(kio::clock::now() - start, std::time::Duration::from_secs(1)); +} +``` + It's used internally by [moq-net](https://github.com/moq-dev/moq/tree/main/rs/moq-net) and friends, but is generic enough to be useful on its own. See the [API documentation](https://docs.rs/kio/) for details. diff --git a/rs/kio/benches/contended.rs b/rs/kio/benches/contended.rs index 5af4c25d9b2..550ffea718c 100644 --- a/rs/kio/benches/contended.rs +++ b/rs/kio/benches/contended.rs @@ -21,6 +21,7 @@ //! iteration, a fixed cost that matters only at a few consumers per thread. //! //! Run with `cargo bench -p kio --bench contended`. +#![expect(clippy::disallowed_methods, reason = "host time measures benchmark throughput")] use std::{ collections::VecDeque, diff --git a/rs/moq-clock/clippy.toml b/rs/kio/clippy.toml similarity index 64% rename from rs/moq-clock/clippy.toml rename to rs/kio/clippy.toml index 02e3531782f..cc37fde2264 100644 --- a/rs/moq-clock/clippy.toml +++ b/rs/kio/clippy.toml @@ -1,14 +1,14 @@ -# Only the backend modules (`runtime`, behind `#[allow]`) read a host clock or arm +# Only the clock backend modules (`runtime`, behind `#[expect]`) read a host clock or arm # a host timer; everything else goes through the ambient clock. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, ] diff --git a/rs/kio/macros/Cargo.toml b/rs/kio/macros/Cargo.toml new file mode 100644 index 00000000000..678979bf2db --- /dev/null +++ b/rs/kio/macros/Cargo.toml @@ -0,0 +1,21 @@ +# The `#[kio::test]` attribute. A separate crate only because a proc macro +# must be; `kio` re-exports it behind its `sim` feature. +[package] +name = "kio-macros" +description = "The #[kio::test] attribute; use it through kio's sim feature." +authors = ["Luke Curley"] +repository = "https://github.com/moq-dev/moq" +license = "MIT OR Apache-2.0" + +version = "0.1.0" +edition = "2024" +rust-version.workspace = true + +keywords = ["async", "test", "simulation"] +categories = ["development-tools::testing"] + +[lib] +proc-macro = true + +[lints] +workspace = true diff --git a/rs/moq-clock/macros/MIGRATE.md b/rs/kio/macros/MIGRATE.md similarity index 73% rename from rs/moq-clock/macros/MIGRATE.md rename to rs/kio/macros/MIGRATE.md index f7e0a138a83..1bbdb6962d7 100644 --- a/rs/moq-clock/macros/MIGRATE.md +++ b/rs/kio/macros/MIGRATE.md @@ -1,4 +1,4 @@ -# Migrating moq-clock-macros +# Migrating kio-macros How to update your code for each breaking change, newest first. diff --git a/rs/moq-clock/macros/src/lib.rs b/rs/kio/macros/src/lib.rs similarity index 69% rename from rs/moq-clock/macros/src/lib.rs rename to rs/kio/macros/src/lib.rs index 7afeb162d53..caae817af76 100644 --- a/rs/moq-clock/macros/src/lib.rs +++ b/rs/kio/macros/src/lib.rs @@ -1,14 +1,14 @@ -//! The `#[moq_clock::test]` attribute: an `async fn` test run on the simulator. +//! The `#[kio::test]` attribute: an `async fn` test run on the simulator. //! -//! Use it through `moq-clock`'s `sim` feature, which re-exports it. +//! Use it through `kio`'s `sim` feature, which re-exports it. use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; -/// Run an `async fn` test to completion on `moq_clock::sim::run`. +/// Run an `async fn` test to completion on `kio::clock::sim::run`. #[proc_macro_attribute] pub fn test(args: TokenStream, item: TokenStream) -> TokenStream { if !args.is_empty() { - return error("#[moq_clock::test] takes no arguments"); + return error("#[kio::test] takes no arguments"); } let mut tokens: Vec = item.into_iter().collect(); @@ -17,17 +17,17 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream { .windows(2) .position(|pair| is(&pair[0], "async") && is(&pair[1], "fn")) else { - return error("#[moq_clock::test] expects an `async fn`"); + return error("#[kio::test] expects an `async fn`"); }; tokens.remove(at); let body = match tokens.pop() { Some(TokenTree::Group(body)) if body.delimiter() == Delimiter::Brace => body, - _ => return error("#[moq_clock::test] expects a function body"), + _ => return error("#[kio::test] expects a function body"), }; - // `{ ::moq_clock::sim::run(async move ) }` - let mut call: TokenStream = "::moq_clock::sim::run".parse().unwrap(); + // `{ ::kio::clock::sim::run(async move ) }` + let mut call: TokenStream = "::kio::clock::sim::run".parse().unwrap(); let block: TokenStream = [ TokenTree::Ident(Ident::new("async", Span::call_site())), TokenTree::Ident(Ident::new("move", Span::call_site())), diff --git a/rs/moq-clock/src/deadline.rs b/rs/kio/src/clock/deadline.rs similarity index 89% rename from rs/moq-clock/src/deadline.rs rename to rs/kio/src/clock/deadline.rs index c79d3da3002..da7727d7131 100644 --- a/rs/moq-clock/src/deadline.rs +++ b/rs/kio/src/clock/deadline.rs @@ -10,7 +10,7 @@ use std::{ time::Duration, }; -use crate::Instant; +use crate::clock::Instant; thread_local! { /// The queue [`Deadlines::enter`] made this thread's ambient clock. @@ -41,16 +41,16 @@ struct Queue { /// The clock installed where the queue was made, whose wall time it reads /// while entered, so its wall and instants come from one clock. #[cfg(feature = "manual")] - installed: Option, + installed: Option, } struct State { /// Orders deadlines armed for the same instant by when they were armed. next: u64, - armed: BTreeMap<(Instant, u64), Arc>>, + armed: BTreeMap<(Instant, u64), Arc>>, /// The owner's poll, woken when a deadline armed outside it becomes the earliest, /// so the owner never sleeps past a deadline it did not see. - owner: kio::WaiterList, + owner: crate::WaiterList, } impl Queue { @@ -67,10 +67,10 @@ impl Deadlines { state: Mutex::new(State { next: 0, armed: BTreeMap::new(), - owner: kio::WaiterList::new(), + owner: crate::WaiterList::new(), }), #[cfg(feature = "manual")] - installed: crate::installed::current(), + installed: crate::clock::installed::current(), })) } @@ -124,7 +124,7 @@ impl Deadlines { /// The earliest armed deadline, registering `waiter` to be woken when an earlier /// one is armed. Ends the poll [`Self::advance`] began: one lock, so a deadline /// armed elsewhere is either reported here or wakes the owner. - pub fn park(&self, waiter: &kio::Waiter) -> Option { + pub fn park(&self, waiter: &crate::Waiter) -> Option { let mut state = self.0.state.lock().unwrap(); waiter.register(&mut state.owner); state.armed.first_key_value().map(|((at, _), _)| *at) @@ -148,8 +148,8 @@ impl Deadlines { /// Make this queue the calling thread's ambient clock until the guard drops. /// - /// While entered, [`now`](crate::now) reads the instant last handed to - /// [`advance`](Self::advance), and [`sleep`](crate::sleep) and the other ambient + /// While entered, [`now`](crate::clock::now) reads the instant last handed to + /// [`advance`](Self::advance), and [`sleep`](crate::clock::sleep) and the other ambient /// timers arm [`Deadline`]s here. Wall time comes from the clock installed on the /// runtime the queue was made in, if any, and otherwise from the clock the thread /// would read. For a runtime that advances the queue from its own reading of the @@ -214,7 +214,7 @@ pub(crate) fn now() -> Option { /// The installed clock behind the queue entered on this thread, if any. #[cfg(feature = "manual")] -pub(crate) fn installed() -> Option { +pub(crate) fn installed() -> Option { ENTERED.with(|entered| entered.borrow().as_ref().and_then(|queue| queue.0.installed.clone())) } @@ -238,11 +238,11 @@ impl WeakDeadlines { } } -/// The [`Deadline`] behind an ambient [`Sleep`](crate::Sleep) on an entered queue, +/// The [`Deadline`] behind an ambient [`Sleep`](crate::clock::Sleep) on an entered queue, /// with the waiter its polls register. pub(crate) struct Timer { deadline: Deadline, - park: kio::Park, + park: crate::Park, } impl Timer { @@ -251,7 +251,7 @@ impl Timer { deadline.set(at); Self { deadline, - park: kio::Park::default(), + park: crate::Park::default(), } } @@ -275,7 +275,7 @@ pub struct Deadline { deadlines: Deadlines, key: Option<(Instant, u64)>, at: Option, - waiters: Arc>, + waiters: Arc>, } impl Deadline { @@ -285,7 +285,7 @@ impl Deadline { deadlines: deadlines.clone(), key: None, at: None, - waiters: Arc::new(Mutex::new(kio::WaiterList::new())), + waiters: Arc::new(Mutex::new(crate::WaiterList::new())), } } @@ -341,7 +341,7 @@ impl Deadline { /// `Ready` once the queue reaches the armed instant, registering `waiter` /// otherwise. Fused until re-armed; a disarmed deadline never fires. - pub fn poll(&mut self, waiter: &kio::Waiter) -> Poll<()> { + pub fn poll(&mut self, waiter: &crate::Waiter) -> Poll<()> { // Register under the queue's lock, so an `advance` past `at` either happened // first (and we see it) or wakes this registration. A disarmed deadline // registers too, so arming it for a reached instant wakes its poller. @@ -354,10 +354,10 @@ impl Deadline { } } -impl kio::Task for Deadline { +impl crate::Task for Deadline { type Output = (); - fn poll(&mut self, waiter: &kio::Waiter) -> Poll<()> { + fn poll(&mut self, waiter: &crate::Waiter) -> Poll<()> { self.poll(waiter) } } @@ -380,7 +380,7 @@ mod tests { use std::sync::atomic::{AtomicUsize, Ordering}; use super::*; - use crate::Manual; + use crate::clock::Manual; /// Counts wakes. struct Wakes { @@ -393,11 +393,11 @@ mod tests { } } - fn counter() -> (Arc, kio::Waiter) { + fn counter() -> (Arc, crate::Waiter) { let wakes = Arc::new(Wakes { count: AtomicUsize::new(0), }); - let waiter = kio::Waiter::new(std::task::Waker::from(wakes.clone())); + let waiter = crate::Waiter::new(std::task::Waker::from(wakes.clone())); (wakes, waiter) } @@ -409,13 +409,13 @@ mod tests { let mut deadline = Deadline::new(&deadlines); deadline.set(Some(at)); assert_eq!(deadlines.next(), Some(at)); - assert!(deadline.poll(&kio::Waiter::noop()).is_pending()); + assert!(deadline.poll(&crate::Waiter::noop()).is_pending()); clock.advance(Duration::from_secs(3)); deadlines.advance(clock.now()); - assert!(deadline.poll(&kio::Waiter::noop()).is_ready()); + assert!(deadline.poll(&crate::Waiter::noop()).is_ready()); assert!( - deadline.poll(&kio::Waiter::noop()).is_ready(), + deadline.poll(&crate::Waiter::noop()).is_ready(), "an elapsed deadline stays fused" ); assert_eq!(deadlines.next(), None); @@ -434,11 +434,11 @@ mod tests { clock.advance(Duration::from_secs(3600)); deadlines.advance(clock.now()); - assert!(disarmed.poll(&kio::Waiter::noop()).is_pending()); + assert!(disarmed.poll(&crate::Waiter::noop()).is_pending()); let mut unrepresentable = Deadline::after(&deadlines, Duration::MAX); assert_eq!(unrepresentable.deadline(), None); - assert!(unrepresentable.poll(&kio::Waiter::noop()).is_pending()); + assert!(unrepresentable.poll(&crate::Waiter::noop()).is_pending()); } #[test] @@ -456,17 +456,17 @@ mod tests { clock.advance(Duration::from_secs(1)); deadlines.advance(clock.now()); assert!( - deadline.poll(&kio::Waiter::noop()).is_pending(), + deadline.poll(&crate::Waiter::noop()).is_pending(), "the old instant is gone" ); clock.advance(Duration::from_secs(4)); deadlines.advance(clock.now()); - assert!(deadline.poll(&kio::Waiter::noop()).is_ready()); + assert!(deadline.poll(&crate::Waiter::noop()).is_ready()); deadline.set(Some(clock.now() + Duration::from_secs(1))); assert!( - deadline.poll(&kio::Waiter::noop()).is_pending(), + deadline.poll(&crate::Waiter::noop()).is_pending(), "an elapsed deadline re-arms" ); } @@ -479,9 +479,9 @@ mod tests { let mut deadline = Deadline::new(&deadlines); deadline.set(Some(clock.now() - Duration::from_secs(1))); - assert!(deadline.poll(&kio::Waiter::noop()).is_ready(), "in the past"); + assert!(deadline.poll(&crate::Waiter::noop()).is_ready(), "in the past"); deadline.set(Some(clock.now())); - assert!(deadline.poll(&kio::Waiter::noop()).is_ready(), "exactly now"); + assert!(deadline.poll(&crate::Waiter::noop()).is_ready(), "exactly now"); assert_eq!(deadlines.next(), None, "neither was queued"); } @@ -548,7 +548,7 @@ mod tests { } } // Kept alive: a list holds its waiters weakly. - let waiter = |name| kio::Waiter::new(std::task::Waker::from(Arc::new(Record(order.clone(), name)))); + let waiter = |name| crate::Waiter::new(std::task::Waker::from(Arc::new(Record(order.clone(), name)))); let (first_waiter, second_waiter) = (waiter("first"), waiter("second")); assert!(first.poll(&first_waiter).is_pending()); assert!(second.poll(&second_waiter).is_pending()); @@ -582,10 +582,10 @@ mod tests { let deadlines = Deadlines::new(start); // A child that re-arms its deadline every time it fires, like a periodic probe. - let mut tasks = kio::Tasks::new(); + let mut tasks = crate::Tasks::new(); let mut tick = Deadline::after(&deadlines, PERIOD); let ticking = deadlines.clone(); - tasks.push(move |waiter: &kio::Waiter| { + tasks.push(move |waiter: &crate::Waiter| { while tick.poll(waiter).is_ready() { tick.set(Some(ticking.now() + PERIOD)); } @@ -595,7 +595,7 @@ mod tests { // `poll(now, waiter)`, minus the protocol. let now = std::cell::Cell::new(start); let next = std::cell::Cell::new(None); - let mut owner = std::pin::pin!(kio::wait(|waiter: &kio::Waiter| { + let mut owner = std::pin::pin!(crate::wait(|waiter: &crate::Waiter| { waiter.batch(|| { deadlines.advance(now.get()); let _ = tasks.poll(waiter); @@ -649,9 +649,9 @@ mod tests { let start = Instant::ZERO + Duration::from_secs(10); let deadlines = Deadlines::new(start); let entered = deadlines.enter(); - assert_eq!(crate::now(), start); + assert_eq!(crate::clock::now(), start); - let mut sleep = std::pin::pin!(crate::sleep(Duration::from_secs(1))); + let mut sleep = std::pin::pin!(crate::clock::sleep(Duration::from_secs(1))); assert_eq!(deadlines.next(), Some(start + Duration::from_secs(1))); let (wakes, waiter) = counter(); let waker = waiter.waker().clone(); @@ -659,14 +659,17 @@ mod tests { assert!(sleep.as_mut().poll(&mut cx).is_pending()); deadlines.advance(start + Duration::from_millis(999)); - assert_eq!(crate::now(), start + Duration::from_millis(999)); + assert_eq!(crate::clock::now(), start + Duration::from_millis(999)); assert_eq!(wakes.count.load(Ordering::SeqCst), 0); deadlines.advance(start + Duration::from_secs(1)); assert_eq!(wakes.count.load(Ordering::SeqCst), 1, "the sleep was not woken"); assert!(sleep.as_mut().poll(&mut cx).is_ready()); drop(entered); - assert!(crate::now() > start + Duration::from_secs(1), "the host clock is back"); + assert!( + crate::clock::now() > start + Duration::from_secs(1), + "the host clock is back" + ); } /// A sleep that never fires leaves nothing armed for the queue's owner to park on. @@ -674,7 +677,7 @@ mod tests { fn a_never_firing_sleep_arms_nothing() { let deadlines = Deadlines::new(Instant::ZERO); let _entered = deadlines.enter(); - let mut sleep = crate::sleep(Duration::MAX); + let mut sleep = crate::clock::sleep(Duration::MAX); assert_eq!(deadlines.next(), None); sleep.reset(Instant::ZERO + Duration::from_secs(1)); assert_eq!(deadlines.next(), Some(Instant::ZERO + Duration::from_secs(1))); @@ -688,12 +691,12 @@ mod tests { let _outer = outer.enter(); { let _inner = inner.enter(); - assert_eq!(crate::now(), Instant::ZERO + Duration::from_secs(2)); + assert_eq!(crate::clock::now(), Instant::ZERO + Duration::from_secs(2)); } - assert_eq!(crate::now(), Instant::ZERO + Duration::from_secs(1)); + assert_eq!(crate::clock::now(), Instant::ZERO + Duration::from_secs(1)); std::thread::spawn(|| { assert!( - crate::now() > Instant::ZERO + Duration::from_secs(2), + crate::clock::now() > Instant::ZERO + Duration::from_secs(2), "other threads keep their own clock" ) }) @@ -727,7 +730,7 @@ mod tests { assert!(result.is_err(), "the out-of-order drop did not panic"); assert!(super::entered().is_none(), "a dropped queue is still the ambient clock"); assert!( - crate::now() > Instant::ZERO + Duration::from_secs(2), + crate::clock::now() > Instant::ZERO + Duration::from_secs(2), "the host clock is back" ); } diff --git a/rs/moq-clock/src/installed.rs b/rs/kio/src/clock/installed.rs similarity index 89% rename from rs/moq-clock/src/installed.rs rename to rs/kio/src/clock/installed.rs index ceefe1f535b..f4757354e44 100644 --- a/rs/moq-clock/src/installed.rs +++ b/rs/kio/src/clock/installed.rs @@ -14,7 +14,7 @@ use std::{ time::Duration, }; -use crate::{Instant, Manual, Wall}; +use crate::clock::{Instant, Manual, Wall}; /// Installed clocks by runtime. Never pruned: one entry per runtime a test installs on. static CLOCKS: LazyLock>> = LazyLock::new(Default::default); @@ -23,8 +23,8 @@ static ANY: AtomicBool = AtomicBool::new(false); /// A [`Manual`] clock that one tokio runtime reads as its ambient clock. /// -/// Inside that runtime, or a thread that entered it, [`now`](crate::now) and -/// [`wall`](crate::wall) read this clock and timers fire only once +/// Inside that runtime, or a thread that entered it, [`now`](crate::clock::now) and +/// [`wall`](crate::clock::wall) read this clock and timers fire only once /// [`advance`](Self::advance) reaches them. Clones share the clock. #[derive(Clone)] pub struct Installed(Arc>); @@ -77,8 +77,8 @@ impl Installed { } /// Complete once this clock reaches `at`, whichever thread polls it. - pub fn sleep_until(&self, at: Instant) -> crate::Sleep { - crate::Sleep::installed(self.clone(), at) + pub fn sleep_until(&self, at: Instant) -> crate::clock::Sleep { + crate::clock::Sleep::installed(self.clone(), at) } /// The current instant. @@ -225,9 +225,9 @@ mod tests { let runtime = runtime(true); let clock = Manual::new().install(runtime.handle()); runtime.block_on(async { - let start = crate::now(); + let start = crate::clock::now(); assert_eq!(start, Instant::ZERO); - let mut sleep = pin!(crate::sleep(Duration::from_secs(1))); + let mut sleep = pin!(crate::clock::sleep(Duration::from_secs(1))); assert!(poll_once(&mut sleep).is_pending()); // Idle on tokio's paused clock for an hour: the installed clock stays put. @@ -236,14 +236,14 @@ mod tests { reason = "the test idles on tokio's clock, not the installed one" )] tokio::time::sleep(Duration::from_secs(3_600)).await; - assert_eq!(crate::now(), start); + assert_eq!(crate::clock::now(), start); assert!(poll_once(&mut sleep).is_pending()); clock.advance(Duration::from_millis(999)); assert!(poll_once(&mut sleep).is_pending()); clock.advance(Duration::from_millis(1)); sleep.await; - assert_eq!(crate::now(), start + Duration::from_secs(1)); + assert_eq!(crate::clock::now(), start + Duration::from_secs(1)); }); } @@ -258,10 +258,10 @@ mod tests { let clock = Manual::new().install(runtime.handle()); let (armed, armed_rx) = std::sync::mpsc::channel(); let task = runtime.spawn(async move { - let sleep = crate::sleep(Duration::from_secs(5)); + let sleep = crate::clock::sleep(Duration::from_secs(5)); armed.send(()).unwrap(); sleep.await; - crate::now() + crate::clock::now() }); armed_rx.recv().unwrap(); clock.advance(Duration::from_secs(5)); @@ -274,7 +274,7 @@ mod tests { let runtime = runtime(false); let clock = Manual::new().install(runtime.handle()); runtime.block_on(async { - let mut sleep = pin!(crate::sleep(Duration::from_secs(1))); + let mut sleep = pin!(crate::clock::sleep(Duration::from_secs(1))); assert!(poll_once(&mut sleep).is_pending()); sleep.as_mut().reset(Instant::ZERO + Duration::from_secs(2)); clock.advance(Duration::from_secs(1)); @@ -290,16 +290,16 @@ mod tests { let runtime = runtime(false); let clock = Manual::new().install(runtime.handle()); let _entered = runtime.enter(); - assert_eq!(crate::wall(), Manual::WALL_START); - assert_eq!(crate::origin(), (Instant::ZERO, Manual::WALL_START)); + assert_eq!(crate::clock::wall(), Manual::WALL_START); + assert_eq!(crate::clock::origin(), (Instant::ZERO, Manual::WALL_START)); clock.advance(Duration::from_secs(5)); - assert_eq!(crate::wall(), Manual::WALL_START + Duration::from_secs(5)); + assert_eq!(crate::clock::wall(), Manual::WALL_START + Duration::from_secs(5)); clock.step_wall(Manual::WALL_START); - assert_eq!(crate::wall(), Manual::WALL_START); - assert_eq!(crate::now(), Instant::ZERO + Duration::from_secs(5)); + assert_eq!(crate::clock::wall(), Manual::WALL_START); + assert_eq!(crate::clock::now(), Instant::ZERO + Duration::from_secs(5)); assert_eq!( - crate::origin(), + crate::clock::origin(), (Instant::ZERO, Manual::WALL_START), "the origin is fixed at its first read" ); @@ -313,9 +313,9 @@ mod tests { let other = runtime(false); // The host clock reads far past zero from its first instant. let host = Instant::ZERO + Duration::from_secs(1 << 31); - assert!(other.block_on(async { crate::now() }) > host); - assert!(crate::now() > host); - assert_eq!(installed.block_on(async { crate::now() }), Instant::ZERO); + assert!(other.block_on(async { crate::clock::now() }) > host); + assert!(crate::clock::now() > host); + assert_eq!(installed.block_on(async { crate::clock::now() }), Instant::ZERO); } /// An advance past the range is refused whole, leaving the clock where it was. diff --git a/rs/moq-clock/src/instant.rs b/rs/kio/src/clock/instant.rs similarity index 97% rename from rs/moq-clock/src/instant.rs rename to rs/kio/src/clock/instant.rs index c52c09eaa87..25906c716d5 100644 --- a/rs/moq-clock/src/instant.rs +++ b/rs/kio/src/clock/instant.rs @@ -24,7 +24,7 @@ impl Instant { /// The current instant on the ambient clock. pub fn now() -> Self { - crate::now() + crate::clock::now() } /// The time elapsed since this instant on the ambient clock, zero if it is in the future. @@ -91,7 +91,7 @@ impl Instant { /// on a platform whose std clock starts at boot. #[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] pub fn into_std(self) -> std::time::Instant { - crate::runtime::into_std(self).expect("instant outside std's clock range") + crate::clock::runtime::into_std(self).expect("instant outside std's clock range") } /// The instant `at` names on std's clock, the inverse of [`Instant::into_std`]. @@ -99,7 +99,7 @@ impl Instant { /// Saturates at the clock's range, like a deadline past it. #[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] pub fn from_std(at: std::time::Instant) -> Self { - crate::runtime::from_std(at) + crate::clock::runtime::from_std(at) } } diff --git a/rs/moq-clock/src/manual.rs b/rs/kio/src/clock/manual.rs similarity index 98% rename from rs/moq-clock/src/manual.rs rename to rs/kio/src/clock/manual.rs index bd770d33636..5985f0e6311 100644 --- a/rs/moq-clock/src/manual.rs +++ b/rs/kio/src/clock/manual.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use crate::{Instant, Wall}; +use crate::clock::{Instant, Wall}; /// A clock that moves only when a test moves it. /// diff --git a/rs/moq-clock/src/lib.rs b/rs/kio/src/clock/mod.rs similarity index 90% rename from rs/moq-clock/src/lib.rs rename to rs/kio/src/clock/mod.rs index 9dc024845e2..46b89e5d094 100644 --- a/rs/moq-clock/src/lib.rs +++ b/rs/kio/src/clock/mod.rs @@ -1,4 +1,4 @@ -//! One clock for Media over QUIC. +//! One clock: logical instants, wall time, deadlines, timers, and a deterministic simulator. //! //! - [`Instant`] is a logical point on the monotonic clock, in nanoseconds from //! the clock's origin, with [`std::time::Instant`]'s methods. [`Wall`] is @@ -15,19 +15,21 @@ //! it, which is how a runtime that reads the host clock itself (an io_uring //! worker) becomes a backend. //! +//! The `runtime` feature arms timers on tokio's clock natively and `setTimeout` in +//! the browser. Without it, reads fall back to std (the browser still reads +//! `performance.now()`), and waiting on the host clock panics. +//! //! The `manual` feature adds `Manual::install`, which makes a [`Manual`] clock //! the ambient clock of one tokio runtime. It moves only when told to, never on //! idle, so a test harness outside the runtime decides when native time passes. //! //! The `sim` feature adds the `sim` module, a deterministic executor whose clock -//! starts at [`Instant::ZERO`], and the `#[moq_clock::test]` attribute that runs an +//! starts at [`Instant::ZERO`], and the `#[kio::test]` attribute that runs an //! `async fn` test on it. Enable it for dev-dependencies only. //! //! The `serde` feature adds `serde::UnixSeconds`, matching existing integer //! Unix-second JSON encodings for wall times. -#![warn(missing_docs)] - mod deadline; #[cfg(feature = "manual")] mod installed; @@ -54,14 +56,6 @@ pub use timer::{ }; pub use wall::{OutOfRange, Wall}; -/// Run an `async fn` test to completion on [`sim::run`]. -#[cfg(feature = "sim")] -pub use moq_clock_macros::test; - -// So `#[moq_clock::test]` resolves inside this crate's own tests. -#[cfg(test)] -extern crate self as moq_clock; - /// The current instant on the ambient clock. pub fn now() -> Instant { if let Some(now) = deadline::now() { diff --git a/rs/moq-clock/src/runtime.rs b/rs/kio/src/clock/runtime.rs similarity index 84% rename from rs/moq-clock/src/runtime.rs rename to rs/kio/src/clock/runtime.rs index 39c194a4c1a..5c63b00551b 100644 --- a/rs/moq-clock/src/runtime.rs +++ b/rs/kio/src/clock/runtime.rs @@ -19,7 +19,7 @@ use std::{ #[cfg(any(feature = "runtime", all(target_arch = "wasm32", not(target_os = "wasi"))))] use web_async::time as host; -use crate::{Instant, Wall}; +use crate::clock::{Instant, Wall}; /// How far past [`Instant::ZERO`] a runtime clock reads at its origin. /// @@ -194,15 +194,15 @@ pub(crate) struct Timer; #[cfg(not(feature = "runtime"))] impl Timer { pub(crate) fn new(_: Instant) -> Self { - panic!("moq-clock runtime support is disabled") + panic!("the kio `runtime` feature is disabled") } pub(crate) fn reset(&mut self, _: Instant) { - panic!("moq-clock runtime support is disabled") + panic!("the kio `runtime` feature is disabled") } pub(crate) fn poll(&mut self, _: &mut Context<'_>) -> Poll<()> { - panic!("moq-clock runtime support is disabled") + panic!("the kio `runtime` feature is disabled") } } @@ -217,7 +217,7 @@ mod paused { }; use super::host; - use crate::{Instant, Wall}; + use crate::clock::{Instant, Wall}; /// A paused runtime counting from its own origin. struct Own { @@ -289,17 +289,17 @@ mod tests { .start_paused(true) .build() .unwrap(); - let _ = crate::now(); + let _ = crate::clock::now(); runtime.block_on(async { - let start = crate::now(); - crate::sleep(Duration::from_secs(5)).await; - assert_eq!(crate::now(), start + Duration::from_secs(5)); + let start = crate::clock::now(); + crate::clock::sleep(Duration::from_secs(5)).await; + assert_eq!(crate::clock::now(), start + Duration::from_secs(5)); tokio::time::advance(Duration::from_secs(60)).await; - assert_eq!(crate::now(), start + Duration::from_secs(65)); - let at = crate::sleep_until(start + Duration::from_secs(70)); + assert_eq!(crate::clock::now(), start + Duration::from_secs(65)); + let at = crate::clock::sleep_until(start + Duration::from_secs(70)); assert_eq!(at.deadline(), start + Duration::from_secs(70)); at.await; - assert_eq!(crate::now(), start + Duration::from_secs(70)); + assert_eq!(crate::clock::now(), start + Duration::from_secs(70)); }); } @@ -318,15 +318,15 @@ mod tests { // from its own origin. let first = paused(); let second = paused(); - let _ = crate::now(); + let _ = crate::clock::now(); first.block_on(async { - let _ = crate::now(); + let _ = crate::clock::now(); tokio::time::advance(Duration::from_secs(60)).await; - let _ = crate::origin(); + let _ = crate::clock::origin(); }); second.block_on(async { - let (instant, _) = crate::origin(); - assert_eq!(instant, crate::now()); + let (instant, _) = crate::clock::origin(); + assert_eq!(instant, crate::clock::now()); }); } @@ -334,7 +334,7 @@ mod tests { /// callers by advancing its clock before the anchor is first taken. #[test] fn a_later_paused_runtime_does_not_skew_the_anchor() { - let _ = crate::now(); + let _ = crate::clock::now(); // Built after the origin, so it counts from the shared origin. let runtime = tokio::runtime::Builder::new_current_thread() .enable_time() @@ -342,12 +342,16 @@ mod tests { .build() .unwrap(); runtime.block_on(async { - let _ = crate::now(); + let _ = crate::clock::now(); tokio::time::advance(Duration::from_secs(3_600)).await; - let _ = crate::origin(); + let _ = crate::clock::origin(); }); - let (instant, _) = crate::origin(); - assert!(instant <= crate::now(), "{instant:?} > {:?}", crate::now()); + let (instant, _) = crate::clock::origin(); + assert!( + instant <= crate::clock::now(), + "{instant:?} > {:?}", + crate::clock::now() + ); } /// On a running clock, a converted instant is the same moment on std's clock. @@ -355,13 +359,13 @@ mod tests { #[expect(clippy::disallowed_methods, reason = "the test compares against std's clock")] fn std_conversion_is_exact_on_a_running_clock() { let before = std::time::Instant::now(); - let now = crate::now(); + let now = crate::clock::now(); let after = std::time::Instant::now(); let host = now.into_std(); assert!(before <= host && host <= after, "{before:?} <= {host:?} <= {after:?}"); - assert_eq!(crate::Instant::from_std(host), now); + assert_eq!(crate::clock::Instant::from_std(host), now); let earlier = now - Duration::from_secs(3_600); - assert_eq!(crate::Instant::from_std(earlier.into_std()), earlier); + assert_eq!(crate::clock::Instant::from_std(earlier.into_std()), earlier); } /// On paused tokio, converted instants keep the time between them. @@ -373,13 +377,13 @@ mod tests { .build() .unwrap(); runtime.block_on(async { - let start = crate::now(); + let start = crate::clock::now(); let host = start.into_std(); tokio::time::advance(Duration::from_secs(60)).await; - let later = crate::now(); + let later = crate::clock::now(); assert_eq!(later.into_std() - host, Duration::from_secs(60)); assert_eq!( - crate::Instant::from_std(host + Duration::from_secs(5)), + crate::clock::Instant::from_std(host + Duration::from_secs(5)), start + Duration::from_secs(5) ); }); @@ -388,9 +392,9 @@ mod tests { /// A std instant past the clock's range saturates instead of wrapping. #[test] fn std_conversion_saturates() { - let now = crate::now(); + let now = crate::clock::now(); let far = now.into_std() + Duration::from_secs(1 << 40); - assert!(crate::Instant::from_std(far) > now + Duration::from_secs(1 << 33)); + assert!(crate::clock::Instant::from_std(far) > now + Duration::from_secs(1 << 33)); } /// A fresh clock names moments before the process started, as std's does, so @@ -403,10 +407,10 @@ mod tests { .build() .unwrap(); runtime.block_on(async { - let now = crate::now(); + let now = crate::clock::now(); assert!(now.checked_sub(Duration::from_secs(3_600)).is_some(), "{now:?}"); }); - assert!(crate::now().checked_sub(Duration::from_secs(3_600)).is_some()); + assert!(crate::clock::now().checked_sub(Duration::from_secs(3_600)).is_some()); } /// Every worker of a multi-thread runtime, and a thread outside any runtime, @@ -418,16 +422,16 @@ mod tests { .enable_time() .build() .unwrap(); - let before = crate::now(); + let before = crate::clock::now(); let reads = runtime.block_on(async { - let tasks: Vec<_> = (0..16).map(|_| tokio::spawn(async { crate::now() })).collect(); + let tasks: Vec<_> = (0..16).map(|_| tokio::spawn(async { crate::clock::now() })).collect(); let mut reads = Vec::new(); for task in tasks { reads.push(task.await.unwrap()); } reads }); - let after = crate::now(); + let after = crate::clock::now(); for read in reads { assert!(before <= read && read <= after, "{before:?} <= {read:?} <= {after:?}"); } @@ -458,41 +462,44 @@ export function restoreWall() { Date.now = originalNow; } #[wasm_bindgen_test] async fn sleep_advances_now_past_its_deadline() { - let start = crate::now(); - let sleep = crate::sleep(Duration::from_millis(20)); + let start = crate::clock::now(); + let sleep = crate::clock::sleep(Duration::from_millis(20)); let deadline = sleep.deadline(); sleep.await; - assert!(crate::now() >= deadline); - assert!(crate::now() > start); + assert!(crate::clock::now() >= deadline); + assert!(crate::clock::now() > start); } #[wasm_bindgen_test] async fn sleep_until_does_not_fire_early() { - let deadline = crate::now() + Duration::from_millis(20); - crate::sleep_until(deadline).await; - assert!(crate::now() >= deadline); + let deadline = crate::clock::now() + Duration::from_millis(20); + crate::clock::sleep_until(deadline).await; + assert!(crate::clock::now() >= deadline); } #[wasm_bindgen_test] async fn timeout_elapses() { let duration = Duration::from_millis(20); - let deadline = crate::now() + duration; - assert!(crate::timeout(duration, pending::<()>()).await.is_err()); - assert!(crate::now() >= deadline); + let deadline = crate::clock::now() + duration; + assert!(crate::clock::timeout(duration, pending::<()>()).await.is_err()); + assert!(crate::clock::now() >= deadline); } #[wasm_bindgen_test] fn interval_first_tick_is_immediate() { - let mut interval = crate::interval(Duration::from_secs(1)); + let mut interval = crate::clock::interval(Duration::from_secs(1)); assert!(interval.tick().now_or_never().is_some()); } #[wasm_bindgen_test] fn wall_reads_date_now() { set_wall(); - let wall = crate::wall(); + let wall = crate::clock::wall(); restore_wall(); - assert_eq!(wall, crate::Wall::UNIX_EPOCH + Duration::from_millis(1_700_000_000_123)); + assert_eq!( + wall, + crate::clock::Wall::UNIX_EPOCH + Duration::from_millis(1_700_000_000_123) + ); } } @@ -505,10 +512,10 @@ mod browser_read_tests { /// Reads work without the runtime, since std has no clock in the browser. #[wasm_bindgen_test] fn reads_without_runtime() { - let start = crate::now(); - assert!(crate::now() >= start); - assert!(crate::wall() > crate::Wall::UNIX_EPOCH); - let (instant, _) = crate::origin(); - assert!(instant <= crate::now()); + let start = crate::clock::now(); + assert!(crate::clock::now() >= start); + assert!(crate::clock::wall() > crate::clock::Wall::UNIX_EPOCH); + let (instant, _) = crate::clock::origin(); + assert!(instant <= crate::clock::now()); } } diff --git a/rs/moq-clock/src/serde.rs b/rs/kio/src/clock/serde.rs similarity index 99% rename from rs/moq-clock/src/serde.rs rename to rs/kio/src/clock/serde.rs index e46487a2279..61dc3bf8bbd 100644 --- a/rs/moq-clock/src/serde.rs +++ b/rs/kio/src/clock/serde.rs @@ -1,6 +1,6 @@ //! JSON adapters that preserve existing wall-time encodings. -use crate::Wall; +use crate::clock::Wall; use ::serde::{Deserialize, Deserializer, Serializer}; use serde_with::{DeserializeAs, SerializeAs, TimestampSeconds}; diff --git a/rs/moq-clock/src/sim.rs b/rs/kio/src/clock/sim.rs similarity index 83% rename from rs/moq-clock/src/sim.rs rename to rs/kio/src/clock/sim.rs index de84bb0d84b..abe3374d67c 100644 --- a/rs/moq-clock/src/sim.rs +++ b/rs/kio/src/clock/sim.rs @@ -1,9 +1,9 @@ //! A single-threaded, deterministic executor with simulated time. //! -//! Inside [`run`], the ambient clock is the simulator's: [`now`](crate::now) starts -//! at [`Instant::ZERO`], [`wall`](crate::wall) at [`Manual::WALL_START`], and -//! [`sleep`](crate::sleep), [`timeout`](crate::timeout), and -//! [`interval`](crate::interval) arm simulated timers. Time never moves on its own: +//! Inside [`run`], the ambient clock is the simulator's: [`now`](crate::clock::now) starts +//! at [`Instant::ZERO`], [`wall`](crate::clock::wall) at [`Manual::WALL_START`], and +//! [`sleep`](crate::clock::sleep), [`timeout`](crate::clock::timeout), and +//! [`interval`](crate::clock::interval) arm simulated timers. Time never moves on its own: //! once every task has stalled, [`run`] jumps the clock to the earliest armed //! timer and wakes it, like tokio's paused clock, so a test never waits on the //! host clock. A run whose tasks are all parked with nothing armed can never @@ -12,10 +12,10 @@ //! //! A task poll that makes more than 4096 ready kio polls panics with the caller's //! source location, so a loop that forgets to yield fails instead of starving its siblings. -//! Each `kio::Tasks` child poll counts on its own, like a spawned task. +//! Each `crate::Tasks` child poll counts on its own, like a spawned task. //! //! Caller-driven state machines take time from their caller: -//! [`drive`](crate::drive) polls one with the simulated instant, and [`attach`] +//! [`drive`](crate::clock::drive) polls one with the simulated instant, and [`attach`] //! keeps a [`Deadlines`] queue in step. use std::{ @@ -34,7 +34,7 @@ use std::{ use futures::{FutureExt, StreamExt, stream::FuturesUnordered}; -use crate::{Deadlines, Instant, Manual, Wall, deadline::WeakDeadlines}; +use crate::clock::{Deadlines, Instant, Manual, Wall, deadline::WeakDeadlines}; thread_local! { static CURRENT: RefCell>> = const { RefCell::new(None) }; @@ -43,7 +43,7 @@ thread_local! { type Task = Pin>>; fn poll(future: Pin<&mut F>, cx: &mut Context<'_>) -> Poll { - let _scope = kio::coop::scope(); + let _scope = crate::coop::scope(); future.poll(cx) } @@ -84,7 +84,7 @@ impl Runtime { }); CURRENT.with(|current| { let mut current = current.borrow_mut(); - assert!(current.is_none(), "moq_clock::sim::run cannot nest"); + assert!(current.is_none(), "kio::clock::sim::run cannot nest"); *current = Some(runtime.clone()); }); runtime @@ -161,7 +161,7 @@ fn current() -> Option> { } fn expect_current() -> Rc { - current().expect("not inside moq_clock::sim::run") + current().expect("not inside kio::clock::sim::run") } /// The simulated instant, when the calling thread is inside [`run`]. @@ -344,10 +344,10 @@ pub fn yield_now() -> impl Future { }) } -/// A simulated timer behind [`Sleep`](crate::Sleep). +/// A simulated timer behind [`Sleep`](crate::clock::Sleep). /// /// Holds plain data rather than the runtime, so enabling `sim` in a test build -/// leaves [`Sleep`](crate::Sleep) `Send`. It finds its run as the thread's current one. +/// leaves [`Sleep`](crate::clock::Sleep) `Send`. It finds its run as the thread's current one. pub(crate) struct Timer { run: u64, at: Instant, @@ -388,7 +388,7 @@ impl Timer { pub(crate) fn poll(&mut self, cx: &mut Context<'_>) -> Poll<()> { let runtime = self .runtime() - .expect("a simulated sleep polled outside its moq_clock::sim::run"); + .expect("a simulated sleep polled outside its kio::clock::sim::run"); let mut time = runtime.time.borrow_mut(); if time.clock.now() >= self.at { if let Some(key) = self.key.take() { @@ -594,12 +594,12 @@ impl Drop for Cancel { #[cfg(test)] mod tests { use super::*; - use crate::{Deadline, Deadlines, Elapsed, MissedTickBehavior}; + use crate::clock::{Deadline, Deadlines, Elapsed, MissedTickBehavior}; fn spin() { - let producer = kio::Producer::new(()); + let producer = crate::Producer::new(()); let consumer = producer.consume(); - let waiter = kio::Waiter::noop(); + let waiter = crate::Waiter::noop(); for _ in 0..10_000 { assert!(consumer.poll(&waiter, |_| Poll::Ready(())).is_ready()); } @@ -629,13 +629,13 @@ mod tests { turns.set(turns.get() + 1); } }); - let producer = kio::Producer::new(()); + let producer = crate::Producer::new(()); let consumer = producer.consume(); - let mut budget = kio::coop::Budget::new(32); + let mut budget = crate::coop::Budget::new(32); for _ in 0..10_000 { - kio::wait(|waiter| budget.poll_yield(waiter)).await; + crate::wait(|waiter| budget.poll_yield(waiter)).await; assert!( - kio::wait(|waiter| consumer.poll(waiter, |_| Poll::Ready(()))) + crate::wait(|waiter| consumer.poll(waiter, |_| Poll::Ready(()))) .await .is_ok() ); @@ -646,9 +646,9 @@ mod tests { #[crate::test] async fn pending_polls_do_not_count_as_work() { - let producer = kio::Producer::new(()); + let producer = crate::Producer::new(()); let consumer = producer.consume(); - let waiter = kio::Waiter::noop(); + let waiter = crate::Waiter::noop(); for _ in 0..10_000 { assert!(consumer.poll(&waiter, |_| Poll::<()>::Pending).is_pending()); } @@ -663,36 +663,36 @@ mod tests { #[crate::test] async fn a_large_task_set_counts_each_child_alone() { - let producer = kio::Producer::new(()); - let mut tasks = kio::Tasks::new(); + let producer = crate::Producer::new(()); + let mut tasks = crate::Tasks::new(); for _ in 0..10_000 { let consumer = producer.consume(); - tasks.push(move |waiter: &kio::Waiter| consumer.poll(waiter, |_| Poll::Ready(())).map(drop)); + tasks.push(move |waiter: &crate::Waiter| consumer.poll(waiter, |_| Poll::Ready(())).map(drop)); } - kio::wait(|waiter| tasks.poll(waiter)).await; + crate::wait(|waiter| tasks.poll(waiter)).await; } #[test] #[should_panic(expected = "kio Ready poll limit")] fn a_spinning_task_set_child_fails() { run(async { - let mut tasks = kio::Tasks::new(); - tasks.push(|_: &kio::Waiter| { + let mut tasks = crate::Tasks::new(); + tasks.push(|_: &crate::Waiter| { spin(); Poll::Ready(()) }); - kio::wait(|waiter| tasks.poll(waiter)).await; + crate::wait(|waiter| tasks.poll(waiter)).await; }); } #[test] fn a_task_set_outside_the_simulator_counts_nothing() { - let mut tasks = kio::Tasks::new(); - tasks.push(|_: &kio::Waiter| { + let mut tasks = crate::Tasks::new(); + tasks.push(|_: &crate::Waiter| { spin(); Poll::Ready(()) }); - assert!(tasks.poll(&kio::Waiter::noop()).is_ready()); + assert!(tasks.poll(&crate::Waiter::noop()).is_ready()); } fn at(secs: u64) -> Instant { @@ -739,8 +739,8 @@ mod tests { #[crate::test] async fn starts_at_zero() { - assert_eq!(crate::now(), Instant::ZERO); - assert_eq!(crate::wall(), Manual::WALL_START); + assert_eq!(crate::clock::now(), Instant::ZERO); + assert_eq!(crate::clock::wall(), Manual::WALL_START); } #[test] @@ -750,13 +750,13 @@ mod tests { for secs in [1, 5, 3] { let fired = fired.clone(); drop(spawn(async move { - crate::sleep(Duration::from_secs(secs)).await; + crate::clock::sleep(Duration::from_secs(secs)).await; fired.set(fired.get() + 1); })); } idle().await; assert_eq!(fired.get(), 3); - assert_eq!(crate::now(), at(5)); + assert_eq!(crate::clock::now(), at(5)); }); } @@ -764,18 +764,18 @@ mod tests { fn time_moves_only_when_every_task_stalls() { run(async { let a = spawn(async { - crate::sleep(Duration::from_secs(5)).await; - crate::now() + crate::clock::sleep(Duration::from_secs(5)).await; + crate::clock::now() }); let b = spawn(async { - crate::sleep(Duration::from_secs(2)).await; - crate::now() + crate::clock::sleep(Duration::from_secs(2)).await; + crate::clock::now() }); - assert_eq!(crate::now(), Instant::ZERO, "spawning does not move time"); + assert_eq!(crate::clock::now(), Instant::ZERO, "spawning does not move time"); assert_eq!(b.await.unwrap(), at(2)); assert_eq!(a.await.unwrap(), at(5)); assert_eq!( - crate::wall(), + crate::clock::wall(), Manual::WALL_START + Duration::from_secs(5), "wall time moved too" ); @@ -784,39 +784,39 @@ mod tests { #[crate::test] async fn timeout_uses_simulated_time() { - let slow = crate::timeout(Duration::from_secs(1), crate::sleep(Duration::from_secs(60))).await; + let slow = crate::clock::timeout(Duration::from_secs(1), crate::clock::sleep(Duration::from_secs(60))).await; assert_eq!(slow.unwrap_err(), Elapsed); - assert_eq!(crate::now(), at(1)); - let fast = crate::timeout(Duration::from_secs(60), async { 7 }).await; + assert_eq!(crate::clock::now(), at(1)); + let fast = crate::clock::timeout(Duration::from_secs(60), async { 7 }).await; assert_eq!(fast, Ok(7)); } #[crate::test] async fn timeout_at_ends_at_the_deadline() { - let slow = crate::timeout_at(at(2), crate::sleep(Duration::from_secs(60))).await; + let slow = crate::clock::timeout_at(at(2), crate::clock::sleep(Duration::from_secs(60))).await; assert_eq!(slow.unwrap_err(), Elapsed); - assert_eq!(crate::now(), at(2)); - let late = crate::timeout_at(at(1), async { 7 }).await; + assert_eq!(crate::clock::now(), at(2)); + let late = crate::clock::timeout_at(at(1), async { 7 }).await; assert_eq!(late, Ok(7), "a ready future wins even past the deadline"); } #[crate::test] async fn advance_wakes_due_timers() { - let timer = spawn(crate::sleep(Duration::from_secs(3))); + let timer = spawn(crate::clock::sleep(Duration::from_secs(3))); yield_now().await; advance(Duration::from_secs(3)).await; assert!(timer.is_finished()); - assert_eq!(crate::now(), at(3)); + assert_eq!(crate::clock::now(), at(3)); } #[crate::test] async fn a_wall_step_passes_no_time() { advance(Duration::from_secs(10)).await; step_wall(Manual::WALL_START + Duration::from_secs(4)); - assert_eq!(crate::now(), at(10), "a step back passes no time"); - assert_eq!(crate::wall(), Manual::WALL_START + Duration::from_secs(4)); + assert_eq!(crate::clock::now(), at(10), "a step back passes no time"); + assert_eq!(crate::clock::wall(), Manual::WALL_START + Duration::from_secs(4)); advance(Duration::from_secs(1)).await; - assert_eq!(crate::wall(), Manual::WALL_START + Duration::from_secs(5)); + assert_eq!(crate::clock::wall(), Manual::WALL_START + Duration::from_secs(5)); } #[crate::test] @@ -825,7 +825,7 @@ mod tests { let task = spawn({ let fired = fired.clone(); async move { - crate::sleep(Duration::from_secs(1)).await; + crate::clock::sleep(Duration::from_secs(1)).await; fired.set(true); } }); @@ -833,29 +833,29 @@ mod tests { task.abort(); assert!(task.await.unwrap_err().is_cancelled()); // Nothing else is armed: a dropped sleep left no timer behind, so time jumps here. - crate::sleep(Duration::from_secs(5)).await; + crate::clock::sleep(Duration::from_secs(5)).await; assert!(!fired.get()); - assert_eq!(crate::now(), at(5)); + assert_eq!(crate::clock::now(), at(5)); } #[crate::test] async fn rearming() { - let mut sleep = crate::sleep(Duration::from_secs(1)); + let mut sleep = crate::clock::sleep(Duration::from_secs(1)); sleep.reset(at(3)); (&mut sleep).await; - assert_eq!(crate::now(), at(3), "the old instant is gone"); + assert_eq!(crate::clock::now(), at(3), "the old instant is gone"); sleep.reset(at(4)); sleep.await; - assert_eq!(crate::now(), at(4), "a completed sleep re-arms"); + assert_eq!(crate::clock::now(), at(4), "a completed sleep re-arms"); } #[crate::test] async fn an_expired_deadline_fires_at_once() { advance(Duration::from_secs(10)).await; - crate::sleep_until(at(5)).await; - crate::sleep_until(at(10)).await; - crate::sleep(Duration::ZERO).await; - assert_eq!(crate::now(), at(10)); + crate::clock::sleep_until(at(5)).await; + crate::clock::sleep_until(at(10)).await; + crate::clock::sleep(Duration::ZERO).await; + assert_eq!(crate::clock::now(), at(10)); } #[crate::test] @@ -863,9 +863,9 @@ mod tests { let order = Rc::new(RefCell::new(Vec::new())); // Created in one order; a sleep arms on its first poll, so spawning them in // the other order arms them in that order. - let first = crate::sleep_until(at(1)); - let second = crate::sleep_until(at(1)); - let record = |name: &'static str, sleep: crate::Sleep| { + let first = crate::clock::sleep_until(at(1)); + let second = crate::clock::sleep_until(at(1)); + let record = |name: &'static str, sleep: crate::clock::Sleep| { let order = order.clone(); spawn(async move { sleep.await; @@ -881,32 +881,32 @@ mod tests { #[crate::test] async fn interval_bursts_missed_ticks_by_default() { - let mut ticks = crate::interval(Duration::from_secs(1)); + let mut ticks = crate::clock::interval(Duration::from_secs(1)); assert_eq!(ticks.tick().await, at(0), "the first tick is immediate"); advance(Duration::from_millis(3500)).await; assert_eq!(ticks.tick().await, at(1)); assert_eq!(ticks.tick().await, at(2)); assert_eq!(ticks.tick().await, at(3)); assert_eq!( - crate::now(), + crate::clock::now(), Instant::ZERO + Duration::from_millis(3500), "caught up at once" ); assert_eq!(ticks.tick().await, at(4)); - assert_eq!(crate::now(), at(4)); + assert_eq!(crate::clock::now(), at(4)); } #[crate::test] async fn interval_at_starts_at_its_first_tick() { - let mut ticks = crate::interval_at(at(2), Duration::from_secs(1)); + let mut ticks = crate::clock::interval_at(at(2), Duration::from_secs(1)); assert_eq!(ticks.tick().await, at(2)); - assert_eq!(crate::now(), at(2), "nothing ticks before the start"); + assert_eq!(crate::clock::now(), at(2), "nothing ticks before the start"); assert_eq!(ticks.tick().await, at(3)); } #[crate::test] async fn interval_delay_restarts_from_the_late_tick() { - let mut ticks = crate::interval(Duration::from_secs(1)); + let mut ticks = crate::clock::interval(Duration::from_secs(1)); ticks.set_missed_tick_behavior(MissedTickBehavior::Delay); ticks.tick().await; advance(Duration::from_millis(3500)).await; @@ -916,7 +916,7 @@ mod tests { #[crate::test] async fn interval_skip_resumes_the_schedule() { - let mut ticks = crate::interval(Duration::from_secs(1)); + let mut ticks = crate::clock::interval(Duration::from_secs(1)); ticks.set_missed_tick_behavior(MissedTickBehavior::Skip); ticks.tick().await; advance(Duration::from_millis(3500)).await; @@ -986,7 +986,7 @@ mod tests { #[test] #[should_panic(expected = "deadlock")] fn a_sleep_past_the_range_never_fires() { - run(async { crate::sleep(Duration::MAX).await }); + run(async { crate::clock::sleep(Duration::MAX).await }); } /// The last instant is a real deadline, not the never-firing overflow. @@ -994,7 +994,7 @@ mod tests { async fn the_last_instant_is_reachable() { // From the epoch, so the wall clock has room to reach it too. step_wall(Wall::UNIX_EPOCH); - let task = spawn(crate::sleep_until(Instant::MAX)); + let task = spawn(crate::clock::sleep_until(Instant::MAX)); yield_now().await; advance(Duration::from_nanos(u64::MAX)).await; task.await.unwrap(); @@ -1007,7 +1007,7 @@ mod tests { run(async { // From the epoch, so the wall clock could reach the last instant. step_wall(Wall::UNIX_EPOCH); - let mut interval = crate::interval(Duration::MAX); + let mut interval = crate::clock::interval(Duration::MAX); interval.tick().await; interval.tick().await; }); @@ -1016,22 +1016,22 @@ mod tests { /// A queue attached behind the clock catches up before the run decides it stalled. #[crate::test] async fn a_queue_attached_behind_the_clock_wakes_at_once() { - let deadlines = Deadlines::new(crate::now()); + let deadlines = Deadlines::new(crate::clock::now()); let mut deadline = Deadline::after(&deadlines, Duration::from_secs(5)); advance(Duration::from_secs(10)).await; - let task = spawn(async move { kio::wait(|waiter| deadline.poll(waiter)).await }); + let task = spawn(async move { crate::wait(|waiter| deadline.poll(waiter)).await }); yield_now().await; attach(&deadlines); task.await.unwrap(); - assert_eq!(crate::now(), at(10)); + assert_eq!(crate::clock::now(), at(10)); } /// Attaching brings the queue to the simulated instant at once, so a deadline /// armed right after counts from it. #[crate::test] async fn attaching_syncs_the_queue() { - let deadlines = Deadlines::new(crate::now()); + let deadlines = Deadlines::new(crate::clock::now()); advance(Duration::from_secs(10)).await; attach(&deadlines); assert_eq!(deadlines.now(), at(10)); @@ -1048,16 +1048,16 @@ mod tests { async fn a_sleep_reset_by_another_task_rearms() { // Armed, and past the clock's range so never firing. for duration in [Duration::from_secs(10), Duration::MAX] { - let sleep = Rc::new(RefCell::new(crate::sleep(duration))); + let sleep = Rc::new(RefCell::new(crate::clock::sleep(duration))); let polled = sleep.clone(); let task = spawn(std::future::poll_fn(move |cx| { Pin::new(&mut *polled.borrow_mut()).poll(cx) })); yield_now().await; - let target = crate::now() + Duration::from_secs(3); + let target = crate::clock::now() + Duration::from_secs(3); sleep.borrow_mut().reset(target); task.await.unwrap(); - assert_eq!(crate::now(), target); + assert_eq!(crate::clock::now(), target); } } @@ -1072,26 +1072,26 @@ mod tests { } } let count = Arc::new(Count(Default::default())); - let owner = kio::Waiter::new(Waker::from(count.clone())); + let owner = crate::Waiter::new(Waker::from(count.clone())); - let deadlines = Deadlines::new(crate::now()); + let deadlines = Deadlines::new(crate::clock::now()); attach(&deadlines); - deadlines.advance(crate::now()); + deadlines.advance(crate::clock::now()); deadlines.park(&owner); - crate::sleep(Duration::from_secs(1)).await; + crate::clock::sleep(Duration::from_secs(1)).await; let mut deadline = Deadline::new(&deadlines); - deadline.set(Some(crate::now() + Duration::from_secs(1))); + deadline.set(Some(crate::clock::now() + Duration::from_secs(1))); assert_eq!(count.0.load(Ordering::SeqCst), 1, "the parked owner was not woken"); } /// The run holds an attached queue weakly and forgets it once its owner drops it. #[crate::test] async fn an_attached_queue_detaches_once_dropped() { - let deadlines = Deadlines::new(crate::now()); + let deadlines = Deadlines::new(crate::clock::now()); attach(&deadlines); drop(deadlines); - crate::sleep(Duration::from_secs(1)).await; + crate::clock::sleep(Duration::from_secs(1)).await; assert!(expect_current().queues.borrow().is_empty()); } @@ -1106,10 +1106,10 @@ mod tests { /// A sleep answers to the clock it was created on, not to the poller's. #[test] - #[should_panic(expected = "polled outside its moq_clock::sim::run")] + #[should_panic(expected = "polled outside its kio::clock::sim::run")] #[expect(clippy::async_yields_async, reason = "the sleep escapes the run on purpose")] fn a_sleep_polled_in_another_run_panics() { - let mut sleep = run(async { crate::sleep(Duration::from_secs(1)) }); + let mut sleep = run(async { crate::clock::sleep(Duration::from_secs(1)) }); run(async move { advance(Duration::from_secs(2)).await; (&mut sleep).await; @@ -1118,18 +1118,18 @@ mod tests { #[crate::test] async fn attached_deadlines_advance_with_time() { - let deadlines = Deadlines::new(crate::now()); + let deadlines = Deadlines::new(crate::clock::now()); attach(&deadlines); let mut deadline = Deadline::after(&deadlines, Duration::from_secs(4)); // Nothing else is armed, so the stall jumps straight to the queue's deadline. - kio::wait(|waiter| deadline.poll(waiter)).await; - assert_eq!(crate::now(), at(4)); + crate::wait(|waiter| deadline.poll(waiter)).await; + assert_eq!(crate::clock::now(), at(4)); } #[crate::test] async fn drive_polls_at_each_requested_instant() { let mut polls = Vec::new(); - let err = crate::drive(|now, _waiter| { + let err = crate::clock::drive(|now, _waiter| { polls.push(now); match polls.len() { 3 => Err("done"), diff --git a/rs/moq-clock/src/timer.rs b/rs/kio/src/clock/timer.rs similarity index 88% rename from rs/moq-clock/src/timer.rs rename to rs/kio/src/clock/timer.rs index ba499e3efb3..ec95ebe38ed 100644 --- a/rs/moq-clock/src/timer.rs +++ b/rs/kio/src/clock/timer.rs @@ -6,7 +6,7 @@ use std::{ time::Duration, }; -use crate::Instant; +use crate::clock::Instant; /// A future that completes once the ambient clock reaches an instant. /// @@ -21,25 +21,25 @@ pub struct Sleep { } enum Timer { - Queue(crate::deadline::Timer), - Host(crate::runtime::Timer), + Queue(crate::clock::deadline::Timer), + Host(crate::clock::runtime::Timer), #[cfg(feature = "sim")] - Sim(crate::sim::Timer), + Sim(crate::clock::sim::Timer), #[cfg(feature = "manual")] - Installed(crate::installed::Timer), + Installed(crate::clock::installed::Timer), } /// Complete once the ambient clock reaches `at`; at once if it already has. pub fn sleep_until(at: Instant) -> Sleep { - if let Some(deadlines) = crate::deadline::entered() { + if let Some(deadlines) = crate::clock::deadline::entered() { return Sleep { at: Some(at), - timer: Timer::Queue(crate::deadline::Timer::new(&deadlines, Some(at))), + timer: Timer::Queue(crate::clock::deadline::Timer::new(&deadlines, Some(at))), parked: None, }; } #[cfg(feature = "sim")] - if let Some(timer) = crate::sim::Timer::new(at) { + if let Some(timer) = crate::clock::sim::Timer::new(at) { return Sleep { at: Some(at), timer: Timer::Sim(timer), @@ -47,12 +47,12 @@ pub fn sleep_until(at: Instant) -> Sleep { }; } #[cfg(feature = "manual")] - if let Some(clock) = crate::installed::current() { + if let Some(clock) = crate::clock::installed::current() { return Sleep::installed(clock, at); } Sleep { at: Some(at), - timer: Timer::Host(crate::runtime::Timer::new(at)), + timer: Timer::Host(crate::clock::runtime::Timer::new(at)), parked: None, } } @@ -61,7 +61,7 @@ pub fn sleep_until(at: Instant) -> Sleep { /// /// A duration past the clock's range never completes. pub fn sleep(duration: Duration) -> Sleep { - let now = crate::now(); + let now = crate::clock::now(); let mut sleep = sleep_until(now); sleep.set(now.checked_add(duration)); sleep @@ -70,10 +70,10 @@ pub fn sleep(duration: Duration) -> Sleep { impl Sleep { /// A sleep on an installed clock, whichever thread polls it. #[cfg(feature = "manual")] - pub(crate) fn installed(clock: crate::Installed, at: Instant) -> Self { + pub(crate) fn installed(clock: crate::clock::Installed, at: Instant) -> Self { Self { at: Some(at), - timer: Timer::Installed(crate::installed::Timer::new(clock, at)), + timer: Timer::Installed(crate::clock::installed::Timer::new(clock, at)), parked: None, } } @@ -210,7 +210,7 @@ pub struct Interval { /// /// When `period` is zero. pub fn interval(period: Duration) -> Interval { - interval_at(crate::now(), period) + interval_at(crate::clock::now(), period) } /// Tick every `period` on the ambient clock, the first tick at `start`. @@ -239,7 +239,7 @@ impl Interval { return Poll::Pending; } let scheduled = self.sleep.deadline(); - let now = crate::now(); + let now = crate::clock::now(); // A tick past the clock's range never comes. let next = scheduled.checked_add(self.period).and_then(|next| { if next > now { @@ -275,11 +275,11 @@ impl Interval { /// /// `poll` is called with the current instant and returns when it next wants to be /// polled: `Ok(Some(at))` by `at` or on a wake, `Ok(None)` only on a wake. -pub async fn drive(mut poll: impl FnMut(Instant, &kio::Waiter) -> Result, E> + Unpin) -> E { +pub async fn drive(mut poll: impl FnMut(Instant, &crate::Waiter) -> Result, E> + Unpin) -> E { let mut timer: Option = None; - kio::wait(move |waiter| { + crate::wait(move |waiter| { loop { - let at = match poll(crate::now(), waiter) { + let at = match poll(crate::clock::now(), waiter) { Ok(Some(at)) => at, Ok(None) => { timer = None; @@ -323,7 +323,8 @@ mod tests { .start_paused(true) .build() .unwrap(); - let (mut sleep, at) = runtime.block_on(async { (sleep(Duration::MAX), crate::now() + Duration::from_secs(1)) }); + let (mut sleep, at) = + runtime.block_on(async { (sleep(Duration::MAX), crate::clock::now() + Duration::from_secs(1)) }); sleep.reset(at); runtime.block_on(sleep); } diff --git a/rs/moq-clock/src/wall.rs b/rs/kio/src/clock/wall.rs similarity index 97% rename from rs/moq-clock/src/wall.rs rename to rs/kio/src/clock/wall.rs index 313871c259f..a2912fe0f5a 100644 --- a/rs/moq-clock/src/wall.rs +++ b/rs/kio/src/clock/wall.rs @@ -6,7 +6,7 @@ use std::{ /// A wall-clock time, in nanoseconds since the Unix epoch. /// -/// Read from the same clock as [`Instant`](crate::Instant) but kept apart from it: +/// Read from the same clock as [`Instant`](crate::clock::Instant) but kept apart from it: /// wall time can be stepped, forward or back, without any monotonic time passing, /// so it never measures elapsed time. Times before 1970 are unrepresentable. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -23,7 +23,7 @@ impl Wall { /// The current wall time on the ambient clock. pub fn now() -> Self { - crate::wall() + crate::clock::wall() } /// The time from `earlier` to this one, or `None` if `earlier` is later. diff --git a/rs/kio/src/consumer.rs b/rs/kio/src/consumer.rs index 9b2347332f6..bb39138bcfb 100644 --- a/rs/kio/src/consumer.rs +++ b/rs/kio/src/consumer.rs @@ -72,7 +72,7 @@ impl Consumer { /// channel is still open, registers the [`Waiter`] for notification. /// Returns `Err(`[`Ref`]`)` if the channel has been closed while the /// condition returned by `f` is still pending. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll(&self, waiter: &Waiter, f: F) -> Poll>> where F: FnOnce(&Ref<'_, T>) -> Poll, @@ -96,7 +96,7 @@ impl Consumer { } /// Poll for channel closure, registering the waiter if still open. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_closed(&self, waiter: &Waiter) -> Poll<()> { let mut state = self.state.lock(); if state.closed { diff --git a/rs/kio/src/coop.rs b/rs/kio/src/coop.rs index 4f3eafc8135..4f82a877166 100644 --- a/rs/kio/src/coop.rs +++ b/rs/kio/src/coop.rs @@ -9,17 +9,17 @@ use std::task::Poll; use crate::Waiter; -#[cfg(feature = "_sim")] +#[cfg(feature = "sim")] thread_local! { static READY: std::cell::Cell> = const { std::cell::Cell::new(None) }; } /// Restores the enclosing count, even when a spawned task panics and its executor /// catches the panic. -#[cfg(feature = "_sim")] +#[cfg(feature = "sim")] struct Reset(Option); -#[cfg(feature = "_sim")] +#[cfg(feature = "sim")] impl Drop for Reset { fn drop(&mut self) { READY.set(self.0); @@ -27,22 +27,22 @@ impl Drop for Reset { } /// Count ready kio polls until the returned guard drops, panicking if the task spins. -#[cfg(feature = "_sim")] +#[cfg(feature = "sim")] #[must_use = "keep the guard until the task poll returns"] -pub fn scope() -> impl Drop { +pub(crate) fn scope() -> impl Drop { Reset(READY.replace(Some(0))) } /// Give a [`Tasks`](crate::Tasks) child's poll its own count, but only inside a counting scope. -#[cfg(feature = "_sim")] +#[cfg(feature = "sim")] pub(crate) fn child() -> impl Drop { Reset(READY.replace(READY.get().map(|_| 0))) } #[inline] -#[cfg_attr(feature = "_sim", track_caller)] +#[cfg_attr(feature = "sim", track_caller)] pub(crate) fn ready(value: T) -> Poll { - #[cfg(feature = "_sim")] + #[cfg(feature = "sim")] { let count = READY.get().map(|count| count + 1); READY.set(count); @@ -75,7 +75,7 @@ impl Budget { /// The yield refills the budget for the next poll. Call it only where `Pending` goes /// straight up to the task: a caller that reads `Pending` as "nothing now" would /// mistake the yield for an answer. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_yield(&mut self, waiter: &Waiter) -> Poll<()> { match self.left.checked_sub(1) { Some(left) => { diff --git a/rs/kio/src/lib.rs b/rs/kio/src/lib.rs index 8b8ab652c88..439c8835c92 100644 --- a/rs/kio/src/lib.rs +++ b/rs/kio/src/lib.rs @@ -18,6 +18,9 @@ //! //! [`coop`] bounds the passes a loop makes per poll, so one that always finds //! work ready still yields. +//! +//! [`clock`] is the time those waits run on: logical instants, wall time, +//! deadlines, timers, and a deterministic simulator for tests. #![warn(missing_docs)] @@ -32,6 +35,7 @@ mod lock; mod sync; mod waiter; +pub mod clock; pub mod coop; pub mod log; @@ -60,6 +64,14 @@ pub use task::{Task, Tasks}; pub use waiter::{Park, Waiter, WaiterList, wait}; pub use weak::{ConsumerWeak, ProducerWeak, Weak}; +/// Run an `async fn` test to completion on [`clock::sim::run`]. +#[cfg(feature = "sim")] +pub use kio_macros::test; + +// So `#[kio::test]` resolves inside this crate's own tests. +#[cfg(test)] +extern crate self as kio; + /// Bytes an `Arc` allocation occupies: `T` behind two reference counts, padded to /// `T`'s alignment and rounded up to the whole layout's. /// @@ -80,7 +92,8 @@ const fn arc_heap() -> usize { mod heap { use std::alloc::Layout; - use super::*; + // Not a glob: it would import `test`, kio's attribute, over the built-in one. + use super::{State, arc_heap, sync}; /// [`arc_heap`] hand-rolls what `Layout` does, because `Layout` isn't `const`. Hold /// it to the real thing, including a `T` aligned past the reference counts. diff --git a/rs/kio/src/producer.rs b/rs/kio/src/producer.rs index 5328d59a80a..155192a2caf 100644 --- a/rs/kio/src/producer.rs +++ b/rs/kio/src/producer.rs @@ -124,7 +124,7 @@ impl Producer { /// while pending. /// /// Returns `Poll::Ready(Err(`[`Ref`]`))` if the channel is closed. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll(&self, waiter: &Waiter, f: F) -> Poll, Ref<'_, T>>> where F: FnOnce(&Ref<'_, T>) -> Poll<()>, @@ -151,7 +151,7 @@ impl Producer { /// [`Mut`], so it never flags the state modified and never wakes consumers. /// Use it to wait on a read condition from the producer side without creating /// a [`Consumer`]. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_ref(&self, waiter: &Waiter, f: F) -> Poll>> where F: FnOnce(&Ref<'_, T>) -> Poll, @@ -193,7 +193,7 @@ impl Producer { /// Poll for channel closure (an explicit [`Mut::close`], e.g. an abort), /// registering the waiter if still open. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_closed(&self, waiter: &Waiter) -> Poll<()> { let mut state = self.state.lock(); if state.closed { @@ -213,7 +213,7 @@ impl Producer { /// Poll-based variant of [`Self::unused`]: `Ready(Ok(()))` when no consumers /// remain, [`Closed`] if the channel closed first, else `Pending`. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_unused(&self, waiter: &Waiter) -> Poll> { let mut state = self.state.lock(); if state.closed { @@ -252,7 +252,7 @@ impl Producer { /// Poll-based variant of [`Self::used`]: `Ready(Ok(()))` once a consumer /// exists, [`Closed`] if the channel closed first, else `Pending`. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_used(&self, waiter: &Waiter) -> Poll> { let mut state = self.state.lock(); if state.closed { diff --git a/rs/kio/src/queue.rs b/rs/kio/src/queue.rs index 1e2202d6229..a4ebba7fe0e 100644 --- a/rs/kio/src/queue.rs +++ b/rs/kio/src/queue.rs @@ -130,7 +130,7 @@ impl Queue { /// (or anything that does). /// /// Registers `waiter` while full; a pop or close re-polls it. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_push_with T>(&self, waiter: &Waiter, make: F) -> Poll> { let mut waiters = { let mut state = self.state.lock(); @@ -181,7 +181,7 @@ impl Queue { /// /// Queued items drain before closure is reported, so [`Closed`] means empty /// *and* closed. Registers `waiter` while empty; a push or close re-polls it. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_pop(&self, waiter: &Waiter) -> Poll> { let (item, mut waiters) = { let mut state = self.state.lock(); diff --git a/rs/kio/src/shared.rs b/rs/kio/src/shared.rs index 41a7bd3d85a..7e77079565d 100644 --- a/rs/kio/src/shared.rs +++ b/rs/kio/src/shared.rs @@ -61,7 +61,7 @@ impl Shared { /// [`Ref`], so it can't flag the state modified and spuriously wake this poll's own /// waiter. Registers `waiter` while pending; any mutation through a [`lock`](Self::lock) /// guard re-polls it. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll(&self, waiter: &Waiter, f: F) -> Poll> where F: FnOnce(&Ref<'_, T>) -> Poll<()>, diff --git a/rs/kio/src/task.rs b/rs/kio/src/task.rs index 0c3e58d4e41..a96212ca040 100644 --- a/rs/kio/src/task.rs +++ b/rs/kio/src/task.rs @@ -342,7 +342,7 @@ impl> Tasks { /// such an arm with [`is_empty`](Self::is_empty). /// `waiter` is registered for the next task wake or push; the tasks /// themselves park on their own wakers. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll(&mut self, waiter: &Waiter) -> Poll<()> { { let mut parent = self.shared.parent.lock().unwrap(); @@ -405,7 +405,7 @@ impl> Tasks { let child_waiter = occupant.park.hold(&cx); // Each child is its own task, so a large sweep of finite children is not // one spinning poll. - #[cfg(feature = "_sim")] + #[cfg(feature = "sim")] let _scope = crate::coop::child(); if occupant.task.poll(child_waiter).is_ready() { self.children[index] = None; diff --git a/rs/kio/src/waiter.rs b/rs/kio/src/waiter.rs index 1d26af18930..0dc9c3a8b45 100644 --- a/rs/kio/src/waiter.rs +++ b/rs/kio/src/waiter.rs @@ -156,7 +156,7 @@ impl Waiter { /// Poll a foreign [`Future`] against this waiter, so it re-wakes the enclosing /// `poll_*` step when it is ready. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_future(&self, future: Pin<&mut F>) -> Poll { match future.poll(&mut self.context()) { Poll::Ready(value) => crate::coop::ready(value), diff --git a/rs/kio/src/weak.rs b/rs/kio/src/weak.rs index cff7c3ce90b..64f2fdc1d34 100644 --- a/rs/kio/src/weak.rs +++ b/rs/kio/src/weak.rs @@ -154,7 +154,7 @@ impl ProducerWeak { } /// Poll for channel closure, registering the waiter if still open. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_closed(&self, waiter: &Waiter) -> Poll<()> { let mut state = self.state.lock(); if state.closed { @@ -174,7 +174,7 @@ impl ProducerWeak { /// Poll-based variant of [`Self::unused`]: `Ready(Ok(()))` when no consumers /// remain, [`Closed`] if the channel closed first, else `Pending`. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_unused(&self, waiter: &Waiter) -> Poll> { // Closure is checked first, matching `Producer::poll_unused`: a closed channel // with no consumers resolves `Closed` from either handle. @@ -215,7 +215,7 @@ impl ProducerWeak { /// Poll-based variant of [`Self::used`]: `Ready(Ok(()))` once a consumer /// exists, [`Closed`] if the channel closed first, else `Pending`. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_used(&self, waiter: &Waiter) -> Poll> { // Closure is checked first, matching `Producer::poll_used`. let mut state = self.state.lock(); @@ -280,7 +280,7 @@ impl ConsumerWeak { /// Available here so a watcher can register for changes without joining the /// consumer count, which is what [`Producer::unused`](crate::Producer::unused) /// keys off. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll(&self, waiter: &Waiter, f: F) -> Poll>> where F: FnOnce(&Ref<'_, T>) -> Poll, @@ -313,7 +313,7 @@ impl ConsumerWeak { } /// Poll for channel closure, registering the waiter if still open. - #[cfg_attr(feature = "_sim", track_caller)] + #[cfg_attr(feature = "sim", track_caller)] pub fn poll_closed(&self, waiter: &Waiter) -> Poll<()> { let mut state = self.state.lock(); if state.closed { diff --git a/rs/libmoq/clippy.toml b/rs/libmoq/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/libmoq/clippy.toml +++ b/rs/libmoq/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-archive/Cargo.toml b/rs/moq-archive/Cargo.toml index a3d6fa17971..85e991def46 100644 --- a/rs/moq-archive/Cargo.toml +++ b/rs/moq-archive/Cargo.toml @@ -15,8 +15,7 @@ categories = ["multimedia", "filesystem"] [dependencies] bytes = { workspace = true } futures = { workspace = true } -kio = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-net = { workspace = true } object_store = { workspace = true } percent-encoding = { workspace = true } diff --git a/rs/moq-archive/clippy.toml b/rs/moq-archive/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-archive/clippy.toml +++ b/rs/moq-archive/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-archive/src/consumer/mod.rs b/rs/moq-archive/src/consumer/mod.rs index 5786bcc3ca8..c2d125a0fdb 100644 --- a/rs/moq-archive/src/consumer/mod.rs +++ b/rs/moq-archive/src/consumer/mod.rs @@ -182,7 +182,7 @@ impl Consumer { let (shared, period) = (self.shared.clone(), self.refresh); refreshing = Some( async move { - moq_clock::sleep(period).await; + kio::clock::sleep(period).await; refresh(shared, snapshots).await } .boxed(), diff --git a/rs/moq-archive/src/consumer/tests.rs b/rs/moq-archive/src/consumer/tests.rs index 505ad2ad613..1389526073d 100644 --- a/rs/moq-archive/src/consumer/tests.rs +++ b/rs/moq-archive/src/consumer/tests.rs @@ -1,7 +1,7 @@ use std::time::Duration; use bytes::Bytes; -use moq_clock::{sleep, timeout}; +use kio::clock::{sleep, timeout}; use moq_net::track::{Order, Position, Subscription}; use moq_net::{Timescale, Timestamp, broadcast, group, track}; use object_store::ObjectStoreExt; diff --git a/rs/moq-archive/src/producer/backends.rs b/rs/moq-archive/src/producer/backends.rs index 0a2218d83a6..9e6674709a1 100644 --- a/rs/moq-archive/src/producer/backends.rs +++ b/rs/moq-archive/src/producer/backends.rs @@ -64,10 +64,10 @@ fn path(store: &Store, track: &str, name: &str) -> Path { /// Wait until every one of `paths` is stored. async fn stored(store: &Store, paths: &[Path]) { - moq_clock::timeout(Duration::from_secs(10), async { + kio::clock::timeout(Duration::from_secs(10), async { for path in paths { while store.inner().head(path).await.is_err() { - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; } } }) @@ -104,12 +104,12 @@ async fn record(store: &Store) { let run = tokio::spawn(Producer::new(store.clone(), second.consume(), config()).run()); for track in &tracks { while track.subscription().is_none() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } track.finish().unwrap(); } second.close(); - moq_clock::timeout(Duration::from_secs(10), run) + kio::clock::timeout(Duration::from_secs(10), run) .await .expect("the producer ends with its broadcast") .unwrap() diff --git a/rs/moq-archive/src/producer/ordered.rs b/rs/moq-archive/src/producer/ordered.rs index 7479b78e551..35c2647adb4 100644 --- a/rs/moq-archive/src/producer/ordered.rs +++ b/rs/moq-archive/src/producer/ordered.rs @@ -8,7 +8,7 @@ use std::pin::Pin; use std::task::Poll; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::track::{Position, Subscriber}; use moq_net::{Datagram, group}; @@ -35,7 +35,7 @@ pub(super) struct Ordered { /// and the ones handed out behind it go once it does, so this holds at most what arrived /// within a max delay. The oldest dates the gap, so a later, lower arrival never extends it. arrivals: VecDeque<(u64, Instant)>, - timer: Option>>, + timer: Option>>, groups_done: bool, datagrams_done: bool, } @@ -59,7 +59,7 @@ impl Ordered { /// Take every arrival so far, registering `waiter` for the next. pub(super) fn poll_arrivals(&mut self, waiter: &kio::Waiter) { - let now = moq_clock::now(); + let now = kio::clock::now(); while !self.groups_done { match self.subscriber.poll_recv_group(waiter) { Poll::Ready(Ok(Some(group))) => self.arrive(group.sequence, Item::Group(Box::new(group)), now), @@ -113,10 +113,10 @@ impl Ordered { // The oldest arrival still pending is when this gap was first seen. let (_, since) = self.arrivals.front().expect("a pending sequence arrived"); let deadline = *since + self.max_delay; - if moq_clock::now() < deadline { + if kio::clock::now() < deadline { let timer = self .timer - .get_or_insert_with(|| Box::pin(moq_clock::sleep_until(deadline))); + .get_or_insert_with(|| Box::pin(kio::clock::sleep_until(deadline))); timer.as_mut().reset(deadline); if waiter.poll_future(timer.as_mut()).is_pending() { return Poll::Pending; @@ -203,9 +203,9 @@ mod tests { group(&track, 4); assert_eq!(next(&mut ordered), None); - moq_clock::sleep(MAX_DELAY - Duration::from_millis(1)).await; + kio::clock::sleep(MAX_DELAY - Duration::from_millis(1)).await; assert_eq!(next(&mut ordered), None); - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; assert_eq!(next(&mut ordered), Some(4)); // Too late for its turn. @@ -223,10 +223,10 @@ mod tests { group(&track, 10); assert_eq!(next(&mut ordered), None); - moq_clock::sleep(MAX_DELAY - Duration::from_millis(1)).await; + kio::clock::sleep(MAX_DELAY - Duration::from_millis(1)).await; group(&track, 9); assert_eq!(next(&mut ordered), None); - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; assert_eq!(next(&mut ordered), Some(9)); assert_eq!(next(&mut ordered), Some(10)); } diff --git a/rs/moq-archive/src/producer/tests.rs b/rs/moq-archive/src/producer/tests.rs index 1325262581d..976076a7704 100644 --- a/rs/moq-archive/src/producer/tests.rs +++ b/rs/moq-archive/src/producer/tests.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use bytes::Bytes; use futures::TryStreamExt; -use moq_clock::sleep; +use kio::clock::sleep; use moq_net::track::Position; use moq_net::{Timescale, Timestamp, broadcast, group, track}; use object_store::ObjectStoreExt; @@ -63,7 +63,7 @@ async fn subscribed(track: &track::Producer) { } async fn finished(task: JoinHandle>) { - moq_clock::timeout(Duration::from_secs(1000), task) + kio::clock::timeout(Duration::from_secs(1000), task) .await .expect("the producer ends with its broadcast") .unwrap() @@ -805,7 +805,7 @@ async fn a_re_added_track_is_stored_under_its_own_properties() { second.finish().unwrap(); broadcast.close(); - let err = moq_clock::timeout(Duration::from_secs(1000), task) + let err = kio::clock::timeout(Duration::from_secs(1000), task) .await .unwrap() .unwrap() diff --git a/rs/moq-archive/src/producer/track.rs b/rs/moq-archive/src/producer/track.rs index e92d338601d..ca1a153cfe2 100644 --- a/rs/moq-archive/src/producer/track.rs +++ b/rs/moq-archive/src/producer/track.rs @@ -7,7 +7,7 @@ use std::task::Poll; use std::time::Duration; use bytes::Bytes; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::track::{Anchor, Order, Position, Range, Subscription}; use moq_net::{StreamError, Timescale, group}; use object_store::path::Path; @@ -104,7 +104,7 @@ impl Track { track.newest = objects.pop(); if track.shared.config.dvr.is_some() { // Their age is unknown, so their window starts now. - let now = moq_clock::now(); + let now = kio::clock::now(); track.superseded = objects.into_iter().map(|path| (now, path)).collect(); } Ok(track) @@ -114,7 +114,7 @@ impl Track { /// to the newest, or `None` once the listing ended. async fn idle(&mut self, queue: &kio::Queue) -> Result> { loop { - let mut timer = self.prune_at().map(|at| Box::pin(moq_clock::sleep_until(at))); + let mut timer = self.prune_at().map(|at| Box::pin(kio::clock::sleep_until(at))); let popped = kio::wait(|waiter| { if let Poll::Ready(popped) = queue.poll_pop(waiter) { return Poll::Ready(Some(popped)); @@ -195,7 +195,7 @@ impl Track { // The group being stored, frame by frame. let mut current: Option> = None; loop { - self.flush_due(moq_clock::now())?; + self.flush_due(kio::clock::now())?; self.write().await?; self.prune().await?; @@ -203,7 +203,7 @@ impl Track { .into_iter() .flatten() .min() - .map(|at| Box::pin(moq_clock::sleep_until(at))); + .map(|at| Box::pin(kio::clock::sleep_until(at))); let event = kio::wait(|waiter| { match current.as_mut() { Some(current) => { @@ -224,7 +224,7 @@ impl Track { }) .await; - let now = moq_clock::now(); + let now = kio::clock::now(); match event { Event::Frame(index, read) => self.frame(&mut current, index, read, now)?, Event::Next(Some((sequence, Item::Datagram(datagram)))) => { @@ -391,7 +391,7 @@ impl Track { if let Some(superseded) = self.newest.replace(path.clone()) && self.shared.config.dvr.is_some() { - self.superseded.push_back((moq_clock::now(), superseded)); + self.superseded.push_back((kio::clock::now(), superseded)); } self.puts.push((path, bytes)); Ok(()) @@ -425,7 +425,7 @@ impl Track { /// Delete the superseded objects whose window and grace have passed. async fn prune(&mut self) -> Result<()> { - let now = moq_clock::now(); + let now = kio::clock::now(); while self.prune_at().is_some_and(|at| at <= now) { let (_, path) = self.superseded.pop_front().expect("a superseded object is due"); match self.shared.store.inner().delete(&path).await { @@ -463,7 +463,7 @@ fn error(err: &moq_net::Error) -> End { } /// Poll an optional timer, pending forever without one. -fn ready_at(timer: &mut Option>>, waiter: &kio::Waiter) -> Poll<()> { +fn ready_at(timer: &mut Option>>, waiter: &kio::Waiter) -> Poll<()> { match timer.as_mut() { Some(timer) => waiter.poll_future(timer.as_mut()), None => Poll::Pending, diff --git a/rs/moq-audio/Cargo.toml b/rs/moq-audio/Cargo.toml index f239078f7d2..2c07b94e0f9 100644 --- a/rs/moq-audio/Cargo.toml +++ b/rs/moq-audio/Cargo.toml @@ -41,7 +41,6 @@ bus = ["dep:ringbuf"] # are target-gated, so this is a no-op elsewhere). capture = [ "dep:cpal", - "dep:kio", "dep:ringbuf", "dep:tokio", "dep:tracing", @@ -57,7 +56,7 @@ capture = [ # Device playback. Mixes any number of `playback::Sink`s into one cpal output # stream (CoreAudio / WASAPI / ALSA). Same libasound build dependency on Linux # as `capture`. -playback = ["dep:cpal", "dep:kio", "dep:ringbuf", "dep:tokio", "dep:tracing"] +playback = ["dep:cpal", "dep:ringbuf", "dep:tokio", "dep:tracing"] # Reach devices through the Linux sound server rather than its ALSA plugin, for # the server's own device names and routing. These customize cpal only when # `capture` or `playback` activates it, so a host flag alone pulls no audio I/O. @@ -75,8 +74,7 @@ bytes = { workspace = true } # without either pulls no new dependency. cpal = { version = "0.18", optional = true } hang = { workspace = true } -kio = { workspace = true, optional = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-mux = { workspace = true } moq-net = { workspace = true } rand = { workspace = true } diff --git a/rs/moq-audio/clippy.toml b/rs/moq-audio/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-audio/clippy.toml +++ b/rs/moq-audio/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-audio/src/capture.rs b/rs/moq-audio/src/capture.rs index 8fcd98a5d7c..f0a75480f00 100644 --- a/rs/moq-audio/src/capture.rs +++ b/rs/moq-audio/src/capture.rs @@ -464,7 +464,7 @@ impl Microphone { // Await the first buffer to surface a permission failure (or dead device) // as an error rather than a silent hang in the capture loop. - let pending = match moq_clock::timeout(FIRST_BUFFER_TIMEOUT, reader.read()).await { + let pending = match kio::clock::timeout(FIRST_BUFFER_TIMEOUT, reader.read()).await { Ok(Ok(Some(samples))) => samples, Ok(Ok(None)) => { return Err(Failure::retry(Error::Capture(format!( diff --git a/rs/moq-audio/src/capture/channel.rs b/rs/moq-audio/src/capture/channel.rs index e336c81d6c1..cec8f33fd5e 100644 --- a/rs/moq-audio/src/capture/channel.rs +++ b/rs/moq-audio/src/capture/channel.rs @@ -12,7 +12,7 @@ use std::sync::{ }; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use tokio::sync::mpsc; diff --git a/rs/moq-audio/src/capture/permission.rs b/rs/moq-audio/src/capture/permission.rs index 07493fbd815..e70e75e5740 100644 --- a/rs/moq-audio/src/capture/permission.rs +++ b/rs/moq-audio/src/capture/permission.rs @@ -67,7 +67,7 @@ async fn request_access(media: &objc2_av_foundation::AVMediaType) -> Result<(), unsafe { AVCaptureDevice::requestAccessForMediaType_completionHandler(media, &handler) }; - match moq_clock::timeout(PROMPT_TIMEOUT, rx).await { + match kio::clock::timeout(PROMPT_TIMEOUT, rx).await { Ok(Ok(true)) => Ok(()), Ok(Ok(false)) => Err(denied()), // Prompt dismissed without a decision, or the callback never fired within diff --git a/rs/moq-audio/src/capture/screencapture.rs b/rs/moq-audio/src/capture/screencapture.rs index e15da5f403a..3068c34c247 100644 --- a/rs/moq-audio/src/capture/screencapture.rs +++ b/rs/moq-audio/src/capture/screencapture.rs @@ -124,7 +124,7 @@ impl SystemAudio { _dispatch: dispatch, }; - let pending = match moq_clock::timeout(FIRST_BUFFER_TIMEOUT, rx.recv()).await { + let pending = match kio::clock::timeout(FIRST_BUFFER_TIMEOUT, rx.recv()).await { Ok(Some(buffer)) => buffer, Ok(None) => { return Err(Error::Capture("system audio stopped before any samples".into())); @@ -352,7 +352,7 @@ async fn shareable_content() -> Result, Error> { }); unsafe { SCShareableContent::getShareableContentWithCompletionHandler(&handler) }; - match moq_clock::timeout(ASYNC_TIMEOUT, rx).await { + match kio::clock::timeout(ASYNC_TIMEOUT, rx).await { Ok(Ok(Ok(content))) => Ok(content.0), Ok(Ok(Err(msg))) => Err(Error::Capture(format!("shareable content: {msg}"))), Ok(Err(_)) => Err(Error::Capture("shareable content handler dropped".into())), @@ -374,7 +374,7 @@ async fn start_capture(stream: &SCStream) -> Result<(), Error> { }); unsafe { stream.startCaptureWithCompletionHandler(Some(&handler)) }; - match moq_clock::timeout(ASYNC_TIMEOUT, rx).await { + match kio::clock::timeout(ASYNC_TIMEOUT, rx).await { Ok(Ok(None)) => Ok(()), Ok(Ok(Some(msg))) => Err(Error::Capture(format!("start system audio: {msg}"))), Ok(Err(_)) => Err(Error::Capture("start-capture handler dropped".into())), diff --git a/rs/moq-audio/src/decode/consumer.rs b/rs/moq-audio/src/decode/consumer.rs index 706fc7c0c83..bf0757e151d 100644 --- a/rs/moq-audio/src/decode/consumer.rs +++ b/rs/moq-audio/src/decode/consumer.rs @@ -2,7 +2,7 @@ use std::collections::VecDeque; -use moq_clock::Instant; +use kio::clock::Instant; use moq_mux::container::Read as Encoded; use std::time::Duration; diff --git a/rs/moq-audio/src/encode/capture.rs b/rs/moq-audio/src/encode/capture.rs index 7059df00052..a3da6b03969 100644 --- a/rs/moq-audio/src/encode/capture.rs +++ b/rs/moq-audio/src/encode/capture.rs @@ -1018,7 +1018,7 @@ impl Supervisor { }; tracing::warn!(error = %failure, "audio capture format unavailable"); - moq_clock::sleep(self.advance()).await; + kio::clock::sleep(self.advance()).await; } } @@ -1145,7 +1145,7 @@ impl Supervisor { } continue 'demand; } - _ = moq_clock::sleep(wait) => {} + _ = kio::clock::sleep(wait) => {} } } } @@ -2078,7 +2078,7 @@ mod tests { /// the broadcast clock's own correlation, so the published timestamp is exactly that /// instant however late the read happens. mod clock { - use moq_clock::Wall; + use kio::clock::Wall; use std::time::Duration; use super::*; @@ -2193,7 +2193,7 @@ mod tests { #[tokio::test] async fn a_late_first_buffer_publishes_its_capture() { let (samples, input) = stream(None); - let mut fixture = Fixture::start(Duration::from_secs(5), moq_clock::wall(), [Open::Stream(input)]); + let mut fixture = Fixture::start(Duration::from_secs(5), kio::clock::wall(), [Open::Stream(input)]); let mut track = fixture.subscribe().await; let published = fixture.deliver(&samples, &mut track, &[]).await; @@ -2206,7 +2206,7 @@ mod tests { #[tokio::test] async fn a_queued_buffer_publishes_its_capture_instant() { let (samples, input) = stream(None); - let mut fixture = Fixture::start(Duration::from_secs(5), moq_clock::wall(), [Open::Stream(input)]); + let mut fixture = Fixture::start(Duration::from_secs(5), kio::clock::wall(), [Open::Stream(input)]); let mut track = fixture.subscribe().await; let captured = Instant::now() - Duration::from_millis(40); @@ -2224,7 +2224,7 @@ mod tests { #[tokio::test] async fn a_buffer_before_the_clock_began_clamps_to_zero() { let (samples, input) = stream(None); - let mut fixture = Fixture::start(Duration::ZERO, moq_clock::wall(), [Open::Stream(input)]); + let mut fixture = Fixture::start(Duration::ZERO, kio::clock::wall(), [Open::Stream(input)]); let mut track = fixture.subscribe().await; samples @@ -2247,7 +2247,7 @@ mod tests { #[tokio::test] async fn a_buffer_captured_after_now_clamps_to_the_read() { let (samples, input) = stream(None); - let mut fixture = Fixture::start(Duration::from_secs(1), moq_clock::wall(), [Open::Stream(input)]); + let mut fixture = Fixture::start(Duration::from_secs(1), kio::clock::wall(), [Open::Stream(input)]); let mut track = fixture.subscribe().await; let pushed = fixture.at(Instant::now()); @@ -2272,7 +2272,7 @@ mod tests { #[tokio::test] async fn a_buffer_without_a_capture_instant_publishes_its_read() { let (samples, input) = stream(None); - let mut fixture = Fixture::start(Duration::from_secs(1), moq_clock::wall(), [Open::Stream(input)]); + let mut fixture = Fixture::start(Duration::from_secs(1), kio::clock::wall(), [Open::Stream(input)]); let mut track = fixture.subscribe().await; let pushed = fixture.at(Instant::now()); @@ -2293,7 +2293,7 @@ mod tests { #[tokio::test] async fn a_gap_reanchors_to_the_next_capture_instant() { let (samples, input) = stream(None); - let mut fixture = Fixture::start(Duration::from_secs(1), moq_clock::wall(), [Open::Stream(input)]); + let mut fixture = Fixture::start(Duration::from_secs(1), kio::clock::wall(), [Open::Stream(input)]); let mut track = fixture.subscribe().await; let second_at = Instant::now() - Duration::from_millis(20); @@ -2319,7 +2319,7 @@ mod tests { let (second, reopened) = stream(None); let mut fixture = Fixture::start( Duration::from_secs(1), - moq_clock::wall(), + kio::clock::wall(), [Open::Stream(failing), Open::Stream(reopened)], ); let mut track = fixture.subscribe().await; @@ -2350,7 +2350,7 @@ mod tests { let (second, resumed) = stream(None); let mut fixture = Fixture::start( Duration::from_secs(1), - moq_clock::wall(), + kio::clock::wall(), [Open::Stream(input), Open::Stream(resumed)], ); @@ -2376,7 +2376,7 @@ mod tests { #[tokio::test] async fn a_system_wall_adjustment_retimes_nothing() { // Whole seconds, so the advertised mapping holds it exactly. - let now = moq_clock::wall().checked_duration_since(Wall::UNIX_EPOCH).unwrap(); + let now = kio::clock::wall().checked_duration_since(Wall::UNIX_EPOCH).unwrap(); let wall = Wall::UNIX_EPOCH + Duration::from_secs(now.as_secs() - 3600); let (samples, input) = stream(None); let mut fixture = Fixture::start(Duration::from_secs(1), wall, [Open::Stream(input)]); @@ -2403,7 +2403,7 @@ mod tests { let (second, resumed) = stream(None); let mut fixture = Fixture::start( Duration::from_secs(1), - moq_clock::wall(), + kio::clock::wall(), [Open::Stream(input), Open::Stream(resumed)], ); let mut live = Vec::new(); diff --git a/rs/moq-audio/src/playback/driver.rs b/rs/moq-audio/src/playback/driver.rs index d0e6453e634..7c4ba2b83c1 100644 --- a/rs/moq-audio/src/playback/driver.rs +++ b/rs/moq-audio/src/playback/driver.rs @@ -5,7 +5,7 @@ //! the hot path; they register themselves in [`Shared`] and hand their consumer //! straight to the mixer. -use moq_clock::Instant; +use kio::clock::Instant; use std::collections::VecDeque; use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU32, Ordering}; #[cfg(feature = "aec")] diff --git a/rs/moq-audio/src/resample.rs b/rs/moq-audio/src/resample.rs index ba1c5ccf578..04f6eabf4a2 100644 --- a/rs/moq-audio/src/resample.rs +++ b/rs/moq-audio/src/resample.rs @@ -550,7 +550,7 @@ mod tests { let mut resampler = Resampler::new(input_rate, output_rate, channels, chunk).unwrap(); let mut elapsed = std::time::Duration::ZERO; for _ in 0..10 { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut count = 0; for (index, samples) in input.chunks(packet * channels as usize).enumerate() { let at = at((index * packet) as u64, input_rate as u64); diff --git a/rs/moq-auth/Cargo.toml b/rs/moq-auth/Cargo.toml index 90e4990e932..d5459641b27 100644 --- a/rs/moq-auth/Cargo.toml +++ b/rs/moq-auth/Cargo.toml @@ -12,7 +12,7 @@ rust-version.workspace = true [features] default = ["client"] # The HTTP client that drives a lease against an auth server. -client = ["dep:reqwest", "dep:rustls", "dep:tokio", "moq-clock/runtime", "dep:tracing", "dep:rand"] +client = ["dep:reqwest", "dep:rustls", "dep:tokio", "kio/runtime", "dep:tracing", "dep:rand"] # The reference auth server behind `moq auth serve`: the policy a relay held, on axum. serve = ["dep:axum", "dep:tokio", "dep:tracing", "tokio/net"] @@ -21,8 +21,7 @@ aws-lc-rs = { workspace = true } axum = { workspace = true, optional = true } base64 = { workspace = true } jsonwebtoken = { workspace = true, features = ["aws_lc_rs"] } -kio = { workspace = true } -moq-clock = { version = "0.11.0", path = "../moq-clock", default-features = false, features = ["serde"] } +kio = { workspace = true, features = ["serde"] } moq-pattern = { workspace = true, features = ["serde"] } p256 = "0.14.0" p384 = "0.14.0" @@ -43,7 +42,7 @@ url = { workspace = true } anyhow = { workspace = true } moq-auth = { path = ".", features = ["client", "serve"] } moq-auth-published = { package = "moq-auth", version = "=0.2.1", default-features = false } -moq-clock = { path = "../moq-clock", features = ["sim"] } +kio = { path = "../kio", features = ["runtime", "sim"] } moq-token = "0.7" tempfile = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread", "test-util"] } diff --git a/rs/moq-auth/MIGRATE.md b/rs/moq-auth/MIGRATE.md index c33155335a0..bbe34b364c6 100644 --- a/rs/moq-auth/MIGRATE.md +++ b/rs/moq-auth/MIGRATE.md @@ -41,9 +41,9 @@ HTTP auth servers can return that JSON shape with 403; legacy plain-text 401/403 ### `Grant` reads the ambient clock -`Grant::deadline` returns a `moq_clock::Instant` instead of a `tokio::time::Instant`, and no longer needs the `tokio` feature. -Wait on it with `moq_clock::sleep_until`, which runs on tokio's clock in production. -`deadline` and `validate` read wall time from `moq_clock::wall()`, so a test on `moq_clock::sim` or a `moq_clock::Manual` clock decides when a grant expires; stamp `expires` from that clock too. +`Grant::deadline` returns a `kio::clock::Instant` instead of a `tokio::time::Instant`, and no longer needs the `tokio` feature. +Wait on it with `kio::clock::sleep_until`, which runs on tokio's clock in production. +`deadline` and `validate` read wall time from `kio::clock::wall()`, so a test on `kio::clock::sim` or a `kio::clock::Manual` clock decides when a grant expires; stamp `expires` from that clock too. `Key::verify` and the reference server's default expiry use that wall clock too. Session `End` durations and the server's idle-session accounting use its monotonic clock, so advancing controlled time advances those durations without a host-clock wait. diff --git a/rs/moq-auth/clippy.toml b/rs/moq-auth/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-auth/clippy.toml +++ b/rs/moq-auth/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-auth/examples/asymmetric.rs b/rs/moq-auth/examples/asymmetric.rs index 830080abada..83c001e03cd 100644 --- a/rs/moq-auth/examples/asymmetric.rs +++ b/rs/moq-auth/examples/asymmetric.rs @@ -20,8 +20,8 @@ fn main() -> anyhow::Result<()> { .with_root("rooms/meeting-123") .with_publish(["alice/**".parse()?]) .with_subscribe(["**".parse()?]) - .with_expires(moq_clock::wall() + Duration::from_secs(3600)) - .with_issued(moq_clock::wall()); + .with_expires(kio::clock::wall() + Duration::from_secs(3600)) + .with_issued(kio::clock::wall()); let token = private_key.sign(&claims)?; println!("Signed token:\n{token}\n"); diff --git a/rs/moq-auth/examples/basic.rs b/rs/moq-auth/examples/basic.rs index 225756a83f8..a875799eeee 100644 --- a/rs/moq-auth/examples/basic.rs +++ b/rs/moq-auth/examples/basic.rs @@ -15,8 +15,8 @@ fn main() -> anyhow::Result<()> { .with_root("demo") .with_publish(["my-stream/**".parse()?]) // Can publish to demo/my-stream and below .with_subscribe(["**".parse()?]) // Can subscribe to anything under demo/ - .with_expires(moq_clock::wall() + Duration::from_secs(3600)) - .with_issued(moq_clock::wall()); + .with_expires(kio::clock::wall() + Duration::from_secs(3600)) + .with_issued(kio::clock::wall()); // Validate the claims (ensures at least one publish or subscribe path). claims.validate()?; diff --git a/rs/moq-auth/src/claims.rs b/rs/moq-auth/src/claims.rs index 867c0fb191b..54d7f478827 100644 --- a/rs/moq-auth/src/claims.rs +++ b/rs/moq-auth/src/claims.rs @@ -126,14 +126,14 @@ pub struct Claims { pub subscribe: Patterns, /// The expiration time of the token as a unix timestamp (`exp`). - pub expires: Option, + pub expires: Option, /// The issued time of the token as a unix timestamp (`iat`). - pub issued: Option, + pub issued: Option, /// The time before which the token is refused, as a unix timestamp (`nbf`). /// Enforced by [`Key::verify`](crate::Key::verify). - pub not_before: Option, + pub not_before: Option, } impl Claims { @@ -158,7 +158,7 @@ impl Claims { /// Expire the token at this time. Enforced by [`Key::verify`](crate::Key::verify). /// /// Accepts an `Option` so a caller can pass one through without unwrapping it. - pub fn with_expires(mut self, at: impl Into>) -> Self { + pub fn with_expires(mut self, at: impl Into>) -> Self { self.expires = at.into(); self } @@ -166,7 +166,7 @@ impl Claims { /// Record when the token was issued. Purely informational; nothing enforces it. /// /// Accepts an `Option` so a caller can pass one through without unwrapping it. - pub fn with_issued(mut self, at: impl Into>) -> Self { + pub fn with_issued(mut self, at: impl Into>) -> Self { self.issued = at.into(); self } @@ -251,8 +251,8 @@ mod tests { root: "test-path".to_string(), publish: patterns(&["test-pub/**"]), subscribe: patterns(&["test-sub/**"]), - expires: Some(moq_clock::wall() + Duration::from_secs(3600)), - issued: Some(moq_clock::wall()), + expires: Some(kio::clock::wall() + Duration::from_secs(3600)), + issued: Some(kio::clock::wall()), not_before: None, } } diff --git a/rs/moq-auth/src/client.rs b/rs/moq-auth/src/client.rs index df347bd2406..b7489c3e9a3 100644 --- a/rs/moq-auth/src/client.rs +++ b/rs/moq-auth/src/client.rs @@ -3,7 +3,7 @@ use std::pin::Pin; use std::sync::Arc; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use url::Url; use crate::lease::{self, Due, Reason}; @@ -369,7 +369,7 @@ async fn ask(server: &S, request: &Request) -> crate::Result { /// Finish a request that nothing else bounds within [`TIMEOUT`], or report the /// server as unavailable, so a stalled server cannot pile up requests. async fn bounded(request: impl Future>) -> crate::Result { - moq_clock::timeout(TIMEOUT, request).await.unwrap_or_else(|_| { + kio::clock::timeout(TIMEOUT, request).await.unwrap_or_else(|_| { Err(Error::Unavailable(format!( "the auth server did not answer within {TIMEOUT:?}" ))) @@ -619,7 +619,7 @@ mod tests { /// as zero and be refused; these tests run on a one-second cadence. fn grant(expires_in: Option, revalidate: Option) -> Grant { let mut grant = Grant::new(patterns(&["**"]), Patterns::new()); - grant.expires = expires_in.map(|d| moq_clock::wall() + d); + grant.expires = expires_in.map(|d| kio::clock::wall() + d); grant.revalidate = revalidate; grant } @@ -1249,7 +1249,7 @@ mod tests { async fn an_expired_grant_is_refused() { tokio::time::pause(); let mut grant = Grant::new(patterns(&["**"]), Patterns::new()); - grant.expires = Some(moq_clock::wall() - Duration::from_secs(1)); + grant.expires = Some(kio::clock::wall() - Duration::from_secs(1)); let script = Script::new(Log::default(), move |_| Some(Ok(grant.clone()))); assert!(matches!(script.connect().await, Err(Error::GrantExpired))); } @@ -1282,7 +1282,7 @@ mod tests { #[tokio::test] async fn an_outage_keeps_the_grant_until_expires() { tokio::time::pause(); - let expires = moq_clock::wall() + Duration::from_secs(3); + let expires = kio::clock::wall() + Duration::from_secs(3); let log = Log::default(); let script = Script::new(log.clone(), move |request| { Some(match request.event { @@ -1297,9 +1297,9 @@ mod tests { // `expires` is wall-clock time, which the client maps onto Tokio's clock // somewhere inside `connect`, so bracket it: the bounds hold however long it takes. - let (wall, tick) = (moq_clock::wall(), tokio::time::Instant::now()); + let (wall, tick) = (kio::clock::wall(), tokio::time::Instant::now()); let consumer = script.connect().await.unwrap(); - let earliest = tick + expires.checked_duration_since(moq_clock::wall()).unwrap(); + let earliest = tick + expires.checked_duration_since(kio::clock::wall()).unwrap(); let latest = tokio::time::Instant::now() + expires.checked_duration_since(wall).unwrap(); // A millisecond either side for Tokio's timer resolution. diff --git a/rs/moq-auth/src/grant.rs b/rs/moq-auth/src/grant.rs index 28615b51502..3ad16c15820 100644 --- a/rs/moq-auth/src/grant.rs +++ b/rs/moq-auth/src/grant.rs @@ -1,4 +1,4 @@ -use moq_clock::Wall; +use kio::clock::Wall; use moq_pattern::Patterns; use serde::{Deserialize, Serialize}; use serde_with::{DurationSeconds, serde_as}; @@ -36,7 +36,7 @@ pub struct Grant { pub mounts: BTreeMap, /// When the session closes, as unix seconds. - #[serde_as(as = "Option")] + #[serde_as(as = "Option")] pub expires: Option, /// How long until the relay asks again, in seconds. @@ -75,11 +75,11 @@ impl Grant { /// Snapshot the expiry on the ambient clock; one already past is now, and one beyond /// the clock's range is never. - pub fn deadline(&self) -> Option { + pub fn deadline(&self) -> Option { // Read the instant first, so a pause between the two reads shortens the grant // instead of extending it. - let start = moq_clock::now(); - let now = moq_clock::wall(); + let start = kio::clock::now(); + let now = kio::clock::wall(); let remaining = self.expires?.checked_duration_since(now).unwrap_or_default(); start.checked_add(remaining) } @@ -107,7 +107,7 @@ impl Grant { if let Some(label) = &self.label { moq_pattern::Pattern::literal(label).map_err(crate::Error::InvalidLabel)?; } - if self.expires.is_some_and(|expires| expires <= moq_clock::wall()) { + if self.expires.is_some_and(|expires| expires <= kio::clock::wall()) { return Err(crate::Error::GrantExpired); } Ok(()) @@ -183,7 +183,7 @@ mod tests { assert_eq!(serde_json::from_str::(r#"{"publish":["**"]}"#).unwrap(), grant); } - #[moq_clock::test] + #[kio::test] async fn validate_refuses_nothing_unbounded_and_expired() { assert!(matches!(Grant::default().validate(), Err(crate::Error::UselessGrant))); @@ -194,7 +194,7 @@ mod tests { assert!(matches!(grant.validate(), Err(crate::Error::UnboundedRevalidate))); // Exact: no grace for an auth server whose clock runs behind. - let now = moq_clock::wall(); + let now = kio::clock::wall(); grant.expires = Some(now); assert!(matches!(grant.validate(), Err(crate::Error::GrantExpired))); @@ -203,7 +203,7 @@ mod tests { grant.expires = Some(now + Duration::from_secs(60)); grant.validate().unwrap(); - moq_clock::sim::advance(Duration::from_secs(60)).await; + kio::clock::sim::advance(Duration::from_secs(60)).await; assert!( matches!(grant.validate(), Err(crate::Error::GrantExpired)), "expiry follows the ambient clock, not the host's" @@ -246,15 +246,15 @@ mod tests { /// The expiry and the instant come from one clock, so time passing before the /// snapshot never shortens the grant. - #[moq_clock::test] + #[kio::test] async fn deadline_is_the_exact_expiry() { - let start = moq_clock::now(); - let now = moq_clock::wall(); + let start = kio::clock::now(); + let now = kio::clock::wall(); let mut grant = Grant::new(patterns(&["**"]), Patterns::default()); assert_eq!(grant.deadline(), None); grant.expires = Some(now + Duration::from_secs(10)); - moq_clock::sim::advance(Duration::from_secs(4)).await; + kio::clock::sim::advance(Duration::from_secs(4)).await; assert_eq!(grant.deadline(), Some(start + Duration::from_secs(10))); grant.expires = Some(now - Duration::from_secs(1)); @@ -265,7 +265,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn expiry_saturates_to_the_wall_range() { let parse = |expires: i64| { serde_json::from_value::(serde_json::json!({"publish":["**"],"expires":expires})).unwrap() diff --git a/rs/moq-auth/src/key.rs b/rs/moq-auth/src/key.rs index bce12e15c50..4a6174a227e 100644 --- a/rs/moq-auth/src/key.rs +++ b/rs/moq-auth/src/key.rs @@ -603,7 +603,7 @@ impl Key { /// [`Claims::authorize`]. pub fn verify(&self, token: &str) -> crate::Result { let claims = self.verify_claims(token)?; - validate_times(&claims, moq_clock::wall())?; + validate_times(&claims, kio::clock::wall())?; Ok(claims) } @@ -682,7 +682,7 @@ impl Key { } /// Refuse claims expired at `now` (`exp <= now`) or not yet valid (`nbf > now`), as `jose` does. -pub(crate) fn validate_times(claims: &Claims, now: moq_clock::Wall) -> crate::Result<()> { +pub(crate) fn validate_times(claims: &Claims, now: kio::clock::Wall) -> crate::Result<()> { if claims.expires.is_some_and(|exp| exp <= now) { return Err(crate::Error::TokenExpired); } @@ -752,7 +752,7 @@ mod tests { fn patterns(texts: &[&str]) -> crate::Patterns { texts.iter().map(|text| text.parse().unwrap()).collect() } - use moq_clock::Wall; + use kio::clock::Wall; use std::time::Duration; fn create_test_key() -> Key { @@ -771,8 +771,8 @@ mod tests { root: "test-path".to_string(), publish: patterns(&["test-pub/**"]), subscribe: patterns(&["test-sub/**"]), - expires: Some(moq_clock::wall() + Duration::from_secs(3600)), - issued: Some(moq_clock::wall()), + expires: Some(kio::clock::wall() + Duration::from_secs(3600)), + issued: Some(kio::clock::wall()), not_before: None, } } @@ -1088,7 +1088,7 @@ mod tests { #[test] fn test_key_verify_only_registered_claims() { let key = create_test_key(); - let now = moq_clock::wall() + let now = kio::clock::wall() .checked_duration_since(Wall::UNIX_EPOCH) .unwrap() .as_secs(); @@ -1126,7 +1126,7 @@ mod tests { fn test_key_verify_enforces_not_before() { let key = create_test_key(); let at = |offset: i64| { - let now = moq_clock::wall() + let now = kio::clock::wall() .checked_duration_since(Wall::UNIX_EPOCH) .unwrap() .as_secs() as i64; @@ -1168,22 +1168,22 @@ mod tests { fn test_key_verify_expired_token() { let key = create_test_key(); let mut claims = create_test_claims(); - claims.expires = Some(moq_clock::wall() - Duration::from_secs(3600)); // 1 hour ago + claims.expires = Some(kio::clock::wall() - Duration::from_secs(3600)); // 1 hour ago let token = key.sign(&claims).unwrap(); let result = key.verify(&token); assert!(result.is_err()); } - #[moq_clock::test] + #[kio::test] async fn token_validity_uses_the_ambient_wall() { let key = create_test_key(); let mut claims = create_test_claims(); - claims.issued = Some(moq_clock::wall()); - claims.expires = Some(moq_clock::wall() + Duration::from_secs(10)); + claims.issued = Some(kio::clock::wall()); + claims.expires = Some(kio::clock::wall() + Duration::from_secs(10)); let token = key.sign(&claims).unwrap(); key.verify(&token).unwrap(); - moq_clock::sleep(Duration::from_secs(10)).await; + kio::clock::sleep(Duration::from_secs(10)).await; assert!(matches!(key.verify(&token), Err(crate::Error::TokenExpired))); } @@ -1214,8 +1214,8 @@ mod tests { root: "test-path".to_string(), publish: patterns(&["test-pub/**"]), subscribe: patterns(&["test-sub/**"]), - expires: Some(moq_clock::wall() + Duration::from_secs(3600)), - issued: Some(moq_clock::wall()), + expires: Some(kio::clock::wall() + Duration::from_secs(3600)), + issued: Some(kio::clock::wall()), not_before: None, }; @@ -1970,7 +1970,7 @@ mod tests { use std::os::unix::fs::PermissionsExt; fn temp_path(name: &str) -> std::path::PathBuf { - let unique = moq_clock::wall() + let unique = kio::clock::wall() .checked_duration_since(Wall::UNIX_EPOCH) .unwrap() .as_nanos(); diff --git a/rs/moq-auth/src/lease.rs b/rs/moq-auth/src/lease.rs index d29a9253580..706218d8512 100644 --- a/rs/moq-auth/src/lease.rs +++ b/rs/moq-auth/src/lease.rs @@ -118,8 +118,8 @@ pub(crate) enum Due { #[cfg(feature = "client")] #[derive(Debug)] struct Clock { - next: Option, - expires: Option, + next: Option, + expires: Option, cadence: Option, failures: u32, revision: u64, @@ -132,7 +132,7 @@ impl Clock { // A cadence too far out to schedule is no scheduled re-check; `expires` still bounds the grant. next: grant .revalidate - .and_then(|cadence| moq_clock::now().checked_add(cadence)), + .and_then(|cadence| kio::clock::now().checked_add(cadence)), expires: grant.deadline(), cadence: grant.revalidate, failures: 0, @@ -210,13 +210,13 @@ impl Producer { }; let revalidate = async { match next { - Some(at) => moq_clock::sleep_until(at).await, + Some(at) => kio::clock::sleep_until(at).await, None => std::future::pending().await, } }; let expire = async { match expires { - Some(at) => moq_clock::sleep_until(at).await, + Some(at) => kio::clock::sleep_until(at).await, None => std::future::pending().await, } }; @@ -253,7 +253,7 @@ impl Producer { let base = Duration::from_secs(1) * 2u32.saturating_pow(clock.failures.saturating_sub(1).min(16)); let base = base.min(clock.cadence.unwrap_or(BACKOFF_MAX)).min(BACKOFF_MAX); let delay = base.mul_f64(rand::rng().random_range(0.75..=1.25)); - clock.next = Some(moq_clock::now() + delay); + clock.next = Some(kio::clock::now() + delay); clock.revision = clock.revision.wrapping_add(1); drop(clock); self.clock_changed.notify_waiters(); @@ -594,7 +594,7 @@ mod tests { tokio::time::pause(); let mut grant = grant("a/**"); grant.revalidate = Some(Duration::from_secs(10)); - grant.expires = Some(moq_clock::wall() + Duration::from_secs(60)); + grant.expires = Some(kio::clock::wall() + Duration::from_secs(60)); let (producer, consumer) = Producer::new(grant.clone()); assert!(tokio::time::timeout(Duration::ZERO, producer.due()).await.is_err()); tokio::time::advance(Duration::from_secs(10)).await; @@ -619,7 +619,7 @@ mod tests { tokio::time::pause(); let mut grant = grant("a/**"); grant.revalidate = Some(Duration::from_secs(30)); - grant.expires = Some(moq_clock::wall() + Duration::from_secs(3600)); + grant.expires = Some(kio::clock::wall() + Duration::from_secs(3600)); let (producer, _consumer) = Producer::new(grant.clone()); let producer = std::sync::Arc::new(producer); let waiter = tokio::spawn({ @@ -639,7 +639,7 @@ mod tests { tokio::time::pause(); let mut grant = grant("a/**"); grant.revalidate = Some(Duration::from_secs(30)); - grant.expires = Some(moq_clock::wall() + Duration::from_secs(3600)); + grant.expires = Some(kio::clock::wall() + Duration::from_secs(3600)); let (producer, _consumer) = Producer::new(grant); let first = producer.failed(); assert!(first >= Duration::from_millis(750) && first <= Duration::from_millis(1250)); @@ -666,7 +666,7 @@ mod tests { async fn due_expires_even_without_a_recheck() { tokio::time::pause(); let mut grant = grant("a/**"); - grant.expires = Some(moq_clock::wall() - Duration::from_secs(4)); + grant.expires = Some(kio::clock::wall() - Duration::from_secs(4)); let (producer, _consumer) = Producer::new(grant); let task = tokio::spawn(async move { producer.due().await }); tokio::task::yield_now().await; diff --git a/rs/moq-auth/src/request.rs b/rs/moq-auth/src/request.rs index afcd17e941d..21ea78abb5d 100644 --- a/rs/moq-auth/src/request.rs +++ b/rs/moq-auth/src/request.rs @@ -1,4 +1,4 @@ -use moq_clock::Wall; +use kio::clock::Wall; use serde::{Deserialize, Serialize}; use serde_with::base64::{Base64, UrlSafe}; use serde_with::formats::Unpadded; @@ -213,7 +213,7 @@ pub struct Peer { /// SHA-256 of the leaf certificate, hex. pub fingerprint: String, /// The certificate's notAfter. - #[serde_as(as = "Option")] + #[serde_as(as = "Option")] pub expires: Option, /// The issuer's distinguished name. pub issuer: String, diff --git a/rs/moq-auth/src/serve.rs b/rs/moq-auth/src/serve.rs index 9c7a090554d..7d95cca2eb7 100644 --- a/rs/moq-auth/src/serve.rs +++ b/rs/moq-auth/src/serve.rs @@ -19,7 +19,7 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use axum::routing::post; use axum::{Json, Router}; -use moq_clock::Instant; +use kio::clock::Instant; use crate::{Event, Grant, Key, KeyId, KeySet, Permissions, Request, Token}; @@ -262,7 +262,7 @@ impl Policy { let mut grant = Grant::new(permissions.publish, permissions.subscribe); grant.expires = match (expires, self.expires) { (Some(expires), _) => Some(expires), - (None, Some(bound)) => Some(moq_clock::wall().checked_add(bound).ok_or(Denial::ExpiresOutOfRange)?), + (None, Some(bound)) => Some(kio::clock::wall().checked_add(bound).ok_or(Denial::ExpiresOutOfRange)?), (None, None) => None, }; grant.revalidate = self.revalidate; @@ -303,7 +303,7 @@ impl Policy { crate::Error::Key(crate::KeyError::KeyNotFound(_)) => Denial::UnknownKey, other => Denial::InvalidToken(other.to_string()), })?; - crate::key::validate_times(&claims, moq_clock::wall()).map_err(|err| match err { + crate::key::validate_times(&claims, kio::clock::wall()).map_err(|err| match err { crate::Error::TokenExpired => Denial::Expired { root: claims.root.clone(), }, @@ -470,7 +470,7 @@ impl Server { } if policy .expires - .is_some_and(|bound| moq_clock::wall().checked_add(bound).is_none()) + .is_some_and(|bound| kio::clock::wall().checked_add(bound).is_none()) { return Err(crate::Error::ExpiresOutOfRange); } @@ -570,7 +570,7 @@ mod tests { request } - #[moq_clock::test] + #[kio::test] async fn default_expiry_uses_the_ambient_wall() { let policy = Policy { public: rules(&["**"], &[]), @@ -578,7 +578,7 @@ mod tests { ..Default::default() }; let grant = policy.decide(&request("/demo")).await.unwrap(); - assert_eq!(grant.expires, Some(moq_clock::wall() + Duration::from_secs(30))); + assert_eq!(grant.expires, Some(kio::clock::wall() + Duration::from_secs(30))); } fn with_token(mut request: Request, jwt: &str) -> Request { @@ -586,7 +586,7 @@ mod tests { request } - fn with_peer(mut request: Request, expires: Option) -> Request { + fn with_peer(mut request: Request, expires: Option) -> Request { request.tls = Some(Peer { name: "edge0".into(), fingerprint: "ab".repeat(32), @@ -604,7 +604,7 @@ mod tests { (dir, key) } - fn sign(key: &Key, root: &str, publish: &[&str], subscribe: &[&str], expires: Option) -> String { + fn sign(key: &Key, root: &str, publish: &[&str], subscribe: &[&str], expires: Option) -> String { let claims = Claims::default() .with_root(root) .with_publish(patterns(publish)) @@ -648,12 +648,12 @@ mod tests { ..Default::default() }; // `exp` is whole seconds on the wire. - let secs = moq_clock::wall() - .checked_duration_since(moq_clock::Wall::UNIX_EPOCH) + let secs = kio::clock::wall() + .checked_duration_since(kio::clock::Wall::UNIX_EPOCH) .unwrap() .as_secs() + 600; - let exp = moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(secs); + let exp = kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(secs); let jwt = sign(&key, "demo/room", &["alice/**"], &["**"], Some(exp)); let grant = policy.decide(&with_token(request("/demo/room/"), &jwt)).await.unwrap(); @@ -674,11 +674,11 @@ mod tests { ..Default::default() }; let jwt = sign(&key, "demo", &["**"], &[], None); - let before = moq_clock::wall(); + let before = kio::clock::wall(); let grant = policy.decide(&with_token(request("/demo"), &jwt)).await.unwrap(); let expires = grant.expires.unwrap(); assert!(expires >= before + Duration::from_secs(3600)); - assert!(expires <= moq_clock::wall() + Duration::from_secs(3600)); + assert!(expires <= kio::clock::wall() + Duration::from_secs(3600)); } #[tokio::test] @@ -716,7 +716,7 @@ mod tests { "demo", &["**"], &[], - Some(moq_clock::wall() - Duration::from_secs(1)), + Some(kio::clock::wall() - Duration::from_secs(1)), ); let err = policy.decide(&with_token(request("/demo"), &jwt)).await.unwrap_err(); assert!(matches!(err, Denial::Expired { .. }), "{err}"); @@ -983,7 +983,7 @@ mod tests { mtls: rules(&["**"], &["**"]), ..Default::default() }; - let not_after = moq_clock::wall() + Duration::from_secs(86400 * 30); + let not_after = kio::clock::wall() + Duration::from_secs(86400 * 30); let grant = policy.decide(&with_peer(request("/"), Some(not_after))).await.unwrap(); assert_eq!(grant.publish, patterns(&["**"])); assert_eq!(grant.expires, Some(not_after)); @@ -1298,7 +1298,7 @@ mod tests { "demo", &["**"], &[], - Some(moq_clock::wall() + Duration::from_secs(60)), + Some(kio::clock::wall() + Duration::from_secs(60)), ); let mut same_host = with_token(request("/demo"), &other); same_host.remote = Some("[::ffff:203.0.113.9]:9".parse().unwrap()); @@ -1324,7 +1324,7 @@ mod tests { ..limited() }) .unwrap(); - let exp = Some(moq_clock::wall() + Duration::from_secs(60)); + let exp = Some(kio::clock::wall() + Duration::from_secs(60)); let a = sign(&key, "demo", &["**"], &[], None); let b = sign(&key, "demo", &["**"], &[], exp); let c = sign( @@ -1332,7 +1332,7 @@ mod tests { "demo", &["**"], &[], - Some(moq_clock::wall() + Duration::from_secs(61)), + Some(kio::clock::wall() + Duration::from_secs(61)), ); let mut first = with_token(request("/demo"), &a); @@ -1388,7 +1388,7 @@ mod tests { use crate::refusal::Reason; let (dir, key) = key_dir(); let stranger = Key::generate(Algorithm::HS256, key.kid.clone()).unwrap(); - let expired = Some(moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(1)); + let expired = Some(kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(1)); for tier in [None, Some("edge")] { let (client, _) = serve(Policy { keys: Some(Keys::Dir(dir.path().into())), @@ -1458,7 +1458,7 @@ mod tests { "attacker", &["**"], &[], - Some(moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(1)), + Some(kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(1)), ); let Error::Refused(refusal) = client .connect(with_token(request("/attacker"), &token)) diff --git a/rs/moq-auth/src/set.rs b/rs/moq-auth/src/set.rs index 0999e831cea..3c3cd6d99e5 100644 --- a/rs/moq-auth/src/set.rs +++ b/rs/moq-auth/src/set.rs @@ -144,7 +144,7 @@ mod tests { texts.iter().map(|text| text.parse().unwrap()).collect() } use crate::Algorithm; - use moq_clock::Wall; + use kio::clock::Wall; use std::time::Duration; fn create_test_claims() -> Claims { @@ -152,8 +152,8 @@ mod tests { root: "test-path".to_string(), publish: patterns(&["test-pub/**"]), subscribe: patterns(&["test-sub/**"]), - expires: Some(moq_clock::wall() + Duration::from_secs(3600)), - issued: Some(moq_clock::wall()), + expires: Some(kio::clock::wall() + Duration::from_secs(3600)), + issued: Some(kio::clock::wall()), not_before: None, } } @@ -370,7 +370,7 @@ mod tests { // Use a random-ish name to avoid collisions let filename = format!( "test_keyset_{}.json", - moq_clock::wall() + kio::clock::wall() .checked_duration_since(Wall::UNIX_EPOCH) .unwrap() .as_nanos() @@ -392,7 +392,7 @@ mod tests { fn test_file_io_permissions() { use std::os::unix::fs::PermissionsExt; - let unique = moq_clock::wall() + let unique = kio::clock::wall() .checked_duration_since(Wall::UNIX_EPOCH) .unwrap() .as_nanos(); diff --git a/rs/moq-auth/src/wire.rs b/rs/moq-auth/src/wire.rs index 61c4896e117..8309bdb5b8d 100644 --- a/rs/moq-auth/src/wire.rs +++ b/rs/moq-auth/src/wire.rs @@ -27,12 +27,12 @@ pub(crate) struct Claims { publish: Option, #[serde(deserialize_with = "present")] subscribe: Option, - #[serde_as(as = "Option")] - exp: Option, - #[serde_as(as = "Option")] - iat: Option, - #[serde_as(as = "Option")] - nbf: Option, + #[serde_as(as = "Option")] + exp: Option, + #[serde_as(as = "Option")] + iat: Option, + #[serde_as(as = "Option")] + nbf: Option, // Registered claims that narrow nothing: an issuer's bookkeeping, read and dropped. // Every other claim is refused, since an unknown one may narrow the grant, and a // misspelled `root` would otherwise widen it to everything. diff --git a/rs/moq-bench/Cargo.toml b/rs/moq-bench/Cargo.toml index 578e83465c8..0ffcfd0420f 100644 --- a/rs/moq-bench/Cargo.toml +++ b/rs/moq-bench/Cargo.toml @@ -44,7 +44,7 @@ websocket = ["moq-tokio/websocket"] [dependencies] anyhow = { workspace = true, features = ["backtrace"] } humantime = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-net = { workspace = true } moq-tokio = { workspace = true, default-features = false, features = ["aws-lc-rs", "net"] } rand = { workspace = true } diff --git a/rs/moq-bench/clippy.toml b/rs/moq-bench/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-bench/clippy.toml +++ b/rs/moq-bench/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-bench/src/config.rs b/rs/moq-bench/src/config.rs index 2fcece1acbe..53926786eb6 100644 --- a/rs/moq-bench/src/config.rs +++ b/rs/moq-bench/src/config.rs @@ -225,7 +225,7 @@ impl Config { deprecated.extend(config.deprecated()); anyhow::ensure!(deprecated.is_empty(), "{deprecated}"); config.origins = Some(resolved); - // `Stats::report` feeds this into `moq_clock::interval`, which panics on a + // `Stats::report` feeds this into `kio::clock::interval`, which panics on a // zero period. Reject it up front with a clear message. anyhow::ensure!(!config.report().is_zero(), "--report must be greater than 0s"); if let Some(fanout) = &config.fanout { @@ -485,7 +485,7 @@ url = "https://example.com" #[test] fn zero_report_is_rejected() { - // A zero report interval would panic `moq_clock::interval`; reject it early. + // A zero report interval would panic `kio::clock::interval`; reject it early. let err = Config::parse_and_merge(["moq-bench", "--report", "0s"]).unwrap_err(); assert!(err.to_string().contains("report"), "unexpected error: {err}"); } diff --git a/rs/moq-bench/src/connection.rs b/rs/moq-bench/src/connection.rs index 0f5bcde0373..2cd0bbe3f81 100644 --- a/rs/moq-bench/src/connection.rs +++ b/rs/moq-bench/src/connection.rs @@ -1,4 +1,4 @@ -use moq_clock::Wall; +use kio::clock::Wall; use std::collections::HashSet; use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; @@ -244,8 +244,8 @@ async fn produce( let zeros = Bytes::from(vec![0u8; rolled.frame_size as usize]); let period = Duration::from_secs_f64(1.0 / rolled.fps as f64); - let mut ticker = moq_clock::interval(period); - ticker.set_missed_tick_behavior(moq_clock::MissedTickBehavior::Delay); + let mut ticker = kio::clock::interval(period); + ticker.set_missed_tick_behavior(kio::clock::MissedTickBehavior::Delay); let mut sequence = 0u64; loop { @@ -262,7 +262,7 @@ async fn produce( group_size: rolled.group_size, broadcasts: rolled.broadcasts, subscribe: rolled.subscribe, - timestamp_ms: moq_clock::wall() + timestamp_ms: kio::clock::wall() .saturating_duration_since(Wall::UNIX_EPOCH) .as_millis(), pad: String::new(), @@ -350,7 +350,7 @@ async fn subscribe( let mut eligible = 0; // Gather candidates until the startup window closes (or the announce stream ends). - let deadline = moq_clock::sleep(startup); + let deadline = kio::clock::sleep(startup); tokio::pin!(deadline); loop { tokio::select! { diff --git a/rs/moq-bench/src/host.rs b/rs/moq-bench/src/host.rs index 439ba50e1c8..86490577573 100644 --- a/rs/moq-bench/src/host.rs +++ b/rs/moq-bench/src/host.rs @@ -16,7 +16,7 @@ #[cfg(target_os = "linux")] mod linux { - use moq_clock::Wall; + use kio::clock::Wall; use std::collections::HashMap; use std::io::Write; use std::time::Duration; @@ -231,7 +231,7 @@ mod linux { target.ctx.retain(|tid| live.contains(&tid)); Ok(Sample { - timestamp_ms: moq_clock::wall() + timestamp_ms: kio::clock::wall() .saturating_duration_since(Wall::UNIX_EPOCH) .as_millis(), pid: target.proc.pid, @@ -277,7 +277,7 @@ mod linux { .join(", ") ); - let start = moq_clock::now(); + let start = kio::clock::now(); loop { // Host-wide once per round: unlike the per-target reads inside `sample`, // a failure here is not a target exiting, so it fails the run. diff --git a/rs/moq-bench/src/main.rs b/rs/moq-bench/src/main.rs index c176871ab64..28e59fee506 100644 --- a/rs/moq-bench/src/main.rs +++ b/rs/moq-bench/src/main.rs @@ -83,7 +83,7 @@ async fn main() -> anyhow::Result<()> { stats: stats.clone(), }; tasks.spawn(async move { - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; connection::run(ctx).await; }); } @@ -91,7 +91,7 @@ async fn main() -> anyhow::Result<()> { let duration = config.duration.map(Into::into); let stop = async move { match duration { - Some(d) => moq_clock::sleep(d).await, + Some(d) => kio::clock::sleep(d).await, None => std::future::pending::<()>().await, } }; diff --git a/rs/moq-bench/src/stats.rs b/rs/moq-bench/src/stats.rs index f7848897e69..97eaf331b82 100644 --- a/rs/moq-bench/src/stats.rs +++ b/rs/moq-bench/src/stats.rs @@ -1,4 +1,4 @@ -use moq_clock::Wall; +use kio::clock::Wall; use std::io::Write; use std::sync::Mutex; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; @@ -101,7 +101,7 @@ impl Stats { /// Record one group keyframe's wall-clock delivery latency. pub fn latency(&self, sent_ms: u128) { // Read the clock before locking so contention is not measured as latency. - let now_ms = moq_clock::wall() + let now_ms = kio::clock::wall() .saturating_duration_since(Wall::UNIX_EPOCH) .as_millis(); self.latency.observe(sent_ms, now_ms); @@ -125,7 +125,7 @@ impl Stats { /// recorded stats are partial is invalid, so the caller must fail the run /// rather than exit green. pub async fn report(&self, interval: Duration, mut output: Option) -> anyhow::Result<()> { - let mut ticker = moq_clock::interval(interval); + let mut ticker = kio::clock::interval(interval); // Skip the immediate first tick so the first report covers a full interval. ticker.tick().await; @@ -427,7 +427,7 @@ impl Latency { // include only part of an observation. One that reads the clock before the // boundary but locks after it counts in the next interval, unaltered. let state = self.state.lock().expect("latency lock poisoned"); - let captured_at = moq_clock::wall(); + let captured_at = kio::clock::wall(); let LatencyState { buckets, max_ms, diff --git a/rs/moq-boy/Cargo.toml b/rs/moq-boy/Cargo.toml index cec2ba135d4..280d1bc654e 100644 --- a/rs/moq-boy/Cargo.toml +++ b/rs/moq-boy/Cargo.toml @@ -34,7 +34,7 @@ boytacean = { version = "0.13", features = ["gen-mock"] } bytes = { workspace = true } hang = { workspace = true } moq-audio = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-json = { workspace = true } moq-mux = { workspace = true } moq-net = { workspace = true } diff --git a/rs/moq-boy/clippy.toml b/rs/moq-boy/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-boy/clippy.toml +++ b/rs/moq-boy/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-boy/src/main.rs b/rs/moq-boy/src/main.rs index deff337f231..ef510255940 100644 --- a/rs/moq-boy/src/main.rs +++ b/rs/moq-boy/src/main.rs @@ -25,7 +25,7 @@ use anyhow::{Context, Result}; use bytes::Bytes; -use moq_clock::Instant; +use kio::clock::Instant; use std::collections::{BTreeMap, HashMap}; use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; diff --git a/rs/moq-boy/src/stats.rs b/rs/moq-boy/src/stats.rs index edd8af3f9e9..ebb09660347 100644 --- a/rs/moq-boy/src/stats.rs +++ b/rs/moq-boy/src/stats.rs @@ -3,7 +3,7 @@ //! Tracks how much wall-clock time is spent on emulation, video encoding, //! and audio encoding. Published to viewers via the status track. -use moq_clock::Instant; +use kio::clock::Instant; use std::time::Duration; use serde::Serialize; diff --git a/rs/moq-boy/src/video.rs b/rs/moq-boy/src/video.rs index 655d6ce44eb..4916a8582ba 100644 --- a/rs/moq-boy/src/video.rs +++ b/rs/moq-boy/src/video.rs @@ -6,7 +6,7 @@ //! encode and the avc3 publish; this module keeps moq-boy's threading, //! frame-dropping, force-keyframe and timing-stats behavior. -use moq_clock::Instant; +use kio::clock::Instant; use std::sync::Arc; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::time::Duration; diff --git a/rs/moq-c/Cargo.toml b/rs/moq-c/Cargo.toml index f9973efee35..0b116b6fd7b 100644 --- a/rs/moq-c/Cargo.toml +++ b/rs/moq-c/Cargo.toml @@ -49,7 +49,7 @@ url = { workspace = true } cbindgen = "0.29" [dev-dependencies] -moq-clock = { path = "../moq-clock" } +kio = { path = "../kio", features = ["runtime"] } moq-loc = { path = "../moq-loc" } # The tests encode with OpenH264, the one encoder a GPU-less host has, so they # turn it on without the `openh264` feature. diff --git a/rs/moq-c/clippy.toml b/rs/moq-c/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-c/clippy.toml +++ b/rs/moq-c/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-c/src/publish.rs b/rs/moq-c/src/publish.rs index 1f1c4c227d1..fa61d888697 100644 --- a/rs/moq-c/src/publish.rs +++ b/rs/moq-c/src/publish.rs @@ -1433,7 +1433,7 @@ mod children_tests { let (broadcast, track, media, readers) = children(&mut state).await; state.publish_close(broadcast).unwrap().run().unwrap(); for mut reader in readers { - let read = moq_clock::timeout(TIMEOUT, reader.recv_group()).await; + let read = kio::clock::timeout(TIMEOUT, reader.recv_group()).await; assert!(matches!( read.expect("the track carried on"), Err(moq_net::Error::Unroutable) @@ -1475,7 +1475,7 @@ mod children_tests { state.publish_close(broadcast).unwrap().run().unwrap(); for mut reader in readers { - let read = moq_clock::timeout(TIMEOUT, reader.recv_group()).await; + let read = kio::clock::timeout(TIMEOUT, reader.recv_group()).await; assert!(matches!( read.expect("the track carried on"), Err(moq_net::Error::Unroutable) @@ -1509,7 +1509,7 @@ mod children_tests { state.publish.media_finish(media).unwrap(); state.publish_close(broadcast).unwrap().run().unwrap(); for mut reader in readers { - let read = moq_clock::timeout(TIMEOUT, reader.recv_group()).await; + let read = kio::clock::timeout(TIMEOUT, reader.recv_group()).await; assert!(matches!(read.expect("the track carried on"), Ok(None))); } } diff --git a/rs/moq-c/src/video.rs b/rs/moq-c/src/video.rs index 248a2dd3493..d752c494025 100644 --- a/rs/moq-c/src/video.rs +++ b/rs/moq-c/src/video.rs @@ -1403,7 +1403,7 @@ mod follow_tests { }); assert_eq!(moved, Ok(None)); - let retried = moq_clock::timeout(Duration::from_secs(60), follower.next()) + let retried = kio::clock::timeout(Duration::from_secs(60), follower.next()) .await .expect("the dropped target is asked for again"); assert_eq!(retried.unwrap(), Target::Enabled(Rate::from_mbps(2))); @@ -1418,7 +1418,7 @@ mod follow_tests { /// Retune at every target until the follower goes a minute without one. async fn quiet(follower: &mut Follower, ceiling: Rate, mut set: impl FnMut(Rate) -> Result<(), moq_video::Error>) { - while let Ok(bitrate) = moq_clock::timeout(Duration::from_secs(60), follower.next()).await { + while let Ok(bitrate) = kio::clock::timeout(Duration::from_secs(60), follower.next()).await { rate(follower, ceiling, bitrate.unwrap(), &mut set).unwrap(); } } diff --git a/rs/moq-cli/Cargo.toml b/rs/moq-cli/Cargo.toml index 700a8f74b6f..4087224dcc4 100644 --- a/rs/moq-cli/Cargo.toml +++ b/rs/moq-cli/Cargo.toml @@ -110,7 +110,7 @@ humantime = { workspace = true } moq-archive = { workspace = true } moq-audio = { workspace = true, optional = true, features = ["aac"] } moq-auth = { workspace = true, features = ["serve"] } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } # `server` enables the HTTP egress server for `moq export hls`; the importer is always available. moq-hls = { workspace = true, features = ["server"] } # Writes and reads the stats and feedback snapshots. diff --git a/rs/moq-cli/clippy.toml b/rs/moq-cli/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-cli/clippy.toml +++ b/rs/moq-cli/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-cli/src/auth.rs b/rs/moq-cli/src/auth.rs index e50445bb213..a70202e7ee7 100644 --- a/rs/moq-cli/src/auth.rs +++ b/rs/moq-cli/src/auth.rs @@ -592,9 +592,9 @@ fn read_token(path: &std::path::Path) -> anyhow::Result { } #[derive(Clone, Copy, Debug)] -struct UnixTimestamp(moq_clock::Wall); +struct UnixTimestamp(kio::clock::Wall); -impl From for moq_clock::Wall { +impl From for kio::clock::Wall { fn from(value: UnixTimestamp) -> Self { value.0 } @@ -608,7 +608,7 @@ impl std::str::FromStr for UnixTimestamp { let timestamp = timestamp.try_into().context("timestamp out of range")?; // Past 2554 saturates, like a decoded token time. Ok(Self( - moq_clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::from_secs(timestamp)), + kio::clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::from_secs(timestamp)), )) } } @@ -998,8 +998,8 @@ mod tests { #[test] fn timestamp_past_the_wall_range_saturates() { - let last = moq_clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::MAX); - let parse = |text: &str| moq_clock::Wall::from(text.parse::().unwrap()); + let last = kio::clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::MAX); + let parse = |text: &str| kio::clock::Wall::from(text.parse::().unwrap()); assert_eq!(parse(&i64::MAX.to_string()), last); assert!(parse("18446744073") < last); } diff --git a/rs/moq-cli/src/complete.rs b/rs/moq-cli/src/complete.rs index d0ca4c98da8..10e001be985 100644 --- a/rs/moq-cli/src/complete.rs +++ b/rs/moq-cli/src/complete.rs @@ -20,8 +20,8 @@ use std::future::Future; use std::time::Duration; use anyhow::Context; -use moq_clock::Instant; -use moq_clock::timeout_at; +use kio::clock::Instant; +use kio::clock::timeout_at; #[cfg(feature = "capture")] use usage_rs::complete::{Candidate, CompleteCtx, CompletionFuture}; use usage_rs::complete::{CompletionOverlay, CompletionRequest, Shell, render}; diff --git a/rs/moq-cli/src/fetch.rs b/rs/moq-cli/src/fetch.rs index 299bbcac48e..8f8e59e2d18 100644 --- a/rs/moq-cli/src/fetch.rs +++ b/rs/moq-cli/src/fetch.rs @@ -6,8 +6,8 @@ use std::time::Duration; use anyhow::Context; use base64::Engine; use hang::moq_net; -use moq_clock::Instant; -use moq_clock::timeout_at; +use kio::clock::Instant; +use kio::clock::timeout_at; use tokio::io::{AsyncWrite, AsyncWriteExt}; use crate::args::MoqSide; diff --git a/rs/moq-cli/src/hls.rs b/rs/moq-cli/src/hls.rs index 7711a85229e..1a44fd57aee 100644 --- a/rs/moq-cli/src/hls.rs +++ b/rs/moq-cli/src/hls.rs @@ -463,7 +463,7 @@ mod test { }; let origin = moq_tokio::origin::spawn(); let exporting = export(origin.consume(), args, "live".to_string()); - let result = moq_clock::timeout(std::time::Duration::from_secs(1), exporting).await; + let result = kio::clock::timeout(std::time::Duration::from_secs(1), exporting).await; assert!(result.is_err(), "the recording gave up: {result:?}"); } diff --git a/rs/moq-cli/src/hls/record.rs b/rs/moq-cli/src/hls/record.rs index 52ddcbcc8df..d9a576c3d29 100644 --- a/rs/moq-cli/src/hls/record.rs +++ b/rs/moq-cli/src/hls/record.rs @@ -427,7 +427,7 @@ struct Entry { /// The rendition's discontinuity sequence for the segment; the playlist adds its offset. discontinuity: u64, /// Written on the first entry and after each discontinuity. - program_date_time: Option, + program_date_time: Option, /// The init file the instance's first media segment maps. map: Option, } @@ -661,7 +661,7 @@ mod tests { async fn record(dir: &Path, broadcaster: &Broadcaster) -> anyhow::Result<()> { let recording = Recording::create(dir.to_path_buf())?; - moq_clock::timeout(TIMEOUT, recording.run(broadcaster)) + kio::clock::timeout(TIMEOUT, recording.run(broadcaster)) .await .expect("the recording ends") } @@ -689,7 +689,7 @@ mod tests { async fn recorded(dir: &Path, name: &str) { let playlist = dir.join("video").join(name).join("media.m3u8"); // The recording writes from blocking threads, which wake nothing here. - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { while !std::fs::read_to_string(&playlist).is_ok_and(|text| text.contains("\n0.m4s\n")) { tokio::task::yield_now().await; } @@ -809,7 +809,7 @@ mod tests { publisher.gop(n); } publisher.finish(); - moq_clock::timeout(TIMEOUT, recording) + kio::clock::timeout(TIMEOUT, recording) .await .expect("the recording ends") .unwrap() @@ -859,7 +859,7 @@ mod tests { .unwrap(); publisher.gop(5); publisher.gop(6); - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { while removed.strong_count() > 0 { tokio::task::yield_now().await; } @@ -869,7 +869,7 @@ mod tests { publisher.gop(7); publisher.finish(); - moq_clock::timeout(TIMEOUT, recording) + kio::clock::timeout(TIMEOUT, recording) .await .expect("the recording ends") .unwrap() @@ -891,7 +891,7 @@ mod tests { let recording = Recording::create(dir.path().to_path_buf()).unwrap(); // Stands in for the colliding sibling, which a case-sensitive filesystem cannot produce. std::fs::create_dir_all(dir.path().join("video").join("video0")).unwrap(); - let err = moq_clock::timeout(TIMEOUT, recording.run(&broadcaster)) + let err = kio::clock::timeout(TIMEOUT, recording.run(&broadcaster)) .await .expect("the recording ends") .unwrap_err(); @@ -917,7 +917,7 @@ mod tests { } catalog.abort(lost); - let ended = moq_clock::timeout(TIMEOUT, recording) + let ended = kio::clock::timeout(TIMEOUT, recording) .await .expect("the recording ends"); let err = ended.unwrap().expect_err("an abrupt end fails"); @@ -1016,7 +1016,7 @@ mod tests { /// running sum of durations no longer gives it. #[test] fn a_discontinuity_restates_the_program_date_time() { - let at = |secs| Some(moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(secs)); + let at = |secs| Some(kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(secs)); let mut playlist = Playlist::default(); for (segment, discontinuity, secs) in [(0, 0, 0), (1, 0, 2), (2, 1, 10), (3, 1, 12)] { playlist.push(Entry { diff --git a/rs/moq-cli/src/play/fake.rs b/rs/moq-cli/src/play/fake.rs index a1efdca02ff..7e633d9a011 100644 --- a/rs/moq-cli/src/play/fake.rs +++ b/rs/moq-cli/src/play/fake.rs @@ -5,8 +5,8 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; +use kio::clock::Instant; use moq_audio::playback::Input; -use moq_clock::Instant; use super::output::{Output, Sink, Speaker}; use super::window::Event; @@ -49,7 +49,7 @@ impl Recorder { pub fn present(&self, media: &super::media::Media) -> Option { let mut video = media.video.lock().unwrap(); let presentation = media.presentation.lock().unwrap(); - let now = moq_clock::now(); + let now = kio::clock::now(); let mut shown = None; while video .front() @@ -127,7 +127,7 @@ pub(super) struct FakeSink { impl Sink for FakeSink { async fn finish(self) { - moq_clock::sleep_until(self.end).await; + kio::clock::sleep_until(self.end).await; } fn write(&mut self, samples: &[u8]) -> anyhow::Result { diff --git a/rs/moq-cli/src/play/media.rs b/rs/moq-cli/src/play/media.rs index faaa17e7f82..6e2727b13d3 100644 --- a/rs/moq-cli/src/play/media.rs +++ b/rs/moq-cli/src/play/media.rs @@ -11,7 +11,7 @@ use moq_mux::catalog::{self, Stream}; use moq_mux::follow::{Event as FollowEvent, Instances}; // The ambient clock, which follows tokio's paused clock when a test drives the // playout clock itself. -use moq_clock::Instant; +use kio::clock::Instant; use super::args::Args; use super::output::{Output, Sink, Speaker}; @@ -656,7 +656,7 @@ async fn play_audio( .due(role.map(frame.timestamp)?) .and_then(|at| at.checked_sub(first)); if let Some(at) = at { - moq_clock::sleep_until(at).await; + kio::clock::sleep_until(at).await; } ended = false; // An end this frame did not cross ends the timeline it resumes. @@ -729,7 +729,7 @@ async fn play_audio( .due(mapped) .and_then(|at| at.checked_sub(lead(delay, &frame))); if let Some(at) = at { - moq_clock::sleep_until(at).await; + kio::clock::sleep_until(at).await; } } @@ -793,7 +793,7 @@ async fn play_audio( async fn drain(sink: impl Sink) { // The estimated target moves, so the depth the sink was opened with says // nothing about what it holds now: read it at retirement instead. - let _ = moq_clock::timeout(sink.buffered() + AUDIO_DRAIN_GRACE, sink.finish()).await; + let _ = kio::clock::timeout(sink.buffered() + AUDIO_DRAIN_GRACE, sink.finish()).await; } #[cfg(test)] @@ -1483,7 +1483,7 @@ mod tests { while index < 50 { old.write(packet(index, OLD)).unwrap(); index += 1; - moq_clock::sleep_until(start + PACKET_DURATION * index as u32).await; + kio::clock::sleep_until(start + PACKET_DURATION * index as u32).await; } // The replacement joins the catalog, then the old track finishes. @@ -1494,7 +1494,7 @@ mod tests { drop(old); while index < 100 { - moq_clock::sleep_until(start + PACKET_DURATION * index as u32).await; + kio::clock::sleep_until(start + PACKET_DURATION * index as u32).await; new.write(packet(index, NEW)).unwrap(); index += 1; } @@ -1579,7 +1579,7 @@ mod tests { _ => a.write(packet(index, BACK)).unwrap(), } index += 1; - moq_clock::sleep_until(start + PACKET_DURATION * index as u32).await; + kio::clock::sleep_until(start + PACKET_DURATION * index as u32).await; } settle(player, &recorder).await; @@ -2001,7 +2001,7 @@ mod tests { let start = Instant::now(); for index in 0..COUNT { let ready = ((index + 1) * PACKET).div_ceil(BLOCK) * BLOCK; - moq_clock::sleep_until(start + Duration::from_secs_f64(ready as f64 / SAMPLE_RATE as f64)).await; + kio::clock::sleep_until(start + Duration::from_secs_f64(ready as f64 / SAMPLE_RATE as f64)).await; audio.write(packet(index, 0.25)).unwrap(); } settle(player, &recorder).await; diff --git a/rs/moq-cli/src/play/metrics.rs b/rs/moq-cli/src/play/metrics.rs index 10c8d451d06..8b6650b3260 100644 --- a/rs/moq-cli/src/play/metrics.rs +++ b/rs/moq-cli/src/play/metrics.rs @@ -15,8 +15,8 @@ use std::sync::{Arc, Mutex}; use std::time::Duration; use anyhow::Context; +use kio::clock::Instant; use moq_audio::playback::{Observation, Observer}; -use moq_clock::Instant; use serde::Serialize; use tokio::sync::mpsc; @@ -98,7 +98,7 @@ pub(super) struct Metrics { /// What closed engines counted, added to the current one's totals. base: Totals, start: Instant, - interval: moq_clock::Interval, + interval: kio::clock::Interval, } impl Metrics { @@ -109,8 +109,8 @@ impl Metrics { ) -> anyhow::Result<(Self, mpsc::UnboundedSender)> { let file = File::create(path).with_context(|| format!("failed to create {}", path.display()))?; let (observe, observers) = mpsc::unbounded_channel(); - let mut interval = moq_clock::interval(INTERVAL); - interval.set_missed_tick_behavior(moq_clock::MissedTickBehavior::Delay); + let mut interval = kio::clock::interval(INTERVAL); + interval.set_missed_tick_behavior(kio::clock::MissedTickBehavior::Delay); let metrics = Self { file: BufWriter::new(file), presentation, @@ -140,7 +140,7 @@ impl Metrics { // The audio thread closes the gap on its next buffer. One that never // comes is a device that stopped pulling, which the render clock // already shows, so the wait is bounded rather than hung on it. - if moq_clock::timeout(FINISH_WAIT, observer.finish()).await.is_err() { + if kio::clock::timeout(FINISH_WAIT, observer.finish()).await.is_err() { tracing::warn!("the speaker never closed out the measurement; the last gap may be missing"); } } diff --git a/rs/moq-cli/src/play/timeline.rs b/rs/moq-cli/src/play/timeline.rs index 977faa942f0..26fd03c50d8 100644 --- a/rs/moq-cli/src/play/timeline.rs +++ b/rs/moq-cli/src/play/timeline.rs @@ -1,7 +1,7 @@ //! Media time: the playout clock, and the audio track's own timeline. use anyhow::Context; -use moq_clock::Instant; +use kio::clock::Instant; use std::time::Duration; use super::playback::Kind; @@ -304,7 +304,7 @@ impl Role { /// Stop while a tail still plays until `drained`, holding a declared end until /// then. Dropping instead discards the tail with the end. pub(super) fn retire(self, drained: Option) { - let now = moq_clock::now(); + let now = kio::clock::now(); let mut presentation = self.presentation.lock().unwrap(); presentation.tails.retain(|tail| *tail > now); if presentation.ends[self.role as usize].take().is_some() @@ -325,7 +325,7 @@ impl Role { /// long as its replacement has not started playing; otherwise this one opens /// a transition of its own. pub(super) fn declare(&self) -> Transition { - let now = moq_clock::now(); + let now = kio::clock::now(); let own = self.role as usize; let mut presentation = self.presentation.lock().unwrap(); presentation.prune(now); @@ -402,7 +402,7 @@ impl Role { pending.members[own] = false; pending.plans[own] = None; } - presentation.prune(moq_clock::now()); + presentation.prune(kio::clock::now()); drop(presentation); self.timeline.notify_waiters(); } @@ -413,7 +413,7 @@ impl Role { if let Some(pending) = presentation.transition(transition) { pending.resumed[self.role as usize] = true; } - presentation.prune(moq_clock::now()); + presentation.prune(kio::clock::now()); drop(presentation); self.timeline.notify_waiters(); } @@ -432,7 +432,7 @@ impl Role { let changed = self.timeline.notified(); let mut changed = std::pin::pin!(changed); changed.as_mut().enable(); - let now = moq_clock::now(); + let now = kio::clock::now(); let end = { let mut presentation = self.presentation.lock().unwrap(); // The peer already resumed this transition after draining every end @@ -451,7 +451,7 @@ impl Role { }; if let Some(end) = end.filter(|end| *end > now) { tokio::select! { - _ = moq_clock::sleep_until(end) => {}, + _ = kio::clock::sleep_until(end) => {}, _ = changed => {}, } continue; @@ -505,7 +505,7 @@ impl Drop for Role { pending.plans[own] = None; } presentation.declared[own] = Transition::default(); - presentation.prune(moq_clock::now()); + presentation.prune(kio::clock::now()); } self.timeline.notify_waiters(); } @@ -682,7 +682,7 @@ mod tests { #[tokio::test] async fn one_ended_role_maps_to_the_continuous_peers_clock() { tokio::time::pause(); - let start = moq_clock::now(); + let start = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); let audio = Role::new(presentation.clone(), Kind::Audio); let video = Role::new(presentation.clone(), Kind::Video); @@ -700,7 +700,7 @@ mod tests { #[tokio::test] async fn a_late_paired_replacement_keeps_its_media_offset() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -725,7 +725,7 @@ mod tests { #[tokio::test] async fn a_late_replacement_pairs_with_its_own_transition() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -753,7 +753,7 @@ mod tests { #[tokio::test] async fn a_peer_two_restarts_ahead_pairs_with_the_first() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -782,7 +782,7 @@ mod tests { #[tokio::test] async fn an_abandoned_replacement_leaves_the_next_transition_alone() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -801,7 +801,7 @@ mod tests { audio.apply(transition, audio.resume(transition, ms(0), Some(DELAY)).await.unwrap()); video.apply(next, video.resume(next, ms(5_000), None).await.unwrap()); // The later replacement maps onto the running clock, not the audio restart's. - let resumed = moq_clock::now() + DELAY; + let resumed = kio::clock::now() + DELAY; assert_eq!( presentation.lock().unwrap().due(video.map(ms(5_000)).unwrap()), Some(resumed) @@ -811,7 +811,7 @@ mod tests { #[tokio::test] async fn an_abandoned_peer_plan_is_not_paired() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -825,7 +825,7 @@ mod tests { video.plan(transition, ms(40), None); tokio::time::advance(DELAY + Duration::from_millis(20)).await; video.apply(transition, video.resume(transition, ms(40), None).await.unwrap()); - let resumed = moq_clock::now() + DELAY; + let resumed = kio::clock::now() + DELAY; assert_eq!( presentation.lock().unwrap().due(video.map(ms(40)).unwrap()), Some(resumed) @@ -835,7 +835,7 @@ mod tests { #[tokio::test] async fn a_resumed_transition_ignores_the_peers_later_end() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -861,7 +861,7 @@ mod tests { #[tokio::test] async fn a_cancelled_role_releases_its_declared_end() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -884,7 +884,7 @@ mod tests { #[tokio::test] async fn a_closed_role_still_holds_its_declared_end() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -907,7 +907,7 @@ mod tests { #[tokio::test] async fn a_retired_end_ignores_a_later_re_pin() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -930,7 +930,7 @@ mod tests { #[tokio::test] async fn a_cancelled_successor_keeps_a_retired_tail() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); @@ -951,7 +951,7 @@ mod tests { #[tokio::test] async fn paired_plans_keep_media_offsets_and_follow_the_speakers_delay() { tokio::time::pause(); - let now = moq_clock::now(); + let now = kio::clock::now(); let presentation = std::sync::Arc::new(std::sync::Mutex::new(Presentation::new(DELAY))); presentation.lock().unwrap().audio(Duration::from_secs(10), DELAY, now); let audio = Role::new(presentation.clone(), Kind::Audio); diff --git a/rs/moq-cli/src/play/video.rs b/rs/moq-cli/src/play/video.rs index 4a4207e05e1..0329f20513b 100644 --- a/rs/moq-cli/src/play/video.rs +++ b/rs/moq-cli/src/play/video.rs @@ -4,7 +4,7 @@ use std::collections::{BTreeSet, VecDeque}; use std::sync::{Arc, Mutex}; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use moq_mux::container::{Frame, Read}; use super::buffer::Buffer; @@ -302,7 +302,7 @@ impl Video { let frames = match step { Step::Wait(Some(at)) => { tokio::select! { - _ = moq_clock::sleep_until(at) => {}, + _ = kio::clock::sleep_until(at) => {}, _ = self.changed.notified() => {}, } continue; diff --git a/rs/moq-cli/src/play/window.rs b/rs/moq-cli/src/play/window.rs index 81a533b0857..36d36f10893 100644 --- a/rs/moq-cli/src/play/window.rs +++ b/rs/moq-cli/src/play/window.rs @@ -5,7 +5,7 @@ use std::collections::VecDeque; use std::sync::{Arc, Mutex}; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use anyhow::Context; use hang::moq_net; @@ -334,7 +334,7 @@ impl ApplicationHandler for App { return; } - let now = moq_clock::now(); + let now = kio::clock::now(); match self.next_redraw { Some(deadline) if deadline <= now => { self.next_redraw = None; diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index 068c293f6d1..33a33b61259 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -669,7 +669,7 @@ async fn decode( // diagnosed by the rate at which these climb, and stdin may never end, so // they have to surface as they accumulate rather than at exit. let mut log = ts::stats::Log::default(); - let mut sampled = moq_clock::now(); + let mut sampled = kio::clock::now(); let sections = report.as_ref().map(crate::report::Stats::sections); let report_mpegts = |snapshot: &ts::stats::Snapshot| { if let Some(sections) = §ions { @@ -694,7 +694,7 @@ async fn decode( } if sampled.elapsed() >= ts::stats::Log::INTERVAL { - sampled = moq_clock::now(); + sampled = kio::clock::now(); if let Some(stats) = decoder.stats() { report_mpegts(&stats); log.sample(stats); @@ -1480,9 +1480,9 @@ pub(crate) mod tests { let Source::Stream { decoder, .. } = &mut publish.source else { panic!("expected a stream source"); }; - let before = moq_clock::wall(); + let before = kio::clock::wall(); decoder.decode_chunk(BBB).unwrap(); - let after = moq_clock::wall(); + let after = kio::clock::wall(); decoder.finish().unwrap(); let catalog = hang::catalog::Catalog::<()>::subscribe(&consumer) diff --git a/rs/moq-cli/src/report.rs b/rs/moq-cli/src/report.rs index d05a2b41542..b035f8bb11a 100644 --- a/rs/moq-cli/src/report.rs +++ b/rs/moq-cli/src/report.rs @@ -209,7 +209,7 @@ impl Stats { /// Write a snapshot every interval, for as long as the import runs beside it. pub async fn run(&mut self) -> Infallible { - let mut interval = moq_clock::interval(INTERVAL); + let mut interval = kio::clock::interval(INTERVAL); loop { interval.tick().await; self.write(); @@ -309,7 +309,7 @@ impl Echo { None } }; - let mut interval = moq_clock::interval(INTERVAL); + let mut interval = kio::clock::interval(INTERVAL); loop { tokio::select! { update = next(&mut catalog) => match update { @@ -553,7 +553,7 @@ impl Readers { }; let id = reader.id(); self.drains.spawn(async move { - moq_clock::sleep(DRAIN).await; + kio::clock::sleep(DRAIN).await; (path, id) }); } diff --git a/rs/moq-cli/src/rtsp.rs b/rs/moq-cli/src/rtsp.rs index 2565277ca2f..8349d0ac090 100644 --- a/rs/moq-cli/src/rtsp.rs +++ b/rs/moq-cli/src/rtsp.rs @@ -52,7 +52,7 @@ pub async fn connect_import(target: ImportTarget, url: Url) -> anyhow::Result<() } tracing::info!(%url, ?backoff, "RTSP reconnecting"); - moq_clock::sleep(backoff).await; + kio::clock::sleep(backoff).await; backoff = (backoff * 2).min(BACKOFF_MAX); } } diff --git a/rs/moq-cli/src/subscribe.rs b/rs/moq-cli/src/subscribe.rs index cde1f32cc9d..b3f116a42ab 100644 --- a/rs/moq-cli/src/subscribe.rs +++ b/rs/moq-cli/src/subscribe.rs @@ -430,7 +430,7 @@ impl Subscribe { // Reports a track that stops reaching the output while the rest keeps flowing, // the way `publish` reports one that stops arriving. let mut log = moq_mux::container::ts::stats::Log::default(); - let mut sampled = moq_clock::now(); + let mut sampled = kio::clock::now(); // The export's drop, gap and out-of-tolerance counts, as last logged. let mut reported = (0, 0, 0, 0); let sections = self.sections; @@ -452,7 +452,7 @@ impl Subscribe { stdout.flush().await?; if sampled.elapsed() >= moq_mux::container::ts::stats::Log::INTERVAL { - sampled = moq_clock::now(); + sampled = kio::clock::now(); let stats = ts.export().stats(); report(&stats); let release = &stats.release; @@ -487,14 +487,14 @@ impl Subscribe { sections.set(|report| report.release = Some(stats.clone())); } }; - let mut sampled = moq_clock::now(); + let mut sampled = kio::clock::now(); let mut reported = (0, 0, 0, 0); while let Some(object) = release.next().await? { stdout.write_all(&object.payload).await?; stdout.flush().await?; if sampled.elapsed() >= moq_mux::container::ts::stats::Log::INTERVAL { - sampled = moq_clock::now(); + sampled = kio::clock::now(); let stats = release.stats(); report(&stats); let counts = (stats.dropped, stats.trimmed, stats.gaps, stats.out_of_tolerance); diff --git a/rs/moq-cli/src/transcode.rs b/rs/moq-cli/src/transcode.rs index 44209bcff7a..3bc8e4b8163 100644 --- a/rs/moq-cli/src/transcode.rs +++ b/rs/moq-cli/src/transcode.rs @@ -290,7 +290,7 @@ mod tests { let first = next(&mut derivatives).await; catalog.finish().unwrap(); - moq_clock::timeout(std::time::Duration::from_secs(1), first.closed()) + kio::clock::timeout(std::time::Duration::from_secs(1), first.closed()) .await .expect("the ladder outlived its source's end"); assert!(!task.is_finished(), "a clean end stopped following"); @@ -313,7 +313,7 @@ mod tests { } } }; - moq_clock::timeout(std::time::Duration::from_secs(1), start) + kio::clock::timeout(std::time::Duration::from_secs(1), start) .await .expect("no derivative instance was announced") } diff --git a/rs/moq-clock/CHANGELOG.md b/rs/moq-clock/CHANGELOG.md deleted file mode 100644 index c08249dd458..00000000000 --- a/rs/moq-clock/CHANGELOG.md +++ /dev/null @@ -1,14 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## [0.11.0] - -### Added - -- First release of the clock library: logical instants, wall time, deadlines, ambient timers, and a deterministic simulator. It replaces the "CLOCK over QUIC" demo binary, last published as 0.10.21 and now the moq-tokio `clock` example. diff --git a/rs/moq-clock/Cargo.toml b/rs/moq-clock/Cargo.toml deleted file mode 100644 index 38372232687..00000000000 --- a/rs/moq-clock/Cargo.toml +++ /dev/null @@ -1,68 +0,0 @@ -[package] -name = "moq-clock" -description = "One clock for Media over QUIC: logical instants, wall time, deadlines, and a deterministic simulator." -authors = ["Luke Curley"] -repository = "https://github.com/moq-dev/moq" -license = "MIT OR Apache-2.0" - -# The crates.io name previously held the "CLOCK over QUIC" demo binary (last 0.10.21). -version = "0.11.0" -edition = "2024" -rust-version.workspace = true - -keywords = ["moq", "time", "clock", "timer", "simulation"] -categories = ["asynchronous", "date-and-time", "development-tools::testing"] - -[package.metadata.docs.rs] -features = ["manual", "sim", "serde"] - -# The self dev-dependency below only enables a feature; no code names it. -[package.metadata.cargo-shear] -ignored = ["moq-clock"] - -[features] -default = ["runtime"] -# Numeric Unix-second JSON adapters for public wall times. -serde = ["dep:serde", "dep:serde_with"] -# The deterministic single-threaded executor and `#[moq_clock::test]`. Meant for -# dev-dependencies, so production builds never compile it. -sim = ["dep:futures", "dep:moq-clock-macros", "kio/_sim"] -runtime = ["dep:tokio", "dep:web-async"] -# `Manual::install`: a clock that only a test moves, as one tokio runtime's ambient -# clock. Native only. Meant for test builds, so production builds never compile it. -manual = ["runtime"] - -[dependencies] -futures = { workspace = true, optional = true } -kio = { workspace = true } -moq-clock-macros = { workspace = true, optional = true } -serde = { workspace = true, optional = true } -serde_with = { workspace = true, optional = true } -web-async = { workspace = true, optional = true } - -# The browser's only clocks, read with or without the runtime's timers. -[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] -web-async = { workspace = true } - -# The runtime handle, to keep a paused runtime's clock on its own origin. -[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies] -tokio = { workspace = true, features = ["rt", "time"], optional = true } - -[dev-dependencies] -# Enable the simulator so its tests run in the merge gate. Without default features, -# so `--no-default-features` still tests the build without the runtime. -moq-clock = { path = ".", default-features = false, features = ["sim", "serde"] } -serde_json = { workspace = true } - -[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies] -# Match the wasm-bindgen CLI schema used by the browser runner. -wasm-bindgen = "=0.2.129" -wasm-bindgen-test = "=0.3.79" - -[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dev-dependencies] -# Test the installed manual clock, which needs tokio's runtime and so is native only. -moq-clock = { path = ".", default-features = false, features = ["manual", "sim", "serde"] } -tokio = { workspace = true, features = ["rt", "rt-multi-thread", "test-util", "time"] } - -[lints] -workspace = true diff --git a/rs/moq-clock/MIGRATE.md b/rs/moq-clock/MIGRATE.md deleted file mode 100644 index bd3b497f610..00000000000 --- a/rs/moq-clock/MIGRATE.md +++ /dev/null @@ -1,15 +0,0 @@ -# Migrating moq-clock - -How to update your code for each breaking change, newest first. - -## Unreleased - -### `anchor()` is `origin()` (#6510) - -Rename `moq_clock::anchor()` to `moq_clock::origin()`, matching `@moq/clock`; it still returns the fixed `(Instant, Wall)` pair. - -### moq-clock is a time library (#5465) - -moq-clock 0.10 was the "CLOCK over QUIC" example binary. -0.11 is a library: logical instants, wall time, deadlines, and a deterministic simulator. -The clock example lives on as `cargo run -p moq-tokio --example clock`, which takes `--connect` instead of `--url`. diff --git a/rs/moq-clock/README.md b/rs/moq-clock/README.md deleted file mode 100644 index a8ae8175d04..00000000000 --- a/rs/moq-clock/README.md +++ /dev/null @@ -1,28 +0,0 @@ -[![Documentation](https://docs.rs/moq-clock/badge.svg)](https://docs.rs/moq-clock/) -[![Crates.io](https://img.shields.io/crates/v/moq-clock.svg)](https://crates.io/crates/moq-clock) -[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/moq-dev/moq/blob/main/LICENSE-MIT) - -# moq-clock - -One clock for [Media over QUIC](https://moq.dev): logical instants, wall time, -deadlines, and a deterministic simulator for tests. - -```bash -cargo add moq-clock -cargo add --dev moq-clock --features sim -``` - -```rust -#[moq_clock::test] -async fn retries_after_a_second() { - let start = moq_clock::now(); // Instant::ZERO - moq_clock::sleep(std::time::Duration::from_secs(1)).await; // returns at once - assert_eq!(moq_clock::now() - start, std::time::Duration::from_secs(1)); -} -``` - -Versions up to 0.10 were the "CLOCK over QUIC" demo binary, now the -[clock example](https://github.com/moq-dev/moq/blob/main/rs/moq-tokio/examples/clock.rs). - -See [docs.rs/moq-clock](https://docs.rs/moq-clock) for the API and -[doc.moq.dev](https://doc.moq.dev/lib/rs/moq-clock) for an overview. diff --git a/rs/moq-clock/macros/Cargo.toml b/rs/moq-clock/macros/Cargo.toml deleted file mode 100644 index 6af8280d5ce..00000000000 --- a/rs/moq-clock/macros/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -# The `#[moq_clock::test]` attribute. A separate crate only because a proc macro -# must be; `moq-clock` re-exports it behind its `sim` feature. -[package] -name = "moq-clock-macros" -description = "The #[moq_clock::test] attribute; use it through moq-clock's sim feature." -authors = ["Luke Curley"] -repository = "https://github.com/moq-dev/moq" -license = "MIT OR Apache-2.0" - -version = "0.1.0" -edition = "2024" -rust-version.workspace = true - -keywords = ["moq", "test", "simulation"] -categories = ["development-tools::testing"] - -[lib] -proc-macro = true - -[lints] -workspace = true diff --git a/rs/moq-congestion/Cargo.toml b/rs/moq-congestion/Cargo.toml index d79e64598f9..94c79aaedd6 100644 --- a/rs/moq-congestion/Cargo.toml +++ b/rs/moq-congestion/Cargo.toml @@ -12,12 +12,12 @@ license = "MIT OR Apache-2.0" testing = [] [dependencies] -moq-clock = { version = "0.11.0", path = "../moq-clock", default-features = false } +kio = { workspace = true } rand = { workspace = true } rand_pcg = { workspace = true } [dev-dependencies] -moq-clock = { path = "../moq-clock" } +kio = { path = "../kio", features = ["runtime"] } stats_alloc = "0.1.10" [target.'cfg(not(target_family = "wasm"))'.dev-dependencies] diff --git a/rs/moq-congestion/README.md b/rs/moq-congestion/README.md index de14ca649ee..898d009fb12 100644 --- a/rs/moq-congestion/README.md +++ b/rs/moq-congestion/README.md @@ -2,7 +2,7 @@ BBR3, Cubic, and Unlimited congestion controllers, consumed by moq-quic and the native transport drivers. -The controllers take explicit `moq_clock::Instant` values and never drive a runtime. The `Controller` trait names no transport types: `on_sent` returns an opaque per-packet state that the transport stores and hands back with each acknowledgement or loss, and the controller paces its own sends. +The controllers take explicit `kio::clock::Instant` values and never drive a runtime. The `Controller` trait names no transport types: `on_sent` returns an opaque per-packet state that the transport stores and hands back with each acknowledgement or loss, and the controller paces its own sends. The code was extracted from [moq-quic](../moq-quic), under the same MIT or Apache-2.0 license. Cubic originated in quinn; BBR3 was ported from moq-dev/noq and carries the fixes listed in [moq-quic's fork history](../moq-quic/README.md). diff --git a/rs/moq-congestion/clippy.toml b/rs/moq-congestion/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-congestion/clippy.toml +++ b/rs/moq-congestion/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-congestion/src/lib.rs b/rs/moq-congestion/src/lib.rs index a45e32909fb..b3fc6b4d53b 100644 --- a/rs/moq-congestion/src/lib.rs +++ b/rs/moq-congestion/src/lib.rs @@ -5,7 +5,7 @@ //! packet's [`Packet`] state is stored by the transport and handed back on ACK or loss, so a //! controller keeps no per-packet table of its own. -use moq_clock::Instant; +use kio::clock::Instant; use std::time::Duration; use std::any::Any; diff --git a/rs/moq-congestion/src/pacer.rs b/rs/moq-congestion/src/pacer.rs index 33137fe6c72..b295b739b01 100644 --- a/rs/moq-congestion/src/pacer.rs +++ b/rs/moq-congestion/src/pacer.rs @@ -1,6 +1,6 @@ //! Pacing of packet transmissions. -use moq_clock::Instant; +use kio::clock::Instant; use std::time::Duration; /// A simple token-bucket pacer diff --git a/rs/moq-congestion/src/rate.rs b/rs/moq-congestion/src/rate.rs index 2a7285bf625..abb57f61bba 100644 --- a/rs/moq-congestion/src/rate.rs +++ b/rs/moq-congestion/src/rate.rs @@ -5,7 +5,7 @@ //! into a rate sample. //! -use moq_clock::Instant; +use kio::clock::Instant; use std::time::Duration; use crate::{Ack, Sent}; diff --git a/rs/moq-e2ee/clippy.toml b/rs/moq-e2ee/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-e2ee/clippy.toml +++ b/rs/moq-e2ee/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-ffi/Cargo.toml b/rs/moq-ffi/Cargo.toml index af8e9c0d83f..cc9b66c9ad6 100644 --- a/rs/moq-ffi/Cargo.toml +++ b/rs/moq-ffi/Cargo.toml @@ -39,14 +39,13 @@ qlog = ["moq-tokio/qlog"] # Test-only hooks for the host suites: control of the runtime clock (`just py test`) and a # count of moq's heap (the Dart leak tests). Released builds leave it off, so they never # carry the `moq_ffi_test_*` symbols or the counting allocator. -testing = ["moq-clock/manual"] +testing = ["kio/manual"] [dependencies] bytes = { workspace = true } hang = { workspace = true } # `kio::MaybeSend` is the `Send` bound that vanishes on wasm; see `ffi::Task`. -kio = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-json = { workspace = true } moq-mux = { workspace = true } moq-net = { workspace = true } diff --git a/rs/moq-ffi/clippy.toml b/rs/moq-ffi/clippy.toml index d2d69deef2c..5b6bf8974be 100644 --- a/rs/moq-ffi/clippy.toml +++ b/rs/moq-ffi/clippy.toml @@ -1,12 +1,12 @@ # The wasm32 lint builds tokio without `time`, where these tokio paths do not resolve. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()", allow-invalid = true }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()", allow-invalid = true }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()", allow-invalid = true }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()", allow-invalid = true }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()", allow-invalid = true }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()", allow-invalid = true }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()", allow-invalid = true }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()", allow-invalid = true }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()", allow-invalid = true }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()", allow-invalid = true }, ] -disallowed-types = [{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" }] +disallowed-types = [{ path = "std::time::SystemTime", reason = "use kio::clock::Wall" }] diff --git a/rs/moq-ffi/src/ffi.rs b/rs/moq-ffi/src/ffi.rs index 532fac2752c..385a09fd676 100644 --- a/rs/moq-ffi/src/ffi.rs +++ b/rs/moq-ffi/src/ffi.rs @@ -24,7 +24,7 @@ pub(crate) struct Runtime { handle: tokio::runtime::Handle, /// The clock a test drives, when the runtime started with one. #[cfg(feature = "testing")] - clock: Option, + clock: Option, /// Taken by [`shutdown`], so the thread is stopped and joined once. thread: std::sync::Mutex>, /// Set by [`shutdown`] to wake the [`Task::run`] calls parked in place, so they observe @@ -67,7 +67,7 @@ pub(crate) fn runtime() -> &'static Runtime { RUNTIME.get_or_init(|| Runtime::new(false)) } -/// Start the runtime on a [`moq_clock::Manual`] clock that only a test moves. +/// Start the runtime on a [`kio::clock::Manual`] clock that only a test moves. /// /// False when the runtime already started, since its timers are armed on the host clock. #[cfg(all(feature = "testing", not(target_arch = "wasm32")))] @@ -82,7 +82,7 @@ pub(crate) fn start_test_clock() -> bool { /// The clock [`start_test_clock`] installed, if it did. #[cfg(all(feature = "testing", not(target_arch = "wasm32")))] -pub(crate) fn test_clock() -> Option<&'static moq_clock::Installed> { +pub(crate) fn test_clock() -> Option<&'static kio::clock::Installed> { RUNTIME.get()?.clock.as_ref() } @@ -103,7 +103,7 @@ impl Runtime { let handle = runtime.handle().clone(); // Before any task runs, so every read and timer lands on it. #[cfg(feature = "testing")] - let clock = test_clock.then(|| moq_clock::Manual::new().install(&handle)); + let clock = test_clock.then(|| kio::clock::Manual::new().install(&handle)); let (stop, stopped) = tokio::sync::oneshot::channel(); let join = std::thread::Builder::new() diff --git a/rs/moq-ffi/src/lib.rs b/rs/moq-ffi/src/lib.rs index c2477b4826a..1a5d8b330ab 100644 --- a/rs/moq-ffi/src/lib.rs +++ b/rs/moq-ffi/src/lib.rs @@ -99,7 +99,7 @@ pub extern "C" fn moq_ffi_test_clock_advance(nanos: u64) -> bool { #[unsafe(no_mangle)] pub extern "C" fn moq_ffi_test_clock_now() -> u64 { ffi::test_clock().map_or(u64::MAX, |clock| { - clock.now().duration_since(moq_clock::Instant::ZERO).as_nanos() as u64 + clock.now().duration_since(kio::clock::Instant::ZERO).as_nanos() as u64 }) } diff --git a/rs/moq-ffi/src/media.rs b/rs/moq-ffi/src/media.rs index 4bb3ce1f75a..30c962c3d92 100644 --- a/rs/moq-ffi/src/media.rs +++ b/rs/moq-ffi/src/media.rs @@ -2021,7 +2021,7 @@ mod timebase_tests { reserve(); } for touched in [1, 16, 256] { - let start = moq_clock::Instant::now(); + let start = kio::clock::Instant::now(); for _ in 0..1000 { for _ in 0..touched { reserve(); diff --git a/rs/moq-ffi/src/session/dial.rs b/rs/moq-ffi/src/session/dial.rs index 10efb740cb0..c3ec69e392b 100644 --- a/rs/moq-ffi/src/session/dial.rs +++ b/rs/moq-ffi/src/session/dial.rs @@ -78,7 +78,7 @@ impl Dial { let handshake = async move { let transport = transport.await.map_err(|err| Failure::Transport(err.to_string()))?; client - .connect(moq_clock::now(), transport) + .connect(kio::clock::now(), transport) .await .map_err(Failure::Handshake) }; diff --git a/rs/moq-ffi/src/test.rs b/rs/moq-ffi/src/test.rs index a2a5974cbdf..099ee5b6d10 100644 --- a/rs/moq-ffi/src/test.rs +++ b/rs/moq-ffi/src/test.rs @@ -6992,13 +6992,13 @@ async fn video_encoder_follows_a_shrinking_grant() { .unwrap(); assert_eq!(reservation.rate(), Some(1_000_000)); - let deadline = moq_clock::Instant::now() + TIMEOUT; + let deadline = kio::clock::Instant::now() + TIMEOUT; loop { if video.applied_bitrate() == 1_000_000 { break; } assert!( - moq_clock::Instant::now() < deadline, + kio::clock::Instant::now() < deadline, "encoder did not follow the shrinking grant, last applied {}", video.applied_bitrate() ); @@ -7693,7 +7693,7 @@ async fn memory_shutdown_pair() -> (Arc, Arc) { let (session, driver) = moq_net::Client::new() .with_origin(a.inner.clone()) .with_versions(version.into()) - .connect(moq_clock::Instant::now(), client) + .connect(kio::clock::Instant::now(), client) .await .unwrap(); tokio::spawn(moq_net::time::run(driver)); @@ -7704,7 +7704,7 @@ async fn memory_shutdown_pair() -> (Arc, Arc) { .with_publisher(&b.inner) .with_subscriber(b.inner.clone()) .with_versions(version.into()) - .accept(moq_clock::Instant::now(), server) + .accept(kio::clock::Instant::now(), server) .await .unwrap(); tokio::spawn(moq_net::time::run(driver)); @@ -7893,7 +7893,7 @@ async fn shutdown_times_out_on_an_unfinished_track() { .unwrap(); shutdown_ready(&track, &reader).await; let receiving = tokio::spawn(async move { reader.read_frame().await }); - let start = moq_clock::Instant::now(); + let start = kio::clock::Instant::now(); let mut closed = Box::pin(publisher.closed()); assert!( closed diff --git a/rs/moq-ffi/src/video.rs b/rs/moq-ffi/src/video.rs index a50fe16113f..3926e93216c 100644 --- a/rs/moq-ffi/src/video.rs +++ b/rs/moq-ffi/src/video.rs @@ -1511,7 +1511,7 @@ mod follow_tests { }); assert_eq!(moved, Ok(None)); - let retried = moq_clock::timeout(Duration::from_secs(60), follower.next()) + let retried = kio::clock::timeout(Duration::from_secs(60), follower.next()) .await .expect("the dropped target is asked for again"); assert_eq!(retried.unwrap(), Target::Enabled(Rate::from_mbps(2))); @@ -1526,7 +1526,7 @@ mod follow_tests { /// Retune at every target until the follower goes a minute without one. async fn quiet(follower: &mut Follower, ceiling: Rate, mut set: impl FnMut(Rate) -> Result<(), moq_video::Error>) { - while let Ok(bitrate) = moq_clock::timeout(Duration::from_secs(60), follower.next()).await { + while let Ok(bitrate) = kio::clock::timeout(Duration::from_secs(60), follower.next()).await { rate(follower, ceiling, bitrate.unwrap(), &mut set).unwrap(); } } diff --git a/rs/moq-flate/clippy.toml b/rs/moq-flate/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-flate/clippy.toml +++ b/rs/moq-flate/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-gst/Cargo.toml b/rs/moq-gst/Cargo.toml index f58ec7d8335..4d0995f17b6 100644 --- a/rs/moq-gst/Cargo.toml +++ b/rs/moq-gst/Cargo.toml @@ -23,7 +23,7 @@ bytes = { workspace = true } gst = { package = "gstreamer", version = "0.25" } gst-audio = { package = "gstreamer-audio", version = "0.25" } hang = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-mux = { workspace = true } moq-net = { workspace = true } moq-tokio = { workspace = true, default-features = true } diff --git a/rs/moq-gst/clippy.toml b/rs/moq-gst/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-gst/clippy.toml +++ b/rs/moq-gst/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-gst/src/sink/imp.rs b/rs/moq-gst/src/sink/imp.rs index a2a3e7c63ec..0ff9e0f6b53 100644 --- a/rs/moq-gst/src/sink/imp.rs +++ b/rs/moq-gst/src/sink/imp.rs @@ -696,7 +696,7 @@ impl MoqSink { }); let sample = super::wall::Sample { running: reference_running_time, - wall: moq_clock::wall(), + wall: kio::clock::wall(), }; let map = buffer.map_readable().map_err(|_| { gst::error!(CAT, "failed to map buffer on pad {}", pad.name()); @@ -1270,7 +1270,7 @@ mod tests { Duration::ZERO, super::super::wall::Sample { running: Some(gst::ClockTime::ZERO), - wall: moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(1_735_689_600), + wall: kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(1_735_689_600), }, ) .unwrap(); @@ -2056,11 +2056,11 @@ mod tests { while bus.pop().is_some() {} let linger = Duration::from_secs(30); - let start = moq_clock::now(); + let start = kio::clock::now(); let finished = moq_mux::Linger::new([broadcast], track, linger); let lingering = tokio::spawn(linger_task(finished, sink.downgrade(), session)); - moq_clock::sleep(linger - Duration::from_secs(1)).await; + kio::clock::sleep(linger - Duration::from_secs(1)).await; let mut late = consumer.track("video").unwrap().subscribe(None).await.unwrap(); assert!( late.recv_group().await.unwrap().is_some(), @@ -2069,7 +2069,7 @@ mod tests { assert!(bus.pop_filtered(&[gst::MessageType::Eos]).is_none(), "the EOS waits"); lingering.await.unwrap(); - assert_eq!(moq_clock::now() - start, linger); + assert_eq!(kio::clock::now() - start, linger); assert!(consumer.is_closed()); assert!( bus.pop_filtered(&[gst::MessageType::Eos]).is_some(), diff --git a/rs/moq-gst/src/sink/wall.rs b/rs/moq-gst/src/sink/wall.rs index 4d3b9fea990..918454d1023 100644 --- a/rs/moq-gst/src/sink/wall.rs +++ b/rs/moq-gst/src/sink/wall.rs @@ -12,7 +12,7 @@ use anyhow::{Context, Result}; #[derive(Clone, Copy)] pub(super) struct Sample { pub running: Option, - pub wall: moq_clock::Wall, + pub wall: kio::clock::Wall, } /// Places running-time zero on the wall clock once per run, holding the first catalog until then. @@ -54,7 +54,7 @@ impl Wall { } } -fn wall_zero(buffer: &gst::BufferRef, pts: Duration, sample: Sample) -> Result { +fn wall_zero(buffer: &gst::BufferRef, pts: Duration, sample: Sample) -> Result { for meta in buffer.iter_meta::() { let Some(reference) = meta.reference().structure(0) else { continue; @@ -68,7 +68,7 @@ fn wall_zero(buffer: &gst::BufferRef, pts: Duration, sample: Sample) -> Result continue, }; - return moq_clock::Wall::UNIX_EPOCH + return kio::clock::Wall::UNIX_EPOCH .checked_add(unix) .and_then(|wall| wall.checked_sub(pts)) .context("reference timestamp cannot place running-time zero"); @@ -93,7 +93,7 @@ mod tests { #[test] fn delayed_buffers_and_unknown_domains_use_the_pipeline_clock() { gst::init().unwrap(); - let now = moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(1_735_689_620); + let now = kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(1_735_689_620); let mut buffer = gst::Buffer::new(); gst::ReferenceTimestampMeta::add( buffer.get_mut().unwrap(), @@ -145,11 +145,11 @@ mod tests { Duration::from_secs(3), Sample { running: None, - wall: moq_clock::Wall::UNIX_EPOCH + wall: kio::clock::Wall::UNIX_EPOCH } ) .unwrap(), - moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(1_735_689_600) + kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(1_735_689_600) ); } } diff --git a/rs/moq-hls/Cargo.toml b/rs/moq-hls/Cargo.toml index 85d2c4c6acf..ed802da26c8 100644 --- a/rs/moq-hls/Cargo.toml +++ b/rs/moq-hls/Cargo.toml @@ -22,9 +22,8 @@ axum = { workspace = true, optional = true } bytes = { workspace = true } hang = { workspace = true } humantime = { workspace = true } -kio = { workspace = true } +kio = { workspace = true, features = ["runtime"] } m3u8-rs = "6" -moq-clock = { workspace = true } moq-mux = { workspace = true } moq-net = { workspace = true } percent-encoding = { workspace = true } diff --git a/rs/moq-hls/clippy.toml b/rs/moq-hls/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-hls/clippy.toml +++ b/rs/moq-hls/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-hls/src/export/mod.rs b/rs/moq-hls/src/export/mod.rs index 9de11ac934c..a339720588c 100644 --- a/rs/moq-hls/src/export/mod.rs +++ b/rs/moq-hls/src/export/mod.rs @@ -334,7 +334,7 @@ impl Broadcaster { &mpd::Manifest { instance: self.instance.clone(), availability_start, - publish: moq_clock::wall(), + publish: kio::clock::wall(), window: self.renditions.window(), finished, video, @@ -405,7 +405,7 @@ async fn watch_catalog(source: moq_mux::Source, renditions: renditions::Producer let wait = delay.mul_f64(0.5 + rand::rng().random::() / 2.0); delay = (delay * 2).min(CATALOG_RETRY_MAX); tokio::select! { - _ = moq_clock::sleep(wait) => {} + _ = kio::clock::sleep(wait) => {} _ = kio::wait(|waiter| broadcast.poll_closed(waiter)) => { renditions.close(); return; @@ -1542,11 +1542,11 @@ mod tests { let broadcaster = Broadcaster::new(crate::resolved(&origin, "live").await, Config::default()); while broadcaster.rendition(Kind::Video, "video0").is_none() { - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; } let mut waiting = std::pin::pin!(broadcaster.video_init()); assert!( - moq_clock::timeout(Duration::from_secs(1), waiting.as_mut()) + kio::clock::timeout(Duration::from_secs(1), waiting.as_mut()) .await .is_err(), "resolved without a listable video" @@ -1558,7 +1558,7 @@ mod tests { group.finish().unwrap(); records[0].push(&gop(sequence)).unwrap(); } - moq_clock::timeout(Duration::from_secs(1), waiting) + kio::clock::timeout(Duration::from_secs(1), waiting) .await .expect("the wait builds video0's init once its records arrive"); } @@ -1964,7 +1964,7 @@ mod tests { settle().await; // PTS zero at exactly the moq epoch, so every timestamp maps to a fixed string. - let wall = moq_clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS); + let wall = kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS); let config = catalog_config() .with_clock(moq_mux::Clock::at(moq_net::time::Instant::now(), wall).expect("a representable wall")); let catalog = moq_mux::catalog::Producer::new(&mut broadcast.broadcast().clone(), config).unwrap(); diff --git a/rs/moq-hls/src/export/mpd.rs b/rs/moq-hls/src/export/mpd.rs index 6b5cb9c4a8d..d82235c1796 100644 --- a/rs/moq-hls/src/export/mpd.rs +++ b/rs/moq-hls/src/export/mpd.rs @@ -14,7 +14,7 @@ //! `Representation` id keeps the raw name. The resources are shared byte-for-byte with the //! HLS routes; only the time-addressed segment alias `seg/t.m4s` is DASH's own. -use moq_clock::Wall; +use kio::clock::Wall; use std::collections::BTreeMap; use std::fmt::Write; use std::sync::Arc; diff --git a/rs/moq-hls/src/export/playlist.rs b/rs/moq-hls/src/export/playlist.rs index fd656d4c5dd..1495586b051 100644 --- a/rs/moq-hls/src/export/playlist.rs +++ b/rs/moq-hls/src/export/playlist.rs @@ -6,7 +6,7 @@ //! (`////media.m3u8`), so they resolve against the rendition //! directory. -use moq_clock::Wall; +use kio::clock::Wall; use std::fmt::Write; use std::sync::Arc; use std::time::Duration; diff --git a/rs/moq-hls/src/export/rendition.rs b/rs/moq-hls/src/export/rendition.rs index 2584ab89816..603811cfe41 100644 --- a/rs/moq-hls/src/export/rendition.rs +++ b/rs/moq-hls/src/export/rendition.rs @@ -1,6 +1,6 @@ //! One rendition: playlists from its own HLS records, and segments fetched on demand. -use moq_clock::Wall; +use kio::clock::Wall; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex, RwLock, Weak}; use std::task::Poll; @@ -1667,10 +1667,10 @@ mod tests { let rendition = rendition.clone(); async move { kio::wait(|waiter| rendition.poll_refused(waiter)).await } }); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; assert!(!refused.is_finished(), "the records have not failed yet"); rendition.fail(crate::Error::Moq(moq_net::Error::Transport("connection lost".into()))); - moq_clock::timeout(Duration::from_secs(1), refused) + kio::clock::timeout(Duration::from_secs(1), refused) .await .expect("the failure wakes the wait") .unwrap(); diff --git a/rs/moq-hls/src/export/renditions.rs b/rs/moq-hls/src/export/renditions.rs index 6faefc92e49..7aee4a175c2 100644 --- a/rs/moq-hls/src/export/renditions.rs +++ b/rs/moq-hls/src/export/renditions.rs @@ -9,7 +9,7 @@ //! set as [`Added`](Event::Added) when first consumed, and returning `None` once the catalog //! finishes cleanly, or an error when the recording is incomplete. -use moq_clock::Wall; +use kio::clock::Wall; use std::collections::{BTreeMap, BTreeSet}; use std::sync::{Arc, Weak}; use std::task::Poll; @@ -266,7 +266,7 @@ impl Fanout { pub fn stamp(&self, key: &Key, broken: bool, end: Duration) -> u64 { let mut feed = self.feed.write().unwrap_or_else(|_| unreachable!("fanout is open")); if feed.anchor.is_none() { - feed.anchor = Some(moq_clock::wall().checked_sub(end).unwrap_or(Wall::UNIX_EPOCH)); + feed.anchor = Some(kio::clock::wall().checked_sub(end).unwrap_or(Wall::UNIX_EPOCH)); } feed.discontinuities.stamp(key, broken) } diff --git a/rs/moq-hls/src/export/segments.rs b/rs/moq-hls/src/export/segments.rs index 8f0aaff9182..dc4a78ba78b 100644 --- a/rs/moq-hls/src/export/segments.rs +++ b/rs/moq-hls/src/export/segments.rs @@ -15,7 +15,7 @@ //! rendition numbers its own segments, so a number means the same on every edge and reload of //! that rendition, but nothing across renditions: players match renditions by timestamp. -use moq_clock::Wall; +use kio::clock::Wall; use std::collections::VecDeque; use std::sync::Arc; use std::task::{Poll, ready}; diff --git a/rs/moq-hls/src/import.rs b/rs/moq-hls/src/import.rs index a211b17dba1..18b500170bc 100644 --- a/rs/moq-hls/src/import.rs +++ b/rs/moq-hls/src/import.rs @@ -742,7 +742,7 @@ impl Import { /// amount of waiting changes either. pub async fn run(&mut self) -> Result<()> { let mut delay = STEP_RETRY_MIN; - let mut deadline = moq_clock::now() + STEP_RETRY_BUDGET; + let mut deadline = kio::clock::now() + STEP_RETRY_BUDGET; loop { // A step where *nothing* ingested while a rendition was failing is a failed pass wearing @@ -766,7 +766,7 @@ impl Import { Ok(outcome) => { // The source is alive, so the earlier failures no longer describe it. delay = STEP_RETRY_MIN; - deadline = moq_clock::now() + STEP_RETRY_BUDGET; + deadline = kio::clock::now() + STEP_RETRY_BUDGET; outcome } Err(err @ Error::ResourceRefused) => return Err(err), @@ -778,7 +778,7 @@ impl Import { // The source rewound its timestamps, which no later pass can import. Err(err @ Error::Rewind { .. }) => return Err(err), Err(err) => { - let now = moq_clock::now(); + let now = kio::clock::now(); if now >= deadline { return Err(err); } @@ -790,7 +790,7 @@ impl Import { .mul_f64(0.5 + rand::rng().random::() / 2.0) .min(deadline - now); delay = (delay * 2).min(STEP_RETRY_MAX); - moq_clock::sleep(wait).await; + kio::clock::sleep(wait).await; continue; } }; @@ -807,7 +807,7 @@ impl Import { "HLS import step complete" ); - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; } } diff --git a/rs/moq-hls/src/server/mod.rs b/rs/moq-hls/src/server/mod.rs index 39dc006b01d..afaef019336 100644 --- a/rs/moq-hls/src/server/mod.rs +++ b/rs/moq-hls/src/server/mod.rs @@ -215,7 +215,7 @@ impl Server { Poll::Ready(Some(_)) => Poll::Ready(true), Poll::Pending => routes.poll_synced(waiter).map(|()| false), }); - if !moq_clock::timeout(RESOLVE_TIMEOUT, routed).await.unwrap_or(false) { + if !kio::clock::timeout(RESOLVE_TIMEOUT, routed).await.unwrap_or(false) { return None; } @@ -223,7 +223,7 @@ impl Server { .map_err(|err| tracing::warn!(%err, %name, "failed to follow broadcast")) .ok()?; // A covering dynamic route may never answer, so the resolution is bounded too. - let broadcast = match moq_clock::timeout(RESOLVE_TIMEOUT, instances.next()).await { + let broadcast = match kio::clock::timeout(RESOLVE_TIMEOUT, instances.next()).await { Ok(Ok(follow::Event::Start(broadcast))) => broadcast, // Nothing was handed out, so there is nothing to end. Ok(Ok(follow::Event::End)) => return None, @@ -412,7 +412,7 @@ mod tests { let origin = produce_origin(); let server = Server::new(origin.consume(), Config::default()); - let start = moq_clock::now(); + let start = kio::clock::now(); assert!(server.broadcaster("live").await.is_none()); assert_eq!(start.elapsed(), Duration::ZERO); } @@ -486,7 +486,7 @@ mod tests { if ready().await { return; } - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; } panic!("never happened"); } diff --git a/rs/moq-hls/src/server/routes.rs b/rs/moq-hls/src/server/routes.rs index 4e8d34a6c2f..58fdaf30b21 100644 --- a/rs/moq-hls/src/server/routes.rs +++ b/rs/moq-hls/src/server/routes.rs @@ -72,7 +72,7 @@ async fn master(server: &Server, broadcast: &str, query: Option<&str>) -> Respon }; // A master listing no variant is unplayable: wait for one that can start, else answer // unavailable. - let _ = moq_clock::timeout(READY_TIMEOUT, broadcaster.advertised()).await; + let _ = kio::clock::timeout(READY_TIMEOUT, broadcaster.advertised()).await; let (video, audio) = broadcaster.variants(query); if video.is_empty() && audio.is_empty() { return not_found(); @@ -84,17 +84,17 @@ async fn manifest(server: &Server, broadcast: &str, query: Option<&str>) -> Resp let Some(broadcaster) = server.broadcaster(broadcast).await else { return not_found(); }; - let _ = moq_clock::timeout(READY_TIMEOUT, broadcaster.ready()).await; + let _ = kio::clock::timeout(READY_TIMEOUT, broadcaster.ready()).await; if broadcaster.is_empty() { return not_found(); } // A manifest whose renditions are all empty confuses players; give the broadcast a moment // to index its first complete segment before answering. - let _ = moq_clock::timeout(READY_TIMEOUT, broadcaster.playable()).await; + let _ = kio::clock::timeout(READY_TIMEOUT, broadcaster.playable()).await; // Each representation names its init by hash, which an inline codec only learns from media. // A player keeps the adaptation sets of the first manifest it loads, so wait for one video // init rather than every init: a stuck rendition never holds a sibling that can play. - let _ = moq_clock::timeout(READY_TIMEOUT, broadcaster.video_init()).await; + let _ = kio::clock::timeout(READY_TIMEOUT, broadcaster.video_init()).await; match broadcaster.manifest(query) { Ok(Some(manifest)) => mpd(manifest), Ok(None) => not_found(), @@ -106,7 +106,7 @@ async fn media(server: &Server, at: At<'_>, query: Option<&str>) -> Response { let Some(rendition) = rendition_for(server, at).await else { return not_found(); }; - match moq_clock::timeout(READY_TIMEOUT, rendition.playlist(query)).await { + match kio::clock::timeout(READY_TIMEOUT, rendition.playlist(query)).await { Ok(Ok(Some(playlist))) => m3u8(playlist), Ok(Ok(None)) | Err(_) => not_found(), Ok(Err(err)) => server_error(err), @@ -150,7 +150,7 @@ impl<'a> At<'a> { /// Resolve a rendition, waiting for the catalog to populate. async fn rendition_for(server: &Server, at: At<'_>) -> Option> { let broadcaster = server.instance(at.broadcast, at.instance).await?; - let _ = moq_clock::timeout(READY_TIMEOUT, broadcaster.ready()).await; + let _ = kio::clock::timeout(READY_TIMEOUT, broadcaster.ready()).await; broadcaster.rendition(at.kind, at.rendition) } diff --git a/rs/moq-hls/tests/integration/disconnect.rs b/rs/moq-hls/tests/integration/disconnect.rs index f04f7c70634..e0b83d6dc83 100644 --- a/rs/moq-hls/tests/integration/disconnect.rs +++ b/rs/moq-hls/tests/integration/disconnect.rs @@ -32,7 +32,7 @@ async fn disconnect(at: At) { let media = media_uri(&app, "live").await; let playlist = listed(&app, &media, ".2.m4s").await; assert_eq!(numbers(&playlist), [0, 1, 2], "{playlist}"); - let first = moq_clock::timeout(TIMEOUT, cursor.next()) + let first = kio::clock::timeout(TIMEOUT, cursor.next()) .await .expect("the first segment") .expect("records") @@ -67,7 +67,7 @@ async fn disconnect(at: At) { ); // The failure is final: every later call answers it again. for _ in 0..2 { - let again = moq_clock::timeout(TIMEOUT, cursor.next()) + let again = kio::clock::timeout(TIMEOUT, cursor.next()) .await .expect("the cursor stalled"); let Err(again) = again else { diff --git a/rs/moq-hls/tests/integration/finish.rs b/rs/moq-hls/tests/integration/finish.rs index bd0cb1bae01..38ff344aefc 100644 --- a/rs/moq-hls/tests/integration/finish.rs +++ b/rs/moq-hls/tests/integration/finish.rs @@ -28,7 +28,7 @@ async fn finish(order: Order) { let media = media_uri(&app, "live").await; listed(&app, &media, ".2.m4s").await; // Reading, as a recorder does, so the cursor's subscription carries every group across. - let first = moq_clock::timeout(TIMEOUT, cursor.next()) + let first = kio::clock::timeout(TIMEOUT, cursor.next()) .await .expect("the first segment") .expect("records") @@ -47,10 +47,10 @@ async fn finish(order: Order) { publisher.media.finish().expect("finish media"); publisher.broadcast.close(); // The server stops serving the instance once `End` reaches it. - let deadline = moq_clock::now() + TIMEOUT; + let deadline = kio::clock::now() + TIMEOUT; while get(&app, &media).await.status() != StatusCode::NOT_FOUND { - assert!(moq_clock::now() < deadline, "End never reached the export"); - moq_clock::sleep(Duration::from_millis(50)).await; + assert!(kio::clock::now() < deadline, "End never reached the export"); + kio::clock::sleep(Duration::from_millis(50)).await; } // `End` alone confirms nothing: the recording stays open until the catalog's EOF. let playlist = rendition.media_playlist(None).expect("live").expect("listed"); @@ -64,7 +64,7 @@ async fn finish(order: Order) { let (read, end) = drain(&mut cursor).await; end.unwrap_or_else(|err| panic!("{order:?}: {err}")); assert_eq!(read, [1, 2, 3, 4], "{order:?}"); - let again = moq_clock::timeout(TIMEOUT, cursor.next()) + let again = kio::clock::timeout(TIMEOUT, cursor.next()) .await .expect("the cursor stalled"); assert!(matches!(again, Ok(None)), "{order:?}: a finished cursor stays finished"); diff --git a/rs/moq-hls/tests/integration/restart.rs b/rs/moq-hls/tests/integration/restart.rs index 2e7112dfe04..d2c3826ad1f 100644 --- a/rs/moq-hls/tests/integration/restart.rs +++ b/rs/moq-hls/tests/integration/restart.rs @@ -48,7 +48,7 @@ async fn takeover(version: &str, case: Case) { assert_old(&app, uri).await; } // Read as a recorder does. A cached segment can return while the live feed is still opening. - let first = moq_clock::timeout(TIMEOUT, cursor.next()) + let first = kio::clock::timeout(TIMEOUT, cursor.next()) .await .expect("the first segment") .expect("records") @@ -60,7 +60,7 @@ async fn takeover(version: &str, case: Case) { )); match case { // Paused, the clock only moves once every task is idle, so the feed has its answer. - Case::Answered => moq_clock::sleep(Duration::from_millis(500)).await, + Case::Answered => kio::clock::sleep(Duration::from_millis(500)).await, Case::FinishedFirst => old.finish(), Case::Unanswered | Case::UnansweredUnfinished => {} } @@ -68,14 +68,14 @@ async fn takeover(version: &str, case: Case) { // The new instance numbers its groups and segments from zero again. let route = moq_net::origin::Route::default().with_epoch(moq_net::Epoch::mint()); let mut new = Publisher::new(&pair.publisher, "live", route); - let deadline = moq_clock::now() + TIMEOUT; + let deadline = kio::clock::now() + TIMEOUT; let current = loop { let current = server.broadcaster("live").await.expect("announced"); if !std::sync::Arc::ptr_eq(¤t, &replaced) { break current; } - assert!(moq_clock::now() < deadline, "the new instance never took over"); - moq_clock::sleep(Duration::from_millis(50)).await; + assert!(kio::clock::now() < deadline, "the new instance never took over"); + kio::clock::sleep(Duration::from_millis(50)).await; }; current.set_generation(Some("run-2")).expect("generation"); new.write(0, 13, NEW); @@ -164,7 +164,7 @@ async fn finished_first() { async fn drain_old(cursor: &mut segments::Consumer) -> (Vec, moq_hls::Result<()>) { let mut read = Vec::new(); loop { - let next = moq_clock::timeout(TIMEOUT, cursor.next()) + let next = kio::clock::timeout(TIMEOUT, cursor.next()) .await .expect("the replaced run's cursor stalled"); let segment = match next { diff --git a/rs/moq-hls/tests/integration/server.rs b/rs/moq-hls/tests/integration/server.rs index 2063df6949a..c10de551695 100644 --- a/rs/moq-hls/tests/integration/server.rs +++ b/rs/moq-hls/tests/integration/server.rs @@ -18,7 +18,7 @@ async fn respond_serves_a_route_rewritten_into_scope() { let mut route = Route::parse(&format!("/tenant{media}")).expect("media route"); route.broadcast = route.broadcast.strip_prefix("tenant/").expect("scoped").to_string(); - let deadline = moq_clock::now() + TIMEOUT; + let deadline = kio::clock::now() + TIMEOUT; let body = loop { let response = server.respond(&route, Some("jwt=abc")).await; if response.status() == StatusCode::OK { @@ -28,8 +28,8 @@ async fn respond_serves_a_route_rewritten_into_scope() { break body; } } - assert!(moq_clock::now() < deadline, "media playlist never listed a segment"); - moq_clock::sleep(std::time::Duration::from_millis(50)).await; + assert!(kio::clock::now() < deadline, "media playlist never listed a segment"); + kio::clock::sleep(std::time::Duration::from_millis(50)).await; }; assert!(body.contains(".mp4?jwt=abc\""), "{body}"); assert!(body.contains(".0.m4s?jwt=abc"), "{body}"); @@ -50,18 +50,18 @@ async fn a_cursor_records_a_publisher_without_fetch() { let mut publisher = Publisher::new(&pair.publisher, "live", Default::default()); let origin = pair.subscriber.consume(); - moq_clock::timeout(TIMEOUT, origin.routed("live")) + kio::clock::timeout(TIMEOUT, origin.routed("live")) .await .expect("announce timed out") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, origin.request_broadcast("live", None)) + let remote = kio::clock::timeout(TIMEOUT, origin.request_broadcast("live", None)) .await .expect("request timed out") .expect("remote broadcast"); let broadcaster = Broadcaster::new(moq_mux::Source::new(origin, remote), Default::default()); // Recorded as soon as the catalog lists it with its records, as a recorder does. let mut renditions = broadcaster.renditions(); - let rendition = match moq_clock::timeout(TIMEOUT, renditions.next()).await { + let rendition = match kio::clock::timeout(TIMEOUT, renditions.next()).await { Ok(Ok(Some(renditions::Event::Added(rendition)))) => rendition, _ => panic!("{version}: the catalog never listed the rendition"), }; @@ -73,7 +73,7 @@ async fn a_cursor_records_a_publisher_without_fetch() { while demand.wanted_changed().await?.is_none() {} moq_net::Result::Ok(()) }; - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { tokio::select! { _ = next.as_mut() => panic!("{version}: a segment before any media"), wanted = wanted => wanted.expect("track open"), @@ -83,7 +83,7 @@ async fn a_cursor_records_a_publisher_without_fetch() { .unwrap_or_else(|_| panic!("{version}: the cursor never subscribed")); publisher.write(0, 5, 1); - let segment = moq_clock::timeout(TIMEOUT, next) + let segment = kio::clock::timeout(TIMEOUT, next) .await .unwrap_or_else(|_| panic!("{version}: no segment recorded")) .unwrap_or_else(|err| panic!("{version}: {err}")) @@ -119,12 +119,12 @@ async fn a_disconnected_publisher_on_the_catalog_broadcast_answers_404() { let media = media_uri(&app, "live").await; let first = segment(&listed(&app, &media, ".0.m4s").await, 0); - let remote = moq_clock::timeout(TIMEOUT, pair.subscriber.consume().request_broadcast("live", None)) + let remote = kio::clock::timeout(TIMEOUT, pair.subscriber.consume().request_broadcast("live", None)) .await .expect("remote resolve timed out") .expect("remote broadcast"); drop(publisher); - moq_clock::timeout(TIMEOUT, remote.closed()) + kio::clock::timeout(TIMEOUT, remote.closed()) .await .expect("publisher close timed out"); @@ -140,7 +140,7 @@ async fn lookups_ride_the_servers_scope_watch() { other.announce(Default::default()).expect("announce other"); let server = pair.server(); - let missing = moq_clock::timeout(TIMEOUT, server.broadcaster("room/missing")) + let missing = kio::clock::timeout(TIMEOUT, server.broadcaster("room/missing")) .await .expect("lookup timed out"); assert!(missing.is_none()); @@ -174,12 +174,12 @@ async fn a_sibling_resolves_through_a_client_session() { media.announce(Default::default()).expect("announce media"); let origin = pair.subscriber.consume(); - let broadcast = moq_clock::timeout(TIMEOUT, origin.routed_broadcast("room/live")) + let broadcast = kio::clock::timeout(TIMEOUT, origin.routed_broadcast("room/live")) .await .expect("catalog resolve timed out") .expect("catalog broadcast"); let source = moq_mux::Source::new(origin, broadcast); - let sibling = moq_clock::timeout( + let sibling = kio::clock::timeout( TIMEOUT, source.resolve(Some(&moq_net::path::Relative::new("./source").unwrap()), None), ) @@ -223,14 +223,14 @@ async fn a_disconnected_sibling_publisher_answers_404() { let first = segment(&listed(&app, &uri, ".0.m4s").await, 0); // Waited on rather than requested once: a client only asks about what it watches. - let remote_media = moq_clock::timeout(TIMEOUT, pair.subscriber.consume().routed_broadcast("room/source")) + let remote_media = kio::clock::timeout(TIMEOUT, pair.subscriber.consume().routed_broadcast("room/source")) .await .expect("sibling resolve timed out") .expect("sibling broadcast"); // Only the sibling goes: the catalog keeps listing the rendition, so the request reaches the // media fetch rather than missing the rendition. media_broadcast.close(); - moq_clock::timeout(TIMEOUT, remote_media.closed()) + kio::clock::timeout(TIMEOUT, remote_media.closed()) .await .expect("sibling close timed out"); diff --git a/rs/moq-hls/tests/integration/support.rs b/rs/moq-hls/tests/integration/support.rs index 1ce48d9d523..66e65ea2365 100644 --- a/rs/moq-hls/tests/integration/support.rs +++ b/rs/moq-hls/tests/integration/support.rs @@ -47,7 +47,7 @@ impl Pair { let (client, server) = tokio::join!( async { let (session, driver) = client - .connect(moq_clock::now(), client_transport) + .connect(kio::clock::now(), client_transport) .await .expect("client session"); tokio::spawn(moq_net::time::run(driver)); @@ -55,7 +55,7 @@ impl Pair { }, async { let (session, driver) = server - .accept(moq_clock::now(), server_transport) + .accept(kio::clock::now(), server_transport) .await .expect("server session"); tokio::spawn(moq_net::time::run(driver)); @@ -179,13 +179,13 @@ pub fn frame(second: u64, payload: u8) -> moq_mux::container::Frame { /// The rendition `server` exports for `path` once its catalog lists it. pub async fn rendition(server: &Server, path: &str) -> std::sync::Arc { - let broadcaster = moq_clock::timeout(TIMEOUT, server.broadcaster(path)) + let broadcaster = kio::clock::timeout(TIMEOUT, server.broadcaster(path)) .await .expect("resolve timed out") .expect("announced"); let mut renditions = broadcaster.renditions(); loop { - match moq_clock::timeout(TIMEOUT, renditions.next()).await { + match kio::clock::timeout(TIMEOUT, renditions.next()).await { Ok(Ok(Some(moq_hls::export::renditions::Event::Added(rendition)))) if rendition.name == TRACK => { return rendition; } @@ -199,7 +199,7 @@ pub async fn rendition(server: &Server, path: &str) -> std::sync::Arc pub async fn drain(cursor: &mut segments::Consumer) -> (Vec, moq_hls::Result<()>) { let mut read = Vec::new(); loop { - match moq_clock::timeout(TIMEOUT, cursor.next()) + match kio::clock::timeout(TIMEOUT, cursor.next()) .await .expect("the cursor stalled") { @@ -224,7 +224,7 @@ pub async fn get(app: &axum::Router, uri: &str) -> Response { /// Poll `uri` until it answers 200 with a body containing `needle`, returning the body. pub async fn listed(app: &axum::Router, uri: &str, needle: &str) -> String { - let deadline = moq_clock::now() + TIMEOUT; + let deadline = kio::clock::now() + TIMEOUT; loop { let response = get(app, uri).await; let body = String::from_utf8_lossy(response.body()).into_owned(); @@ -232,11 +232,11 @@ pub async fn listed(app: &axum::Router, uri: &str, needle: &str) -> String { return body; } assert!( - moq_clock::now() < deadline, + kio::clock::now() < deadline, "{uri} never listed {needle}: {} {body}", response.status() ); - moq_clock::sleep(Duration::from_millis(50)).await; + kio::clock::sleep(Duration::from_millis(50)).await; } } diff --git a/rs/moq-ice/Cargo.toml b/rs/moq-ice/Cargo.toml index 58956326500..905c603487f 100644 --- a/rs/moq-ice/Cargo.toml +++ b/rs/moq-ice/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["webrtc", "ice", "stun", "str0m", "moq"] categories = ["network-programming", "multimedia"] [dependencies] -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } str0m = { workspace = true } stun-types = { workspace = true } thiserror = { workspace = true } diff --git a/rs/moq-ice/clippy.toml b/rs/moq-ice/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-ice/clippy.toml +++ b/rs/moq-ice/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-ice/src/agent.rs b/rs/moq-ice/src/agent.rs index d93ed360453..2ef83e50807 100644 --- a/rs/moq-ice/src/agent.rs +++ b/rs/moq-ice/src/agent.rs @@ -4,7 +4,7 @@ use std::ops::{Deref, DerefMut}; use std::sync::Arc; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use str0m::net::{Protocol, Receive}; use str0m::{Candidate, IceConnectionState, Input, Output, Rtc}; use stun_types::attribute::XorMappedAddress; @@ -250,7 +250,7 @@ impl Agent { self.receive(&data, src); continue; } - _ = moq_clock::sleep_until(deadline) => {} + _ = kio::clock::sleep_until(deadline) => {} } } diff --git a/rs/moq-json/clippy.toml b/rs/moq-json/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-json/clippy.toml +++ b/rs/moq-json/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-loc/clippy.toml b/rs/moq-loc/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-loc/clippy.toml +++ b/rs/moq-loc/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-msf/clippy.toml b/rs/moq-msf/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-msf/clippy.toml +++ b/rs/moq-msf/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-mux/Cargo.toml b/rs/moq-mux/Cargo.toml index ff9da615d99..deb7f2fd0b7 100644 --- a/rs/moq-mux/Cargo.toml +++ b/rs/moq-mux/Cargo.toml @@ -21,9 +21,8 @@ ebml-iterable = { workspace = true } h264-parser = { version = "0.4.2" } h264-reader = "0.9.0" hang = { workspace = true } -kio = { workspace = true } +kio = { workspace = true, features = ["runtime"] } memchr = "2" -moq-clock = { workspace = true } moq-flate = { workspace = true } moq-json = { workspace = true } moq-loc = { workspace = true } @@ -48,7 +47,7 @@ webm-iterable = "0.7" [dev-dependencies] criterion = { workspace = true } futures = { workspace = true } -moq-clock = { workspace = true, features = ["sim"] } +kio = { workspace = true, features = ["sim"] } proptest = { workspace = true } tokio = { workspace = true, features = ["test-util"] } tracing-test = { workspace = true, features = ["no-env-filter"] } diff --git a/rs/moq-mux/benches/decode_clock.rs b/rs/moq-mux/benches/decode_clock.rs index 66345e1a427..f902508c466 100644 --- a/rs/moq-mux/benches/decode_clock.rs +++ b/rs/moq-mux/benches/decode_clock.rs @@ -4,7 +4,7 @@ use std::time::Duration; use bytes::Bytes; use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; -use moq_clock::Instant; +use kio::clock::Instant; #[path = "../src/container/decode.rs"] #[allow( diff --git a/rs/moq-mux/benches/jitter.rs b/rs/moq-mux/benches/jitter.rs index 1c083bc5328..90c81fd5460 100644 --- a/rs/moq-mux/benches/jitter.rs +++ b/rs/moq-mux/benches/jitter.rs @@ -15,13 +15,13 @@ mod jitter; /// Every track sends a frame a second as it decodes, for as many two-second steering steps as /// fill the rate window with `floors`, each step measuring every track heard. async fn steer(tracks: u16, floors: u64) -> u64 { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = jitter::Buffer::new(Duration::from_millis(500)); buffer.expect(1..=tracks); let waiter = kio::Waiter::noop(); for second in 0..floors * 2 { let at = start + Duration::from_secs(second); - tokio::time::advance(at.saturating_duration_since(moq_clock::now())).await; + tokio::time::advance(at.saturating_duration_since(kio::clock::now())).await; for track in 1..=tracks { let arrival = jitter::Arrival { arrived: at, @@ -77,7 +77,7 @@ fn acquisition(c: &mut Criterion) { group.bench_function(BenchmarkId::new(tracks.to_string(), frames), |b| { b.iter(|| { runtime.block_on(async { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = jitter::Buffer::new(Duration::from_millis(500)); buffer.expect(1..=tracks); for track in 1..=tracks { @@ -125,7 +125,7 @@ fn handoff(c: &mut Criterion) { group.bench_function(BenchmarkId::new(tracks.to_string(), frames), |b| { b.iter(|| { runtime.block_on(async { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = jitter::Buffer::new(Duration::from_millis(500)); buffer.expect(1..=tracks); for instance in 0..2 { diff --git a/rs/moq-mux/clippy.toml b/rs/moq-mux/clippy.toml index d2d69deef2c..5b6bf8974be 100644 --- a/rs/moq-mux/clippy.toml +++ b/rs/moq-mux/clippy.toml @@ -1,12 +1,12 @@ # The wasm32 lint builds tokio without `time`, where these tokio paths do not resolve. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()", allow-invalid = true }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()", allow-invalid = true }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()", allow-invalid = true }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()", allow-invalid = true }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()", allow-invalid = true }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()", allow-invalid = true }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()", allow-invalid = true }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()", allow-invalid = true }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()", allow-invalid = true }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()", allow-invalid = true }, ] -disallowed-types = [{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" }] +disallowed-types = [{ path = "std::time::SystemTime", reason = "use kio::clock::Wall" }] diff --git a/rs/moq-mux/src/binary.rs b/rs/moq-mux/src/binary.rs index 4b562515108..ce42bf56887 100644 --- a/rs/moq-mux/src/binary.rs +++ b/rs/moq-mux/src/binary.rs @@ -35,7 +35,7 @@ //! //! A payload timed on the broadcast [`Clock`](crate::Clock) is written at that timestamp as given, //! and the entry advertises how late payloads reach the transport as its `jitter` and `delay`, the -//! way a media rendition does. A capture [`Instant`](moq_clock::Instant) converts with +//! way a media rendition does. A capture [`Instant`](kio::clock::Instant) converts with //! [`Clock::capture`](crate::Clock::capture) on the catalog's clock: //! //! ```no_run @@ -43,7 +43,7 @@ //! # catalog: &moq_mux::catalog::Producer, //! # thumbnail: &mut moq_mux::binary::Snapshot, //! # jpeg: bytes::Bytes, -//! # captured: moq_clock::Instant, +//! # captured: kio::clock::Instant, //! # ) -> moq_mux::Result<()> { //! let at = catalog.clock().capture(captured)?; //! thumbnail.update(moq_net::Timed::from(jpeg).at(at))?; @@ -627,7 +627,7 @@ mod test { /// payload would read as a near-zero bitrate. #[test] fn an_unset_host_clock_still_marks_a_reanchor() { - use moq_clock::Wall; + use kio::clock::Wall; use std::time::Duration; crate::clock::fake_host_wall(Wall::UNIX_EPOCH + Duration::from_secs(86_400)); diff --git a/rs/moq-mux/src/catalog/producer.rs b/rs/moq-mux/src/catalog/producer.rs index 5df43ad42b5..06ff0beaeea 100644 --- a/rs/moq-mux/src/catalog/producer.rs +++ b/rs/moq-mux/src/catalog/producer.rs @@ -91,7 +91,7 @@ const ESTIMATE_WINDOW: std::time::Duration = std::time::Duration::from_secs(1); #[derive(Default)] struct Throttle { /// When the last publish carrying an estimate went out. - last: Option, + last: Option, /// An estimate is in the catalog but not yet on the wire. pending: bool, } @@ -100,7 +100,7 @@ impl Throttle { /// A publish is going out: any held estimate rides it and opens a new window. fn fold(&mut self) { if std::mem::take(&mut self.pending) { - self.last = Some(moq_clock::now()); + self.last = Some(kio::clock::now()); } } } @@ -580,7 +580,7 @@ impl Producer { &mut self, timebase: &std::sync::OnceLock, pts: moq_net::Timestamp, - wall: Option, + wall: Option, ) -> crate::Result { let mut guard = self.modify()?; // Another clone of the timebase may have anchored first; the lock orders them. A placement @@ -1146,7 +1146,7 @@ impl Guard<'_, E> { if !estimates.pending { return Ok(()); } - let now = moq_clock::now(); + let now = kio::clock::now(); if throttle && estimates.last.is_some_and(|last| now < last + ESTIMATE_WINDOW) { return Ok(()); } @@ -2188,8 +2188,8 @@ mod test { fn sibling_broadcasts_share_a_clock_and_capture_time() { use std::time::Duration; - let captured = moq_clock::now(); - let wall = moq_clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS + 60_000); + let captured = kio::clock::now(); + let wall = kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS + 60_000); let clock = crate::Clock::at(captured, wall).unwrap(); let (origin, _driver) = moq_net::origin::Producer::new(Default::default()); let front = origin.create_broadcast("robot/front.hang").unwrap(); @@ -2242,14 +2242,14 @@ mod test { /// A `with_clock` catalog is fixed from the start: even the first importer shifts onto it, /// landing at the clock's reading on arrival, and the advertised mapping never moves. - #[moq_clock::test] + #[kio::test] async fn with_clock_shifts_the_first_importer() { use std::time::Duration; - moq_clock::sleep(Duration::from_secs(5)).await; + kio::clock::sleep(Duration::from_secs(5)).await; let mut broadcast = moq_net::broadcast::Info::new().produce(); - let wall = moq_clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS + 60_000); - let start = moq_clock::now() - Duration::from_secs(5); + let wall = kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS + 60_000); + let start = kio::clock::now() - Duration::from_secs(5); let config = Config::default().with_clock(crate::Clock::at(start, wall).expect("a representable wall")); let catalog = Producer::new(&mut broadcast, config).unwrap(); @@ -2285,7 +2285,7 @@ mod test { let clock = catalog.clock(); assert_eq!(catalog.snapshot().clock, clock.wall(), "the anchor is advertised"); let actual = clock.wall_clock(first).unwrap(); - let now = moq_clock::wall(); + let now = kio::clock::wall(); let drift = actual.max(now).saturating_duration_since(actual.min(now)); assert!(drift < Duration::from_secs(1), "the first timestamp is live on arrival"); @@ -2356,7 +2356,7 @@ mod test { fn a_placed_input_lands_where_it_says() { use std::time::Duration; - let wall = moq_clock::Wall::now() - Duration::from_secs(2); + let wall = kio::clock::Wall::now() - Duration::from_secs(2); let pts = moq_net::Timestamp::from_micros(100_000_000).unwrap(); let later = moq_net::Timestamp::from_micros(101_000_000).unwrap(); @@ -2392,7 +2392,7 @@ mod test { fn a_placement_alone_publishes_nothing() { use std::time::Duration; - let wall = moq_clock::Wall::now() - Duration::from_secs(2); + let wall = kio::clock::Wall::now() - Duration::from_secs(2); let mut broadcast = moq_net::broadcast::Info::new().produce(); let mut catalog = Producer::new(&mut broadcast, Config::default()).unwrap(); catalog.timebase().place(moq_net::Timestamp::ZERO, wall).unwrap(); @@ -2418,7 +2418,7 @@ mod test { let now = Duration::from_secs(86_400); crate::clock::fake_host_wall( - moq_clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS) + now, + kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS) + now, ); let zero = moq_net::Timestamp::from_secs(now.as_secs() - 3600).unwrap(); hang::catalog::Clock::new(zero.convert(scale).unwrap()).unwrap() @@ -2471,12 +2471,12 @@ mod test { // The same mapping from `with_clock` agrees in any units, without reading the host's wall // clock, which may be unset. - let zero = moq_clock::Wall::UNIX_EPOCH + let zero = kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS) + Duration::from_micros(input.wall.as_micros() as u64); - let fixed = crate::Clock::at(moq_clock::now(), zero).unwrap(); + let fixed = crate::Clock::at(kio::clock::now(), zero).unwrap(); seed.clock = Some(an_hour_ago(moq_net::Timescale::MILLI)); - crate::clock::fake_host_wall(moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(86_400)); + crate::clock::fake_host_wall(kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(86_400)); let config = Config::default().with_catalog(seed.clone()).with_clock(fixed); let mut broadcast = moq_net::broadcast::Info::new().produce(); let mut catalog = Producer::new(&mut broadcast, config).unwrap(); @@ -2485,7 +2485,7 @@ mod test { assert_eq!(catalog.snapshot().clock, Some(input)); // A different one is refused before any catalog track exists. - let other = crate::Clock::at(moq_clock::now(), zero + Duration::from_secs(1)).unwrap(); + let other = crate::Clock::at(kio::clock::now(), zero + Duration::from_secs(1)).unwrap(); let config = Config::default().with_catalog(seed).with_clock(other); let mut broadcast = moq_net::broadcast::Info::new().produce(); assert!(matches!( @@ -2555,12 +2555,12 @@ mod test { fn an_unset_host_clock_publishes_without_a_wall() { use std::time::Duration; - crate::clock::fake_host_wall(moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(86_400)); + crate::clock::fake_host_wall(kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(86_400)); let mut broadcast = moq_net::broadcast::Info::new().produce(); let catalog = Producer::new(&mut broadcast, Config::default()).unwrap(); assert_eq!(catalog.snapshot().clock, None); - let wall = moq_clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS); + let wall = kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS); let pts = moq_net::Timestamp::from_micros(1_000_000).unwrap(); assert!(matches!( catalog.timebase().place(pts, wall), diff --git a/rs/moq-mux/src/catalog/timebase.rs b/rs/moq-mux/src/catalog/timebase.rs index 36640f52750..61ed913d4d3 100644 --- a/rs/moq-mux/src/catalog/timebase.rs +++ b/rs/moq-mux/src/catalog/timebase.rs @@ -44,7 +44,7 @@ impl Timebase { /// A placement alone publishes nothing: the clock goes out with the catalog's first track. /// Refused once this timebase has an offset, and when the host's wall clock was unset, leaving no /// wall to place it on. - pub fn place(&self, pts: moq_net::Timestamp, wall: moq_clock::Wall) -> crate::Result<()> { + pub fn place(&self, pts: moq_net::Timestamp, wall: kio::clock::Wall) -> crate::Result<()> { self.catalog.clone().anchor(&self.offset, pts, Some(wall))?; Ok(()) } diff --git a/rs/moq-mux/src/clock.rs b/rs/moq-mux/src/clock.rs index 0bdf0679d49..142ffeba6a4 100644 --- a/rs/moq-mux/src/clock.rs +++ b/rs/moq-mux/src/clock.rs @@ -17,11 +17,11 @@ //! anything fixes the clock places the mapping so that frame is live on arrival; any other shifts //! onto the clock (see [`catalog::Timebase`](crate::catalog::Timebase)). -use moq_clock::Wall; +use kio::clock::Wall; use std::time::Duration; use hang::catalog::{MAX_SAFE_INTEGER, MOQ_EPOCH_UNIX_MILLIS}; -use moq_clock::Instant; +use kio::clock::Instant; /// Microseconds from the moq epoch (2020) to `wall`, negative before it. fn moq_micros(wall: Wall) -> i128 { @@ -31,7 +31,7 @@ fn moq_micros(wall: Wall) -> i128 { /// The host's wall clock, or `None` while it reads before the moq epoch (2020): unset. pub(crate) fn host_wall() -> Option { - let now = moq_clock::wall(); + let now = kio::clock::wall(); #[cfg(test)] let now = HOST_WALL.get().unwrap_or(now); (moq_micros(now) >= 0).then_some(now) @@ -98,7 +98,7 @@ impl Clock { /// name: media needs only the monotonic timeline. pub fn new() -> Self { Self { - instant: moq_clock::now(), + instant: kio::clock::now(), reading: Self::LEAD.as_micros() as u64, wall: host_wall().and_then(|now| wall_clock(now.checked_sub(Self::LEAD)?).ok()), } @@ -121,7 +121,7 @@ impl Clock { /// Refuses a `since` so large that PTS zero lands before the moq epoch (2020), which the wall /// mapping cannot name. On a host whose wall clock is unset, the clock has no wall mapping. pub(crate) fn arrival(since: Duration) -> crate::Result { - let instant = moq_clock::now(); + let instant = kio::clock::now(); let unmappable = || crate::Error::UnmappableTimestamp(format!("{since:?} puts PTS zero before 2020")); let wall = match host_wall() { Some(now) => { @@ -183,7 +183,7 @@ impl Clock { /// /// No `Instant` arithmetic, so a PTS zero before this host booted still maps. fn mapped(zero: hang::catalog::Clock, unmappable: impl Fn(&str) -> crate::Error) -> crate::Result { - let instant = moq_clock::now(); + let instant = kio::clock::now(); let now = host_wall().ok_or_else(|| unmappable("needs the host wall clock, which is unset"))?; // Saturating would stamp everything early by the skew without saying so. let reading = u64::try_from(moq_micros(now) - zero.wall.as_micros() as i128) @@ -221,7 +221,7 @@ impl Clock { /// Refuses an instant ahead of now, which would claim the payload reached the transport before /// it existed, and one before PTS zero, which no timestamp can name. pub fn capture(&self, at: Instant) -> crate::Result { - if at > moq_clock::now() { + if at > kio::clock::now() { return Err(crate::Error::InvalidCapture); } let micros = match at.checked_duration_since(self.instant) { @@ -265,7 +265,7 @@ mod tests { use super::*; fn epoch() -> Instant { - moq_clock::now() + kio::clock::now() } fn moq_epoch() -> Wall { @@ -278,15 +278,15 @@ mod tests { /// A capture maps onto the clock's own timeline, and one ahead of now or before the epoch is /// refused rather than clamped. - #[moq_clock::test] + #[kio::test] async fn a_capture_maps_onto_the_clock() { - moq_clock::sleep(Duration::from_secs(6)).await; - let now = moq_clock::now(); + kio::clock::sleep(Duration::from_secs(6)).await; + let now = kio::clock::now(); let clock = Clock::at(now - Duration::from_secs(5), moq_epoch()).unwrap(); assert_eq!(clock.capture(now - Duration::from_secs(2)).unwrap(), us(3_000_000)); assert!(matches!( - clock.capture(moq_clock::now() + Duration::from_secs(1)), + clock.capture(kio::clock::now() + Duration::from_secs(1)), Err(crate::Error::InvalidCapture) )); assert!(matches!( @@ -295,16 +295,16 @@ mod tests { )); } - #[moq_clock::test] + #[kio::test] async fn simulated_clock_preserves_logical_boundaries() { - moq_clock::sleep(Duration::from_secs(10)).await; - let epoch = moq_clock::now(); + kio::clock::sleep(Duration::from_secs(10)).await; + let epoch = kio::clock::now(); let clock = Clock::at(epoch, moq_epoch()).unwrap(); let fresh = Clock::new(); let before = fresh.now(); let wall = clock.wall(); - moq_clock::sleep(Duration::from_secs(3)).await; + kio::clock::sleep(Duration::from_secs(3)).await; assert_eq!(clock.now(), us(3_000_000)); assert_eq!(fresh.now().as_micros() - before.as_micros(), 3_000_000); assert_eq!(clock.wall(), wall); @@ -313,8 +313,8 @@ mod tests { moq_epoch() + Duration::from_secs(3) ); - let stepped = moq_clock::Manual::WALL_START + Duration::from_secs(3600); - moq_clock::sim::step_wall(stepped); + let stepped = kio::clock::Manual::WALL_START + Duration::from_secs(3600); + kio::clock::sim::step_wall(stepped); assert_eq!(clock.wall(), wall, "a wall correction does not retime archived media"); assert_eq!( Clock::new().wall(), @@ -366,26 +366,26 @@ mod tests { // and the mapping still names the current wall time. assert!(clock.now().as_micros() >= Clock::LEAD.as_micros()); let now = clock.wall_clock(clock.now()).unwrap(); - let host = moq_clock::wall(); + let host = kio::clock::wall(); let drift = now.max(host).saturating_duration_since(now.min(host)); assert!(drift < Duration::from_secs(1), "wall + now is the current wall time"); } /// A source whose first timestamp is ten hours in reads that timestamp now, mapped to now. - #[moq_clock::test] + #[kio::test] async fn arrival_maps_the_first_timestamp_to_now() { - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let since = Duration::from_secs(10 * 3600); let clock = Clock::arrival(since).unwrap(); let now = clock.now(); assert!(now.as_micros() >= since.as_micros()); let actual = clock.wall_clock(now).unwrap(); - let host = moq_clock::wall(); + let host = kio::clock::wall(); let drift = actual.max(host).saturating_duration_since(actual.min(host)); assert!(drift < Duration::from_secs(1), "the first timestamp is live on arrival"); // A capture from before the arrival still maps, down to PTS zero. - let earlier = clock.capture(moq_clock::now() - Duration::from_secs(1)).unwrap(); + let earlier = clock.capture(kio::clock::now() - Duration::from_secs(1)).unwrap(); assert!(earlier.as_micros() < now.as_micros()); // PTS zero before 2020 cannot be named on the wire. diff --git a/rs/moq-mux/src/codec/av1/split.rs b/rs/moq-mux/src/codec/av1/split.rs index b41aaa51fad..ca95fa9d1a9 100644 --- a/rs/moq-mux/src/codec/av1/split.rs +++ b/rs/moq-mux/src/codec/av1/split.rs @@ -20,7 +20,7 @@ use crate::Result; /// stdin); call [`flush`](Self::flush) to emit the final in-flight temporal unit. pub struct Split { current: Au, - zero: Option, + zero: Option, pending: Vec, // Bytes carried across calls: a partial OBU at the tail of one `decode` waits // here for the rest to arrive on the next call. @@ -169,7 +169,7 @@ impl Split { if let Some(pts) = hint { return Ok(pts); } - let zero = self.zero.get_or_insert_with(moq_clock::Instant::now); + let zero = self.zero.get_or_insert_with(kio::clock::Instant::now); Ok(moq_net::Timestamp::from_micros(zero.elapsed().as_micros() as u64)?) } } diff --git a/rs/moq-mux/src/codec/h264/split.rs b/rs/moq-mux/src/codec/h264/split.rs index 1863173c07e..1e687cfa04e 100644 --- a/rs/moq-mux/src/codec/h264/split.rs +++ b/rs/moq-mux/src/codec/h264/split.rs @@ -38,7 +38,7 @@ pub struct Split { /// Retained PPS NALs. A keyframe may carry several (slices reference them by /// id); all are kept and re-injected, but a new GOP's set supersedes them. pps: ParameterSets, - zero: Option, + zero: Option, pending: Vec, } @@ -267,7 +267,7 @@ impl Split { if let Some(pts) = hint { return Ok(pts); } - let zero = self.zero.get_or_insert_with(moq_clock::Instant::now); + let zero = self.zero.get_or_insert_with(kio::clock::Instant::now); Ok(moq_net::Timestamp::from_micros(zero.elapsed().as_micros() as u64)?) } } diff --git a/rs/moq-mux/src/codec/h265/split.rs b/rs/moq-mux/src/codec/h265/split.rs index db8adaa714d..1da2fde3c75 100644 --- a/rs/moq-mux/src/codec/h265/split.rs +++ b/rs/moq-mux/src/codec/h265/split.rs @@ -36,7 +36,7 @@ pub struct Split { /// Retained PPS NALs. A keyframe may carry several (slices reference them by /// id); all are kept and re-injected, but a new GOP's set supersedes them. pps: ParameterSets, - zero: Option, + zero: Option, pending: Vec, } @@ -274,7 +274,7 @@ impl Split { if let Some(pts) = hint { return Ok(pts); } - let zero = self.zero.get_or_insert_with(moq_clock::Instant::now); + let zero = self.zero.get_or_insert_with(kio::clock::Instant::now); Ok(moq_net::Timestamp::from_micros(zero.elapsed().as_micros() as u64)?) } } diff --git a/rs/moq-mux/src/container/consumer.rs b/rs/moq-mux/src/container/consumer.rs index 1c010612bec..b9a6263c2ae 100644 --- a/rs/moq-mux/src/container/consumer.rs +++ b/rs/moq-mux/src/container/consumer.rs @@ -1,7 +1,7 @@ use std::collections::VecDeque; use std::task::{Poll, ready}; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::Timestamp; use super::{Container, Frame, Read, TimestampRewind}; @@ -124,7 +124,7 @@ pub struct Consumer { max_delay: std::time::Duration, // Wakes the reader once the hole at the cursor expires. - hole_timer: Option>>, + hole_timer: Option>>, // The furthest presentation point delivered so far: max(timestamp + duration), endpoints // included. `None` until the first item, so a loss before it is no gap. @@ -445,7 +445,7 @@ impl Consumer { // Said now rather than with the gap, which waits for the next group: what // the caller holds of this one need not wait for a successor. return Poll::Ready(Ok(Some(Event::Cut { - observed: moq_clock::now(), + observed: kio::clock::now(), }))); } // Cleanly finished group: advance to the next sequence. @@ -567,7 +567,7 @@ impl Consumer { if let Some(wake) = since.checked_add(self.max_delay) { let timer = self .hole_timer - .get_or_insert_with(|| Box::pin(moq_clock::sleep_until(wake))); + .get_or_insert_with(|| Box::pin(kio::clock::sleep_until(wake))); timer.as_mut().reset(wake); let _ = waiter.poll_future(timer.as_mut()); } @@ -753,7 +753,7 @@ struct GroupBuffer { // From then on, any sequence missing below this group is late: the earliest arrival among it // and the groups past it, kept on insert so a hole reads it without scanning the backlog. - late: moq_clock::Instant, + late: kio::clock::Instant, // The current frame index within the group. index: usize, @@ -795,7 +795,7 @@ impl GroupBuffer { fn new(group: moq_net::group::Consumer) -> Self { Self { group, - late: moq_clock::now(), + late: kio::clock::now(), index: 0, empty: true, media: false, @@ -1259,8 +1259,8 @@ mod tests { assert!(reader.poll_read(&kio::Waiter::noop()).is_pending()); tokio::time::advance(budget - Duration::from_millis(1)).await; assert!(reader.poll_read(&kio::Waiter::noop()).is_pending()); - let before = moq_clock::now(); - let read = moq_clock::timeout(Duration::from_millis(2), reader.read()) + let before = kio::clock::now(); + let read = kio::clock::timeout(Duration::from_millis(2), reader.read()) .await .unwrap() .unwrap(); diff --git a/rs/moq-mux/src/container/decode.rs b/rs/moq-mux/src/container/decode.rs index b065ff28fa3..fdc3dd3b81b 100644 --- a/rs/moq-mux/src/container/decode.rs +++ b/rs/moq-mux/src/container/decode.rs @@ -3,7 +3,7 @@ use std::collections::VecDeque; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; /// The largest supported reorder span in 90 kHz ticks. pub(crate) const MAX_REORDER: u64 = 2 * 90_000; diff --git a/rs/moq-mux/src/container/flv/export.rs b/rs/moq-mux/src/container/flv/export.rs index ac707f3eca7..bd36ed9e7de 100644 --- a/rs/moq-mux/src/container/flv/export.rs +++ b/rs/moq-mux/src/container/flv/export.rs @@ -182,7 +182,7 @@ struct FlvTrack { source: ExportSource, pending: Option>, /// When the source was last empty, bounding the next frame's arrival. - empty: moq_clock::Instant, + empty: kio::clock::Instant, finished: bool, /// The FLV payload shape (legacy CodecID vs enhanced FourCC) to mux this /// track as, fixed from its catalog codec when it's bound. @@ -209,7 +209,7 @@ impl FlvTrack { fn rebind(&mut self, source: ExportSource) { self.source = source.continuing(&self.source); self.finished = false; - self.empty = moq_clock::now(); + self.empty = kio::clock::now(); } /// The tag timestamp of a frame presented at `pts` on the tag clock, on the inferred clock. @@ -226,7 +226,7 @@ impl FlvTrack { fn start_group( &mut self, key: (u8, usize), - arrived: moq_clock::Instant, + arrived: kio::clock::Instant, shift: u32, jitter: &mut crate::jitter::Buffer<(u8, usize), Tag>, ) -> anyhow::Result<()> { @@ -244,7 +244,7 @@ impl FlvTrack { fn release( &mut self, key: (u8, usize), - settled: Option, + settled: Option, shift: u32, flush: bool, jitter: &mut crate::jitter::Buffer<(u8, usize), Tag>, @@ -448,7 +448,7 @@ impl Export { } #[cfg(test)] - pub(super) fn next_deadline(&self) -> Option { + pub(super) fn next_deadline(&self) -> Option { self.jitter.next_deadline() } @@ -500,7 +500,7 @@ impl Export { break; } Poll::Pending => { - track.empty = moq_clock::now(); + track.empty = kio::clock::now(); break; } }; @@ -510,7 +510,7 @@ impl Export { } crate::jitter::Arrival { arrived: track.empty, - read: moq_clock::now(), + read: kio::clock::now(), decode: frame.timestamp.into(), restart: track.source.markers(), skip: track.source.skips(), @@ -681,7 +681,7 @@ impl Export { track_id, source, pending: None, - empty: moq_clock::now(), + empty: kio::clock::now(), finished: false, flavor, fallback_description, @@ -730,7 +730,7 @@ impl Export { track_id, source, pending: None, - empty: moq_clock::now(), + empty: kio::clock::now(), finished: false, flavor, fallback_description: None, diff --git a/rs/moq-mux/src/container/flv/export_test.rs b/rs/moq-mux/src/container/flv/export_test.rs index 4a6e495c0d3..4d81d76780b 100644 --- a/rs/moq-mux/src/container/flv/export_test.rs +++ b/rs/moq-mux/src/container/flv/export_test.rs @@ -137,7 +137,7 @@ async fn drain_export(mut exporter: Export, import Ok(Err(e)) => panic!("exporter error: {e}"), Err(_) => { if let Some(deadline) = exporter.next_deadline() { - tokio::time::advance(deadline.saturating_duration_since(moq_clock::now())).await; + tokio::time::advance(deadline.saturating_duration_since(kio::clock::now())).await; } else { importer = None; // No scheduled frames remain; close the broadcast. } @@ -1558,7 +1558,7 @@ async fn drain_until_idle( Ok(Err(e)) => return Some(Err(e)), Err(_) => { let deadline = exporter.next_deadline()?; - tokio::time::advance(deadline.saturating_duration_since(moq_clock::now())).await; + tokio::time::advance(deadline.saturating_duration_since(kio::clock::now())).await; } } } @@ -1743,7 +1743,7 @@ async fn delay_drops_late_frames_and_drains_the_final_frame() { let delay = std::time::Duration::from_millis(100); let mut export = super::Export::new(live.source().await, live.catalog_stream().await).with_delay(delay); export.next().await.unwrap().unwrap(); - let start = moq_clock::now(); + let start = kio::clock::now(); live.track.write(raw_frame(0, b"first", true)).unwrap(); let first = export.next().await.unwrap().unwrap(); assert!(first.windows(5).any(|part| part == b"first")); diff --git a/rs/moq-mux/src/container/flv/import_test.rs b/rs/moq-mux/src/container/flv/import_test.rs index 9c68a77a074..295bb4e4eab 100644 --- a/rs/moq-mux/src/container/flv/import_test.rs +++ b/rs/moq-mux/src/container/flv/import_test.rs @@ -811,7 +811,7 @@ struct Imported { video: String, /// The root clock the catalog advertised. clock: hang::catalog::Clock, - arrival: std::ops::RangeInclusive, + arrival: std::ops::RangeInclusive, /// Why a chunk was refused, if one was. refused: Option, } @@ -824,7 +824,7 @@ async fn import(chunks: &[Vec]) -> Imported { let catalog = crate::catalog::Producer::new(&mut broadcast, Default::default()).unwrap(); let mut importer = Import::new(broadcast, catalog.reserve()); - let before = moq_clock::wall(); + let before = kio::clock::wall(); let mut after = before; let mut refused = None; for (i, chunk) in chunks.iter().enumerate() { @@ -833,7 +833,7 @@ async fn import(chunks: &[Vec]) -> Imported { break; } if i == 0 { - after = moq_clock::wall(); + after = kio::clock::wall(); } } importer.finish().unwrap(); diff --git a/rs/moq-mux/src/container/fmp4/import_test.rs b/rs/moq-mux/src/container/fmp4/import_test.rs index 2163af94dff..2181ce66f80 100644 --- a/rs/moq-mux/src/container/fmp4/import_test.rs +++ b/rs/moq-mux/src/container/fmp4/import_test.rs @@ -2299,7 +2299,7 @@ struct Imported { video: String, /// The root clock the catalog advertised. clock: hang::catalog::Clock, - arrival: std::ops::RangeInclusive, + arrival: std::ops::RangeInclusive, /// Where the video's first HLS segment starts. record: moq_net::Timestamp, /// Why a chunk was refused, if one was. @@ -2320,7 +2320,7 @@ async fn import_session(chunks: &[Vec]) -> Imported { let video = snapshot.video.renditions.keys().next().unwrap().clone(); let mut records = subscribe(&consumer, &video).await; - let before = moq_clock::wall(); + let before = kio::clock::wall(); let mut after = before; let mut refused = None; for (i, chunk) in chunks.iter().enumerate() { @@ -2329,7 +2329,7 @@ async fn import_session(chunks: &[Vec]) -> Imported { break; } if i == 0 { - after = moq_clock::wall(); + after = kio::clock::wall(); } } fmp4.finish().unwrap(); @@ -3197,7 +3197,7 @@ async fn ttml_samples_become_timed_text_with_source_metadata() { /// The source joins a catalog clock another input already fixed, so its TTML times move with it. #[tokio::test(start_paused = true)] async fn ttml_follows_a_shifted_source_clock() { - let wall = moq_clock::wall(); + let wall = kio::clock::wall(); let mut broadcast = moq_net::broadcast::Info::new().produce(); let consumer = broadcast.consume(); let catalog = crate::catalog::Producer::new(&mut broadcast, Default::default()).unwrap(); diff --git a/rs/moq-mux/src/container/mkv/export.rs b/rs/moq-mux/src/container/mkv/export.rs index 74bc7338b03..bafc84a0061 100644 --- a/rs/moq-mux/src/container/mkv/export.rs +++ b/rs/moq-mux/src/container/mkv/export.rs @@ -83,9 +83,9 @@ struct MkvTrack { source: ExportSource, pending: Option>, // When the source was subscribed: nothing it delivers reached the export before then. - subscribed: moq_clock::Instant, + subscribed: kio::clock::Instant, // The latest arrival read from the source, which settles the frames held for their DTS. - latest: moq_clock::Instant, + latest: kio::clock::Instant, finished: bool, track_number: u64, kind: TrackKind, @@ -107,8 +107,8 @@ impl MkvTrack { reorder: None, source, pending: None, - subscribed: moq_clock::now(), - latest: moq_clock::Instant::ZERO, + subscribed: kio::clock::now(), + latest: kio::clock::Instant::ZERO, finished: false, track_number, kind, @@ -131,7 +131,7 @@ impl MkvTrack { self.reorder = None; self.source = source.continuing(&self.source); self.finished = false; - self.subscribed = moq_clock::now(); + self.subscribed = kio::clock::now(); self.moved = true; Ok(()) } @@ -451,7 +451,7 @@ impl Export { } #[cfg(test)] - pub(super) fn next_deadline(&self) -> Option { + pub(super) fn next_deadline(&self) -> Option { self.jitter.next_deadline() } @@ -532,7 +532,7 @@ impl Export { } crate::jitter::Arrival { arrived, - read: moq_clock::now(), + read: kio::clock::now(), decode: frame.timestamp.into(), restart: track.source.markers(), skip: track.source.skips(), diff --git a/rs/moq-mux/src/container/mkv/export_test.rs b/rs/moq-mux/src/container/mkv/export_test.rs index 7c41893d1f2..52cde2d9906 100644 --- a/rs/moq-mux/src/container/mkv/export_test.rs +++ b/rs/moq-mux/src/container/mkv/export_test.rs @@ -551,7 +551,7 @@ async fn export_emits_blocks_for_each_frame() { Ok(Err(e)) => panic!("exporter error: {e}"), Err(_) => { if let Some(deadline) = exporter.next_deadline() { - tokio::time::advance(deadline.saturating_duration_since(moq_clock::now())).await; + tokio::time::advance(deadline.saturating_duration_since(kio::clock::now())).await; } else { importer = None; } @@ -794,7 +794,7 @@ async fn export_fragment_duration_batches_blocks() { Ok(Err(e)) => panic!("exporter error: {e}"), Err(_) => { if let Some(deadline) = exporter.next_deadline() { - tokio::time::advance(deadline.saturating_duration_since(moq_clock::now())).await; + tokio::time::advance(deadline.saturating_duration_since(kio::clock::now())).await; } else { importer = None; } @@ -1147,7 +1147,7 @@ async fn delay_drops_late_frames_and_drains_the_final_frame() { .with_delay(delay) .with_fragment_duration(std::time::Duration::ZERO); export.next().await.unwrap().unwrap(); - let start = moq_clock::now(); + let start = kio::clock::now(); live.track.write(raw_frame(0, b"first", true)).unwrap(); let first = export.next().await.unwrap().unwrap(); assert!(first.windows(5).any(|part| part == b"first")); diff --git a/rs/moq-mux/src/container/mkv/import_test.rs b/rs/moq-mux/src/container/mkv/import_test.rs index ebf4544f1b7..2d5e94c6874 100644 --- a/rs/moq-mux/src/container/mkv/import_test.rs +++ b/rs/moq-mux/src/container/mkv/import_test.rs @@ -1002,7 +1002,7 @@ struct Imported { published: std::collections::BTreeMap>, /// The root clock the catalog advertised. clock: hang::catalog::Clock, - arrival: std::ops::RangeInclusive, + arrival: std::ops::RangeInclusive, /// Why a chunk was refused, if one was. refused: Option, } @@ -1015,7 +1015,7 @@ async fn import_chunked(data: &[u8], chunk: usize) -> Imported { let catalog = crate::catalog::Producer::new(&mut broadcast, Default::default()).unwrap(); let mut mkv = crate::container::mkv::Import::new(broadcast, catalog.reserve()); - let before = moq_clock::wall(); + let before = kio::clock::wall(); let mut refused = None; for piece in data.chunks(chunk) { if let Err(err) = mkv.decode(piece) { @@ -1023,7 +1023,7 @@ async fn import_chunked(data: &[u8], chunk: usize) -> Imported { break; } } - let after = moq_clock::wall(); + let after = kio::clock::wall(); mkv.finish().unwrap(); let snapshot = catalog.snapshot(); diff --git a/rs/moq-mux/src/container/ts/damage.rs b/rs/moq-mux/src/container/ts/damage.rs index c04f4c85210..41fb20fd202 100644 --- a/rs/moq-mux/src/container/ts/damage.rs +++ b/rs/moq-mux/src/container/ts/damage.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; -use moq_clock::Instant; +use kio::clock::Instant; use super::stats; @@ -28,7 +28,7 @@ impl Burst { impl Log { pub fn record(&mut self, pid: u16, error: &anyhow::Error) { - let now = moq_clock::now(); + let now = kio::clock::now(); self.flush(now); let first = match self.bursts.entry(pid) { std::collections::btree_map::Entry::Occupied(mut entry) => { @@ -117,7 +117,7 @@ mod tests { tokio::time::advance(stats::Log::INTERVAL / 2).await; log.record(97, &error); tokio::time::advance(stats::Log::INTERVAL / 2).await; - log.flush(moq_clock::now()); + log.flush(kio::clock::now()); // This PID is quiet for a full interval before the next global summary tick. tokio::time::advance(stats::Log::INTERVAL / 2).await; log.record(97, &error); diff --git a/rs/moq-mux/src/container/ts/export.rs b/rs/moq-mux/src/container/ts/export.rs index 7d7360e73d7..0c66f173136 100644 --- a/rs/moq-mux/src/container/ts/export.rs +++ b/rs/moq-mux/src/container/ts/export.rs @@ -119,8 +119,8 @@ where pending: Option>>, next_program: u64, active_program: u64, - follow_until: Option, - follow_timer: Option>>, + follow_until: Option, + follow_timer: Option>>, } /// Input and mux state belonging to one publisher instance. The release clock @@ -195,7 +195,7 @@ where /// edge: a test exporting a broadcast it wrote whole. replay: bool, /// Wakes the export when the next grid slot is due on the jitter buffer's clock. - slot_timer: Option>>, + slot_timer: Option>>, /// Output frames ready to hand out, one per grid slot, each with what it tells /// [`Export::stats`] once returned. queue: VecDeque<(Frame, Tally)>, @@ -253,9 +253,9 @@ struct Pending { cut: u64, /// When it landed in this node's cache ([`moq_net::frame::Frame::arrived`]), so a stall /// that holds the export back too does not hide that it came late. - arrived: moq_clock::Instant, + arrived: kio::clock::Instant, /// When it was read. - read: moq_clock::Instant, + read: kio::clock::Instant, } /// A frame waiting in the jitter buffer, with what it needs from the moment it was read. @@ -298,9 +298,9 @@ struct Track { pending: Option, /// When the source was subscribed. Nothing it delivers reached the export before then, /// however long the cache held it. - subscribed: moq_clock::Instant, + subscribed: kio::clock::Instant, /// The latest frame arrival or observed loss, which settles frames held for their DTS. - latest: moq_clock::Instant, + latest: kio::clock::Instant, /// The marker count the decode clock runs under. restart: u64, /// The marker, skip and cut counts of the sources the track read before this one, so the @@ -372,8 +372,8 @@ impl Track { key: TrackKey::default(), source, pending: None, - subscribed: moq_clock::now(), - latest: moq_clock::Instant::ZERO, + subscribed: kio::clock::now(), + latest: kio::clock::Instant::ZERO, restart: 0, base: (0, 0, 0), finished: false, @@ -496,7 +496,7 @@ impl Track { skip: self.base.1 + self.source.skips(), cut: self.base.2 + self.source.cuts(), arrived, - read: moq_clock::now(), + read: kio::clock::now(), }; // A new timeline must reach the reset before tune-in alignment can drop it. if let Some(start) = input.video_start @@ -761,8 +761,8 @@ impl Track { }; // Logical clocks can begin at zero. Shift both readings by the same representable amount so // their ordering survives even when the full replay lead would precede the clock's origin. - let ahead = ahead.min(arrived.duration_since(moq_clock::Instant::ZERO)); - let ahead = ahead.min(read.duration_since(moq_clock::Instant::ZERO)); + let ahead = ahead.min(arrived.duration_since(kio::clock::Instant::ZERO)); + let ahead = ahead.min(read.duration_since(kio::clock::Instant::ZERO)); let arrival = Arrival { arrived: arrived - ahead, read: read - ahead, @@ -1427,7 +1427,7 @@ where if self.pending.is_none() || !super::follower::left(&err) { return Poll::Ready(Err(err)); } - self.follow_until = Some(moq_clock::now()); + self.follow_until = Some(kio::clock::now()); self.stop_old(waiter)?; } if self.pending.is_some() { @@ -1496,7 +1496,7 @@ where for (name, track) in &mut self.program.tracks { track.release(name, &mut self.jitter, true)?; } - tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "commit-program", now = ?moq_clock::now(), old = self.program.id, new = ready.track.program, generation = ready.generation, pts = ?ready.item.frame.timestamp, key = ?ready.item.key, decode = ?ready.item.decode); + tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "commit-program", now = ?kio::clock::now(), old = self.program.id, new = ready.track.program, generation = ready.generation, pts = ?ready.item.frame.timestamp, key = ?ready.item.key, decode = ?ready.item.decode); self.jitter.commit(ready)?; break; } @@ -1850,7 +1850,7 @@ where } } if self.program.id != self.active_program && !self.jitter.has_pending() && !self.jitter.is_committed() { - tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "prepared", now = ?moq_clock::now(), program = self.program.id, old = self.active_program, tracks = self.program.tracks.len(), video_start = ?self.program.video_start); + tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "prepared", now = ?kio::clock::now(), program = self.program.id, old = self.active_program, tracks = self.program.tracks.len(), video_start = ?self.program.video_start); self.jitter.start( self.program.tracks.values().map(|track| track.key.clone()), self.program.expected.clone(), @@ -1860,7 +1860,7 @@ where // Hand the held frames to the jitter buffer in arrival order, so the // earliest anchors its clock, then read on. - let mut held: Vec<(moq_clock::Instant, String)> = self + let mut held: Vec<(kio::clock::Instant, String)> = self .program .tracks .iter() @@ -1883,12 +1883,12 @@ where return Ok(()); } - let expired = self.follow_until.is_some_and(|until| moq_clock::now() >= until); + let expired = self.follow_until.is_some_and(|until| kio::clock::now() >= until); if !expired { if let Some(until) = self.follow_until { let timer = self .follow_timer - .get_or_insert_with(|| Box::pin(moq_clock::sleep_until(until))); + .get_or_insert_with(|| Box::pin(kio::clock::sleep_until(until))); if timer.deadline() != until { timer.as_mut().reset(until); } @@ -1896,7 +1896,7 @@ where } return Ok(()); } - tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "follow-expired", now = ?moq_clock::now(), program = self.program.id, committed = self.jitter.is_committed()); + tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "follow-expired", now = ?kio::clock::now(), program = self.program.id, committed = self.jitter.is_committed()); self.program.retired = true; self.follow_timer = None; self.follow_until = None; @@ -1925,7 +1925,7 @@ where return Ok(()); } let mut next = self.pending.take().expect("checked above"); - tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "adopt", now = ?moq_clock::now(), old = self.program.id, new = next.id, generation = ready.generation, old_pts = ?self.program.last_timestamp, new_pts = ?ready.item.frame.timestamp, new_key = ?ready.item.key); + tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "adopt", now = ?kio::clock::now(), old = self.program.id, new = next.id, generation = ready.generation, old_pts = ?self.program.last_timestamp, new_pts = ?ready.item.frame.timestamp, new_key = ?ready.item.key); let out = self .program .psi @@ -2294,7 +2294,7 @@ where track.base.1 += track.source.skips() + 1; track.base.2 += track.source.cuts() + 1; track.source = source; - track.subscribed = moq_clock::now(); + track.subscribed = kio::clock::now(); track.finished = false; } Ok(()) @@ -2342,7 +2342,7 @@ where track.declared = None; track.source = source.continuing(&track.source); track.finished = false; - track.subscribed = moq_clock::now(); + track.subscribed = kio::clock::now(); } Ok(()) } @@ -2448,7 +2448,7 @@ where /// When the next queued frame is due, or the next grid slot while media is queued or /// every source has finished and the tail runs out. #[cfg(test)] - pub(super) fn next_due(&self) -> Option { + pub(super) fn next_due(&self) -> Option { let finished = !self.program.tracks.is_empty() && self.program.tracks.values().all(|track| track.finished); let slot = self .slot_due() @@ -2502,7 +2502,7 @@ where catalog: S, follow: Duration, ) -> Result<(), crate::Error> { - tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "follow", now = ?moq_clock::now(), program = self.program.id, pending = ?self.pending.as_ref().map(|pending| pending.id), old_epoch = ?self.program.instance, new_epoch = ?broadcast.info().epoch, ?follow); + tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "follow", now = ?kio::clock::now(), program = self.program.id, pending = ?self.pending.as_ref().map(|pending| pending.id), old_epoch = ?self.program.instance, new_epoch = ?broadcast.info().epoch, ?follow); if self.pending.is_some() && self.program.instance.is_some() && broadcast.info().epoch == self.program.instance { self.cancel_pending(); @@ -2514,7 +2514,7 @@ where self.cancel_pending(); let next = self.replacement(self.program.source.switched(broadcast), catalog); self.pending = Some(Box::new(next)); - self.follow_until.get_or_insert_with(|| moq_clock::now() + follow); + self.follow_until.get_or_insert_with(|| kio::clock::now() + follow); return Ok(()); } if let Some(mut pending) = self.pending.take() { @@ -3389,7 +3389,7 @@ where /// never on when they arrived, and the output keeps the clock's pace while media is queued /// (in the schedule or still in the jitter buffer) or still to decode. `None` without a /// delay, where frames settle the slots instead. - fn slot_due(&self) -> Option<(u128, moq_clock::Instant)> { + fn slot_due(&self) -> Option<(u128, kio::clock::Instant)> { let (known, settled) = self.slot_settled()?; let settled = Timestamp::from_micros(u64::try_from(settled / 1_000).ok()?).ok()?; // The tail of the generation still going out keeps its own clock after the next is acquired. @@ -3442,11 +3442,11 @@ where /// Lay out every grid slot whose time has come, and wake when the next one is due. fn lay_due(&mut self, waiter: &kio::Waiter) -> anyhow::Result<()> { while let Some((known, at)) = self.slot_due() { - if moq_clock::now() < at { + if kio::clock::now() < at { let timer = self .program .slot_timer - .get_or_insert_with(|| Box::pin(moq_clock::sleep_until(at))); + .get_or_insert_with(|| Box::pin(kio::clock::sleep_until(at))); if timer.deadline() != at { timer.as_mut().reset(at); } @@ -4557,7 +4557,7 @@ mod tests { payload: bytes::Bytes::from_static(b"frame"), keyframe: at % 600 == 0, }; - let start = moq_clock::now(); + let start = kio::clock::now(); let mut jitter = super::jitter::Buffer::new(Duration::from_millis(500)); jitter.expect([super::TrackKey::new(0, "video"), super::TrackKey::new(0, "audio")]); let mut trimmed = 0; @@ -4729,7 +4729,7 @@ mod tests { let mut clock = DecodeClock::default(); let mut dts = vec![0; pts.len()]; for (i, &p) in pts.iter().enumerate() { - clock.push(i, p, moq_clock::Instant::ZERO); + clock.push(i, p, kio::clock::Instant::ZERO); while let Some((i, d)) = clock.pop(jitter, floor, Settle::Due) { dts[i] = d; } diff --git a/rs/moq-mux/src/container/ts/export_test.rs b/rs/moq-mux/src/container/ts/export_test.rs index 63a4e9c03e6..efc420943c0 100644 --- a/rs/moq-mux/src/container/ts/export_test.rs +++ b/rs/moq-mux/src/container/ts/export_test.rs @@ -5474,7 +5474,7 @@ where // Run the paused clock only as far as the next frame due, so a test that writes // more afterwards is still on time for it. if let Some(deadline) = export.next_due() { - moq_clock::sleep_until(deadline).await; + kio::clock::sleep_until(deadline).await; continue; } match tokio::time::timeout(Duration::from_millis(10), export.next()).await { @@ -8598,7 +8598,7 @@ async fn the_same_instance_continues_after_a_drop() { /// A returning route serves the same publisher's catalog and monotonically numbered groups. #[tokio::test(start_paused = true)] async fn a_return_keeps_catalog_and_group_history() { - let wall = moq_clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS + 86_400_000); + let wall = kio::clock::Wall::UNIX_EPOCH + Duration::from_millis(hang::catalog::MOQ_EPOCH_UNIX_MILLIS + 86_400_000); crate::clock::fake_host_wall(wall); let start = tokio::time::Instant::now(); let origin = crate::source::produce_origin(); diff --git a/rs/moq-mux/src/container/ts/export_timing_test.rs b/rs/moq-mux/src/container/ts/export_timing_test.rs index 0fe2c2de406..3311f2694ed 100644 --- a/rs/moq-mux/src/container/ts/export_timing_test.rs +++ b/rs/moq-mux/src/container/ts/export_timing_test.rs @@ -12,7 +12,7 @@ use std::time::Duration; use bytes::{Bytes, BytesMut}; use hang::catalog::{AAC, AudioConfig, Container, H264, VideoConfig}; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::Timestamp; use mpeg2ts::ts::{ReadTsPacket, TsPacketReader, TsPayload}; @@ -150,7 +150,7 @@ impl Live { audio_lag, reorder: false, delta_size: 400, - start: moq_clock::now(), + start: kio::clock::now(), tick: 0, audio_index: 0, } @@ -202,7 +202,7 @@ impl Live { /// same timeline from the next group, as its replacement or the other half of a 1+1 pair /// would. async fn fall_silent(&mut self, gap: Duration, legs: &mut [&mut Leg]) { - let resume = moq_clock::now() + gap; + let resume = kio::clock::now() + gap; advance(resume, legs).await; let media = (resume.duration_since(self.start).as_secs_f64() * self.scale * 1e6) as u64; self.tick = media.div_ceil(VIDEO_US * GOP) * GOP; @@ -219,7 +219,7 @@ impl Live { Leg { export, every, - next_poll: moq_clock::now(), + next_poll: kio::clock::now(), out: Vec::new(), } } @@ -353,7 +353,7 @@ impl Leg { fn poll(&mut self) { let waiter = kio::Waiter::noop(); - let now = moq_clock::now(); + let now = kio::clock::now(); while let std::task::Poll::Ready(frame) = self.export.poll_next(&waiter) { match frame.expect("exporter error") { Some(frame) => self.out.push((now, frame)), @@ -367,11 +367,11 @@ impl Leg { loop { self.poll(); if let Some(deadline) = self.export.next_due() { - moq_clock::sleep_until(deadline).await; + kio::clock::sleep_until(deadline).await; continue; } match tokio::time::timeout(Duration::from_millis(10), self.export.next()).await { - Ok(Ok(Some(frame))) => self.out.push((moq_clock::now(), frame)), + Ok(Ok(Some(frame))) => self.out.push((kio::clock::now(), frame)), Ok(Ok(None)) => break, Err(_) if self.export.next_due().is_none() => break, Err(_) => {} @@ -394,8 +394,8 @@ async fn advance(at: Instant, legs: &mut [&mut Leg]) { .filter(|wake| *wake <= at) .min() { - moq_clock::sleep_until(wake).await; - let now = moq_clock::now(); + kio::clock::sleep_until(wake).await; + let now = kio::clock::now(); for leg in legs.iter_mut() { if leg.wake().is_some_and(|wake| wake <= now) { leg.poll(); @@ -407,7 +407,7 @@ async fn advance(at: Instant, legs: &mut [&mut Leg]) { } } } - moq_clock::sleep_until(at).await; + kio::clock::sleep_until(at).await; // Read up to the instant the next frame arrives, so the arrival is timed exactly. for leg in legs.iter_mut() { leg.poll_now(); @@ -654,7 +654,7 @@ async fn frames_held_through_a_silence_drop_as_late() { let tail = if declared { 2 } else { 5 }; live.run(8 * GOP + tail, &mut [&mut leg], |_| false).await; live.fall_silent(Duration::from_secs(3), &mut [&mut leg]).await; - let resumed = moq_clock::now(); + let resumed = kio::clock::now(); live.run(live.tick + 8 * GOP, &mut [&mut leg], |_| false).await; let dropped = leg.export.dropped(); @@ -700,7 +700,7 @@ async fn a_cut_judges_held_video_when_the_loss_is_observed() { let tail = if declared { 2 } else { 8 }; live.run(8 * GOP + tail, &mut [&mut leg], |_| false).await; live.fall_silent(silence, &mut [&mut leg]).await; - let observed = moq_clock::now(); + let observed = kio::clock::now(); live.group.take().unwrap().abort(moq_net::Error::Unroutable).unwrap(); leg.poll_now(); live.run(live.tick + 8 * GOP, &mut [&mut leg], |_| false).await; diff --git a/rs/moq-mux/src/container/ts/follower.rs b/rs/moq-mux/src/container/ts/follower.rs index 7e62c8a03c3..9501a1c68e5 100644 --- a/rs/moq-mux/src/container/ts/follower.rs +++ b/rs/moq-mux/src/container/ts/follower.rs @@ -5,7 +5,7 @@ use std::pin::Pin; use std::task::Poll; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use super::{Export, catalog}; use crate::container::Frame; @@ -99,7 +99,7 @@ pub struct Follower { refused: bool, follow: Duration, stitch: bool, - timer: Option>>, + timer: Option>>, } impl Follower { @@ -209,7 +209,7 @@ impl Follower { self.following(&end); self.state = State::Settling { end, - deadline: moq_clock::now() + self.follow, + deadline: kio::clock::now() + self.follow, }; } State::Settling { end, deadline } => { @@ -384,7 +384,7 @@ impl Follower { end: Err( anyhow::anyhow!("replacement broadcast `{}` ended before serving its catalog", self.path).into(), ), - deadline: moq_clock::now() + self.follow, + deadline: kio::clock::now() + self.follow, }, } } @@ -415,10 +415,10 @@ impl Follower { /// Whether `at` has come, registering `waiter` to wake then if not. fn elapsed(&mut self, waiter: &kio::Waiter, at: Instant) -> bool { - if moq_clock::now() >= at { + if kio::clock::now() >= at { return true; } - let timer = self.timer.get_or_insert_with(|| Box::pin(moq_clock::sleep_until(at))); + let timer = self.timer.get_or_insert_with(|| Box::pin(kio::clock::sleep_until(at))); if timer.deadline() != at { timer.as_mut().reset(at); } diff --git a/rs/moq-mux/src/container/ts/import.rs b/rs/moq-mux/src/container/ts/import.rs index 4b48737537c..4af42b9c9ff 100644 --- a/rs/moq-mux/src/container/ts/import.rs +++ b/rs/moq-mux/src/container/ts/import.rs @@ -386,7 +386,7 @@ impl Import { /// coalesces a junction's burst of sub-table commits into few groups instead of one per /// commit. pub(super) fn flush_batch(&mut self) -> anyhow::Result<()> { - self.damage_log.flush(moq_clock::now()); + self.damage_log.flush(kio::clock::now()); self.si.flush(self.last_pts.unwrap_or(Timestamp::ZERO), false) } @@ -5514,7 +5514,7 @@ pub(super) mod test { if anchored { // The shift then depends on the wall clock, so only its consistency is checked. let first = Timestamp::from_scale(picture(0), 90_000).unwrap(); - timebase.place(first, moq_clock::wall()).unwrap(); + timebase.place(first, kio::clock::wall()).unwrap(); } let mut import = super::Import::new(broadcast, timebase.reserve()); @@ -10200,7 +10200,7 @@ pub(super) mod test { std::task::Poll::Ready(Err(err)) => panic!("exporter error: {err}"), std::task::Poll::Pending => { let Some(deadline) = exporter.next_due() else { break }; - moq_clock::sleep_until(deadline).await; + kio::clock::sleep_until(deadline).await; } } } diff --git a/rs/moq-mux/src/container/ts/import_test.rs b/rs/moq-mux/src/container/ts/import_test.rs index beef3734bd5..9d21957ecad 100644 --- a/rs/moq-mux/src/container/ts/import_test.rs +++ b/rs/moq-mux/src/container/ts/import_test.rs @@ -703,7 +703,7 @@ struct Imported { published: std::collections::BTreeMap>, /// The root clock the catalog advertised. clock: hang::catalog::Clock, - arrival: std::ops::RangeInclusive, + arrival: std::ops::RangeInclusive, } /// Import `data` on a catalog with the default clock. @@ -713,9 +713,9 @@ async fn import_stream(data: &[u8]) -> Imported { let catalog = crate::catalog::Producer::new(&mut broadcast, Default::default()).unwrap(); let mut import = crate::container::ts::Import::new(broadcast, catalog.reserve()); - let before = moq_clock::wall(); + let before = kio::clock::wall(); import.decode(data).unwrap(); - let after = moq_clock::wall(); + let after = kio::clock::wall(); import.finish().unwrap(); let snapshot = catalog.snapshot(); diff --git a/rs/moq-mux/src/container/ts/programs.rs b/rs/moq-mux/src/container/ts/programs.rs index 2a6fb1e1acb..ba3c60f9f16 100644 --- a/rs/moq-mux/src/container/ts/programs.rs +++ b/rs/moq-mux/src/container/ts/programs.rs @@ -1040,7 +1040,7 @@ mod test { ); let input = two_programs(); - let before = moq_clock::wall(); + let before = kio::clock::wall(); programs.decode(&input[..100]).unwrap(); assert!( programs.programs.is_empty(), @@ -1048,7 +1048,7 @@ mod test { ); programs.decode(&input[100..]).unwrap(); programs.finish().unwrap(); - let after = moq_clock::wall(); + let after = kio::clock::wall(); for (path, fills) in [("event/1.hang", [0xAA, 0xBB]), ("event/2.hang", [0xCC, 0xDD])] { let consumer = origin.consume().request_broadcast(path, None).await.unwrap(); diff --git a/rs/moq-mux/src/container/ts/release.rs b/rs/moq-mux/src/container/ts/release.rs index a2a3a1e7dc9..018c0a6972f 100644 --- a/rs/moq-mux/src/container/ts/release.rs +++ b/rs/moq-mux/src/container/ts/release.rs @@ -3,7 +3,7 @@ use std::task::Poll; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use crate::catalog::{CatalogFormat, Stream}; use crate::container::consumer::Event; @@ -53,7 +53,7 @@ impl Release { source, catalog: Some(catalog), track: None, - subscribed: moq_clock::now(), + subscribed: kio::clock::now(), finished: false, released: false, delay: Duration::ZERO, @@ -158,7 +158,7 @@ impl Release { // does not make them late, and a stall of the whole path does not hide that they are. let arrival = Arrival { arrived: arrived.max(self.subscribed), - read: moq_clock::now(), + read: kio::clock::now(), decode: frame.timestamp.into(), restart: track.markers(), skip: track.skips(), @@ -208,7 +208,7 @@ impl Release { false => source.live(), }; self.track = Some((m2ts.track.clone(), source)); - self.subscribed = moq_clock::now(); + self.subscribed = kio::clock::now(); } Some((name, _)) if *name != m2ts.track => { return Err(anyhow::anyhow!("the `m2ts` track moved from `{name}` to `{}`", m2ts.track).into()); diff --git a/rs/moq-mux/src/container/ts/si.rs b/rs/moq-mux/src/container/ts/si.rs index 09bd8790304..a1c3295c8fc 100644 --- a/rs/moq-mux/src/container/ts/si.rs +++ b/rs/moq-mux/src/container/ts/si.rs @@ -30,7 +30,7 @@ use std::collections::{BTreeMap, BTreeSet}; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use bytes::Bytes; use moq_net::Timestamp; @@ -628,7 +628,7 @@ impl Capture { /// the host clock ([`DEBOUNCE`]), and a first snapshot is never delayed. `force` /// overrides the debounce, for end of stream. pub fn flush(&mut self, pts: Timestamp, force: bool) -> anyhow::Result<()> { - let now = moq_clock::now(); + let now = kio::clock::now(); for (key, entry) in self.entries.iter_mut() { entry.expire(self.now); if !entry.dirty { @@ -774,7 +774,7 @@ mod tests { use super::*; use crate::container::ts::fixture::{Flags, Mux}; - #[moq_clock::test] + #[kio::test] async fn program_clock_places_and_retires_si_without_media_pts() { let mut broadcast = moq_net::broadcast::Info::new().produce(); let catalog = crate::catalog::Producer::new( @@ -859,7 +859,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn incomplete_generations_expire_on_their_table_intervals() { let (mut capture, _) = capture(); let mut input = Input::new(&mut capture); @@ -897,7 +897,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn pending_renewal_replaces_its_deadline_without_renewing_other_versions() { let (mut capture, _) = capture(); let mut input = Input::new(&mut capture); @@ -921,7 +921,7 @@ mod tests { assert!(capture.entries[&(0x11, 0x42)].pending.is_empty()); } - #[moq_clock::test] + #[kio::test] async fn retirement_publishes_reduced_and_empty_snapshots_without_host_debounce() { let (mut capture, catalog) = capture(); let mut input = Input::new(&mut capture); @@ -967,13 +967,13 @@ mod tests { assert_eq!(catalog.snapshot().ext.mpegts.si[&0x10][&0x40].track, name); } - #[moq_clock::test] + #[kio::test] async fn host_time_and_new_si_at_one_input_position_do_not_age_si() { let (mut capture, _) = capture(); let input = Input::new(&mut capture); input.section(&mut capture, 0x12, section(0x4e, 0, 0, 0)); capture.flush(Timestamp::ZERO, false).unwrap(); - moq_clock::sleep(Duration::from_secs(60)).await; + kio::clock::sleep(Duration::from_secs(60)).await; for id in 1..1024 { input.section(&mut capture, 0x12, section(0x4e, id, 0, 1)); } @@ -1032,7 +1032,7 @@ mod tests { assert_eq!(at(&clock, count), Some(4_000)); } - #[moq_clock::test] + #[kio::test] async fn fresh_si_ages_out_while_the_pcr_stalls() { for silent in [false, true] { let (mut capture, _) = capture(); @@ -1058,7 +1058,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn short_form_repetitions_replace_their_deadline_and_latest_value() { let (mut capture, _) = capture(); let mut input = Input::new(&mut capture); diff --git a/rs/moq-mux/src/jitter.rs b/rs/moq-mux/src/jitter.rs index 0cd02b5be23..d47c91a0649 100644 --- a/rs/moq-mux/src/jitter.rs +++ b/rs/moq-mux/src/jitter.rs @@ -7,7 +7,7 @@ use std::pin::Pin; use std::task::Poll; use std::time::Duration; -use moq_clock::{Instant, Sleep}; +use kio::clock::{Instant, Sleep}; use moq_net::Timestamp; /// One active publisher and at most one independently acquiring replacement. @@ -234,7 +234,7 @@ impl Buffer { .horizon .zip(first) .map_or(Duration::ZERO, |(old, new)| old.saturating_duration_since(new)); - tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "commit-clock", now = ?moq_clock::now(), old_horizon = ?self.active.horizon, new_first = ?first, ?shift, old_clock = ?self.active.clock.map(|clock| (clock.anchor, clock.base, clock.generation)), new_clock = ?engine.clock.map(|clock| (clock.anchor, clock.base, clock.generation))); + tracing::debug!(target: "moq_mux::container::ts::handoff", phase = "commit-clock", now = ?kio::clock::now(), old_horizon = ?self.active.horizon, new_first = ?first, ?shift, old_clock = ?self.active.clock.map(|clock| (clock.anchor, clock.base, clock.generation)), new_clock = ?engine.clock.map(|clock| (clock.anchor, clock.base, clock.generation))); let offset = self.active.clock.map_or(0, |clock| clock.generation + 1); for clock in [&mut engine.clock, &mut engine.previous].into_iter().flatten() { clock.anchor = clock.anchor.checked_add(shift).ok_or(moq_net::TimeOverflow)?; @@ -1253,7 +1253,7 @@ impl Engine { fn poll_available(&mut self, waiter: &kio::Waiter, held: Option<&BTreeMap>>) -> Poll> { loop { - let now = moq_clock::now(); + let now = kio::clock::now(); let acquired = self.acquired_by(); if acquired.is_some_and(|end| now >= end) { self.acquired(); @@ -1286,7 +1286,9 @@ impl Engine { self.timer = None; return Poll::Pending; }; - let timer = self.timer.get_or_insert_with(|| Box::pin(moq_clock::sleep_until(wake))); + let timer = self + .timer + .get_or_insert_with(|| Box::pin(kio::clock::sleep_until(wake))); if timer.deadline() != wake { timer.as_mut().reset(wake); } @@ -1395,7 +1397,7 @@ impl Engine { self.tracks .get(key) .and_then(|track| track.queue.front()) - .is_some_and(|(_, _, deadline, _)| self.delay.is_zero() || *deadline <= moq_clock::now()) + .is_some_and(|(_, _, deadline, _)| self.delay.is_zero() || *deadline <= kio::clock::now()) } /// How many frames are waiting. @@ -1503,9 +1505,9 @@ mod tests { const DELAY: Duration = Duration::from_millis(100); /// A pending publisher cannot clobber active expected tracks or automatic clock jumps. - #[moq_clock::test] + #[kio::test] async fn pending_keys_and_active_timeline_jumps_use_independent_clocks() { - let start = moq_clock::now(); + let start = kio::clock::now(); let delay = Duration::from_millis(500); let mut buffer = Buffer::new(delay).replay(); buffer.expect([0u16]); @@ -1516,7 +1518,7 @@ mod tests { buffer.expect_pending([1, 3], [1, 3]); buffer.push(2, arrival(start, 0, "A2")).unwrap(); buffer.push(3, arrival(start, 10_000, "B3")).unwrap(); - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; assert_eq!(due(&mut buffer), ["A0", "A2"]); let Poll::Ready(first) = buffer.poll_pending(&kio::Waiter::noop()) else { panic!("B ready"); @@ -1533,17 +1535,17 @@ mod tests { 0, Arrival { restart: 1, - ..arrival(moq_clock::now(), 0, "A restart") + ..arrival(kio::clock::now(), 0, "A restart") }, ) .unwrap(); - buffer.push(3, arrival(moq_clock::now(), 10_020, "B next")).unwrap(); - moq_clock::sleep(Duration::from_millis(20)).await; + buffer.push(3, arrival(kio::clock::now(), 10_020, "B next")).unwrap(); + kio::clock::sleep(Duration::from_millis(20)).await; let Poll::Ready(next) = buffer.poll_pending(&kio::Waiter::noop()) else { panic!("B clock kept its deadline"); }; assert_eq!((next.item, next.generation), ("B next", 0)); - moq_clock::sleep(delay - Duration::from_millis(20)).await; + kio::clock::sleep(delay - Duration::from_millis(20)).await; let Poll::Ready(next) = buffer.poll_next(&kio::Waiter::noop()) else { panic!("A restart ready"); }; @@ -1551,9 +1553,9 @@ mod tests { } /// A caller can hold B's first issued item, cancel before adoption, and resume A. - #[moq_clock::test] + #[kio::test] async fn cancelling_an_issued_replacement_keeps_the_active_clock_and_queue() { - let start = moq_clock::now(); + let start = kio::clock::now(); let delay = Duration::from_millis(500); let mut buffer = Buffer::new(delay).replay(); buffer.push(0u16, arrival(start, 0, "A0")).unwrap(); @@ -1563,14 +1565,14 @@ mod tests { buffer.push(1, arrival(start, 10_000, "B")).unwrap(); buffer.lose(&1, true); buffer.lose(&1, true); - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; assert_eq!(due(&mut buffer), ["A0"]); let Poll::Ready(first) = buffer.poll_pending(&kio::Waiter::noop()) else { panic!("B ready"); }; buffer.commit(first).unwrap(); assert_eq!(buffer.reporting().dropped(), 1); - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; let Poll::Ready(tail) = buffer.poll_next(&kio::Waiter::noop()) else { panic!("A tail retained"); }; @@ -1582,12 +1584,12 @@ mod tests { buffer.cancel(); assert_eq!(buffer.reporting().dropped(), 1); assert_eq!(buffer.at(0, ms(200)), Some(start + delay + Duration::from_millis(200))); - buffer.push(0, arrival(moq_clock::now(), 200, "A resumed")).unwrap(); + buffer.push(0, arrival(kio::clock::now(), 200, "A resumed")).unwrap(); buffer.start([2], [2]); - buffer.push(2, arrival(moq_clock::now(), 20_000, "C")).unwrap(); - moq_clock::sleep(Duration::from_millis(100)).await; + buffer.push(2, arrival(kio::clock::now(), 20_000, "C")).unwrap(); + kio::clock::sleep(Duration::from_millis(100)).await; assert_eq!(due(&mut buffer), ["A resumed"]); - moq_clock::sleep(Duration::from_millis(400)).await; + kio::clock::sleep(Duration::from_millis(400)).await; let Poll::Ready(first) = buffer.poll_pending(&kio::Waiter::noop()) else { panic!("C ready"); }; @@ -1601,33 +1603,33 @@ mod tests { } /// A restart the old publisher is still acquiring at commit goes out before the replacement. - #[moq_clock::test] + #[kio::test] async fn a_commit_drains_the_old_publishers_acquiring_restart() { - let start = moq_clock::now(); + let start = kio::clock::now(); let delay = Duration::from_millis(500); let mut buffer = Buffer::new(delay); buffer.push(0u16, arrival(start, 0, "A0")).unwrap(); - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; assert_eq!(released(&mut buffer), [("A0", 0)]); buffer.start([1], [1]); - buffer.push(1, arrival(moq_clock::now(), 10_000, "B")).unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + buffer.push(1, arrival(kio::clock::now(), 10_000, "B")).unwrap(); + kio::clock::sleep(Duration::from_millis(10)).await; buffer - .push(0, after(1, arrival(moq_clock::now(), 5_000, "A restart"))) + .push(0, after(1, arrival(kio::clock::now(), 5_000, "A restart"))) .unwrap(); - moq_clock::sleep(delay - Duration::from_millis(10)).await; + kio::clock::sleep(delay - Duration::from_millis(10)).await; let Poll::Ready(first) = buffer.poll_pending(&kio::Waiter::noop()) else { panic!("B ready"); }; // A's acquisition has 10 ms left to run, so only the commit can settle it. buffer.commit(first).unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; assert_eq!(released(&mut buffer), [("A restart", 1), ("B", 2)]); } - #[moq_clock::test] + #[kio::test] async fn a_handoff_past_the_clock_range_returns_overflow() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); buffer.push(0u16, arrival(start, 0, "A")).unwrap(); let last = Instant::ZERO.checked_add(Duration::from_nanos(u64::MAX)).unwrap(); @@ -1644,16 +1646,16 @@ mod tests { buffer.start([1], [1]); buffer.push(1, arrival(start, 0, "B first")).unwrap(); buffer.push(1, arrival(start, 1, "B after last")).unwrap(); - moq_clock::sleep(DELAY).await; + kio::clock::sleep(DELAY).await; let Poll::Ready(first) = buffer.poll_pending(&kio::Waiter::noop()) else { panic!("B ready"); }; assert_eq!(buffer.commit(first), Err(moq_net::TimeOverflow)); } - #[moq_clock::test] + #[kio::test] async fn decode_before_zero_keeps_its_deadline_and_media_order() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); buffer.push(2, arrival(start, 0, "audio")).unwrap(); let before_zero = Decode::from_nanos(-22_223); @@ -1671,13 +1673,13 @@ mod tests { Some(start + DELAY - Duration::from_nanos(22_223)) ); assert_eq!(buffer.at(0, ms(0)), Some(start + DELAY)); - moq_clock::sleep(DELAY).await; + kio::clock::sleep(DELAY).await; assert_eq!(due(&mut buffer), ["video", "audio"]); } - #[moq_clock::test] + #[kio::test] async fn moving_media_zero_preserves_acquisition_and_deadlines() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut negative = Buffer::new(DELAY); let mut positive = Buffer::new(DELAY); for buffer in [&mut negative, &mut positive] { @@ -1696,7 +1698,7 @@ mod tests { .unwrap(); } } - moq_clock::sleep(DELAY).await; + kio::clock::sleep(DELAY).await; assert_eq!(due(&mut negative), due(&mut positive)); for nanos in [-22_223, -11_112, 0, 11_111] { assert_eq!( @@ -1768,7 +1770,7 @@ mod tests { #[tokio::test(start_paused = true)] async fn acquisition_observes_every_tracks_available_frames() { for order in [[1, 2], [2, 1]] { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(Duration::from_millis(500)); buffer.expect([1, 2]); // The held first frames reach the jitter buffer before the rest of the fill. @@ -1808,7 +1810,7 @@ mod tests { #[tokio::test(start_paused = true)] async fn releases_at_the_delay_in_decode_order() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); assert_eq!(buffer.push(1, arrival(start, 0, "v0")).unwrap(), Push::Queued); assert_eq!(buffer.push(1, arrival(start, 40, "v40")).unwrap(), Push::Queued); @@ -1873,7 +1875,7 @@ mod tests { /// its deadline, emit the same order. #[tokio::test(start_paused = true)] async fn arrival_skew_does_not_change_the_order() { - let start = moq_clock::now(); + let start = kio::clock::now(); let (mut early, mut late) = (Buffer::new(DELAY).replay(), Buffer::new(DELAY).replay()); let frames = [ (1, 0, "v0"), @@ -1905,7 +1907,7 @@ mod tests { /// dropped a frame waits for its next sync frame. #[tokio::test(start_paused = true)] async fn late_frames_are_dropped_until_a_sync_frame() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); buffer.push(1, arrival(start, 0, "v0")).unwrap(); buffer.push(2, arrival(start, 0, "a0")).unwrap(); @@ -1975,7 +1977,7 @@ mod tests { /// A restart before anything went out keeps the clock, so the tracks stay on one. #[tokio::test(start_paused = true)] async fn a_skip_before_the_first_release_keeps_one_clock() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); // The video's first group is stale and anchors the clock; the audio is live. buffer.push(1, arrival(start, 0, "v0")).unwrap(); @@ -2003,7 +2005,7 @@ mod tests { /// runs on it, whether or not that track saw the restart. #[tokio::test(start_paused = true)] async fn every_track_joins_a_new_generation_at_its_next_frame() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); buffer.push(1, arrival(start, 0, "v0")).unwrap(); buffer.push(2, arrival(start, 0, "a0")).unwrap(); @@ -2013,7 +2015,7 @@ mod tests { // The publisher resumes a second later with its timeline five seconds on. let resume = start + Duration::from_secs(1); - tokio::time::advance(resume - moq_clock::now()).await; + tokio::time::advance(resume - kio::clock::now()).await; assert_eq!( buffer.push(1, after(1, arrival(resume, 5_000, "v5000"))).unwrap(), Push::Queued @@ -2039,7 +2041,7 @@ mod tests { /// clock anchors on it, the track sent latest, so it keeps the delay. #[tokio::test(start_paused = true)] async fn a_track_without_the_restart_joins_the_acquisition() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.expect([1, 2]); buffer.push(1, arrival(start, 0, "v0")).unwrap(); @@ -2050,19 +2052,19 @@ mod tests { // The publisher resumes a second later with its timeline five seconds on, and sends // the audio further behind the video than the delay. let resume = start + Duration::from_secs(1); - tokio::time::advance(resume - moq_clock::now()).await; + tokio::time::advance(resume - kio::clock::now()).await; assert_eq!( buffer.push(1, after(1, arrival(resume, 5_000, "v5000"))).unwrap(), Push::Queued ); let lag = resume + DELAY + Duration::from_millis(50); - tokio::time::advance(lag - moq_clock::now()).await; + tokio::time::advance(lag - kio::clock::now()).await; assert_eq!(buffer.push(2, arrival(lag, 5_000, "a5000")).unwrap(), Push::Queued); tokio::time::advance(Duration::from_millis(20)).await; - let next = moq_clock::now(); + let next = kio::clock::now(); assert_eq!(buffer.push(2, arrival(next, 5_020, "a5020")).unwrap(), Push::Queued); - tokio::time::advance(lag + DELAY - moq_clock::now()).await; + tokio::time::advance(lag + DELAY - kio::clock::now()).await; assert_eq!(released(&mut buffer), [("v5000", 1), ("a5000", 1)]); tokio::time::advance(Duration::from_millis(20)).await; assert_eq!(released(&mut buffer), [("a5020", 1)]); @@ -2074,7 +2076,7 @@ mod tests { /// timeline 15 seconds on: each released frame's generation, and how many were dropped. async fn cross(steps: u64, tail: u64) -> (Vec, u64) { const LAG: u64 = 300; - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.expect([1, 2]); @@ -2097,7 +2099,7 @@ mod tests { let mut out = Vec::new(); for (read, key, restart, decode) in frames { let at = start + Duration::from_millis(read); - tokio::time::advance(at - moq_clock::now()).await; + tokio::time::advance(at - kio::clock::now()).await; out.extend(released(&mut buffer).into_iter().map(|(_, generation)| generation)); buffer.push(key, after(restart, arrival(at, decode, "frame"))).unwrap(); } @@ -2135,7 +2137,7 @@ mod tests { /// neither clock, so it drops as late without steering, and the track's next frame on the /// new timeline still joins it. async fn stray(to: u64) { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.expect([1]); buffer.push(1, arrival(start, 10_000, "v")).unwrap(); @@ -2144,12 +2146,12 @@ mod tests { assert_eq!(due(&mut buffer), ["v", "d"]); let resume = start + Duration::from_secs(1); - tokio::time::advance(resume - moq_clock::now()).await; + tokio::time::advance(resume - kio::clock::now()).await; buffer.push(1, after(1, arrival(resume, to, "v'"))).unwrap(); tokio::time::advance(DELAY).await; assert_eq!(released(&mut buffer), [("v'", 1)]); - let now = moq_clock::now(); + let now = kio::clock::now(); assert_eq!(buffer.push(2, arrival(now, 10_040, "d")).unwrap(), Push::Late); assert!(buffer.is_empty(), "the old frame was queued on the new clock"); assert!(buffer.steer.floor.is_none(), "the old frame was steered on"); @@ -2172,7 +2174,7 @@ mod tests { /// dropped, and the next on-time frame goes out on the same generation. #[tokio::test(start_paused = true)] async fn a_skip_keeps_the_clock() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.push(1, arrival(start, 0, "a0")).unwrap(); tokio::time::advance(DELAY).await; @@ -2180,7 +2182,7 @@ mod tests { // Group 1 is skipped: frames from 100 ms on arrive after a 250 ms stall. let stalled = start + Duration::from_millis(350); - tokio::time::advance(stalled - moq_clock::now()).await; + tokio::time::advance(stalled - kio::clock::now()).await; let skipped = |decode, item| Arrival { skip: 1, ..arrival(stalled, decode, item) @@ -2196,13 +2198,13 @@ mod tests { /// publisher shed, so it opens a generation. #[tokio::test(start_paused = true)] async fn a_skip_that_leaps_ahead_opens_a_generation() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.push(1, arrival(start, 0, "a0")).unwrap(); tokio::time::advance(DELAY).await; assert_eq!(due(&mut buffer), ["a0"]); - let now = moq_clock::now(); + let now = kio::clock::now(); let leapt = Arrival { skip: 1, ..arrival(now, 5_000, "a5000") @@ -2217,13 +2219,13 @@ mod tests { #[tokio::test(start_paused = true)] async fn a_track_sent_ahead_resuming_after_a_skip_keeps_the_clock() { const LEAD: u64 = 300; - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.expect([1, 2]); let mut out = Vec::new(); for at in (0..12_000).step_by(40) { - tokio::time::advance(start + Duration::from_millis(at) - moq_clock::now()).await; - let now = moq_clock::now(); + tokio::time::advance(start + Duration::from_millis(at) - kio::clock::now()).await; + let now = kio::clock::now(); assert_eq!(buffer.push(1, arrival(now, at, "v")).unwrap(), Push::Queued); // Track 2 is sent LEAD ahead, and skips a second of its own. let decode = at + LEAD; @@ -2259,7 +2261,7 @@ mod tests { sync, skip: cut, cut, - ..arrival(moq_clock::now(), decode, item) + ..arrival(kio::clock::now(), decode, item) }; buffer.push(1, video(0, true, 0, "v0")).unwrap(); tokio::time::advance(Duration::from_millis(40)).await; @@ -2283,7 +2285,7 @@ mod tests { /// clock puts earlier. #[tokio::test(start_paused = true)] async fn generations_go_out_in_turn() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); buffer.push(1, arrival(start, 0, "v0")).unwrap(); buffer.push(1, arrival(start, 40, "v40")).unwrap(); @@ -2292,7 +2294,7 @@ mod tests { assert_eq!(due(&mut buffer), ["v0"]); // A backlog across a jump in the timeline, read in one go. - let now = moq_clock::now(); + let now = kio::clock::now(); buffer.push(1, after(1, arrival(now, 5_000, "v5000"))).unwrap(); buffer.push(2, arrival(now, 4_900, "a4900")).unwrap(); buffer.push(2, arrival(now, 5_020, "a5020")).unwrap(); @@ -2330,8 +2332,8 @@ mod tests { /// fails. async fn drift(ppm: f64, hours: f64, settled: f64, queueing: impl Fn(f64) -> Duration) -> Run { let delay = Duration::from_millis(500); - let start = moq_clock::now(); - let clock = moq_clock::Deadlines::new(start); + let start = kio::clock::now(); + let clock = kio::clock::Deadlines::new(start); let _entered = clock.enter(); let mut buffer = Buffer::new(delay); let mut run = Run { @@ -2520,8 +2522,8 @@ mod tests { /// clock reaching us at `arrive(track, sent)`, or with the frame of its track before it if /// that is later, or never if `None`, in the order they reach us, until a push fails. async fn feed(shape: &Shape, ppm: f64, secs: f64, arrive: impl Fn(u16, f64) -> Option) -> Fed { - let start = moq_clock::now(); - let clock = moq_clock::Deadlines::new(start); + let start = kio::clock::now(); + let clock = kio::clock::Deadlines::new(start); let _entered = clock.enter(); let mut buffer = Buffer::new(shape.delay); let mut frames = Vec::new(); @@ -2758,7 +2760,7 @@ mod tests { /// goes out a delay after it arrived. #[tokio::test(start_paused = true)] async fn a_joiner_anchors_on_its_freshest_frame() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); let video = |arrived, decode, sync, item| Arrival { sync, @@ -2843,7 +2845,7 @@ mod tests { /// keep the delay: anchored on the video, every audio frame would be late. #[tokio::test(start_paused = true)] async fn a_joiner_anchors_on_the_track_sent_latest() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.expect([1, 2]); // Video is sent 300 ms ahead of its decode time, audio as it decodes. @@ -2862,7 +2864,7 @@ mod tests { /// the one sent latest, but two delays at most. #[tokio::test(start_paused = true)] async fn the_acquisition_waits_two_delays_at_most_for_a_silent_track() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); buffer.expect([1, 2]); buffer.push(1, arrival(start, 0, "v0")).unwrap(); @@ -2876,7 +2878,7 @@ mod tests { /// moment each was read. #[tokio::test(start_paused = true)] async fn a_steering_step_does_not_reorder_a_tie() { - let start = moq_clock::now(); + let start = kio::clock::now(); let order = |first: (u16, &'static str), second: (u16, &'static str)| { let mut buffer = Buffer::new(DELAY).replay(); buffer.push(1, arrival(start, 0, "v0")).unwrap(); @@ -2896,7 +2898,7 @@ mod tests { /// acquisition ends when the first of them falls due rather than drop it. #[tokio::test(start_paused = true)] async fn the_acquisition_ends_before_a_held_frame_is_due() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY); // Joined 60 ms into a group: its keyframe is due 40 ms from now. let key = Arrival { @@ -2922,7 +2924,7 @@ mod tests { /// frame behind the clock still goes out. #[tokio::test(start_paused = true)] async fn zero_delay_releases_on_arrival() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(Duration::ZERO); buffer.push(1, arrival(start, 0, "v0")).unwrap(); buffer.push(1, arrival(start, 40, "v40")).unwrap(); @@ -2939,7 +2941,7 @@ mod tests { /// reader leaves the rest in the source. #[tokio::test(start_paused = true)] async fn a_track_is_full_once_a_frame_is_due() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut buffer = Buffer::new(DELAY).replay(); assert!(!buffer.full(&1)); buffer.push(1, arrival(start, 0, "v0")).unwrap(); diff --git a/rs/moq-mux/src/json.rs b/rs/moq-mux/src/json.rs index 29809366e74..207a7751225 100644 --- a/rs/moq-mux/src/json.rs +++ b/rs/moq-mux/src/json.rs @@ -36,7 +36,7 @@ //! //! A value timed on the broadcast [`Clock`](crate::Clock) is written at that timestamp as given, //! and the entry advertises how late values reach the transport as its `jitter` and `delay`, the -//! way a media rendition does. A capture [`Instant`](moq_clock::Instant) converts with +//! way a media rendition does. A capture [`Instant`](kio::clock::Instant) converts with //! [`Clock::capture`](crate::Clock::capture) on the catalog's clock: //! //! ```no_run @@ -44,7 +44,7 @@ //! # catalog: &moq_mux::catalog::Producer, //! # gps: &mut moq_mux::json::Stream, //! # fix: serde_json::Value, -//! # received: moq_clock::Instant, +//! # received: kio::clock::Instant, //! # ) -> moq_mux::Result<()> { //! let at = catalog.clock().capture(received)?; //! gps.append(moq_net::Timed::from(&fix).at(at))?; diff --git a/rs/moq-mux/src/linger.rs b/rs/moq-mux/src/linger.rs index 804dc4f0ab6..e02ac9c1231 100644 --- a/rs/moq-mux/src/linger.rs +++ b/rs/moq-mux/src/linger.rs @@ -21,9 +21,9 @@ pub struct Linger { // Dropped after `Drop::drop` closes the broadcasts. _owner: T, // `None` when the duration overflows the clock, so only an interrupt ends it. - deadline: Option, + deadline: Option, // Armed at the deadline, created on first poll. - timer: Option, + timer: Option, } impl Linger<()> { @@ -45,7 +45,7 @@ impl Linger { Self { broadcasts: broadcasts.into_iter().collect(), _owner: owner, - deadline: moq_clock::now().checked_add(duration), + deadline: kio::clock::now().checked_add(duration), timer: None, } } @@ -56,7 +56,7 @@ impl Linger { let Some(deadline) = self.deadline else { return Poll::Pending; }; - let timer = self.timer.get_or_insert_with(|| moq_clock::sleep_until(deadline)); + let timer = self.timer.get_or_insert_with(|| kio::clock::sleep_until(deadline)); waiter.poll_future(Pin::new(timer)) } @@ -108,10 +108,10 @@ mod tests { async fn a_late_subscriber_drains_the_tail_until_the_deadline() { let origin = crate::source::produce_origin(); let (broadcast, track) = finished(&origin); - let start = moq_clock::now(); + let start = kio::clock::now(); let linger = tokio::spawn(Linger::new([broadcast], track, Duration::from_secs(30)).wait()); - moq_clock::sleep(Duration::from_secs(29)).await; + kio::clock::sleep(Duration::from_secs(29)).await; let late = origin.consume().request_broadcast(PATH, None).await.unwrap(); let video = late.track("video").unwrap(); for sequence in 0..3 { @@ -127,7 +127,7 @@ mod tests { ); linger.await.unwrap(); - assert_eq!(moq_clock::now() - start, Duration::from_secs(30)); + assert_eq!(kio::clock::now() - start, Duration::from_secs(30)); assert!(unroutable(&origin).await); } @@ -136,12 +136,12 @@ mod tests { async fn the_deadline_is_fixed_at_the_end() { let origin = crate::source::produce_origin(); let (broadcast, track) = finished(&origin); - let start = moq_clock::now(); + let start = kio::clock::now(); let linger = Linger::new([broadcast], track, Duration::from_secs(30)); - moq_clock::sleep(Duration::from_secs(20)).await; + kio::clock::sleep(Duration::from_secs(20)).await; linger.wait().await; - assert_eq!(moq_clock::now() - start, Duration::from_secs(30)); + assert_eq!(kio::clock::now() - start, Duration::from_secs(30)); } /// Dropping the handle, as an interrupt does, closes the broadcast at once. diff --git a/rs/moq-mux/src/pace.rs b/rs/moq-mux/src/pace.rs index c99eea7531b..2ac863de442 100644 --- a/rs/moq-mux/src/pace.rs +++ b/rs/moq-mux/src/pace.rs @@ -1,6 +1,6 @@ //! Pacing of media frames onto the wall clock. -use moq_clock::Instant; +use kio::clock::Instant; use std::time::Duration; use moq_net::Timestamp; @@ -248,7 +248,7 @@ mod tests { /// frame onto the anchor. #[test] fn paces_across_timescales() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_lead(Duration::from_millis(500)); // A PCR slot at microsecond scale anchors the stream. @@ -266,7 +266,7 @@ mod tests { /// panics on a large but valid `Duration` (`--delay` is unbounded). #[test] fn huge_lead_does_not_overflow() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_lead(Duration::MAX); assert_eq!(pacer.pace(ms(0), start), start); assert_eq!(pacer.pace(ms(40), start), start + Duration::from_millis(40)); @@ -279,7 +279,7 @@ mod tests { /// arrival cadence rather than the media one. #[test] fn absorbs_a_standing_delivery_lag() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_lead(Duration::from_millis(500)); assert_eq!(pacer.pace(ms(0), start), start, "the first frame anchors at now"); @@ -299,7 +299,7 @@ mod tests { /// rather than growing with every outlier. #[test] fn absorbed_lag_is_capped_by_the_lead() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_lead(Duration::from_millis(50)); assert_eq!(pacer.pace(ms(0), start), start); @@ -316,7 +316,7 @@ mod tests { /// Zero lead (SRT, whose receiver owns the jitter buffer) absorbs nothing. #[test] fn zero_lead_absorbs_nothing() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default(); assert_eq!(pacer.pace(ms(0), start), start); @@ -327,7 +327,7 @@ mod tests { #[test] fn hurry_makes_the_frame_the_live_edge() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_lead(Duration::from_millis(500)); assert_eq!(pacer.pace(ms(0), start), start); @@ -343,7 +343,7 @@ mod tests { /// onto a re-anchor the delay itself provoked. #[test] fn the_delay_is_outside_the_lead_comparison() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_delay(Duration::from_millis(100)); assert_eq!(pacer.pace(ms(0), start), start + Duration::from_millis(100)); @@ -361,7 +361,7 @@ mod tests { /// playback back toward live rather than leaving it there for the session. #[test] fn an_earlier_arrival_re_anchors_and_keeps_the_delay() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_delay(Duration::from_millis(100)); // The first frame was produced 500ms ago; nothing here knows that yet. @@ -386,7 +386,7 @@ mod tests { /// present at it: the offset playback holds behind the edge has to survive. #[test] fn hurry_keeps_the_delay() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_delay(Duration::from_millis(100)); assert_eq!(pacer.hurry(ms(800), start), start + Duration::from_millis(100)); @@ -399,7 +399,7 @@ mod tests { /// second arrival in. #[test] fn due_reads_the_anchor_without_moving_it() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_delay(Duration::from_millis(100)); assert_eq!(pacer.due(ms(0)), None, "no anchor until the first frame"); @@ -415,7 +415,7 @@ mod tests { #[test] fn lead_schedules_bursts_into_the_future() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut pacer = Pacer::default().with_lead(Duration::from_millis(500)); assert_eq!(pacer.pace(ms(0), start), start); diff --git a/rs/moq-mux/src/rate.rs b/rs/moq-mux/src/rate.rs index 113f2031d53..ddccff5fcaf 100644 --- a/rs/moq-mux/src/rate.rs +++ b/rs/moq-mux/src/rate.rs @@ -12,7 +12,7 @@ use std::{ time::Duration, }; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::bandwidth; @@ -116,11 +116,11 @@ pub enum Target { /// ``` /// # use moq_mux::rate::{Control, Policy, Target}; /// # use moq_net::bandwidth; -/// # use moq_clock::Instant; +/// # use kio::clock::Instant; /// let mut control = Control::new(Policy::new(bandwidth::Rate::from_mbps(4))); /// // A 2 Mbps estimate takes the 4 Mbps target down to what the link will carry. /// assert_eq!( -/// control.update(Some(bandwidth::Rate::from_mbps(2)), moq_clock::now()), +/// control.update(Some(bandwidth::Rate::from_mbps(2)), kio::clock::now()), /// Some(Target::Enabled(bandwidth::Rate::from_mbps(2))) /// ); /// @@ -131,7 +131,7 @@ pub enum Target { /// let mut control = Control::new(policy); /// control.set_probed(true); /// assert_eq!( -/// control.update(Some(bandwidth::Rate::from_mbps(3)), moq_clock::now()), +/// control.update(Some(bandwidth::Rate::from_mbps(3)), kio::clock::now()), /// Some(Target::Disabled) /// ); /// ``` @@ -428,7 +428,7 @@ pub struct Follower { grant: bandwidth::Consumer, control: Control, /// Armed at the control's deadline, created on first use. - timer: Option, + timer: Option, /// Feed the current grant on the next poll, after [`set_policy`](Self::set_policy) /// changed it. refeed: bool, @@ -478,7 +478,7 @@ impl Follower { self.grant.peek() }; self.control.set_probed(self.grant.probed()); - if let Some(target) = self.control.update(estimate, moq_clock::now()) { + if let Some(target) = self.control.update(estimate, kio::clock::now()) { return Poll::Ready(Ok(target)); } } @@ -496,7 +496,7 @@ impl Follower { /// step from now, so a quiet grant still retries and a sender that keeps failing /// is not hammered. Does nothing once another poll has fed the grant. pub fn failed(&mut self) { - self.control.failed(moq_clock::now()); + self.control.failed(kio::clock::now()); } fn poll_deadline(&mut self, waiter: &kio::Waiter) -> Poll<()> { @@ -504,7 +504,7 @@ impl Follower { self.timer = None; return Poll::Pending; }; - let timer = self.timer.get_or_insert_with(|| moq_clock::sleep_until(at)); + let timer = self.timer.get_or_insert_with(|| kio::clock::sleep_until(at)); if timer.deadline() != at { timer.reset(at); } @@ -550,7 +550,7 @@ mod tests { let mut control = control(); // A 2 Mbps pipe: take the target down to it at once, no ramp, no waiting. assert_eq!( - control.update(Some(bps(2_000_000)), moq_clock::now()), + control.update(Some(bps(2_000_000)), kio::clock::now()), Some(on(bps(2_000_000))) ); assert_eq!(control.target(), on(bps(2_000_000))); @@ -559,7 +559,7 @@ mod tests { #[test] fn missing_estimate_holds_the_target() { let mut control = control(); - let now = moq_clock::now(); + let now = kio::clock::now(); control.update(Some(bps(2_000_000)), now).unwrap(); // Losing the estimate (disconnected) is not evidence the uplink is @@ -572,7 +572,7 @@ mod tests { fn estimate_never_raises_above_max() { let mut control = control(); // A wildly optimistic estimate is not licence to exceed what was configured. - assert_eq!(control.update(Some(bps(100_000_000)), moq_clock::now()), None); + assert_eq!(control.update(Some(bps(100_000_000)), kio::clock::now()), None); assert_eq!(control.target(), on(bps(4_000_000))); } @@ -580,14 +580,14 @@ mod tests { fn target_never_falls_below_min() { let mut control = control(); // A near-dead uplink floors at min (max/10) rather than chasing to zero. - assert_eq!(control.update(Some(bps(1)), moq_clock::now()), Some(on(bps(400_000)))); + assert_eq!(control.update(Some(bps(1)), kio::clock::now()), Some(on(bps(400_000)))); assert_eq!(control.target(), on(bps(400_000))); } #[test] fn raise_is_ramp_limited() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); // target 1M // The pipe reopens to 4 Mbps. One second later the default 25%/s ramp @@ -606,7 +606,7 @@ mod tests { #[test] fn suppressed_raises_do_not_starve_the_ramp() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); // target 1M // Tick at 100ms: each tick alone is under the 5% threshold. @@ -632,7 +632,7 @@ mod tests { #[test] fn a_raise_reaching_the_ceiling_beats_hysteresis() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); // Walk up until it settles, then confirm where it settled. @@ -658,7 +658,7 @@ mod tests { #[test] fn upward_jitter_stays_inside_the_deadband() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(2_000_000)), start).unwrap(); // target 2M, well under the 4M ceiling // A 0.5% rise: inside the 5% deadband, and nowhere near the ceiling. @@ -690,7 +690,7 @@ mod tests { #[test] fn small_moves_are_suppressed() { let mut control = control(); - let now = moq_clock::now(); + let now = kio::clock::now(); control.update(Some(bps(2_000_000)), now).unwrap(); // target 2M // 2% under the current target: inside the 5% deadband, so no reconfigure. @@ -712,7 +712,7 @@ mod tests { let mut control = Control::new(policy); assert_eq!(control.target(), on(bps(1_000_000))); - assert_eq!(control.update(Some(bps(2_000_000)), moq_clock::now()), None); + assert_eq!(control.update(Some(bps(2_000_000)), kio::clock::now()), None); assert_eq!(control.target(), on(bps(1_000_000))); } @@ -739,7 +739,7 @@ mod tests { #[test] fn a_quiet_grant_recovers_on_deadlines() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); assert_eq!(control.deadline(), None, "a drop lands at once"); @@ -764,7 +764,7 @@ mod tests { /// band could leave a deadline that applies nothing and spins its caller. #[test] fn every_deadline_applies_a_change() { - let start = moq_clock::now(); + let start = kio::clock::now(); for max in [15, 20, 21, 999, 1_000_003, 4_000_000, 1 << 50] { for floor in [1, max / 10, max / 3, max - max / 25] { let mut control = Control::new(Policy::new(bps(max))); @@ -781,7 +781,7 @@ mod tests { #[test] fn reaching_the_estimate_clears_the_deadline() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); assert_eq!( control.update(Some(bps(1_100_000)), start + Duration::from_secs(1)), @@ -795,7 +795,7 @@ mod tests { #[test] fn a_climb_below_the_ceiling_settles_in_the_deadband() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); control .update(Some(bps(2_000_000)), start + Duration::from_secs(1)) @@ -811,7 +811,7 @@ mod tests { /// not scheduled, whether it is all of the raise or what one step leaves over. #[test] fn a_raise_inside_the_deadband_is_not_scheduled() { - let start = moq_clock::now(); + let start = kio::clock::now(); let mut whole = control(); whole.update(Some(bps(2_000_000)), start).unwrap(); assert_eq!(whole.update(Some(bps(2_050_000)), start + Duration::from_secs(1)), None); @@ -830,7 +830,7 @@ mod tests { /// Losing the estimate or a drop cancels a scheduled raise. #[test] fn a_missing_estimate_or_a_drop_clears_the_deadline() { - let start = moq_clock::now(); + let start = kio::clock::now(); let scheduled = || { let mut control = control(); control.update(Some(bps(1_000_000)), start).unwrap(); @@ -858,7 +858,7 @@ mod tests { #[test] fn a_failed_raise_is_retried() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); control .update(Some(bps(4_000_000)), start + Duration::from_secs(1)) @@ -889,7 +889,7 @@ mod tests { #[test] fn a_failed_drop_is_retried() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(1_000_000)), start).unwrap(); control.failed(start); assert_eq!(control.target(), on(bps(4_000_000))); @@ -905,7 +905,7 @@ mod tests { #[test] fn a_failure_after_no_change_does_nothing() { let mut control = control(); - let start = moq_clock::now(); + let start = kio::clock::now(); control.update(Some(bps(2_000_000)), start).unwrap(); assert_eq!( control.update(Some(bps(1_960_000)), start + Duration::from_secs(1)), @@ -932,7 +932,7 @@ mod tests { let mut applied = Vec::new(); let mut refused = false; // A minute without a wake is far past anything the ramp still needs. - while let Ok(target) = moq_clock::timeout(Duration::from_secs(60), follower.next()).await { + while let Ok(target) = kio::clock::timeout(Duration::from_secs(60), follower.next()).await { let Target::Enabled(target) = target.unwrap() else { panic!("a policy without a lower rendition disabled the sender") }; @@ -962,7 +962,7 @@ mod tests { // The 3 Mbps grant no longer fits under the new 2 Mbps ceiling, which is where a // new policy starts, so nothing moves until the grant does. assert!( - moq_clock::timeout(Duration::from_secs(60), follower.next()) + kio::clock::timeout(Duration::from_secs(60), follower.next()) .await .is_err() ); @@ -971,7 +971,7 @@ mod tests { assert_eq!(follower.next().await.unwrap(), on(bps(3_000_000))); follower.set_policy(Policy::new(bps(4_000_000))); assert!( - moq_clock::timeout(Duration::from_secs(60), follower.next()) + kio::clock::timeout(Duration::from_secs(60), follower.next()) .await .is_err() ); @@ -986,7 +986,7 @@ mod tests { let mut follower = Follower::new(grant.consume(), Policy::new(bps(2_000_000))); grant.set(Some(bps(2_000_000))).unwrap(); assert!( - moq_clock::timeout(Duration::from_secs(60), follower.next()) + kio::clock::timeout(Duration::from_secs(60), follower.next()) .await .is_err(), "settled at the 2 Mbps ceiling" @@ -1012,7 +1012,7 @@ mod tests { follower.set_policy(policy); let mut applied = Vec::new(); - while let Ok(target) = moq_clock::timeout(Duration::from_secs(60), follower.next()).await { + while let Ok(target) = kio::clock::timeout(Duration::from_secs(60), follower.next()).await { applied.push(target.unwrap()); } assert_eq!(applied.last(), Some(&on(bps(4_000_000))), "{applied:?}"); @@ -1052,7 +1052,7 @@ mod tests { #[test] fn a_rung_disables_below_its_boundary() { let mut rung = rung(); - let start = moq_clock::now(); + let start = kio::clock::now(); // Squeezed, but still inside its band: it adapts like any sender. assert_eq!(rung.update(Some(bps(3_500_000)), start), Some(on(bps(3_500_000)))); @@ -1069,7 +1069,7 @@ mod tests { fn the_lowest_rung_never_disables() { let mut lowest = Control::new(Policy::new(bps(350_000))); lowest.set_probed(true); - assert_eq!(lowest.update(Some(bps(1)), moq_clock::now()), Some(on(bps(35_000)))); + assert_eq!(lowest.update(Some(bps(1)), kio::clock::now()), Some(on(bps(35_000)))); } /// Without a session probing for it, a stopped rendition could never see the estimate @@ -1079,7 +1079,7 @@ mod tests { let mut rung = rung(); rung.set_probed(false); assert_eq!( - rung.update(Some(bps(1_000_000)), moq_clock::now()), + rung.update(Some(bps(1_000_000)), kio::clock::now()), Some(on(bps(1_000_000))) ); } @@ -1089,7 +1089,7 @@ mod tests { #[test] fn a_disabled_rung_resumes_when_probing_stops() { let mut rung = rung(); - let start = moq_clock::now(); + let start = kio::clock::now(); assert_eq!(rung.update(Some(bps(1_000_000)), start), Some(Target::Disabled)); rung.set_probed(false); @@ -1102,7 +1102,7 @@ mod tests { #[test] fn a_rung_resumes_past_the_hysteresis_and_ramps() { let mut rung = rung(); - let start = moq_clock::now(); + let start = kio::clock::now(); assert_eq!(rung.update(Some(bps(3_000_000)), start), Some(Target::Disabled)); // Back over the boundary, but not by the 5% hysteresis: stay off. @@ -1125,7 +1125,7 @@ mod tests { #[test] fn jitter_at_the_boundary_does_not_flap() { let mut rung = rung(); - let start = moq_clock::now(); + let start = kio::clock::now(); rung.update(Some(bps(3_400_000)), start).unwrap(); // About 3% either side of the boundary, every 100ms for 10s. @@ -1149,7 +1149,7 @@ mod tests { #[test] fn a_missing_estimate_holds_a_disabled_rung() { let mut rung = rung(); - let now = moq_clock::now(); + let now = kio::clock::now(); rung.update(Some(bps(1_000_000)), now).unwrap(); assert_eq!(rung.update(None, now + Duration::from_secs(10)), None); assert_eq!(rung.target(), Target::Disabled); @@ -1163,7 +1163,7 @@ mod tests { policy.lower = Some(bps(950_000)); let mut rung = Control::new(policy); rung.set_probed(true); - let now = moq_clock::now(); + let now = kio::clock::now(); assert_eq!(rung.update(Some(bps(500_000)), now), Some(Target::Disabled)); assert_eq!( rung.update(Some(bps(10_000_000)), now + Duration::from_secs(1)), @@ -1178,7 +1178,7 @@ mod tests { policy.lower = Some(bps(1_000_000)); let mut rung = Control::new(policy); rung.set_probed(true); - assert_eq!(rung.update(Some(bps(1)), moq_clock::now()), Some(on(bps(100_000)))); + assert_eq!(rung.update(Some(bps(1)), kio::clock::now()), Some(on(bps(100_000)))); } /// A disable or resume the sender failed to apply is taken back and retried, so the @@ -1186,7 +1186,7 @@ mod tests { #[test] fn a_failed_toggle_is_retried() { let mut rung = rung(); - let start = moq_clock::now(); + let start = kio::clock::now(); assert_eq!(rung.update(Some(bps(3_000_000)), start), Some(Target::Disabled)); rung.failed(start); assert_eq!(rung.target(), on(bps(5_000_000))); @@ -1210,7 +1210,7 @@ mod tests { #[test] fn a_failed_resume_under_the_margin_stops_retrying() { let mut rung = rung(); - let start = moq_clock::now(); + let start = kio::clock::now(); assert_eq!(rung.update(Some(bps(3_000_000)), start), Some(Target::Disabled)); let resumed = start + Duration::from_secs(1); assert_eq!(rung.update(Some(bps(5_000_000)), resumed), Some(on(bps(3_333_333)))); @@ -1228,7 +1228,7 @@ mod tests { fn a_rung_under_its_boundary_disables_when_probing_starts() { let mut rung = rung(); rung.set_probed(false); - let start = moq_clock::now(); + let start = kio::clock::now(); assert_eq!(rung.update(Some(bps(3_000_000)), start), Some(on(bps(3_000_000)))); let mut funded = rung.clone(); @@ -1250,7 +1250,7 @@ mod tests { #[test] fn a_rung_under_a_raised_boundary_disables() { let mut rung = rung(); - let start = moq_clock::now(); + let start = kio::clock::now(); assert_eq!(rung.update(Some(bps(3_500_000)), start), Some(on(bps(3_500_000)))); // The boundary moves from 3.33 Mbps to 3.67 Mbps, over the applied target. @@ -1299,7 +1299,7 @@ mod tests { controls.push(control); tracks.push(track); } - let start = moq_clock::now(); + let start = kio::clock::now(); let mut update = |at: Instant| -> Vec { controls .iter_mut() @@ -1527,7 +1527,7 @@ mod tests { policy.lower = lower.map(bps); let mut model = Model { control: Control::new(policy), - now: moq_clock::now(), + now: kio::clock::now(), grant: None, probed: false, }; diff --git a/rs/moq-mux/src/stats.rs b/rs/moq-mux/src/stats.rs index a46724ace88..c9d057a6bd7 100644 --- a/rs/moq-mux/src/stats.rs +++ b/rs/moq-mux/src/stats.rs @@ -5,7 +5,7 @@ //! the catalog [`Producer`](crate::catalog::Producer) for what a publisher writes, the export //! [`Source`](crate::Source) for what a viewer reads. -use moq_clock::Wall; +use kio::clock::Wall; use std::collections::BTreeMap; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering::Relaxed}; use std::sync::{Arc, Mutex, PoisonError}; diff --git a/rs/moq-native/clippy.toml b/rs/moq-native/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-native/clippy.toml +++ b/rs/moq-native/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-net-tests/Cargo.toml b/rs/moq-net-tests/Cargo.toml index 73fe5cb3933..9450844734c 100644 --- a/rs/moq-net-tests/Cargo.toml +++ b/rs/moq-net-tests/Cargo.toml @@ -14,7 +14,7 @@ ignored = ["tokio"] [dev-dependencies] futures = { workspace = true } -moq-clock = { path = "../moq-clock", default-features = false, features = ["sim"] } +kio = { path = "../kio", features = ["sim"] } moq-json = { path = "../moq-json" } moq-net = { path = "../moq-net", features = ["fuzz"] } serde_json = { workspace = true } diff --git a/rs/moq-net-tests/tests/integration/ietf_conformance.rs b/rs/moq-net-tests/tests/integration/ietf_conformance.rs index e458c15a3dd..5fa74c06b1b 100644 --- a/rs/moq-net-tests/tests/integration/ietf_conformance.rs +++ b/rs/moq-net-tests/tests/integration/ietf_conformance.rs @@ -29,7 +29,7 @@ async fn routing(version: &str, cluster: bool) { let track = broadcast.create_track("test", moq_net::track::Info::default()).unwrap(); let serving = prefix.clone(); let answer = broadcast.consume(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { let request = serving.requested_broadcast().await.unwrap(); assert_eq!(request.path().as_str(), NAMESPACE); moq_net::fuzz::accept(request, answer); @@ -74,14 +74,14 @@ async fn routing(version: &str, cluster: bool) { drop((links, prefix, broadcast, track)); } -#[moq_clock::test] +#[kio::test] async fn conformance_namespaces_route_through_one_relay() { for version in ["moq-transport-18"] { routing(version, false).await; } } -#[moq_clock::test] +#[kio::test] async fn conformance_namespaces_route_through_a_lite_cluster() { for version in ["moq-transport-18"] { routing(version, true).await; diff --git a/rs/moq-net-tests/tests/integration/refresh.rs b/rs/moq-net-tests/tests/integration/refresh.rs index 1ed4866c3e1..3b78da85206 100644 --- a/rs/moq-net-tests/tests/integration/refresh.rs +++ b/rs/moq-net-tests/tests/integration/refresh.rs @@ -12,7 +12,7 @@ fn origin(hop: u64) -> origin::Producer { /// The JSON owner answers demand across a publisher link, a cluster peer, and a reader link. /// Existing readers keep their deltas; the late reader receives the cached group, then a new /// complete snapshot. -#[moq_clock::test] +#[kio::test] async fn json_snapshot_refresh_crosses_a_two_relay_cluster() { use moq_json::snapshot; use moq_net::{Timed, Timescale, Timestamp}; @@ -90,7 +90,7 @@ async fn json_snapshot_refresh_crosses_a_two_relay_cluster() { original.read_frame().await.unwrap().unwrap(); assert!(delta_bytes > ratio as usize * snapshot_bytes); // Simulated time passing cannot roll a group, even with deltas over the ratio. - moq_clock::sleep(Duration::from_secs(60)).await; + kio::clock::sleep(Duration::from_secs(60)).await; assert!(producer.poll_refresh(&kio::Waiter::noop()).is_pending()); assert_eq!(track.demand().wanted(), Some(0)); @@ -98,7 +98,7 @@ async fn json_snapshot_refresh_crosses_a_two_relay_cluster() { // Poll the new reader while the owner drives refresh: a front does not join its // serving copy until read. Refresh is a request, not a hold, so the cached group // arrives first, whole, and the fresh one follows. - let (mut cached, mut fresh) = moq_clock::timeout(Duration::from_secs(1), async { + let (mut cached, mut fresh) = kio::clock::timeout(Duration::from_secs(1), async { let (refreshed, groups) = futures::join!(producer.refresh(), async { let cached = late.recv_group().await.unwrap().unwrap(); (cached, late.recv_group().await.unwrap().unwrap()) @@ -142,7 +142,7 @@ async fn json_snapshot_refresh_crosses_a_two_relay_cluster() { } } -#[moq_clock::test] +#[kio::test] async fn ratio_joins_cross_two_relays() { for name in ["moq-lite-06", "moq-lite-07-wip"] { let version: Version = name.parse().unwrap(); @@ -186,14 +186,14 @@ async fn ratio_joins_cross_two_relays() { } if name == "moq-lite-07-wip" { let mut demand = producer.demand(); - moq_clock::timeout(Duration::from_secs(1), async { + kio::clock::timeout(Duration::from_secs(1), async { while demand.wanted_changed().await.unwrap() != Some(1) {} }) .await .unwrap(); } else { // Drain runnable protocol tasks on simulated time, without a wall-clock sleep. - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; assert_eq!(producer.demand().wanted(), Some(0)); } drop((joins, under, received, baseline, group, links)); diff --git a/rs/moq-net-tests/tests/integration/restart.rs b/rs/moq-net-tests/tests/integration/restart.rs index 3d86b8fc6e9..1bc880a146e 100644 --- a/rs/moq-net-tests/tests/integration/restart.rs +++ b/rs/moq-net-tests/tests/integration/restart.rs @@ -38,12 +38,12 @@ async fn link(version: Version, from: &origin::Producer, to: &origin::Producer) /// Let every task settle, past the update hold. Time is paused, so this returns once /// the runtime is idle. async fn settle() { - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; } /// The next announce event, failing on a hang. async fn next_event(announced: &mut announce::Consumer) -> announce::Event { - moq_clock::timeout(Duration::from_secs(10), announced.next()) + kio::clock::timeout(Duration::from_secs(10), announced.next()) .await .expect("announce hung") .expect("announce ended") @@ -79,7 +79,7 @@ async fn expect_replaced(version: Version, announced: &mut announce::Consumer, p /// Nothing more arrives, past the update hold. async fn quiet(version: Version, announced: &mut announce::Consumer) { - if let Ok(event) = moq_clock::timeout(Duration::from_secs(1), announced.next()).await { + if let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { panic!("{version}: expected nothing more, got {event:?}"); } } @@ -93,7 +93,7 @@ fn write(track: &track::Producer, tag: &str) { /// The next frame a subscription delivers, as text. async fn read(subscription: &mut track::Subscriber) -> String { - let mut group = moq_clock::timeout(Duration::from_secs(10), subscription.recv_group()) + let mut group = kio::clock::timeout(Duration::from_secs(10), subscription.recv_group()) .await .expect("subscription hung") .unwrap() @@ -152,9 +152,9 @@ async fn relay_chain(version: &str) { macro_rules! relay_chain_tests { ($($name:ident: $version:literal,)*) => { $( - #[moq_clock::test] + #[kio::test] async fn $name() { - moq_clock::timeout(TEST_TIMEOUT, relay_chain($version)) + kio::clock::timeout(TEST_TIMEOUT, relay_chain($version)) .await .expect("timed out"); } @@ -187,7 +187,7 @@ impl Worker { ); let outputs = Rc::new(RefCell::new(Vec::new())); let (handler, served) = (claim.clone(), outputs.clone()); - drop(moq_clock::sim::spawn(async move { + drop(kio::clock::sim::spawn(async move { while let Ok(request) = handler.requested_broadcast().await { let output = broadcast::Info::new().produce(); let track = output.create_track("video", timed()).unwrap(); @@ -242,16 +242,16 @@ async fn prefix_pool(version: &str) { } } -#[moq_clock::test] +#[kio::test] async fn prefix_pool_lite06() { - moq_clock::timeout(TEST_TIMEOUT, prefix_pool("moq-lite-06")) + kio::clock::timeout(TEST_TIMEOUT, prefix_pool("moq-lite-06")) .await .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn prefix_pool_lite07() { - moq_clock::timeout(TEST_TIMEOUT, prefix_pool("moq-lite-07-wip")) + kio::clock::timeout(TEST_TIMEOUT, prefix_pool("moq-lite-07-wip")) .await .expect("timed out"); } @@ -273,7 +273,7 @@ impl Claim { Rc::new(moq_net::fuzz::requests_route(origin, moq_net::Path::from_static("live"), route).unwrap()); let outputs = Rc::new(RefCell::new(Vec::new())); let (handler, served) = (dynamic.clone(), outputs.clone()); - drop(moq_clock::sim::spawn(async move { + drop(kio::clock::sim::spawn(async move { while let Ok(request) = handler.requested_broadcast().await { let output = broadcast::Info::new().produce(); let track = output.create_track("video", timed()).unwrap(); @@ -330,7 +330,7 @@ async fn dynamic_epoch(version: &str, from: Option, to: Option) { // A re-price at the same epoch is an update at most: every handle survives. claim.update_route(claim.dynamic.route().with_cost(5)); - while let Ok(event) = moq_clock::timeout(Duration::from_secs(1), announced.next()).await { + while let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { assert!( matches!(event, Some(announce::Event::Update(_))), "{version}: a re-price delivered {event:?}" @@ -382,11 +382,11 @@ fn epochs() -> (Epoch, Epoch) { macro_rules! dynamic_epoch_tests { ($($name:ident: $version:literal,)*) => { $( - #[moq_clock::test] + #[kio::test] async fn $name() { let (a, b) = epochs(); for (from, to) in [(Some(a.clone()), Some(b.clone())), (Some(a), None), (None, Some(b))] { - moq_clock::timeout(TEST_TIMEOUT, dynamic_epoch($version, from, to)) + kio::clock::timeout(TEST_TIMEOUT, dynamic_epoch($version, from, to)) .await .expect("timed out"); } @@ -405,7 +405,7 @@ dynamic_epoch_tests! { /// An update does not override route selection: with a second claim still at the /// epoch, a claim dropping it hands re-requests to the second, which outranks any /// route without one. -#[moq_clock::test] +#[kio::test] async fn dynamic_epoch_second_route_keeps_winning() { let (a, _) = epochs(); let origin = produce_origin(1); @@ -427,7 +427,7 @@ async fn dynamic_epoch_second_route_keeps_winning() { // The epoch still stands through the second claim, so this is no restart, and the // instance's subscriptions resume through it. first.update_epoch(None); - while let Ok(event) = moq_clock::timeout(Duration::from_secs(1), announced.next()).await { + while let Ok(event) = kio::clock::timeout(Duration::from_secs(1), announced.next()).await { assert!( matches!(event, Some(announce::Event::Update(_))), "dropping a shared epoch delivered {event:?}" @@ -511,9 +511,9 @@ async fn retired_fetch(version: &str, explicit: bool) { macro_rules! retired_fetch_tests { ($($name:ident: $version:literal,)*) => { $( - #[moq_clock::test] + #[kio::test] async fn $name() { - moq_clock::timeout(TEST_TIMEOUT, retired_fetch($version, false)).await.expect("timed out"); + kio::clock::timeout(TEST_TIMEOUT, retired_fetch($version, false)).await.expect("timed out"); } )* }; } @@ -553,7 +553,7 @@ async fn unanswered_takeover(version: &str) { expect_restart(version, &mut announced, "live").await; write(&old_track, "old:0"); - let next = moq_clock::timeout(Duration::from_secs(10), subscription.recv_group()) + let next = kio::clock::timeout(Duration::from_secs(10), subscription.recv_group()) .await .expect("subscription hung"); match next { @@ -567,9 +567,9 @@ async fn unanswered_takeover(version: &str) { macro_rules! unanswered_takeover_tests { ($($name:ident: $version:literal,)*) => { $( - #[moq_clock::test] + #[kio::test] async fn $name() { - moq_clock::timeout(TEST_TIMEOUT, unanswered_takeover($version)).await.expect("timed out"); + kio::clock::timeout(TEST_TIMEOUT, unanswered_takeover($version)).await.expect("timed out"); } )* }; } @@ -582,14 +582,14 @@ unanswered_takeover_tests! { unanswered_takeover_lite07: "moq-lite-07-wip", } -#[moq_clock::test] +#[kio::test] async fn retired_fetch_explicit_epoch_control() { - moq_clock::timeout(TEST_TIMEOUT, retired_fetch("moq-lite-07-wip", true)) + kio::clock::timeout(TEST_TIMEOUT, retired_fetch("moq-lite-07-wip", true)) .await .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn withdrawal_refuses_new_fetches_but_keeps_open_reads() { for version in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { let version: Version = version.parse().unwrap(); @@ -612,7 +612,7 @@ async fn withdrawal_refuses_new_fetches_but_keeps_open_reads() { } } -#[moq_clock::test] +#[kio::test] async fn a_more_specific_source_cannot_fill_a_held_covering_track() { for name in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { let version: Version = name.parse().unwrap(); @@ -654,7 +654,7 @@ impl Pool { let outputs = Rc::new(RefCell::new(std::collections::HashMap::new())); let answered = Rc::new(RefCell::new(0)); let (handler, served, count) = (claim.clone(), outputs.clone(), answered.clone()); - drop(moq_clock::sim::spawn(async move { + drop(kio::clock::sim::spawn(async move { while let Ok(request) = handler.requested_broadcast().await { let path = request.path().to_string(); let prepared = request.prepare(Epoch::mint()).unwrap(); @@ -739,9 +739,9 @@ async fn claim_restart(version: &str) { macro_rules! claim_restart_tests { ($($name:ident: $version:literal,)*) => { $( - #[moq_clock::test] + #[kio::test] async fn $name() { - moq_clock::timeout(TEST_TIMEOUT, claim_restart($version)) + kio::clock::timeout(TEST_TIMEOUT, claim_restart($version)) .await .expect("timed out"); } diff --git a/rs/moq-net/AGENTS.md b/rs/moq-net/AGENTS.md index 633d6ea0f17..5c46c82ff6e 100644 --- a/rs/moq-net/AGENTS.md +++ b/rs/moq-net/AGENTS.md @@ -15,6 +15,6 @@ The wire layer. Generic over the transport and media-agnostic: the relay never i # Testing -- Tests never use tokio or the wall clock. Prefer a plain `#[test]` that polls with explicit instants; async bodies use `#[moq_clock::test]`, whose simulated time jumps only when every task is stalled. tokio is for the benches. +- Tests never use tokio or the wall clock. Prefer a plain `#[test]` that polls with explicit instants; async bodies use `#[kio::test]`, whose simulated time jumps only when every task is stalled. tokio is for the benches. - `just rs fuzz ` (one per file in `fuzz/fuzz_targets/`) needs nightly. The target bodies live in `src/fuzz.rs`; `fuzz/regressions//` replays under `just check`, so commit every crash input there. - `just rs loom` model-checks the concurrent handoffs. A hang is a lost wakeup, not a flake. diff --git a/rs/moq-net/Cargo.toml b/rs/moq-net/Cargo.toml index 869f2527551..f34665fa013 100644 --- a/rs/moq-net/Cargo.toml +++ b/rs/moq-net/Cargo.toml @@ -18,7 +18,7 @@ ignored = ["getrandom"] [features] default = ["async"] # Runtime-backed helpers and Lite/IETF sessions; explicit-time model drivers stay available. -async = ["dep:futures", "moq-clock/runtime"] +async = ["dep:futures", "kio/runtime"] # Exposes the wire codecs to the `fuzz/` harness and the announce, codec, path, varint, frame, and canonical storage benches, # and session views of an origin to the viewers bench, through the hidden `fuzz` module. Off by @@ -35,7 +35,6 @@ futures = { workspace = true, optional = true } hashbrown = { workspace = true } hashlink = { workspace = true } kio = { workspace = true } -moq-clock = { version = "0.11.0", path = "../moq-clock", default-features = false } moq-pattern = { workspace = true, features = ["serde"] } num_enum = { workspace = true } rand = { workspace = true } @@ -56,7 +55,7 @@ loom = { workspace = true } criterion = { workspace = true } futures = { workspace = true } # The tests' executor, with simulated time. -moq-clock = { path = "../moq-clock", features = ["sim"] } +kio = { path = "../kio", features = ["runtime", "sim"] } serde_json = { workspace = true } # The benches run on tokio. test-util (tokio::time::pause/advance) is test-only and # is NOT supported on wasm, so it must not leak into the normal dependency feature set. diff --git a/rs/moq-net/benches/memory.rs b/rs/moq-net/benches/memory.rs index ac45febd683..88148c2cb72 100644 --- a/rs/moq-net/benches/memory.rs +++ b/rs/moq-net/benches/memory.rs @@ -94,7 +94,7 @@ fn runtime() -> tokio::runtime::Runtime { } fn now() -> moq_net::time::Instant { - moq_clock::now() + kio::clock::now() } /// One publisher and one subscriber session over an in-memory pair. diff --git a/rs/moq-net/benches/origin.rs b/rs/moq-net/benches/origin.rs index baa2457165d..688f0336957 100644 --- a/rs/moq-net/benches/origin.rs +++ b/rs/moq-net/benches/origin.rs @@ -1447,7 +1447,7 @@ impl Generation { async fn announce(&self, epoch: &Epoch) { self.route(epoch); for track in &self.tracks { - moq_clock::timeout(COPY_WAIT, support::wanted(track.demand())) + kio::clock::timeout(COPY_WAIT, support::wanted(track.demand())) .await .expect("route swap did not splice") .expect("replacement track closed"); @@ -1477,14 +1477,14 @@ async fn copy_walk(tracks: usize, copies: usize) -> CopyWalk { let epoch = Epoch::mint(); let first = Generation::build(&producer, tracks); first.route(&epoch); - let resolved = moq_clock::timeout(COPY_WAIT, producer.consume().request_broadcast(COPY_PATH, None)) + let resolved = kio::clock::timeout(COPY_WAIT, producer.consume().request_broadcast(COPY_PATH, None)) .await .expect("front did not resolve") .expect("front refused"); let mut subscribers = Vec::with_capacity(tracks); for i in 0..tracks { let track = resolved.track(&format!("{i}")).unwrap(); - let subscriber = moq_clock::timeout(COPY_WAIT, track.subscribe(None)) + let subscriber = kio::clock::timeout(COPY_WAIT, track.subscribe(None)) .await .expect("track did not splice") .expect("subscribe failed"); @@ -1638,7 +1638,7 @@ async fn resume_overlap(shape: ResumeShape, ordered: bool) -> ResumeOverlap { (broadcast, track) }; let mut generations = vec![generation(&mut (0..retained))]; - let resolved = moq_clock::timeout(COPY_WAIT, producer.consume().request_broadcast(COPY_PATH, None)) + let resolved = kio::clock::timeout(COPY_WAIT, producer.consume().request_broadcast(COPY_PATH, None)) .await .expect("front did not resolve") .expect("front refused"); @@ -1647,7 +1647,7 @@ async fn resume_overlap(shape: ResumeShape, ordered: bool) -> ResumeOverlap { let subscription = track::Subscription::default().with_max_delay(Duration::from_secs(3600)); let mut subscribers = Vec::with_capacity(readers); for _ in 0..readers { - let subscriber = moq_clock::timeout(COPY_WAIT, track.subscribe(subscription.clone())) + let subscriber = kio::clock::timeout(COPY_WAIT, track.subscribe(subscription.clone())) .await .expect("track did not splice") .expect("subscribe failed"); @@ -1665,7 +1665,7 @@ async fn resume_overlap(shape: ResumeShape, ordered: bool) -> ResumeOverlap { generation(&mut (0..retained).rev()) }); let (_, latest) = generations.last().unwrap(); - moq_clock::timeout(COPY_WAIT, support::wanted(latest.demand())) + kio::clock::timeout(COPY_WAIT, support::wanted(latest.demand())) .await .expect("route swap did not splice") .expect("replacement track closed"); diff --git a/rs/moq-net/benches/session/mod.rs b/rs/moq-net/benches/session/mod.rs index 603833d728e..1cf3f47dfea 100644 --- a/rs/moq-net/benches/session/mod.rs +++ b/rs/moq-net/benches/session/mod.rs @@ -1361,7 +1361,7 @@ impl IdleRoom { async fn measure(&self, iters: u64) -> Duration { let start = Instant::now(); for _ in 0..iters { - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; } start.elapsed() } @@ -1420,7 +1420,7 @@ pub(crate) fn withdrawal(c: &mut Criterion) { .unwrap() }) .collect(); - while moq_clock::timeout(Duration::from_secs(1), announced.next()) + while kio::clock::timeout(Duration::from_secs(1), announced.next()) .await .is_ok() {} @@ -1428,7 +1428,7 @@ pub(crate) fn withdrawal(c: &mut Criterion) { drop(live); let mut retracted = 0; while let Ok(Some(event)) = - moq_clock::timeout(Duration::from_secs(1), announced.next()).await + kio::clock::timeout(Duration::from_secs(1), announced.next()).await { assert!(matches!(event, moq_net::announce::Event::End(_)), "{event:?}"); retracted += 1; diff --git a/rs/moq-net/clippy.toml b/rs/moq-net/clippy.toml index 9460b0fd5c8..1fc5f0c2931 100644 --- a/rs/moq-net/clippy.toml +++ b/rs/moq-net/clippy.toml @@ -1,11 +1,11 @@ disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, ] -disallowed-types = [{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" }] +disallowed-types = [{ path = "std::time::SystemTime", reason = "use kio::clock::Wall" }] diff --git a/rs/moq-net/src/auth.rs b/rs/moq-net/src/auth.rs index 353f54f13a4..444b0249a87 100644 --- a/rs/moq-net/src/auth.rs +++ b/rs/moq-net/src/auth.rs @@ -2489,7 +2489,7 @@ impl Enforce { mod tests { use super::*; - #[moq_clock::test] + #[kio::test] async fn a_request_waits_for_an_unanswered_token() { let handle = Link::new(true); let setup = handle.present(Bytes::new(), true).unwrap(); @@ -3073,7 +3073,7 @@ mod request_token_tests { /// A request token reaches the app's acceptor like any other token, and the grant the /// app answers is what the verdict resolves to. - #[moq_clock::test] + #[kio::test] async fn a_request_token_reaches_the_acceptor() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3089,7 +3089,7 @@ mod request_token_tests { /// An AUTH token has no type, so a request token of any type but out-of-band cannot reach /// the acceptor as one: it is unsupported, never handed over as if it were a plain token. - #[moq_clock::test] + #[kio::test] async fn a_typed_request_token_is_unsupported() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3126,7 +3126,7 @@ mod request_token_tests { /// request message, not the AUTH stream, so `requests()` stays live on a session whose /// `supported` is false, even once the peer turns out not to speak AUTH. This is the shape /// a standard moq-transport peer presents when it does not negotiate the AUTH extension. - #[moq_clock::test] + #[kio::test] async fn a_request_token_is_verified_without_the_auth_extension() { let handle = Link::new(false); let mut requests = handle.handle().requests(); @@ -3142,7 +3142,7 @@ mod request_token_tests { /// With no `requests()` consumer, a request token cannot be verified in band, so the verdict /// is Unsupported and the caller refuses the request NOT_SUPPORTED. - #[moq_clock::test] + #[kio::test] async fn no_consumer_refuses_a_request_token_as_unsupported() { let handle = Link::new(true); let verdict = handle.verify_request(token(b"jwt", 0), None); @@ -3152,7 +3152,7 @@ mod request_token_tests { /// A refused request token resolves to the refusal, which the caller sends the peer as /// UNAUTHORIZED. - #[moq_clock::test] + #[kio::test] async fn a_refused_request_token_is_unauthorized() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3167,7 +3167,7 @@ mod request_token_tests { /// A grant the acceptor revoked, dropped or replaced before the verdict was read is admitted /// as it stands now, never as first issued. - #[moq_clock::test] + #[kio::test] async fn a_grant_ended_before_admission_is_refused() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3198,7 +3198,7 @@ mod request_token_tests { /// The grant lives exactly as long as the request: dropping the verdict ends the /// acceptor's issued grant, so it never outlives the request nor joins the union. - #[moq_clock::test] + #[kio::test] async fn dropping_the_verdict_ends_the_grant() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3212,7 +3212,7 @@ mod request_token_tests { /// A request token never joins the session union: the union stays what the connection /// credential earned, not what a request token granted. - #[moq_clock::test] + #[kio::test] async fn a_request_token_never_joins_the_union() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3239,7 +3239,7 @@ mod request_token_tests { /// The session's scope for unnamed requests is the connection credential's grant and every /// grant issued to an AUTH token, and nothing a request token earned: a token on one /// request never widens what tokenless requests may do. - #[moq_clock::test] + #[kio::test] async fn the_scope_is_session_tokens_only() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3285,7 +3285,7 @@ mod request_token_tests { } /// Revoking or dropping an AUTH token's grant takes it out of the scope. - #[moq_clock::test] + #[kio::test] async fn an_ended_auth_grant_leaves_the_scope() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3307,7 +3307,7 @@ mod request_token_tests { /// A session never authorized is bound by its origin handles alone, whatever its AUTH /// tokens were granted: the scope only exists once the connection credential has a grant. - #[moq_clock::test] + #[kio::test] async fn an_unauthorized_session_has_no_scope() { let handle = Link::new(true); let mut requests = handle.handle().requests(); @@ -3330,7 +3330,7 @@ mod request_token_tests { } /// The request grant carries the acceptor's expiry, which is the deadline it lapses at. - #[moq_clock::test] + #[kio::test] async fn a_request_grant_has_the_acceptors_expiry() { let runtime = crate::time::sim(); let handle = Link::new(true); @@ -3355,7 +3355,7 @@ mod request_token_tests { /// A grant that has already expired never admits the request or renews it, even for the /// moment before its deadline would fire. - #[moq_clock::test] + #[kio::test] async fn an_already_expired_grant_is_refused() { let runtime = crate::time::sim(); let handle = Link::new(true); @@ -3403,7 +3403,7 @@ mod request_token_tests { } /// An accepted REQUEST_UPDATE replaces the grant and its expiry. - #[moq_clock::test] + #[kio::test] async fn a_renewal_token_replaces_the_grant_and_expiry() { let runtime = crate::time::sim(); let handle = Link::new(true); @@ -3441,7 +3441,7 @@ mod request_token_tests { /// With no accepted renewal, the deadline ends the request as Expired, and the /// session is not closed by it. - #[moq_clock::test] + #[kio::test] async fn the_deadline_expires_the_request_without_renewal() { let runtime = crate::time::sim(); let handle = Link::new(true); @@ -3467,7 +3467,7 @@ mod request_token_tests { /// A renewal the acceptor granted before the old deadline lapsed keeps the request, even /// when the serve loop applies it only after the deadline. - #[moq_clock::test] + #[kio::test] async fn a_granted_renewal_outlives_the_old_deadline() { let runtime = crate::time::sim(); let handle = Link::new(true); @@ -3489,7 +3489,7 @@ mod request_token_tests { let second = grant_in(&runtime, 600); let second_expires = second.expires; let _issued2 = requests.next().await.unwrap().accept(second); - moq_clock::sleep(Duration::from_secs(61)).await; + kio::clock::sleep(Duration::from_secs(61)).await; let pending = kio::wait(|waiter| Poll::Ready(request_grant.poll_ended(waiter).is_pending())).await; assert!(pending, "the lapsed deadline ended a request whose renewal was granted"); @@ -3505,7 +3505,7 @@ mod request_token_tests { /// untouched and ends only when its own deadline lapses. The serve loops end the request on /// a refusal separately (a refused renewal ends only that request); this covers only that /// the grant object is not mutated. - #[moq_clock::test] + #[kio::test] async fn a_refused_renewal_leaves_the_grant() { let runtime = crate::time::sim(); let handle = Link::new(true); @@ -3551,7 +3551,7 @@ mod request_token_tests { /// An acceptor-side update that no longer covers the request ends it, even when the /// replacement has no expiry to lapse at; one that still covers it is folded in. - #[moq_clock::test] + #[kio::test] async fn an_update_that_stops_covering_ends_the_request() { let runtime = crate::time::sim(); let handle = Link::new(true); @@ -3575,7 +3575,7 @@ mod request_token_tests { assert!(pending, "a covering update keeps the request"); issued.update(Grant::default()); - let err = moq_clock::timeout( + let err = kio::clock::timeout( Duration::from_secs(1), kio::wait(|waiter| request_grant.poll_ended(waiter)), ) @@ -3634,7 +3634,7 @@ mod request_token_tests { /// An acceptor-side revoke ends the request before the deadline, and does not close the /// session. - #[moq_clock::test] + #[kio::test] async fn an_acceptor_revoke_ends_the_request() { let runtime = crate::time::sim(); let handle = Link::new(true); diff --git a/rs/moq-net/src/client.rs b/rs/moq-net/src/client.rs index 7a6b047d01b..06f8c90d440 100644 --- a/rs/moq-net/src/client.rs +++ b/rs/moq-net/src/client.rs @@ -830,8 +830,8 @@ mod tests { ); // Start the returned driver after the handshake completes. - let (_session, driver) = client.connect(moq_clock::now(), fake.clone()).await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + let (_session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); + kio::clock::sim::spawn(crate::time::run(driver)); // Verify the client offered every configured moq-lite version over the `moql` SETUP. let mut setup_bytes = Bytes::from(fake.control_writes()); @@ -865,7 +865,7 @@ mod tests { /// `connect` for the life of the session, since it waited for the initial announce /// set. Resolving a path you need is `routed`'s job, which waits for /// that path rather than for the peer to finish talking. - #[moq_clock::test] + #[kio::test] async fn connect_does_not_wait_for_the_peer_to_announce() { // Serves bidi streams, so the announce stream opens, and never answers on them. let gate = kio::Producer::new(true); @@ -880,9 +880,9 @@ mod tests { // Paused time auto-advances while every task is idle, so a `connect` that waits // on the silent peer trips this rather than hanging the suite. - let (_session, _driver) = moq_clock::timeout( + let (_session, _driver) = kio::clock::timeout( std::time::Duration::from_secs(30), - client.connect(moq_clock::now(), transport), + client.connect(kio::clock::now(), transport), ) .await .expect("connect waited on a peer that never announced") @@ -963,12 +963,12 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn alpn_lite_falls_back_to_moql_setup_and_switches_version_post_setup() { run_alpn_lite_fallback_case(Some(ALPN_LITE)).await; } - #[moq_clock::test] + #[kio::test] async fn no_alpn_falls_back_to_moql_setup_and_switches_version_post_setup() { run_alpn_lite_fallback_case(None).await; } @@ -1140,14 +1140,14 @@ mod tests { // `stats()` reads the machine's latest sample and primes the sampler, so a // periodic poller observes fresh counters without consuming the bandwidth // channel. - #[moq_clock::test] + #[kio::test] async fn stats_reads_prime_the_sampler() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); fake.set_send_rate(Some(1_000_000)); let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); - let (session, driver) = client.connect(moq_clock::now(), fake.clone()).await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); + kio::clock::sim::spawn(crate::time::run(driver)); // The construction-time snapshot, before the machine sampled anything. assert_eq!( @@ -1159,7 +1159,7 @@ mod tests { // so the new rate shows up within an interval (paused time auto-advances). fake.set_send_rate(Some(2_000_000)); while session.stats().estimated_send_rate != Some(crate::bandwidth::Rate::from_bps(2_000_000)) { - moq_clock::sleep(std::time::Duration::from_millis(10)).await; + kio::clock::sleep(std::time::Duration::from_millis(10)).await; } } @@ -1169,15 +1169,15 @@ mod tests { // the construction-time snapshot: this backend reports no send rate, so // there is no bandwidth consumer keeping the sampler ticking, and the test // never reads stats while the session is live. - #[moq_clock::test] + #[kio::test] async fn stats_capture_the_final_counters() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); fake.set_send_rate(None); fake.set_sent_bytes(0); let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); - let (session, driver) = client.connect(moq_clock::now(), fake.clone()).await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); + kio::clock::sim::spawn(crate::time::run(driver)); assert!( session.send_bandwidth().is_none(), "no send-rate estimate, so nothing samples on its own" @@ -1198,20 +1198,20 @@ mod tests { // The send-bandwidth sampler lives inside the driver: it samples as soon as a // consumer exists and keeps sampling on its interval. Simulated time makes // the interval fire deterministically. - #[moq_clock::test] + #[kio::test] async fn send_bandwidth_samples_while_the_driver_runs() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()); fake.set_send_rate(Some(1_000_000)); let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); - let (session, driver) = client.connect(moq_clock::now(), fake.clone()).await.unwrap(); + let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); let mut bandwidth = session.send_bandwidth().expect("backend reports an estimate"); assert_eq!( bandwidth.peek(), Some(crate::bandwidth::Rate::from_bps(1_000_000)), "the estimate is readable before the sampler first runs" ); - moq_clock::sim::spawn(crate::time::run(driver)); + kio::clock::sim::spawn(crate::time::run(driver)); assert_eq!( bandwidth.changed().await.unwrap(), @@ -1236,20 +1236,20 @@ mod tests { /// Run the driver until the sender's target reads `bps`. async fn probes_to(fake: &FakeSession, bps: u64) { while fake.probe_target() != bps { - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } } // The session probes for every reservation on its allocator, demanded or not: a // stopped rendition loses its viewers, and still has to be funded to resume. - #[moq_clock::test] + #[kio::test] async fn the_sender_probes_to_the_reservations() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()).with_probe(); fake.set_send_rate(Some(1_000_000)); let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); - let (session, driver) = client.connect(moq_clock::now(), fake.clone()).await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); + kio::clock::sim::spawn(crate::time::run(driver)); let bandwidth = session.allocator(); let (_watched_broadcast, watched) = reservable(); @@ -1272,12 +1272,12 @@ mod tests { // An override replaces the sum, zero turns probing off, and clearing it follows the // reservations again. - #[moq_clock::test] + #[kio::test] async fn an_override_replaces_the_reservations() { let fake = FakeSession::new(Some(ALPN_LITE_04), Vec::new()).with_probe(); let client = Client::new().with_versions(Version::Lite(lite::Version::Lite04).into()); - let (session, driver) = client.connect(moq_clock::now(), fake.clone()).await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + let (session, driver) = client.connect(kio::clock::now(), fake.clone()).await.unwrap(); + kio::clock::sim::spawn(crate::time::run(driver)); let bandwidth = session.allocator(); let (_broadcast, track) = reservable(); @@ -1296,7 +1296,7 @@ mod tests { // A reconnecting caller dials every session with one allocator, so a reservation // taken before the reconnect still moves the next session's target. - #[moq_clock::test] + #[kio::test] async fn a_reconnect_keeps_following_the_reservations() { let bandwidth = crate::bandwidth::Allocator::default(); let client = Client::new() @@ -1307,16 +1307,16 @@ mod tests { let reserved = bandwidth.reserve(&track.demand(), crate::bandwidth::Rate::from_bps(4_000_000)); let first = FakeSession::new(Some(ALPN_LITE_04), Vec::new()).with_probe(); - let (session, driver) = client.connect(moq_clock::now(), first.clone()).await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + let (session, driver) = client.connect(kio::clock::now(), first.clone()).await.unwrap(); + kio::clock::sim::spawn(crate::time::run(driver)); probes_to(&first, 4_000_000).await; session.abort(Error::Cancel); session.closed().await; drop(session); let second = FakeSession::new(Some(ALPN_LITE_04), Vec::new()).with_probe(); - let (_session, driver) = client.connect(moq_clock::now(), second.clone()).await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + let (_session, driver) = client.connect(kio::clock::now(), second.clone()).await.unwrap(); + kio::clock::sim::spawn(crate::time::run(driver)); probes_to(&second, 4_000_000).await; reserved.update(crate::bandwidth::Rate::from_bps(3_000_000)); diff --git a/rs/moq-net/src/coding/stream.rs b/rs/moq-net/src/coding/stream.rs index 7af38aaacbc..81a5c1a3401 100644 --- a/rs/moq-net/src/coding/stream.rs +++ b/rs/moq-net/src/coding/stream.rs @@ -166,7 +166,7 @@ mod tests { /// starves it: quinn schedules strictly by priority and round-robins only /// within a level, so a rank-0 group with bytes pending is enough to keep /// the scheduler from ever reaching the transport's default of 0. - #[moq_clock::test] + #[kio::test] async fn open_prioritises_the_stream() { let gate = kio::Producer::new(true); let mut session = SinkSession::gated_bi(gate.consume()); @@ -184,7 +184,7 @@ mod tests { /// The accepted half answers on the stream it was handed (track info, subscribe /// responses), so it needs the same order as one we opened. A fix that only /// covered `open` would leave every reply behind the media. - #[moq_clock::test] + #[kio::test] async fn accept_prioritises_the_stream() { let gate = kio::Producer::new(true); let mut session = SinkSession::accepted_bi(gate.consume()); diff --git a/rs/moq-net/src/coding/writer.rs b/rs/moq-net/src/coding/writer.rs index b7d08673cc7..a35bb0291c9 100644 --- a/rs/moq-net/src/coding/writer.rs +++ b/rs/moq-net/src/coding/writer.rs @@ -324,7 +324,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn raw_payload_stop_uses_the_negotiated_registry() { for (version, expected) in [ ( diff --git a/rs/moq-net/src/ietf/auth.rs b/rs/moq-net/src/ietf/auth.rs index e2d9d70888c..cb26a4f6ca1 100644 --- a/rs/moq-net/src/ietf/auth.rs +++ b/rs/moq-net/src/ietf/auth.rs @@ -595,7 +595,7 @@ mod tests { use crate::Pattern; #[cfg(feature = "async")] - #[moq_clock::test] + #[kio::test] async fn auth_refused_without_credit_spends_no_request_id() { for version in [Version::Draft18] { for client in [false, true] { diff --git a/rs/moq-net/src/ietf/peer.rs b/rs/moq-net/src/ietf/peer.rs index 415dc86825c..5150035d1fa 100644 --- a/rs/moq-net/src/ietf/peer.rs +++ b/rs/moq-net/src/ietf/peer.rs @@ -140,7 +140,7 @@ mod tests { /// The announce loops read the peer's declaration once and hold it, while /// subscription serving re-reads it. A second SETUP overwriting the identity would /// split those two apart, so the first write is the one that counts. - #[moq_clock::test] + #[kio::test] async fn first_write_wins() { let first = Peer { cluster: cluster::Peer { @@ -176,7 +176,7 @@ mod tests { } /// MoQ Epoch needs both sides: a peer declaring it to a side that declined leaves it off. - #[moq_clock::test] + #[kio::test] async fn epoch_needs_our_offer_too() { let declared = Peer { epoch: true, diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index f5d8396da80..66e80b5b16c 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -5867,7 +5867,7 @@ mod group_priority_test { use crate::ietf::priority; use crate::lite::test_transport::SinkSession; - #[moq_clock::test] + #[kio::test] async fn standalone_end_of_track_does_not_claim_end_of_group() { let log = crate::lite::test_transport::Log::default(); let session = SinkSession::new(log.clone()); @@ -5896,7 +5896,7 @@ mod group_priority_test { /// The standalone END_OF_TRACK stream ranks as the group it ends, not at the raw /// subscriber priority. - #[moq_clock::test] + #[kio::test] async fn standalone_end_of_track_ranks_as_its_group() { let log = crate::lite::test_transport::Log::default(); let queue = PriorityQueue::default(); @@ -5921,7 +5921,7 @@ mod group_priority_test { /// Cancelled while its FIN waits for the acknowledgement, a ranked stream resets as it /// gives up its rank, rather than sending on with a send order the queue has reused. - #[moq_clock::test] + #[kio::test] async fn a_ranked_stream_cancelled_after_its_fin_resets() { let log = crate::lite::test_transport::Log::default(); let queue = PriorityQueue::default(); @@ -5955,7 +5955,7 @@ mod group_priority_test { assert_eq!(rival.current(), 0, "and released its rank"); } - #[moq_clock::test] + #[kio::test] async fn exact_end_of_track_survives_the_final_group_fin() { use crate::lite::test_transport::Sent; for version in [Version::Draft18, Version::Draft22] { @@ -6020,7 +6020,7 @@ mod group_priority_test { /// An inline END_OF_TRACK spares the standalone marker only once its stream is /// acknowledged: a stream reset after its FIN may never deliver it. - #[moq_clock::test] + #[kio::test] async fn an_unacknowledged_inline_end_of_track_is_not_sent() { for acked in [true, false] { let mut session = SinkSession::new(Default::default()); @@ -6075,7 +6075,7 @@ mod group_priority_test { ); assert!(!terminal.sent.load(Ordering::Relaxed), "not until acknowledged"); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(crate::Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -6103,7 +6103,7 @@ mod group_priority_test { /// lower ones"), matching the transport trait's send order, so the higher-priority /// subscription's group stream must get the higher send order. An inversion here /// would transmit the LOWEST-priority track first under contention. - #[moq_clock::test] + #[kio::test] async fn group_stream_preserves_model_priority() { let log = crate::lite::test_transport::Log::default(); let queue = PriorityQueue::default(); @@ -6156,7 +6156,7 @@ mod group_priority_test { /// prefers when it has no subscriber preference to go on, so it has to reach the wire. /// It went out as a flat 0 before, which put catalog, audio, and video in one tier for /// every moq-transport peer. - #[moq_clock::test] + #[kio::test] async fn group_header_carries_the_publisher_priority() { let header = serve_group_header(track::Info::timed().with_priority(hang_audio_priority())).await; assert_eq!( @@ -6173,7 +6173,7 @@ mod group_priority_test { /// A track that never set a priority goes out at the midpoint, 127, one step off the /// draft's usual 128 so it mirrors moq-lite's 128, and not 255, the least urgent value a /// peer like moxygen would deprioritize. - #[moq_clock::test] + #[kio::test] async fn group_header_defaults_to_the_midpoint() { let header = serve_group_header(track::Info::timed()).await; assert_eq!(header.publisher_priority, 127); @@ -6227,7 +6227,7 @@ mod group_priority_test { } /// A track that always has another group ready yields within its budget. - #[moq_clock::test] + #[kio::test] async fn a_busy_track_yields_to_its_siblings() { /// `TrackServe`'s passes per poll; each starts at most one group. const BUDGET: usize = 32; @@ -6373,7 +6373,7 @@ mod group_priority_test { } /// A group with more objects ready than one poll's budget drains over several polls. - #[moq_clock::test] + #[kio::test] async fn a_long_group_drains_within_the_budget() { /// `GroupServe`'s passes per poll; each writes at most one object. const BUDGET: usize = 32; @@ -6461,14 +6461,14 @@ mod group_priority_test { async fn settle_serve(serve: &mut TrackServe) { for _ in 0..8 { let _ = serve.poll(&kio::Waiter::noop()); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } } /// A peer withholding stream credit makes each subscription hold one group machine, /// however many tracks it subscribes to and groups they publish: the backlog waits in the /// cache. Granting credit then serves every group still worth sending. - #[moq_clock::test] + #[kio::test] async fn withheld_credit_holds_one_group_machine_per_subscription() { for (tracks, groups) in [(1, 1), (1, 64), (16, 1), (16, 64)] { let gate = kio::Producer::new(false); @@ -6519,7 +6519,7 @@ mod group_priority_test { /// A group waiting for stream credit that the cache evicts leaves at once, rather than /// spending the credit on a reset once it arrives. The next group takes its place. - #[moq_clock::test] + #[kio::test] async fn an_evicted_group_waiting_for_credit_leaves_at_once() { let gate = kio::Producer::new(false); let track = track::Producer::new( @@ -6559,7 +6559,7 @@ mod group_priority_test { } /// A subgroup waiting for stream credit keeps its subscription expiry armed. - #[moq_clock::test] + #[kio::test] async fn group_waiting_for_stream_credit_expires() { let gate = kio::Producer::new(false); let session = SinkSession::gated_open_uni(gate.consume()); @@ -6595,7 +6595,7 @@ mod group_priority_test { "stream credit is exhausted" ); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(crate::Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -6606,7 +6606,7 @@ mod group_priority_test { /// A local group that never held the requested prefix fails rather than serving its /// tail as the whole group, with or without an end inside it. - #[moq_clock::test] + #[kio::test] async fn a_group_missing_its_prefix_fails() { for until in [None, Some(5)] { let track = track::Producer::new( @@ -6645,7 +6645,7 @@ mod group_priority_test { /// A FIN holds the subgroup's bytes until the peer acknowledges it, so a subgroup /// that goes stale while waiting still expires instead of pinning them. - #[moq_clock::test] + #[kio::test] async fn unacknowledged_fin_expires_with_the_group() { let session = SinkSession::new(Default::default()).with_unacked_fin(); let log = session.log.clone(); @@ -6682,7 +6682,7 @@ mod group_priority_test { ); assert!(log.resets().is_empty()); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(crate::Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -6693,7 +6693,7 @@ mod group_priority_test { } /// A stream parked on its FIN acknowledgement still follows each priority update. - #[moq_clock::test] + #[kio::test] async fn unacknowledged_fin_follows_priority_updates() { let session = SinkSession::new(Default::default()).with_unacked_fin(); let log = session.log.clone(); @@ -6744,7 +6744,7 @@ mod group_priority_test { } /// The final payload remains guarded after its frame has advanced the group cursor. - #[moq_clock::test] + #[kio::test] async fn blocked_final_transport_chunk_expires_with_the_group() { let gate = kio::Producer::new(true); let session = SinkSession::gated_uni(gate.consume()); @@ -6794,7 +6794,7 @@ mod group_priority_test { "the final byte is transport-blocked" ); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(crate::Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -6811,7 +6811,7 @@ mod subscribe_cursor_test { /// A group retention gives up on while a FETCH reads it is refused as too old, rather /// than answered with the prefix read so far. - #[moq_clock::test] + #[kio::test] async fn a_fetch_past_retention_is_refused_not_truncated() { let track = track::Producer::new( std::sync::Arc::new(crate::broadcast::Info::default()), @@ -6822,8 +6822,8 @@ mod subscribe_cursor_test { open.write_frame(crate::Timestamp::ZERO, b"a".to_vec()).unwrap(); let consumer = track.consume(); - let read = moq_clock::sim::spawn(async move { read_fetch(&consumer, 0, 0, None, 0, false).await.map(|_| ()) }); - moq_clock::sim::yield_now().await; + let read = kio::clock::sim::spawn(async move { read_fetch(&consumer, 0, 0, None, 0, false).await.map(|_| ()) }); + kio::clock::sim::yield_now().await; // The track runs a full second past the group's successor. for ms in [1000, 2000] { let mut group = track.append_group().unwrap(); @@ -6838,7 +6838,7 @@ mod subscribe_cursor_test { /// A subscription's cursor starts at the oldest cached group, so serving it verbatim /// replays every retained group at once, each on its own stream. Relays reject the burst /// and players skip straight back to the live edge, so the catch-up is pure waste. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_is_served_from_the_live_edge() { let log = Log::default(); let session = SinkSession::new(log.clone()); @@ -6881,7 +6881,7 @@ mod serve_tests { use crate::lite::test_transport::{Log, ScriptedSession, Sent, SinkSession}; use crate::model::ProduceTest; - #[moq_clock::test] + #[kio::test] async fn idle_advertisements_keep_reading_goaways() { let version = Version::Draft22; let session = ScriptedSession::new(vec![0x10, 0, 2, 0, 0]); @@ -6921,7 +6921,7 @@ mod serve_tests { assert_eq!(session.log.closes()[0].0, 0x03); } - #[moq_clock::test] + #[kio::test] async fn an_update_after_draft18_goaway_is_refused_without_closing_the_session() { let version = Version::Draft18; let h = serve(version); @@ -6960,7 +6960,7 @@ mod serve_tests { assert_eq!(body.message::(version).unwrap().error_code, 0x06); } - #[moq_clock::test] + #[kio::test] async fn a_subscription_keeps_its_goaway_count_until_the_final_marker() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -7082,7 +7082,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn requester_fin_is_version_gated_for_subscriptions() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -7127,7 +7127,7 @@ mod serve_tests { } /// A reset request stream still cancels the subscription on every draft. - #[moq_clock::test] + #[kio::test] async fn requester_reset_cancels_subscriptions() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -7157,7 +7157,7 @@ mod serve_tests { /// A close must count requests before their first poll and release them even /// when a dispatched task is cancelled or its message is refused. - #[moq_clock::test] + #[kio::test] async fn drain_counts_dispatched_subscribe_and_fetch() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -7231,7 +7231,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn subscription_update_applies_priority_without_ending_the_request() { let version = Version::Draft18; let h = serve(version); @@ -7267,7 +7267,7 @@ mod serve_tests { /// A priority update moves the group streams already in flight too, not only the /// ones opened after it. - #[moq_clock::test] + #[kio::test] async fn subscription_update_reprioritizes_open_group_streams() { let version = Version::Draft18; let h = serve(version); @@ -7426,13 +7426,13 @@ mod serve_tests { what: &str, ready: impl Fn() -> bool, ) { - moq_clock::timeout(std::time::Duration::from_secs(10), async { + kio::clock::timeout(std::time::Duration::from_secs(10), async { while !ready() { assert!( futures::poll!(serve.as_mut()).is_pending(), "the subscription ended before {what}" ); - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } }) .await @@ -7456,7 +7456,7 @@ mod serve_tests { /// A track error ends a draft-22 subscription while its group stream waits for the /// next object. The abort reaches the group, which resets its stream before /// PUBLISH_DONE(INTERNAL_ERROR) is sent. - #[moq_clock::test] + #[kio::test] async fn publish_done_after_a_track_error_follows_every_stream_close() { let version = Version::Draft22; let h = serve(version); @@ -7474,7 +7474,7 @@ mod serve_tests { .await; h.track.abort(Error::Transport("upstream failed".into())).unwrap(); - moq_clock::timeout(std::time::Duration::from_secs(10), serve) + kio::clock::timeout(std::time::Duration::from_secs(10), serve) .await .expect("the track error ends the subscription") .ok(); @@ -7490,7 +7490,7 @@ mod serve_tests { /// A subscription that runs to the track's end counts every data stream it opened, /// the fill and the END_OF_TRACK marker included, and closes each one before /// PUBLISH_DONE(TRACK_ENDED). - #[moq_clock::test] + #[kio::test] async fn publish_done_at_the_track_end_counts_and_follows_every_stream() { let version = Version::Draft22; let h = serve(version); @@ -7509,7 +7509,7 @@ mod serve_tests { group.finish().unwrap(); h.track.finish().unwrap(); - moq_clock::timeout(std::time::Duration::from_secs(10), serve) + kio::clock::timeout(std::time::Duration::from_secs(10), serve) .await .expect("the track's end ends the subscription") .unwrap(); @@ -7525,7 +7525,7 @@ mod serve_tests { /// A finished group's stream whose FIN is never acknowledged holds PUBLISH_DONE only until /// the group goes stale: its successor's arrival plus the budget, even under a budget past /// the cache window, which evicts both groups first. - #[moq_clock::test] + #[kio::test] async fn publish_done_waits_on_an_unacknowledged_fin_until_the_group_is_stale() { let version = Version::Draft22; let session = ScriptedSession::per_stream(vec![Vec::new()]).with_unacked_uni_fins(1); @@ -7541,7 +7541,7 @@ mod serve_tests { msg.max_age = Some(budget.as_millis() as u64); // `create_broadcast` registers the broadcast from a spawned task. - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), version) .await .unwrap(); @@ -7566,7 +7566,7 @@ mod serve_tests { let step = Duration::from_secs(1); async fn wait(mut serve: std::pin::Pin<&mut F>, seconds: u64) { for _ in 0..seconds { - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; assert!( futures::poll!(serve.as_mut()).is_pending(), "PUBLISH_DONE went out early" @@ -7588,8 +7588,8 @@ mod serve_tests { wait(serve.as_mut(), budget.as_secs() - 12).await; assert!(h.log.resets().is_empty()); - moq_clock::sim::advance(step).await; - moq_clock::timeout(step, serve) + kio::clock::sim::advance(step).await; + kio::clock::timeout(step, serve) .await .expect("the stale group releases PUBLISH_DONE") .unwrap(); @@ -7603,7 +7603,7 @@ mod serve_tests { /// A track that ends with an Unsupported error (a relay refusing a copy whose metadata /// changed does) ends its subscription with INTERNAL_ERROR: UPDATE_FAILED is only for an /// update the publisher could not apply. - #[moq_clock::test] + #[kio::test] async fn an_unsupported_track_error_is_not_a_failed_update() { let version = Version::Draft18; let h = serve(version); @@ -7685,7 +7685,7 @@ mod serve_tests { // REQUEST_UPDATE, Request ID 2, one NEW_GROUP_REQUEST (0x32) of 0. request.push(&[0x02, 0, 4, 2, 1, 0x32, 0x00]); - moq_clock::timeout(std::time::Duration::from_secs(10), serve) + kio::clock::timeout(std::time::Duration::from_secs(10), serve) .await .expect("the failed update ends the subscription") .ok(); @@ -7703,7 +7703,7 @@ mod serve_tests { wire } - #[moq_clock::test] + #[kio::test] async fn publish_done_after_a_failed_update_follows_every_stream_close() { fail_update_mid_flight(Version::Draft22) .await @@ -7712,7 +7712,7 @@ mod serve_tests { /// Draft-22 §9.9: Stream Count is every data stream the publisher opened, "including /// any fill fetch streams", or 2^64-1 when it can't be exact. - #[moq_clock::test] + #[kio::test] async fn publish_done_after_a_failed_update_counts_the_open_fill() { let wire = fail_update_mid_flight(Version::Draft22).await; let (_, count) = wire.publish_done.unwrap(); @@ -7746,7 +7746,7 @@ mod serve_tests { /// FORWARD=0 drops the subscription, and its upstream demand, while the request stays /// established; FORWARD=1 subscribes again as a new SUBSCRIBE would, at the live edge. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_pauses_and_resumes_as_a_new_subscriber() { for version in [Version::Draft22] { for start_paused in [false, true] { @@ -7808,7 +7808,7 @@ mod serve_tests { /// A resume joins as a new SUBSCRIBE would, so a joining FETCH after it is served from where /// the resume joined rather than refused as the pause left it. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_after_a_resume_is_served() { let version = Version::Draft18; let h = serve(version); @@ -7840,7 +7840,7 @@ mod serve_tests { /// A resume that cannot subscribe again fails its update: REQUEST_ERROR answers it, then /// PUBLISH_DONE says UPDATE_FAILED. - #[moq_clock::test] + #[kio::test] async fn a_failed_resume_answers_its_update() { for version in [Version::Draft22] { let h = serve(version); @@ -7859,7 +7859,7 @@ mod serve_tests { h.track.abort(Error::Transport("upstream failed".into())).unwrap(); request.push(&forward_update(version, 4, true)); - moq_clock::timeout(std::time::Duration::from_secs(10), serve) + kio::clock::timeout(std::time::Duration::from_secs(10), serve) .await .expect("the failed resume ends the subscription") .unwrap_err(); @@ -7924,7 +7924,7 @@ mod serve_tests { /// A SUBSCRIBE is a join, with or without NEW_GROUP_REQUEST: a track opted in to refresh /// wants the group past one over its ratio, and SUBSCRIBE_OK advertises DYNAMIC_GROUPS. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_joins_under_the_refresh_ratio() { for version in [Version::Draft22] { for refresh in [Some(1), None] { @@ -7953,7 +7953,7 @@ mod serve_tests { } /// An absolute filter has a fixed start, so its SUBSCRIBE is no join even over the ratio. - #[moq_clock::test] + #[kio::test] async fn an_absolute_subscribe_is_no_join() { let version = Version::Draft22; let h = serve_track(version, crate::track::Info::timed().with_refresh(1)); @@ -7975,7 +7975,7 @@ mod serve_tests { /// An absolute SUBSCRIBE carrying NEW_GROUP_REQUEST asks as an update would: past a group /// the track holds, it is a join under the ratio. - #[moq_clock::test] + #[kio::test] async fn an_absolute_subscribe_with_a_new_group_request_joins() { let version = Version::Draft22; for (value, wanted) in [(0, 5), (5, 5), (4, 0)] { @@ -8002,7 +8002,7 @@ mod serve_tests { /// An update's NEW_GROUP_REQUEST is a join on a track opted in to refresh, answered with /// REQUEST_OK. One naming a group the track holds asks nothing. - #[moq_clock::test] + #[kio::test] async fn a_new_group_update_joins_a_refreshing_track() { for version in [Version::Draft22] { for (value, wanted) in [(0, 5), (5, 5), (4, 0)] { @@ -8045,7 +8045,7 @@ mod serve_tests { /// A track without refresh cannot honor a NEW_GROUP_REQUEST update, which fails the /// subscription like any update it cannot apply. - #[moq_clock::test] + #[kio::test] async fn a_new_group_update_without_refresh_fails() { for version in [Version::Draft22] { let h = serve(version); @@ -8090,7 +8090,7 @@ mod serve_tests { /// An update's AUTHORIZATION TOKEN that this endpoint cannot use closes the session with /// the draft's code, as it would on the SUBSCRIBE, not only the subscription. - #[moq_clock::test] + #[kio::test] async fn an_update_token_that_cannot_be_used_closes_the_session() { for version in [Version::Draft22] { for (token, expected, why) in [ @@ -8162,7 +8162,7 @@ mod serve_tests { /// Distinct tokens are legal but refused NOT_SUPPORTED, /// since authorizing on one would ignore the rest. Either way the session stays open, and /// a single token is answered as usual. - #[moq_clock::test] + #[kio::test] async fn a_request_with_repeated_or_several_tokens_is_refused_alone() { for (version, malformed) in [(Version::Draft22, 0x4)] { let request = |tokens: &[&[u8]]| { @@ -8209,7 +8209,7 @@ mod serve_tests { /// An update whose tokens repeat is answered MALFORMED_AUTH_TOKEN rather than /// NOT_SUPPORTED, and one with several distinct tokens NOT_SUPPORTED. Either fails only its /// subscription. - #[moq_clock::test] + #[kio::test] async fn a_repeated_or_several_update_tokens_are_refused() { let other: &[u8] = &[0x03, 0x00, 0xBB]; for (version, tokens, code) in [ @@ -8264,7 +8264,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn subscription_track_property_filter_closes_the_session() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -8302,7 +8302,7 @@ mod serve_tests { } /// A source track failing to decode ends only the subscriptions it feeds, not the requester's session. - #[moq_clock::test] + #[kio::test] async fn source_decode_failure_keeps_the_session() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -8335,7 +8335,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn namespace_updates_do_not_postpone_an_auth_withdrawal() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -8377,7 +8377,7 @@ mod serve_tests { /// A refused namespace update waits for its REQUEST_ERROR to be acknowledged instead of /// letting the writer's drop reset discard it. - #[moq_clock::test] + #[kio::test] async fn refused_namespace_update_is_delivered_before_the_stream_ends() { let version = Version::Draft22; let h = serve(version); @@ -8413,7 +8413,7 @@ mod serve_tests { assert!(h.log.closes().is_empty(), "{version}: the session closed"); } - #[moq_clock::test] + #[kio::test] async fn namespace_updates_move_the_prefix_after_acknowledgement() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -8473,11 +8473,11 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn namespace_requester_fin_is_version_gated() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let session = ScriptedSession::per_stream_eof(vec![vec![]]); let stream = Stream::open(&mut crate::driver::Transport::new(session.clone()), version) .await @@ -8527,7 +8527,7 @@ mod serve_tests { async fn run_live(h: &mut Serve, msg: ietf::Subscribe<'static>) { // `create_broadcast` registers the broadcast from a spawned task, so yield to the // runtime before subscribing or the lookup 404s. - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; let session = h.session.clone(); let stream = Stream::open(&mut crate::driver::Transport::new(session.clone()), h.publisher.version) @@ -8553,7 +8553,7 @@ mod serve_tests { /// one re-authenticates instead of waiting for the announcement. The reply is encoded here rather than matched by code alone, so /// a value slipping outside the draft's table cannot pass, and the reason phrase is the /// origin's own, which is what carries a refusal the registry has no value for. - #[moq_clock::test] + #[kio::test] async fn a_missing_broadcast_is_refused_with_the_draft_s_code() { for version in [Version::Draft18, Version::Draft22] { let error_code = 0x10; @@ -8663,7 +8663,7 @@ mod serve_tests { /// MoQ Epoch pins SUBSCRIBE, FETCH and TRACK_STATUS to the instance they name: the /// broadcast under the path now being another instance, or one with no epoch at all, /// refuses them as gone instead of serving another instance's content. - #[moq_clock::test] + #[kio::test] async fn a_request_for_another_instance_is_refused() { for version in [Version::Draft22] { let served = crate::Epoch::mint(); @@ -8705,7 +8705,7 @@ mod serve_tests { /// A SUBSCRIBE pinned to a gone instance is refused as missing even when it asks to /// wait: an instance never comes back, so there is nothing to rendezvous with. - #[moq_clock::test] + #[kio::test] async fn a_pinned_request_never_waits_for_its_instance() { for version in [Version::Draft22] { let stale = crate::Epoch::mint(); @@ -8750,7 +8750,7 @@ mod serve_tests { /// An EPOCH on a request breaks a session that did not negotiate MoQ Epoch: the peer /// cannot have learned an instance it was never told about. - #[moq_clock::test] + #[kio::test] async fn an_epoch_without_the_extension_is_a_violation() { for version in [Version::Draft22] { let h = serve(version); @@ -8788,7 +8788,7 @@ mod serve_tests { /// TRACK_STATUS gets what a SUBSCRIBE_OK would carry, as far as each draft's answer has /// room, without subscribing to the track. INCLUDE_PROPERTIES=0 empties the properties. - #[moq_clock::test] + #[kio::test] async fn track_status_is_answered_on_every_draft() { for version in ALL_VERSIONS { for wanted in [true, false] { @@ -8796,7 +8796,7 @@ mod serve_tests { let mut group = h.track.create_group(group::Info { sequence: 4 }).unwrap(); group.write_frame(timestamp(), b"a".as_slice()).unwrap(); group.write_frame(timestamp(), b"b".as_slice()).unwrap(); - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), version) .await @@ -8841,7 +8841,7 @@ mod serve_tests { /// A TRACK_STATUS outside what the peer may subscribe to is refused before the track /// resolves, and one whose grant narrows while it resolves is refused too. - #[moq_clock::test] + #[kio::test] async fn track_status_outside_the_grant_is_refused() { let nothing = || crate::auth::Grant { publish: Default::default(), @@ -8859,7 +8859,7 @@ mod serve_tests { let auth = crate::auth::Link::new(false); auth.handle().authorize(¬hing()); h.publisher = h.publisher.clone().with_auth(auth); - let code = moq_clock::timeout( + let code = kio::clock::timeout( std::time::Duration::from_secs(1), answer_code(&h, track_status("live/cam", true, version), version), ) @@ -8915,7 +8915,7 @@ mod serve_tests { /// A request's USE_VALUE token decodes but grants nothing yet, so a TRACK_STATUS outside /// the session grant is still refused. - #[moq_clock::test] + #[kio::test] async fn a_request_token_does_not_widen_the_grant() { let nothing = crate::auth::Grant { publish: Default::default(), @@ -8940,7 +8940,7 @@ mod serve_tests { /// A TRACK_STATUS answer parked on its request stream when the grant narrows is reset, /// never delivered once the stream drains. - #[moq_clock::test] + #[kio::test] async fn track_status_narrowed_while_answering_is_reset() { for version in ALL_VERSIONS { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -8986,7 +8986,7 @@ mod serve_tests { )); for _ in 0..100 { assert!(futures::poll!(answer.as_mut()).is_pending(), "{version}: never parked"); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } auth.handle().authorize(&crate::auth::Grant { @@ -8999,7 +8999,7 @@ mod serve_tests { }; *writable = true; drop(writable); - let res = moq_clock::timeout(std::time::Duration::from_secs(1), answer) + let res = kio::clock::timeout(std::time::Duration::from_secs(1), answer) .await .unwrap_or_else(|_| panic!("{version}: still answering after the grant narrowed")); assert!(matches!(res, Err(Error::Unauthorized)), "{version}: {res:?}"); @@ -9045,7 +9045,7 @@ mod serve_tests { } /// A TRACK_STATUS for a broadcast we do not serve is refused as a SUBSCRIBE would be. - #[moq_clock::test] + #[kio::test] async fn track_status_for_a_missing_broadcast_is_refused() { for version in ALL_VERSIONS { let code = refusal(version, ietf::TrackStatus::ID, track_status("absent", true, version)).await; @@ -9056,7 +9056,7 @@ mod serve_tests { /// Opting out of SUBSCRIBE_OK's properties does not strip the objects' timestamps: /// their units come from TRACK_STATUS instead. - #[moq_clock::test] + #[kio::test] async fn the_properties_opt_out_keeps_object_timestamps() { let version = Version::Draft22; let stamp = crate::Timestamp::from_millis(123_456).unwrap(); @@ -9106,7 +9106,7 @@ mod serve_tests { ietf::RequestError::decode(&mut buf, version).unwrap().error_code } - #[moq_clock::test] + #[kio::test] async fn range_filters_over_the_default_limit_get_invalid_filter() { for version in [Version::Draft18, Version::Draft22] { let h = serve(version); @@ -9161,7 +9161,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn rendezvous_wait_is_capped_at_zero_but_answers_timeout() { for version in [Version::Draft18, Version::Draft22] { // A wait applies only to a missing publisher; a missing track on a live one does not exist. @@ -9191,7 +9191,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn reserved_namespace_requests_never_reach_the_application() { let version = Version::Draft22; for path in [".", "./child", ".session", ".session/extension"] { @@ -9222,7 +9222,7 @@ mod serve_tests { /// A namespace that overflows `Path::MAX_BYTES` under a deep root is refused per /// request, and the session stays open. - #[moq_clock::test] + #[kio::test] async fn a_namespace_too_long_under_the_root_is_refused_per_request() { for version in ALL_VERSIONS { let h = serve(version); @@ -9268,7 +9268,7 @@ mod serve_tests { /// Legal requests we don't serve are refused NOT_SUPPORTED one at a time, and the /// session stays open for the next one. - #[moq_clock::test] + #[kio::test] async fn legal_requests_we_do_not_serve_are_refused_per_request() { const NOT_SUPPORTED: u64 = 0x3; @@ -9323,7 +9323,7 @@ mod serve_tests { } /// A SUBSCRIBE_NAMESPACE always asks for namespaces, and gets NAMESPACE for each. - #[moq_clock::test] + #[kio::test] async fn subscribe_namespace_gets_namespaces() { let version = Version::Draft18; let h = serve(version); @@ -9378,7 +9378,7 @@ mod serve_tests { /// A Next Object or unfiltered join gives its current-group fill the head exactly /// once, while the subscription starts after that snapshot. - #[moq_clock::test] + #[kio::test] async fn canonical_join_serves_the_head_on_a_fetch_stream() { for filter in [Filter::NextObject, Filter::Unfiltered] { let mut h = serve(Version::Draft22); @@ -9420,7 +9420,7 @@ mod serve_tests { /// Narrowing an open subscription retires a group the new range excludes, whole or in /// part, before it forwards an object outside that range. - #[moq_clock::test] + #[kio::test] async fn narrowing_retires_an_open_live_group() { let narrowed = [ // The whole group falls below the new start. @@ -9442,7 +9442,7 @@ mod serve_tests { let h = serve(version); let mut group = h.track.create_group(group::Info { sequence: 1 }).unwrap(); group.write_frame(timestamp(), b"before-update".as_slice()).unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let mut request = ScriptedSession::new(Vec::new()); request.log = h.log.clone(); let stream = Stream::open(&mut crate::driver::Transport::new(request.clone()), version) @@ -9499,7 +9499,7 @@ mod serve_tests { /// Widening with a fill hands each remaining object of the current group to exactly one /// stream: the live stream for what it still covers, and a fill tail for the rest, /// including all of it once a narrowing retired the live stream. - #[moq_clock::test] + #[kio::test] async fn widening_with_a_fill_streams_the_current_group_once() { let open = Filter::Unfiltered; // The live stream stops after object 1, which the widening lifts. @@ -9526,7 +9526,7 @@ mod serve_tests { history.finish().unwrap(); let mut group = h.track.create_group(group::Info { sequence: 1 }).unwrap(); group.write_frame(timestamp(), b"before-update".as_slice()).unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let mut request = ScriptedSession::new(Vec::new()); request.log = h.log.clone(); let stream = Stream::open(&mut crate::driver::Transport::new(request.clone()), version) @@ -9593,7 +9593,7 @@ mod serve_tests { /// A fill-only update keeps a live join's floor, so a fill short of the live edge does not /// also hand the groups below that floor to the live cursor. - #[moq_clock::test] + #[kio::test] async fn a_fill_only_update_keeps_the_live_join_floor() { let version = Version::Draft22; let h = serve(version); @@ -9602,7 +9602,7 @@ mod serve_tests { history.finish().unwrap(); let mut group = h.track.create_group(group::Info { sequence: 1 }).unwrap(); group.write_frame(timestamp(), b"live".as_slice()).unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let mut request = ScriptedSession::new(Vec::new()); request.log = h.log.clone(); let stream = Stream::open(&mut crate::driver::Transport::new(request.clone()), version) @@ -9651,14 +9651,14 @@ mod serve_tests { } /// An independent historical fill never expands the subscription's live bounds. - #[moq_clock::test] + #[kio::test] async fn a_historical_update_fill_keeps_the_live_bounds() { for end in [None, Some(EndLocation { group: 0, object: None })] { let version = Version::Draft22; let h = serve(version); let mut group = h.track.create_group(group::Info { sequence: 1 }).unwrap(); group.write_frame(timestamp(), b"history".as_slice()).unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let mut request = ScriptedSession::new(Vec::new()); request.log = h.log.clone(); let stream = Stream::open(&mut crate::driver::Transport::new(request.clone()), version) @@ -9729,7 +9729,7 @@ mod serve_tests { /// moq-lite's own join over draft-22: Relative(1) names the start of the current /// group, so the cache replays the whole group on the subscription stream. - #[moq_clock::test] + #[kio::test] async fn relative_one_replays_the_current_group() { let mut h = serve(Version::Draft22); @@ -9749,7 +9749,7 @@ mod serve_tests { /// A Next Object subscription never receives the already-published head of the /// current group: everything below the snapshot is outside the requested range. - #[moq_clock::test] + #[kio::test] async fn next_object_does_not_replay_the_head() { let mut h = serve(Version::Draft22); @@ -9771,7 +9771,7 @@ mod serve_tests { } /// A fill spanning several groups carries every cached group on one fetch stream. - #[moq_clock::test] + #[kio::test] async fn a_multi_group_fill_serves_its_range() { let mut h = serve(Version::Draft22); @@ -9801,7 +9801,7 @@ mod serve_tests { /// A sparse fill follows its requested order, inherits the subscription's when /// omitted, and caps only the current group's head at the snapshot. - #[moq_clock::test] + #[kio::test] async fn a_multi_group_fill_obeys_order_and_object_bounds() { for order in [None, Some(GroupOrder::Ascending), Some(GroupOrder::Descending)] { let h = serve(Version::Draft22); @@ -9892,7 +9892,7 @@ mod serve_tests { /// A fill ranks as the group it fills, in its subscription's GROUP_ORDER, and follows /// that rank while it is open: the queue moving it, and its subscriber priority. - #[moq_clock::test] + #[kio::test] async fn a_fill_ranks_as_the_group_it_fills() { let h = serve(Version::Draft22); let mut group = h.track.create_group(group::Info { sequence: 4 }).unwrap(); @@ -9954,7 +9954,7 @@ mod serve_tests { /// A fill of the current group outranks the live stream carrying the rest of that group, /// which the subscriber cannot use without the fill's objects first. - #[moq_clock::test] + #[kio::test] async fn a_fill_outranks_the_rest_of_its_group() { let h = serve(Version::Draft22); let mut group = h.track.create_group(group::Info { sequence: 4 }).unwrap(); @@ -9989,7 +9989,7 @@ mod serve_tests { /// A standalone FETCH competes with group streams by its subscriber priority alone, its /// request id breaking ties, whatever group and GROUP_ORDER it asks for. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_ranks_by_its_priority() { for version in [Version::Draft22] { for (group, group_order) in [(1, GroupOrder::Ascending), (3, GroupOrder::Descending)] { @@ -10013,7 +10013,7 @@ mod serve_tests { /// A joining FETCH ranks as the group it fetches in the subscription it joins, not as a /// request of its own. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_ranks_in_its_subscription() { const LATEST: u64 = 5; @@ -10067,7 +10067,7 @@ mod serve_tests { /// Yield so the broadcast registered by `serve` is visible to the lookup. async fn settle() { - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } /// Fill the track with finished groups 0..=`latest`, so the live edge is a group past 0 @@ -10130,7 +10130,7 @@ mod serve_tests { /// FETCH returns the saved multi-object prefix, including empty objects, and excludes /// later objects that belong to the subscription. Decode the wire fields independently. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_is_answered_with_fetch_ok() { const LATEST: u64 = 5; @@ -10225,7 +10225,7 @@ mod serve_tests { } /// Dispatch order must not depend on which request task gets polled first. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_waits_for_its_dispatched_subscription() { let version = Version::Draft18; let mut h = serve(version); @@ -10257,7 +10257,7 @@ mod serve_tests { assert!(h.log.resets().is_empty()); } - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_waits_for_a_reordered_subscription() { let version = Version::Draft18; let mut h = serve(version); @@ -10289,7 +10289,7 @@ mod serve_tests { assert!(h.log.resets().is_empty()); } - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_wakes_when_its_pending_subscription_is_dropped() { for version in JOINING_DRAFTS { let h = serve(version); @@ -10322,7 +10322,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_times_out_an_unresolved_subscription() { let version = Version::Draft18; let h = serve(version); @@ -10351,7 +10351,7 @@ mod serve_tests { /// The group never held the promised prefix, so the fetch itself fails and the /// refusal carries that error: refused before FETCH_OK, and never reset. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_refuses_a_missing_prefix_before_fetch_ok() { let version = Version::Draft18; let h = serve(version); @@ -10388,7 +10388,7 @@ mod serve_tests { /// A joining FETCH reaching back past an evicted prefix group is refused, even when an /// earlier group it holds has as many objects as the prefix promised. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_refuses_a_prefix_group_it_lost() { let version = Version::Draft18; let h = serve(version); @@ -10442,7 +10442,7 @@ mod serve_tests { /// A joining FETCH that arrives after its subscription ended has no live edge to name, so /// it is refused rather than answered from a group that is no longer the edge of anything. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_without_its_subscription_is_refused() { for version in JOINING_DRAFTS { let mut h = serve(version); @@ -10464,7 +10464,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_rejects_unsupported_filters() { for version in JOINING_DRAFTS { for filter in [Filter::Unfiltered, Filter::Relative(0)] { @@ -10500,7 +10500,7 @@ mod serve_tests { /// A subscription that started on an empty track has no prefix to serve, so the /// fetch range is invalid on every draft that carries joining FETCH. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_rejects_an_empty_snapshot() { for version in JOINING_DRAFTS { let h = serve(version); @@ -10565,7 +10565,7 @@ mod serve_tests { run_fetch(h, fetch_type, group_order, true).await } - #[moq_clock::test] + #[kio::test] async fn a_cached_standalone_fetch_yields_while_writing() { for version in FETCH_DRAFTS { let h = serve(version); @@ -10578,7 +10578,7 @@ mod serve_tests { let done = std::rc::Rc::new(std::cell::Cell::new(false)); let saw_payload = std::rc::Rc::new(std::cell::Cell::new(false)); - let sibling = moq_clock::sim::spawn({ + let sibling = kio::clock::sim::spawn({ let done = done.clone(); let saw_payload = saw_payload.clone(); let log = h.log.clone(); @@ -10587,7 +10587,7 @@ mod serve_tests { if log.writes.lock().unwrap().len() > 1024 { saw_payload.set(true); } - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } } }); @@ -10721,7 +10721,7 @@ mod serve_tests { } /// A whole group is answered on one fetch stream. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_serves_one_whole_group() { for version in FETCH_DRAFTS { let mut h = serve(version); @@ -10751,7 +10751,7 @@ mod serve_tests { /// FETCH_OK carries the properties SUBSCRIBE_OK would, as far as each draft has room for /// them, and INCLUDE_PROPERTIES=0 empties the block. Either way the objects keep their /// Timestamps wherever the draft can declare their units. - #[moq_clock::test] + #[kio::test] async fn fetch_ok_carries_the_track_properties() { let info = track::Info { max_age: Some(Duration::from_secs(5)), @@ -10820,7 +10820,7 @@ mod serve_tests { /// Every answer describing the track forwards the properties moq-net does not interpret /// unchanged, beside the ones it does, on every draft with a Track Properties block. - #[moq_clock::test] + #[kio::test] async fn unknown_track_properties_are_forwarded() { for version in [Version::Draft22] { let upstream = unknown_properties(version); @@ -10877,7 +10877,7 @@ mod serve_tests { } /// Immutable Properties keep the bytes their publisher sealed. - #[moq_clock::test] + #[kio::test] async fn immutable_track_properties_keep_their_encoding() { // Sealed: OBJECT_DELIVERY_TIMEOUT = 42 and DYNAMIC_GROUPS = 1. let block = [0x0b, 4, 0x02, 42, 0x2e, 1]; @@ -10921,7 +10921,7 @@ mod serve_tests { /// that boundary as an object property does: dropped when mutable, refused when sealed. /// Drafts 18 and 22 serialize alike, so across a relay hop only the track's carried /// ingress draft says which meaning it has. - #[moq_clock::test] + #[kio::test] async fn track_property_0x06_does_not_cross_to_draft_22() { let upstream = |block: &[u8]| { let properties = @@ -10980,7 +10980,7 @@ mod serve_tests { /// A range ending inside its group stops at its End Object, which draft 22 counts /// inclusively and older drafts count as one past. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_stops_at_its_end_object() { for version in FETCH_DRAFTS { let mut h = serve(version); @@ -11004,7 +11004,7 @@ mod serve_tests { /// A group holding no objects at or past the start is answered empty, on draft 22 with /// an End Location covering the range asked for (section 9.11). The whole group covers /// at least its start. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_past_the_last_object_is_empty() { for version in FETCH_DRAFTS { for (end, covered) in [(0, 2), (6, 5)] { @@ -11093,7 +11093,7 @@ mod serve_tests { /// On draft 22, a start past Largest Object is refused INVALID_RANGE (section 9.11), /// wherever the publisher knows it. Where it does not, it answers empty. A start beyond /// the final group's last object still finds the track's end there. - #[moq_clock::test] + #[kio::test] async fn a_draft22_fetch_past_the_largest_object_is_refused() { let version = Version::Draft22; for largest in [ @@ -11142,7 +11142,7 @@ mod serve_tests { /// On a live feed whose newest group finished with no objects, Largest Object sits in the /// group before it, so a draft-22 FETCH of the empty group starts past it. - #[moq_clock::test] + #[kio::test] async fn a_draft22_fetch_of_an_empty_newest_group_is_refused() { let version = Version::Draft22; let mut h = serve(version); @@ -11164,7 +11164,7 @@ mod serve_tests { /// On draft 22, an End Object past a finished group's last object is still the End /// Location reported (section 10.14), even in the group holding Largest Object, unless /// the track ends there. - #[moq_clock::test] + #[kio::test] async fn a_draft22_fetch_past_a_group_end_reports_the_requested_end() { let version = Version::Draft22; for (group, largest, reported) in [ @@ -11203,7 +11203,7 @@ mod serve_tests { /// A fill that fails for a reason other than the group's absence refuses the whole range, /// rather than leaving the group out as though it did not exist. - #[moq_clock::test] + #[kio::test] async fn a_range_fetch_refuses_a_failed_fill() { for version in FETCH_DRAFTS { let h = serve(version); @@ -11233,7 +11233,7 @@ mod serve_tests { /// A track whose cache only ever answered a fetch has no live feed, so its newest /// object is not Largest Object: a draft-22 FETCH past it echoes the requested end. - #[moq_clock::test] + #[kio::test] async fn a_draft22_fetch_of_a_fetch_only_cache_is_not_capped() { let version = Version::Draft22; let h = serve(version); @@ -11262,7 +11262,7 @@ mod serve_tests { /// The last group of a finished track ends the response at its last object, with End /// of Track set. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_of_the_last_group_reports_the_end_of_track() { for version in FETCH_DRAFTS { let mut h = serve(version); @@ -11290,7 +11290,7 @@ mod serve_tests { /// A bounded range ending at the last object still reports the track's end; a /// shorter prefix must not claim that the track ends there. - #[moq_clock::test] + #[kio::test] async fn a_fetch_ending_at_the_final_object_reports_the_end_of_track() { for version in FETCH_DRAFTS { for end in [1, 2] { @@ -11317,7 +11317,7 @@ mod serve_tests { /// A draft-22 filter bounded by Largest Object resolves against it, starting past it only /// for Next Object. An idle copy resolves from its upstream report, and refuses /// a relative filter when it has not learned that report. - #[moq_clock::test] + #[kio::test] async fn a_draft22_fetch_relative_to_largest_object_resolves_against_it() { for version in [Version::Draft22] { for (filter, groups) in [ @@ -11372,7 +11372,7 @@ mod serve_tests { /// A range touching several groups is answered on one fetch stream in the order asked /// for, from its start object to its end object, without the groups that do not exist. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_serves_several_groups_in_order() { for version in FETCH_DRAFTS { for order in [GroupOrder::Ascending, GroupOrder::Descending] { @@ -11402,7 +11402,7 @@ mod serve_tests { /// A highest group that cannot be fetched is left out like any other, and the End Location /// names the last object sent rather than promising the group left out. - #[moq_clock::test] + #[kio::test] async fn a_fetch_skips_an_unfetchable_highest_group() { for version in FETCH_DRAFTS { let mut h = serve(version); @@ -11442,7 +11442,7 @@ mod serve_tests { /// A range reaching past a live track's Largest Object ends with its group, which it /// waits on until the group finishes rather than cutting it at the Largest Object, and /// never claims the track ends. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_waits_for_the_largest_object_group() { for version in FETCH_DRAFTS { let mut h = serve(version); @@ -11471,7 +11471,7 @@ mod serve_tests { } /// A range through a finished track's last object ends the track, wherever it starts. - #[moq_clock::test] + #[kio::test] async fn a_fetch_of_several_groups_through_the_final_object_reports_the_end_of_track() { for version in FETCH_DRAFTS { let mut h = serve(version); @@ -11495,7 +11495,7 @@ mod serve_tests { /// A whole End Group at the wire's limit is valid: a range from the first group stops at /// the track's end, and a missing single group is not found. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_through_the_maximum_group_is_capped() { for version in FETCH_DRAFTS { let maximum = u64::MAX; @@ -11539,7 +11539,7 @@ mod serve_tests { } /// A group that does not exist, below the newest one or past it, is refused. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_of_a_missing_group_is_refused() { for version in FETCH_DRAFTS { for missing in [2, 5] { @@ -11571,7 +11571,7 @@ mod serve_tests { /// A standalone FETCH outside what the peer may subscribe to is refused before it /// reaches the origin, and one whose grant narrows while its group loads is refused too. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_outside_the_grant_is_refused() { let unauthorized = |version| { crate::ietf::error::request::to_code( @@ -11623,7 +11623,7 @@ mod serve_tests { "{version}: served an unwritten group" ); auth.handle().authorize(¬hing); - let buf = moq_clock::timeout(std::time::Duration::from_secs(1), fetch) + let buf = kio::clock::timeout(std::time::Duration::from_secs(1), fetch) .await .unwrap_or_else(|_| panic!("{version}: still loading after the grant narrowed")); assert_eq!( @@ -11636,7 +11636,7 @@ mod serve_tests { /// A grant that narrows while a standalone FETCH waits on stream credit for its response /// stops it there: nothing it no longer may send reaches the wire. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_narrowed_while_responding_stops() { for version in FETCH_DRAFTS { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -11697,7 +11697,7 @@ mod serve_tests { if session.log.writes.lock().unwrap().len() > mark { break; } - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!( session.log.writes.lock().unwrap().len() > mark, @@ -11709,7 +11709,7 @@ mod serve_tests { subscribe: Default::default(), expires: None, }); - let res = moq_clock::timeout(std::time::Duration::from_secs(1), fetch) + let res = kio::clock::timeout(std::time::Duration::from_secs(1), fetch) .await .unwrap_or_else(|_| panic!("{version}: still responding after the grant narrowed")); assert!(matches!(res, Err(Error::Unauthorized)), "{version}: {res:?}"); @@ -11776,7 +11776,7 @@ mod serve_tests { if session.log.writes.lock().unwrap().len() > mark { break; } - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!( session.log.writes.lock().unwrap().len() > mark, @@ -11787,7 +11787,7 @@ mod serve_tests { /// A FETCH whose answer waits on an earlier group still being written, after FETCH_OK /// is out, ends when the subscriber cancels it rather than holding the group. - #[moq_clock::test] + #[kio::test] async fn a_fetch_cancelled_after_its_fetch_ok_stops_waiting() { use crate::lite::test_transport::Close; for version in FETCH_DRAFTS { @@ -11800,7 +11800,7 @@ mod serve_tests { /// A request stream carries at most one GOAWAY, counted across the whole FETCH: one /// before FETCH_OK and another after it close the session. - #[moq_clock::test] + #[kio::test] async fn a_fetch_counts_goaways_across_its_fetch_ok() { const GOAWAY: [u8; 5] = [0x10, 0, 2, 0, 0]; for version in [Version::Draft18, Version::Draft22] { @@ -11815,7 +11815,7 @@ mod serve_tests { /// A joining FETCH answers from its subscription's cache, which outlives the /// subscription, so it holds its own gate: one parked on stream credit when the grant /// narrows stops there, and nothing reaches the wire once credit returns. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_narrowed_while_responding_stops() { const PAYLOAD: &[u8] = b"joined-prefix"; @@ -11898,7 +11898,7 @@ mod serve_tests { if session.log.writes.lock().unwrap().len() > mark { break; } - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!( session.log.writes.lock().unwrap().len() > mark, @@ -11910,7 +11910,7 @@ mod serve_tests { subscribe: Default::default(), expires: None, }); - let res = moq_clock::timeout(std::time::Duration::from_secs(1), fetch) + let res = kio::clock::timeout(std::time::Duration::from_secs(1), fetch) .await .unwrap_or_else(|_| panic!("{version}: still responding after the grant narrowed")); assert!(matches!(res, Err(Error::Unauthorized)), "{version}: {res:?}"); @@ -11933,7 +11933,7 @@ mod serve_tests { /// A joining FETCH holds no authority of its own: revocation or dropping its parent /// ends it even while stream credit blocks the response after FETCH_OK. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_ends_with_its_subscription() { for (version, token) in JOINING_DRAFTS .into_iter() @@ -12025,7 +12025,7 @@ mod serve_tests { if session.log.writes.lock().unwrap().len() > mark { break; } - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!( session.log.writes.lock().unwrap().len() > mark, @@ -12034,7 +12034,7 @@ mod serve_tests { if let Some(enforced) = enforced { enforced.revoke(crate::SessionError::Unauthorized, "revoked"); - let _ = moq_clock::timeout(std::time::Duration::from_secs(1), subscription.as_mut()) + let _ = kio::clock::timeout(std::time::Duration::from_secs(1), subscription.as_mut()) .await .unwrap_or_else(|_| panic!("{version}: the revoked subscription kept serving")); } else { @@ -12042,7 +12042,7 @@ mod serve_tests { drop(subscription); } - let res = moq_clock::timeout(std::time::Duration::from_secs(1), fetch) + let res = kio::clock::timeout(std::time::Duration::from_secs(1), fetch) .await .unwrap_or_else(|_| panic!("{version}: the fetch outlived its subscription")); assert!(matches!(res, Err(Error::Unauthorized)), "{version}: {res:?}"); @@ -12064,7 +12064,7 @@ mod serve_tests { /// A token subscription's grant ending ends it at every await, setup and teardown /// included, not only while it serves: what it holds upstream is released first, and the /// peer is then told as far as it got, refused before SUBSCRIBE_OK and done after it. - #[moq_clock::test] + #[kio::test] async fn a_revoked_token_ends_a_subscription_wherever_it_waits() { for version in ALL_VERSIONS { for parked in [Parked::Resolving, Parked::Acking, Parked::Ending] { @@ -12181,7 +12181,7 @@ mod serve_tests { *writable = true; drop(writable); } - let _ = moq_clock::timeout(std::time::Duration::from_secs(1), subscription.as_mut()) + let _ = kio::clock::timeout(std::time::Duration::from_secs(1), subscription.as_mut()) .await .unwrap_or_else(|_| panic!("{version} {parked:?}: outlived its grant")); @@ -12218,7 +12218,7 @@ mod serve_tests { /// A subscriber withdrawing a SUBSCRIBE while its setup waits on a producer that never /// answers ends it at once: its demand and its slot are given back, and nothing answers it. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_withdrawn_during_setup_releases_its_demand() { for version in ALL_VERSIONS { for setup in [Setup::Resolving, Setup::Subscribing, Setup::Live] { @@ -12228,7 +12228,7 @@ mod serve_tests { } /// Broadcast resolution cannot hold a withdrawn FETCH or TRACK_STATUS alive. - #[moq_clock::test] + #[kio::test] async fn requests_withdrawn_while_resolving_release_their_demand() { for version in ALL_VERSIONS { for kind in [request::Kind::Fetch, request::Kind::TrackStatus] { @@ -12365,7 +12365,7 @@ mod serve_tests { assert_eq!(demanded(), !matches!(setup, Setup::Resolving), "{version} {setup:?}"); withdraw(&request, version); - let res = moq_clock::timeout(std::time::Duration::from_secs(1), serving) + let res = kio::clock::timeout(std::time::Duration::from_secs(1), serving) .await .unwrap_or_else(|_| panic!("{version} {setup:?}: outlived its withdrawal")); assert!(res.is_ok(), "{version} {setup:?}: {res:?}"); @@ -12381,7 +12381,7 @@ mod serve_tests { /// A resume subscribes again as a new SUBSCRIBE does, so a subscriber withdrawing the /// request while the resume waits on an idle copy's live edge ends it at once too. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_withdrawn_while_resuming_releases_its_demand() { for version in ALL_VERSIONS { let mut h = serve(version); @@ -12410,7 +12410,7 @@ mod serve_tests { } withdraw(&request, version); - moq_clock::timeout(std::time::Duration::from_secs(1), serve) + kio::clock::timeout(std::time::Duration::from_secs(1), serve) .await .unwrap_or_else(|_| panic!("{version}: outlived its withdrawal")) .unwrap(); @@ -12421,7 +12421,7 @@ mod serve_tests { /// A datagram group is never fetchable: a FETCH for one is refused like a group that /// does not exist, newest or not, and opens no fetch stream for its payload. - #[moq_clock::test] + #[kio::test] async fn a_standalone_fetch_of_a_datagram_group_is_refused() { for version in FETCH_DRAFTS { for newest in [true, false] { @@ -12449,7 +12449,7 @@ mod serve_tests { /// A joining FETCH reaching back before the subscription's group is answered whole up to /// where the subscription starts. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_reaching_back_is_served() { for version in JOINING_DRAFTS { let mut h = serve(version); @@ -12517,7 +12517,7 @@ mod serve_tests { } /// An absolute joining FETCH starting past the subscription's group names an empty range. - #[moq_clock::test] + #[kio::test] async fn an_absolute_joining_fetch_past_the_subscription_is_refused() { let version = Version::Draft18; let mut h = serve(version); @@ -12563,7 +12563,7 @@ mod serve_tests { } /// A fill against an empty track has an empty range: no fetch stream is owed. - #[moq_clock::test] + #[kio::test] async fn an_empty_track_opens_no_fill_stream() { let mut h = serve(Version::Draft22); @@ -12611,7 +12611,7 @@ mod serve_tests { /// SUBSCRIBE_OK announces the publisher's default order, newest first, whatever the /// subscription asked for. - #[moq_clock::test] + #[kio::test] async fn subscribe_ok_announces_the_default_order() { for version in [Version::Draft18, Version::Draft22] { for requested in [GroupOrder::Ascending, GroupOrder::Descending, GroupOrder::Any] { @@ -12636,7 +12636,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn largest_object_is_the_live_edge_before_draft22() { for version in [Version::Draft18] { assert_eq!( @@ -12647,7 +12647,7 @@ mod serve_tests { } } - #[moq_clock::test] + #[kio::test] async fn largest_object_is_the_live_edge_on_draft22() { assert_eq!( subscribe_ok_largest(Version::Draft22).await, @@ -12659,7 +12659,7 @@ mod serve_tests { /// The filter's object bounds trim what `run_group` writes: the skipped head is not /// sent, the first written object's delta is its absolute id, and a capped tail stops /// early. Extensions are off so the wire is just deltas, sizes, and payloads. - #[moq_clock::test] + #[kio::test] async fn run_group_honors_the_slice() { fn header() -> ietf::GroupHeader { ietf::GroupHeader { @@ -12730,7 +12730,7 @@ mod serve_tests { /// A stream cut short by the range's end Location does not claim END_OF_GROUP, since /// the group goes on past it. A range ending on a whole group still does. A cap at or past /// the group's real end clears the bit too, since the header is written before we know. - #[moq_clock::test] + #[kio::test] async fn capped_group_does_not_claim_its_end() { async fn serve(object: Option) -> ietf::GroupHeader { let log = crate::lite::test_transport::Log::default(); @@ -12925,7 +12925,7 @@ mod serve_tests { /// subscription alive past the old grant's expiry: the reader re-verifies the token off /// the subscribe stream and re-arms the deadline. Proven against the deadline the /// original grant would otherwise have lapsed at. - #[moq_clock::test] + #[kio::test] async fn a_request_update_renews_a_token_subscription_past_the_old_expiry() { const VERSION: Version = Version::Draft18; @@ -12987,7 +12987,7 @@ mod serve_tests { // Past the original 60s expiry: the renewal re-armed the deadline, so the // subscription lives on. - moq_clock::sim::advance(Duration::from_secs(120)).await; + kio::clock::sim::advance(Duration::from_secs(120)).await; for _ in 0..50 { let _ = futures::poll!(acceptor.as_mut()); assert!( @@ -13000,7 +13000,7 @@ mod serve_tests { /// A pause is answered before a renewal riding it could be verified, so an update carrying /// both fails instead of acknowledging a token nobody checked. - #[moq_clock::test] + #[kio::test] async fn a_pause_carrying_a_token_fails_the_update() { for version in [Version::Draft18] { let (auth, mut requests, _cred) = auth_covering_other(); @@ -13091,7 +13091,7 @@ mod serve_tests { /// verified and answered, not collapsed. The loop keeps per-update state while a verify is /// pending (draft-18 section 10.9.1 answers each update); the single slot it replaced /// dropped the middle renewal (0x42) entirely, so its token was never verified. - #[moq_clock::test] + #[kio::test] async fn two_renewals_buffered_behind_a_pending_verdict_each_get_a_verdict() { const VERSION: Version = Version::Draft18; @@ -13162,7 +13162,7 @@ mod serve_tests { /// Draft-22 advertises MAX_REQUEST_UPDATES, so a peer that leaves more outstanding than that /// broke the negotiated limit: draft-22 section 9.1.7 closes the session with /// TOO_MANY_REQUEST_UPDATES. - #[moq_clock::test] + #[kio::test] async fn renewals_past_the_advertised_limit_close_the_session() { const VERSION: Version = Version::Draft22; @@ -13218,7 +13218,7 @@ mod serve_tests { /// Exactly MAX_REQUEST_UPDATES outstanding (the one being verified plus the queue) is within /// the advertised limit, so a draft-22 peer holding that many is not faulted: the request /// keeps running and the session stays up. - #[moq_clock::test] + #[kio::test] async fn renewals_at_the_advertised_limit_keep_the_request() { const VERSION: Version = Version::Draft18; @@ -13267,7 +13267,7 @@ mod serve_tests { /// Drafts below 19 carry no MAX_REQUEST_UPDATES option, so a peer there agreed to no ceiling: /// the same flood that closes a draft-22 session must neither end the request nor close the /// session on draft-18, because a conforming peer must not be stranded for a limit it never saw. - #[moq_clock::test] + #[kio::test] async fn older_drafts_do_not_strand_a_renewal_flood() { const VERSION: Version = Version::Draft18; @@ -13311,7 +13311,7 @@ mod serve_tests { /// answer restores one MAX_REQUEST_UPDATES credit. A peer that only sends token-less priority /// updates must keep its credit so it can still renew, so each gets a REQUEST_OK and the /// session stays up well past the advertised limit. - #[moq_clock::test] + #[kio::test] async fn token_less_updates_are_each_acknowledged() { const VERSION: Version = Version::Draft18; @@ -13388,7 +13388,7 @@ mod serve_tests { /// renewal, never before it: an answer names no Request ID, so its order is /// all that ties it to its update. The renewal is refused, so its REQUEST_ERROR is the first /// answer either way, and the token-less update behind it is never answered ahead of it. - #[moq_clock::test] + #[kio::test] async fn an_update_behind_a_pending_renewal_is_answered_in_order() { for version in [Version::Draft18] { let (auth, mut requests, _cred) = auth_covering_other(); @@ -13453,7 +13453,7 @@ mod serve_tests { /// On drafts without the option the guard is a memory backstop, not a protocol limit: a flood /// past it ends the one request through PUBLISH_DONE, never the session. - #[moq_clock::test] + #[kio::test] async fn an_older_draft_flood_past_the_guard_ends_the_request() { const VERSION: Version = Version::Draft18; @@ -13500,7 +13500,7 @@ mod serve_tests { /// too: with a grant that never expires and an acceptor sitting on the renewal, the stream /// closing drops the subscription's demand at once. The request keeps its stream, and so its /// credit, until the acceptor lets go of the renewal. - #[moq_clock::test] + #[kio::test] async fn a_closed_subscription_ends_while_a_renewal_is_pending() { const VERSION: Version = Version::Draft18; @@ -13588,7 +13588,7 @@ mod serve_tests { /// A REQUEST_UPDATE the acceptor refuses ends only that subscription, at once, through the /// PUBLISH_DONE UPDATE_FAILED path (draft-18 section 10.9.1). The old /// grant does not keep it alive to its 60s expiry, and the session stays up. - #[moq_clock::test] + #[kio::test] async fn a_refused_request_update_ends_the_subscription() { const VERSION: Version = Version::Draft18; @@ -13663,7 +13663,7 @@ mod serve_tests { /// A slow acceptor answering a renewal must not stall serving nor let the request outlive /// its grant: the renewal verify is raced against the old deadline, which still fires and /// sends PUBLISH_DONE. The stream keeps its credit until the acceptor lets go of the renewal. - #[moq_clock::test] + #[kio::test] async fn a_slow_renewal_does_not_stall_serving() { const VERSION: Version = Version::Draft18; let (auth, mut requests, _cred) = auth_covering_other(); @@ -13713,7 +13713,7 @@ mod serve_tests { // The acceptor is stuck. Past the old 60s expiry the deadline must still fire and end // the request EXPIRED, rather than the pending renewal stalling serving. - moq_clock::sim::advance(Duration::from_secs(120)).await; + kio::clock::sim::advance(Duration::from_secs(120)).await; let done = { let log = Log::default(); let mut writer = crate::coding::Writer::new( @@ -13767,7 +13767,7 @@ mod serve_tests { /// Publisher / SUBSCRIBE side: on a session without the AUTH extension the union is /// `None` forever. A token-bearing SUBSCRIBE the limit does not cover is verified by the /// application, not admitted by the permissive union. - #[moq_clock::test] + #[kio::test] async fn a_request_token_on_a_no_auth_session_is_verified() { const VERSION: Version = Version::Draft18; let auth = crate::auth::Link::new(false); @@ -13869,7 +13869,7 @@ mod serve_tests { /// A subscriber's token grant is checked on its `subscribe` patterns: a write-only grant /// does not admit a SUBSCRIBE, a read-only one does. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_token_needs_a_subscribe_grant() { let read_only = crate::auth::Grant { publish: crate::Patterns::new(), @@ -13890,7 +13890,7 @@ mod serve_tests { /// A request token stands in for the limit this side set on the peer, so a SUBSCRIBE the /// limit refuses is admitted on the token and a later narrowing leaves it standing. - #[moq_clock::test] + #[kio::test] async fn a_request_token_stands_in_for_the_local_limit() { let nothing = Some(crate::auth::Grant::default()); let (auth, _h, mut serving) = serve_token_subscribe(crate::auth::Grant::all(), nothing).await; @@ -13912,7 +13912,7 @@ mod serve_tests { /// What the peer's AUTH_OK grants us never authorizes what the peer asks of us: with a /// covering peer grant and no limit, the application still verifies the SUBSCRIBE's token, /// and its refusal refuses the subscription. - #[moq_clock::test] + #[kio::test] async fn a_covering_peer_grant_never_skips_the_verifier() { const VERSION: Version = Version::Draft18; let auth = crate::auth::Link::new(true); @@ -13952,7 +13952,7 @@ mod serve_tests { /// Every token is verified, even on a SUBSCRIBE the limit already covers: the verifier /// refusing it refuses the subscription, and one it grants stands outside the limit, so /// narrowing the limit away from it leaves the subscription its token admitted. - #[moq_clock::test] + #[kio::test] async fn a_covering_limit_still_verifies_the_token() { let limit = |subtree: &str| crate::auth::Grant { publish: crate::Patterns::new(), @@ -13976,7 +13976,7 @@ mod serve_tests { /// Where tokens decide, a token arriving on an update for a subscription admitted without /// one is refused NOT_SUPPORTED rather than taken unread, failing only that subscription. - #[moq_clock::test] + #[kio::test] async fn a_token_on_a_subscription_admitted_without_one_is_refused() { for version in [Version::Draft22] { let auth = crate::auth::Link::new(false); @@ -14031,7 +14031,7 @@ mod serve_tests { /// With no verifier, a limited session refuses a token as unsupported rather than /// unauthorized, even one its limit covers, and a session never limited ignores the token. - #[moq_clock::test] + #[kio::test] async fn a_token_without_a_verifier_is_unsupported() { const VERSION: Version = Version::Draft18; for limit in [crate::auth::Grant::default(), crate::auth::Grant::all()] { @@ -14098,7 +14098,7 @@ mod serve_tests { /// A token waiting on the application holds the subscription's slot. Withdrawn while still /// queued it gives the slot back at once; once the application took it, the slot stays /// counted until the application answers, and that late answer authorizes nothing. - #[moq_clock::test] + #[kio::test] async fn a_stalled_verification_holds_the_subscription_slot() { const VERSION: Version = Version::Draft18; @@ -14167,7 +14167,7 @@ mod serve_tests { /// A peer that cancels a SUBSCRIBE whose token the application took keeps the request's /// stream, and so its credit, until the application answers: cancelling and resubscribing /// cannot leave more verifications in flight than the peer's credit admits. - #[moq_clock::test] + #[kio::test] async fn a_cancelled_subscribe_keeps_its_stream_until_the_application_answers() { const VERSION: Version = Version::Draft18; let auth = crate::auth::Link::new(false); @@ -14213,7 +14213,7 @@ mod serve_tests { /// What the peer granted us bounds what we send, so a request token never admits a /// SUBSCRIBE outside it, and the application is not even asked. - #[moq_clock::test] + #[kio::test] async fn a_request_token_cannot_exceed_the_peers_grant() { const VERSION: Version = Version::Draft18; let auth = crate::auth::Link::new(true); @@ -14276,7 +14276,7 @@ mod tests { use futures::FutureExt; async fn settle() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } fn occurrences(log: &crate::lite::test_transport::Log, needle: &[u8]) -> usize { @@ -14402,7 +14402,7 @@ mod tests { /// (`Client::with_peer_hop`) is never advertised to that peer; it would only /// echo the peer's own content back at it. A broadcast with an independent /// route still is. - #[moq_clock::test] + #[kio::test] async fn assigned_peer_hop_filters_echoed_announces() { let assigned = crate::Hop::new(777).unwrap(); let (publisher, consumer, _routes) = echo_harness(assigned).await; @@ -14420,7 +14420,7 @@ mod tests { /// An anonymous chain received from an identified peer keeps the 0 on the wire /// and is never advertised back to that session: split-horizon matches `via` /// as well as the chain. - #[moq_clock::test] + #[kio::test] async fn anonymous_chain_is_forwarded_with_zero_and_not_echoed() { let assigned = crate::Hop::new(777).unwrap(); let r1 = crate::Hop::new(9).unwrap(); @@ -14464,7 +14464,7 @@ mod tests { /// negotiated peer always sends its own HOP_PATH, so a route attributed to the /// assigned identity is a state this peer class cannot reach; see /// [`a_declared_zero_chain_is_not_advertised_back`] for what it gets instead. - #[moq_clock::test] + #[kio::test] async fn withheld_peer_hop_falls_back_to_assigned() { let assigned = crate::Hop::new(777).unwrap(); let declared = crate::Hop::new(9).unwrap(); @@ -14491,7 +14491,7 @@ mod tests { /// and one that declared 0 names itself 0 there. An arriving chain is not rewritten, /// so the route carries 0; the assigned identity stays on `via` and split-horizon /// matches it, so the peer is not advertised its own route back. - #[moq_clock::test] + #[kio::test] async fn a_declared_zero_chain_is_not_advertised_back() { let assigned = crate::Hop::new(777).unwrap(); let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -14529,7 +14529,7 @@ mod tests { /// MoQ Active Count: the OK counts exactly the NAMESPACE messages that follow it, /// so a route this peer is never told about is not counted either. Counting one would /// leave the peer waiting on a message that never comes. - #[moq_clock::test] + #[kio::test] async fn the_ok_counts_only_what_is_advertised() { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -14606,7 +14606,7 @@ mod tests { /// without an origin-level (un)announce, silently flipping `advertisable`. /// Namespace forwarding must follow: advertise when a clean route appears, /// withdraw when the last one detaches. - #[moq_clock::test] + #[kio::test] async fn namespace_follows_route_eligibility_changes() { let assigned = crate::Hop::new(777).unwrap(); let clean_publisher = crate::Hop::new(778).unwrap(); @@ -14709,7 +14709,7 @@ mod tests { /// A peer that refuses an advertisement with a retry interval of 0 is asking not to be /// offered it again. Coming back anyway turns a permanent refusal (unauthorized, /// uninterested) into a request every few seconds for the life of the session. - #[moq_clock::test] + #[kio::test] async fn a_refusal_that_forbids_retrying_is_not_retried() { const VERSION: Version = Version::Draft18; @@ -14761,7 +14761,7 @@ mod tests { /// withdraws the old, and only once the peer accepted it, since the two streams are /// unordered. The peer never sees the namespace absent. A peer without the extension /// cannot tell the two apart, so it still sees the old one withdrawn first. - #[moq_clock::test] + #[kio::test] async fn another_epoch_is_advertised_before_the_old_is_withdrawn() { use crate::lite::test_transport::Sent; const VERSION: Version = Version::Draft18; @@ -14864,7 +14864,7 @@ mod tests { /// A peer that declared nothing is told without being asked. Relays that never send /// SUBSCRIBE_NAMESPACE hear nothing otherwise, and every third-party one behaves /// that way: a publisher is expected to announce itself. - #[moq_clock::test] + #[kio::test] async fn a_peer_that_declared_nothing_is_told_unsolicited() { const VERSION: Version = Version::Draft18; @@ -14909,7 +14909,7 @@ mod tests { /// A PUBLISH_NAMESPACE is withdrawn by cancelling its request: reset /// plus STOP_SENDING. A FIN there is a protocol violation some peers close on. - #[moq_clock::test] + #[kio::test] async fn publish_namespace_withdraws_by_reset() { for version in [Version::Draft18, Version::Draft22] { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -14972,7 +14972,7 @@ mod tests { /// ACTIVE_COUNT only answers SUBSCRIBE_NAMESPACE (MoQ Active Count), so one on the OK /// to a PUBLISH_NAMESPACE is the peer breaking the extension, negotiated or not. - #[moq_clock::test] + #[kio::test] async fn a_counted_publish_namespace_ok_is_a_violation() { const VERSION: Version = Version::Draft18; @@ -15012,7 +15012,7 @@ mod tests { VERSION, ); - let res = moq_clock::timeout(Duration::from_secs(5), publisher.run_publish_namespaces()) + let res = kio::clock::timeout(Duration::from_secs(5), publisher.run_publish_namespaces()) .await .expect("the violation ends the loop"); assert!(matches!(res, Err(Error::ProtocolViolation)), "{res:?}"); @@ -15134,7 +15134,7 @@ mod tests { /// segment. The subscription also repeats every visible /// namespace the unsolicited loop already sent. A NAMESPACE is discovery, not /// a second route. - #[moq_clock::test] + #[kio::test] async fn hidden_namespaces_need_an_opt_in() { for (solicit, prefix, hidden, cam, stats) in [ (Some(false), "", false, 2, 0), @@ -15158,7 +15158,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn hidden_discovery_obeys_peer_setup_and_requested_prefix() { for version in [Version::Draft18, Version::Draft22] { for declared in [false, true] { @@ -15196,7 +15196,7 @@ mod tests { /// unsolicited PUBLISH_NAMESPACE and a NAMESPACE on the SUBSCRIBE_NAMESPACE stream. /// Those are two discoveries of one namespace, not two routes. A peer that asked to /// be solicited hears it only on the stream. - #[moq_clock::test] + #[kio::test] async fn a_non_solicit_peer_hears_a_namespace_both_ways() { let (times, streams) = advertise_both_ways(Some(false)).await; assert_eq!(times, 2, "PUBLISH_NAMESPACE and NAMESPACE"); @@ -15210,7 +15210,7 @@ mod tests { /// A peer that did not send SOLICIT still gets NAMESPACE on its SUBSCRIBE_NAMESPACE /// stream: one for a match that already exists, one announced /// after, then NAMESPACE_DONE when that announcement ends. - #[moq_clock::test] + #[kio::test] async fn a_non_solicit_subscribe_namespace_carries_namespace() { for version in [Version::Draft18] { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -15299,7 +15299,7 @@ mod tests { /// Send capacity can park an admitted stream's header. That must not wedge the loop: /// withdrawals queued behind it still need to progress. A withdrawal ends its request's /// own stream, which needs no new open, so it is visible while every open is blocked. - #[moq_clock::test] + #[kio::test] async fn a_parked_open_still_lets_a_namespace_be_withdrawn() { const VERSION: Version = Version::Draft18; @@ -15380,7 +15380,7 @@ mod tests { /// A namespace nobody can advertise any more is not pending, whatever happened before. /// `deferred` outliving the want would arm the retry timer forever for a wire message /// that can never happen: not a spin, but a session that never sleeps. - #[moq_clock::test] + #[kio::test] async fn a_namespace_that_stops_being_advertisable_stops_being_deferred() { let assigned = crate::Hop::new(777).unwrap(); @@ -15422,7 +15422,7 @@ mod tests { /// A minimum wait binds every path back to the namespace, not just the retry sweep. /// A route change re-prices the advertisement; it does not excuse us from the wait the /// peer asked for. - #[moq_clock::test] + #[kio::test] async fn a_route_change_still_waits_out_a_refusal() { const VERSION: Version = Version::Draft18; @@ -15519,7 +15519,7 @@ mod tests { /// request that already carries it, sending the changed parameter only. The new cost /// is 0, which has to be explicit: REQUEST_UPDATE keeps an omitted parameter, so /// leaving it out would keep the old price. - #[moq_clock::test] + #[kio::test] async fn a_repricing_is_a_request_update() { const VERSION: Version = Version::Draft18; @@ -15597,7 +15597,7 @@ mod tests { /// ACTIVE_COUNT only answers SUBSCRIBE_NAMESPACE (MoQ Active Count), so one on the OK /// to a REQUEST_UPDATE is the peer breaking the extension too. - #[moq_clock::test] + #[kio::test] async fn a_counted_update_ok_is_a_violation() { const VERSION: Version = Version::Draft18; @@ -15659,7 +15659,7 @@ mod tests { .announce("cam", crate::origin::Route::default().with_epoch(epoch).with_cost(0)) .unwrap(); - let res = moq_clock::timeout(Duration::from_secs(5), run) + let res = kio::clock::timeout(Duration::from_secs(5), run) .await .expect("the violation ends the loop"); assert!(matches!(res, Err(Error::ProtocolViolation)), "{res:?}"); @@ -15672,7 +15672,7 @@ mod tests { /// updates the advertisement in place, like any other change within an instance: /// withdrawing it would make the namespace briefly vanish downstream just because /// its replica moved. - #[moq_clock::test] + #[kio::test] async fn a_replica_change_is_a_request_update() { const VERSION: Version = Version::Draft18; @@ -15816,7 +15816,7 @@ mod tests { /// A route's auth rides its PUBLISH_NAMESPACE as the request's token, and swapping it /// renews the request in place: REQUEST_UPDATE on the same stream, carrying only the /// new token. - #[moq_clock::test] + #[kio::test] async fn swapping_a_route_auth_is_a_request_update() { swaps_a_route_auth(Version::Draft18).await; } @@ -15884,7 +15884,7 @@ mod tests { /// An auth another handle issued is not this session's to present: the route is /// advertised under the session's scope, and the credential never reaches this peer. - #[moq_clock::test] + #[kio::test] async fn a_foreign_route_auth_is_not_carried() { const VERSION: Version = Version::Draft18; @@ -15913,7 +15913,7 @@ mod tests { /// moq-transport cannot name an auth on a request that had none, so naming one /// withdraws the request and makes it again with the token. - #[moq_clock::test] + #[kio::test] async fn naming_an_auth_restarts_an_unnamed_request() { const VERSION: Version = Version::Draft18; @@ -15939,7 +15939,7 @@ mod tests { /// Renewals wait on their answers side by side: one the peer has not answered holds up /// neither another namespace's renewal nor a new announcement. - #[moq_clock::test] + #[kio::test] async fn renewals_are_in_flight_together() { const VERSION: Version = Version::Draft18; @@ -15986,7 +15986,7 @@ mod tests { /// From draft 18 an idle advertisement keeps reading, so a peer that FINs or resets its /// answer while nothing is pending has the namespace offered again, after a wait that /// doubles each time so a peer ending every advertisement does not get a request loop. - #[moq_clock::test] + #[kio::test] async fn an_idle_advertisement_that_ends_is_offered_again() { use crate::transport::memory; const VERSION: Version = Version::Draft18; @@ -16006,10 +16006,10 @@ mod tests { declared(Some(false)), VERSION, ); - let run = moq_clock::sim::spawn(publisher.run_publish_namespaces()); + let run = kio::clock::sim::spawn(publisher.run_publish_namespaces()); let offered = async || { - let mut stream = moq_clock::timeout( + let mut stream = kio::clock::timeout( Duration::from_secs(10), Stream::accept(&mut crate::driver::Transport::new(peer.clone()), VERSION), ) @@ -16026,12 +16026,12 @@ mod tests { stream.writer.write_all(&mut ok).await.unwrap(); // Paused time advances once every task is idle: the answer was read, and the // advertisement is parked on its idle reader. - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; match fin { true => stream.writer.finish().unwrap(), false => stream.writer.abort(&Error::Cancel), } - let ended = moq_clock::Instant::now(); + let ended = kio::clock::Instant::now(); stream = offered().await; assert!( ended.elapsed() >= wait, @@ -16046,7 +16046,7 @@ mod tests { /// A peer that resets or ends one namespace's PUBLISH_NAMESPACE before answering it ends /// only that advertisement: the next namespace is still answered and withdrawn as usual, /// and the failed one is offered again after a backoff rather than in a loop. - #[moq_clock::test] + #[kio::test] async fn a_failed_advertisement_ends_only_its_namespace() { for version in [Version::Draft18] { for fin in [true, false] { @@ -16075,11 +16075,11 @@ mod tests { declared(Some(false)), version, ); - let run = moq_clock::sim::spawn(publisher.run_publish_namespaces()); + let run = kio::clock::sim::spawn(publisher.run_publish_namespaces()); // The next advertisement, with the namespace it names. let offered = async || { - let mut stream = moq_clock::timeout( + let mut stream = kio::clock::timeout( Duration::from_secs(10), Stream::accept(&mut crate::driver::Transport::new(peer.clone()), version), ) @@ -16100,7 +16100,7 @@ mod tests { true => failed.writer.finish().unwrap(), false => failed.writer.abort(&Error::Cancel), } - let ended = moq_clock::Instant::now(); + let ended = kio::clock::Instant::now(); let (mut held, second) = offered().await; assert_ne!( @@ -16134,7 +16134,7 @@ mod tests { /// A PUBLISH_NAMESPACE whose header fails to send backs off that namespace rather than /// closing the session. - #[moq_clock::test] + #[kio::test] async fn a_failed_header_backs_off_the_namespace() { use crate::transport::memory; @@ -16161,9 +16161,9 @@ mod tests { version, ) .with_auth(auth.clone()); - let run = moq_clock::sim::spawn(publisher.run_publish_namespaces()); + let run = kio::clock::sim::spawn(publisher.run_publish_namespaces()); - moq_clock::timeout( + kio::clock::timeout( Duration::from_secs(10), Stream::accept(&mut crate::driver::Transport::new(peer.clone()), version), ) @@ -16172,7 +16172,7 @@ mod tests { .unwrap(); // Offered again after the backoff, on a session that stays open. - moq_clock::timeout( + kio::clock::timeout( Duration::from_secs(10), Stream::accept(&mut crate::driver::Transport::new(peer.clone()), version), ) @@ -16185,7 +16185,7 @@ mod tests { /// A peer that resets a request's stream while its renewal is in flight ends only that /// request: the loop keeps running and advertises the namespace afresh. - #[moq_clock::test] + #[kio::test] async fn a_reset_renewal_ends_only_its_request() { const VERSION: Version = Version::Draft18; @@ -16224,7 +16224,7 @@ mod tests { // The advertisement comes back on the retry, jittered up to RETRY_BASE, which // outlasts poll_until. - moq_clock::sleep(RETRY_BASE).await; + kio::clock::sleep(RETRY_BASE).await; poll_until(&mut run, &log, b"second", 2).await; assert_eq!( occurrences(&log, b"second"), @@ -16236,7 +16236,7 @@ mod tests { /// An update the peer never answers drops its request once the timeout passes, and /// the retry advertises the namespace afresh under the current auth. - #[moq_clock::test] + #[kio::test] async fn an_unanswered_renewal_advertises_again() { advertises_again_unanswered(Version::Draft18).await; } @@ -16264,7 +16264,7 @@ mod tests { break; } assert!(futures::poll!(run.as_mut()).is_pending()); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; } assert_eq!( occurrences(&log, b"second"), @@ -16275,7 +16275,7 @@ mod tests { /// moq-transport has no restart: another source winning a namespace without an epoch /// withdraws it and advertises it afresh, so the peer resubscribes. - #[moq_clock::test] + #[kio::test] async fn a_restart_re_advertises_the_namespace() { const VERSION: Version = Version::Draft18; @@ -16333,7 +16333,7 @@ mod tests { /// advertisement. The namespace is then not held at all, so it comes back as a fresh /// PUBLISH_NAMESPACE once the refusal's wait is out, not as another update on a /// stream the peer already ended. - #[moq_clock::test] + #[kio::test] async fn a_refused_update_is_re_advertised_fresh() { const VERSION: Version = Version::Draft18; @@ -16407,7 +16407,7 @@ mod tests { /// The peer granting a stream is only half the exchange. One it accepts and then never /// answers on wedges the loop exactly as a parked open does, so the response is bounded /// too: everything queued behind it is otherwise stranded for the session. - #[moq_clock::test] + #[kio::test] async fn a_silent_answer_still_lets_the_next_namespace_be_advertised() { const VERSION: Version = Version::Draft18; @@ -16454,7 +16454,7 @@ mod tests { /// An advertisement the peer never answers is given up at its deadline: its own stream's /// reset ends it. - #[moq_clock::test] + #[kio::test] async fn an_unanswered_advertisement_is_withdrawn() { for version in [Version::Draft18] { let origin = unheld_origin(); @@ -16477,11 +16477,11 @@ mod tests { poll_until(&mut run, &log, b"cam", 1).await; let withdrawn = || !log.resets().is_empty(); - moq_clock::sleep(ADVERTISE_TIMEOUT - Duration::from_millis(10)).await; + kio::clock::sleep(ADVERTISE_TIMEOUT - Duration::from_millis(10)).await; assert!(futures::poll!(run.as_mut()).is_pending()); assert!(!withdrawn(), "{version}: withdrawn before its deadline"); - moq_clock::sleep(Duration::from_millis(20)).await; + kio::clock::sleep(Duration::from_millis(20)).await; assert!(futures::poll!(run.as_mut()).is_pending()); assert!( withdrawn(), @@ -16493,7 +16493,7 @@ mod tests { /// Credit returning raises no signal of its own, so only the retry timer brings back an /// advertisement refused for credit; without it the namespace stays undiscoverable for /// the life of the session. The refusal itself must not spend a request ID. - #[moq_clock::test] + #[kio::test] async fn an_advertisement_without_credit_is_retried_and_spends_no_id() { use std::sync::atomic::Ordering; for version in [Version::Draft18] { @@ -16544,7 +16544,7 @@ mod tests { /// Send capacity returning raises no signal of its own: no announce, no route change, nothing /// the loop is watching. Only a retry brings the namespace back, and without one it /// stays undiscoverable for the life of the session. - #[moq_clock::test] + #[kio::test] async fn an_advertisement_waiting_for_send_capacity_is_retried_on_its_own() { const VERSION: Version = Version::Draft18; @@ -16593,7 +16593,7 @@ mod tests { /// Advance far enough that a parked open gives up and its retry comes due, without /// making the test wait: time is paused, so this only moves the clock the loop reads. async fn tick() { - moq_clock::sim::advance(Duration::from_millis(200)).await; + kio::clock::sim::advance(Duration::from_millis(200)).await; } fn set_gate(gate: &kio::Producer, open: bool) { @@ -16709,7 +16709,7 @@ mod tests { /// has to survive the trip. `Writer` resets the stream on drop, and a reset that races the /// write discards the bytes the peer has not read yet, which leaves the subscriber waiting /// on a request we already refused. Finishing first makes the drop-time reset a no-op. - #[moq_clock::test] + #[kio::test] async fn missing_broadcast_is_refused_without_resetting_the_stream() { for version in [Version::Draft18, Version::Draft22] { let (writes, resets) = subscribe_missing(version).await; @@ -16726,7 +16726,7 @@ mod tests { /// Every FETCH we refuse goes out through its own error encoder, so it needs the same /// finish: a reset there loses the rejection the same way. - #[moq_clock::test] + #[kio::test] async fn a_refused_fetch_does_not_reset_the_stream() { let refused = || { [ @@ -17136,7 +17136,7 @@ mod range_tests { /// A start past the live edge is what the subscriber asked for, so it is used as given. /// Clamping it to the live edge would serve a group outside the requested range. - #[moq_clock::test] + #[kio::test] async fn a_future_start_is_not_clamped_to_the_live_edge() { let track = track::Producer::new( std::sync::Arc::new(crate::broadcast::Info::default()), @@ -17722,7 +17722,7 @@ mod compression_tests { } /// The actual JS SETUP offer selects the plain egress of a compressed Rust track. - #[moq_clock::test] + #[kio::test] #[ignore = "requires Bun; run by just test interop"] async fn ietf_compression_fallback_interop() { use crate::coding::Decode; diff --git a/rs/moq-net/src/ietf/publisher/tracks.rs b/rs/moq-net/src/ietf/publisher/tracks.rs index 19b1bfa6970..fbcef9ae28d 100644 --- a/rs/moq-net/src/ietf/publisher/tracks.rs +++ b/rs/moq-net/src/ietf/publisher/tracks.rs @@ -1418,7 +1418,7 @@ mod tests { let id = accepted.reader.varint().await.unwrap(); let body: ietf::Body = accepted.reader.decode().await.unwrap(); let task = self.publisher.handle_stream(id, body, accepted, false).unwrap(); - moq_clock::sim::spawn(task); + kio::clock::sim::spawn(task); stream } @@ -1440,7 +1440,7 @@ mod tests { } async fn timeout(future: F) -> F::Output { - moq_clock::timeout(TIMEOUT, future).await.expect("timed out") + kio::clock::timeout(TIMEOUT, future).await.expect("timed out") } /// The next message on a request stream: its type and body. @@ -1492,7 +1492,7 @@ mod tests { /// A paused listing PUBLISHes every track under the prefix, later ones included, each /// paused, and ends a track's PUBLISH with PUBLISH_DONE once it is no longer listed. - #[moq_clock::test] + #[kio::test] async fn a_paused_listing_publishes_every_track() { for version in DRAFTS { let mut h = harness(version); @@ -1535,7 +1535,7 @@ mod tests { /// A track that finishes while its PUBLISH awaits the answer still ends with TRACK_ENDED /// once answered, since the peer listed it on the PUBLISH; a reset would fail its listing. - #[moq_clock::test] + #[kio::test] async fn a_track_finished_before_the_answer_ends_cleanly() { for version in DRAFTS { let mut h = harness(version); @@ -1551,7 +1551,7 @@ mod tests { let track = h.tracks.remove("video").unwrap(); track.finish().unwrap(); drop(track); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; publish_ok(&mut video).await; let (id, body) = next(&mut video).await; assert_eq!(id, ietf::PublishDone::ID, "{version}"); @@ -1567,7 +1567,7 @@ mod tests { /// A broadcast closing right after a track finished ends that track's PUBLISH with /// TRACK_ENDED, whether its producer is still held or not, while a track left unfinished /// still ends in error. - #[moq_clock::test] + #[kio::test] async fn a_clean_end_keeps_its_finishes() { for version in DRAFTS { for held in [false, true] { @@ -1581,7 +1581,7 @@ mod tests { publish_ok(&mut stream).await; published.insert(name, stream); } - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let video = h.tracks.remove("video").unwrap(); video.finish().unwrap(); @@ -1603,7 +1603,7 @@ mod tests { /// A REQUEST_UPDATE with FORWARD=1 resumes a paused PUBLISH: its answer names where the /// subscription joins, and new groups flow. FORWARD=0 pauses it again. - #[moq_clock::test] + #[kio::test] async fn an_update_resumes_and_pauses_a_publish() { for version in DRAFTS { let mut h = harness(version); @@ -1656,7 +1656,7 @@ mod tests { let mut group = video.append_group().unwrap(); group.write_frame(crate::Timestamp::ZERO, b"paused".as_slice()).unwrap(); group.finish().unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let more = futures::poll!(std::future::poll_fn(|cx| h.peer.poll_accept_uni(cx))); assert!(more.is_pending(), "{version}: a paused PUBLISH forwarded"); @@ -1671,7 +1671,7 @@ mod tests { /// A listed compressed track is declared and served compressed only to a peer that /// negotiated FLATE; any other peer gets the plain copy with no declaration. - #[moq_clock::test] + #[kio::test] async fn a_publish_compresses_only_when_negotiated() { for version in DRAFTS { for flate in [false, true] { @@ -1729,7 +1729,7 @@ mod tests { /// FORWARD=1 asks for every track's objects, which we never push unasked: from /// draft-22 each track is skipped, and draft-18, with no way to skip, refuses it. - #[moq_clock::test] + #[kio::test] async fn a_forwarding_listing_skips_every_track() { for version in DRAFTS { let mut h = harness(version); @@ -1760,7 +1760,7 @@ mod tests { } /// A prefix overlapping an established listing is refused, and freed by its cancel. - #[moq_clock::test] + #[kio::test] async fn an_overlapping_prefix_is_refused() { for version in DRAFTS { let mut h = harness(version); @@ -1776,7 +1776,7 @@ mod tests { assert_eq!(request_error(&body, version), request::PREFIX_OVERLAP, "{version}"); first.writer.abort(&Error::Cancel); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; nested.request_id = RequestId(4); let mut third = h.request(&nested).await; assert_eq!(next(&mut third).await.0, ietf::RequestOk::ID, "{version}"); @@ -1785,7 +1785,7 @@ mod tests { /// Draft-18 allows one subscription per track: a SUBSCRIBE to a PUBLISHed track is a /// duplicate. Later drafts serve it. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_to_a_published_track() { for version in DRAFTS { let mut h = harness(version); @@ -1828,7 +1828,7 @@ mod tests { /// Each PUBLISH opens only as the peer's stream credit admits it: a peer that withholds /// credit and reads nothing holds as many PUBLISHes as it grants, however many tracks are /// listed, and each track is PUBLISHed once credit returns. - #[moq_clock::test] + #[kio::test] async fn a_listing_publishes_only_as_credit_admits() { const CREDIT: usize = 2; for version in DRAFTS { @@ -1849,7 +1849,7 @@ mod tests { let mut request = h.request(&listing(false)).await; assert_eq!(next(&mut request).await.0, ietf::RequestOk::ID, "{version}"); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; assert_eq!(held(&h), CREDIT, "{version} catalog={catalog}"); // Refusing each PUBLISH returns its credit, which opens the next. @@ -1867,7 +1867,7 @@ mod tests { /// A FORWARD=1 listing reads its next track only once the request stream has taken the /// last skip, so a peer that stops reading leaves one skip queued, however many tracks /// are listed. - #[moq_clock::test] + #[kio::test] async fn a_forwarding_listing_reads_only_as_skips_go_out() { for version in [Version::Draft18, Version::Draft22] { for catalog in CATALOGS { @@ -1897,7 +1897,7 @@ mod tests { skips: skips.clone(), live: live.consume(), }; - moq_clock::sim::spawn(h.publisher.clone().run_listed_broadcast( + kio::clock::sim::spawn(h.publisher.clone().run_listed_broadcast( request, crate::Path::from_static("room/cam"), None, @@ -1906,13 +1906,13 @@ mod tests { let mut skipped = HashSet::new(); while skipped.len() < catalog { - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let mut queued = skips.lock(); assert_eq!(queued.len(), 1, "{version} catalog={catalog}"); let ((_, name), ()) = queued.pop_front().unwrap(); assert!(skipped.insert(name), "{version}: skipped a track twice"); } - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; assert!(skips.read().is_empty(), "{version}: skipped past the listing"); } } @@ -1920,7 +1920,7 @@ mod tests { /// Cancelling the listing stops new PUBLISHes, while those already sent live on until /// their broadcast ends, which ends each with PUBLISH_DONE. - #[moq_clock::test] + #[kio::test] async fn a_cancelled_listing_keeps_its_publishes() { for version in DRAFTS { let mut h = harness(version); @@ -1932,12 +1932,12 @@ mod tests { publish_ok(&mut second).await; request.writer.abort(&Error::Cancel); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let _late = h .broadcast .create_track("captions", crate::track::Info::timed()) .unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let opened = futures::poll!(std::pin::pin!(Stream::accept( &mut crate::driver::Transport::new(h.peer.clone()), version @@ -1954,7 +1954,7 @@ mod tests { /// On draft-18 a replacement listing skips the tracks whose PUBLISHes outlive the one it /// replaced, since each is still the peer's one subscription; later drafts PUBLISH them /// again. - #[moq_clock::test] + #[kio::test] async fn a_relisting_skips_tracks_still_published_on_draft_18() { let version = Version::Draft18; let mut h = harness(version); @@ -1965,7 +1965,7 @@ mod tests { publish_ok(&mut first).await; publish_ok(&mut second).await; request.writer.abort(&Error::Cancel); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let relisting = ietf::SubscribeTracks { request_id: RequestId(2), @@ -1989,7 +1989,7 @@ mod tests { /// On draft 18 a PUBLISH_OK may ask for a new group only if the PUBLISH sent /// DYNAMIC_GROUPS; one that asks anyway ends the PUBLISH in error. - #[moq_clock::test] + #[kio::test] async fn a_publish_ok_new_group_needs_dynamic_groups() { let version = Version::Draft18; let mut h = harness(version); @@ -2015,7 +2015,7 @@ mod tests { } /// Draft-18 lets PUBLISH_OK forward at once, with no update to answer. - #[moq_clock::test] + #[kio::test] async fn a_forwarding_publish_ok_resumes() { for version in [Version::Draft18] { let mut h = harness(version); @@ -2057,7 +2057,7 @@ mod tests { /// A REQUEST_UPDATE on the listing admits its Request ID like any other: one of the /// wrong parity closes the session rather than only refusing the update. - #[moq_clock::test] + #[kio::test] async fn a_listing_update_admits_its_request_id() { for version in DRAFTS { let mut h = harness(version); @@ -2080,7 +2080,7 @@ mod tests { /// A REQUEST_UPDATE on the listing is answered with REQUEST_ERROR. From draft-22 it may /// carry FORWARD, which is refused the same way rather than closing the session. - #[moq_clock::test] + #[kio::test] async fn a_listing_update_is_refused() { for version in DRAFTS { let mut h = harness(version); @@ -2099,7 +2099,7 @@ mod tests { } /// A listing update past our GOAWAY is refused as GOING_AWAY, not as unsupported. - #[moq_clock::test] + #[kio::test] async fn a_listing_update_after_goaway_is_going_away() { for version in DRAFTS { let mut h = harness(version); @@ -2121,7 +2121,7 @@ mod tests { /// NEW_GROUP_REQUEST resuming a paused PUBLISH is a join under the track's refresh /// ratio, as on a SUBSCRIBE, even when the filter's fixed start is not. - #[moq_clock::test] + #[kio::test] async fn a_resume_asks_for_a_new_group() { let version = Version::Draft22; let mut h = harness(version); @@ -2160,7 +2160,7 @@ mod tests { /// On draft-22 an update may ask for a new group only if its PUBLISH sent /// DYNAMIC_GROUPS, which INCLUDE_PROPERTIES=0 leaves out even for a dynamic track. - #[moq_clock::test] + #[kio::test] async fn a_new_group_needs_the_advertised_dynamic_groups() { for version in [Version::Draft22] { let mut h = harness(version); @@ -2202,7 +2202,7 @@ mod tests { /// While forwarding, an update's NEW_GROUP_REQUEST also needs the advertised /// DYNAMIC_GROUPS, which INCLUDE_PROPERTIES=0 leaves out. - #[moq_clock::test] + #[kio::test] async fn a_forwarding_new_group_needs_the_advertised_dynamic_groups() { let version = Version::Draft22; let mut h = harness(version); @@ -2239,7 +2239,7 @@ mod tests { /// A paused subscription opens no groups, so an update that pauses may not ask for one, /// while forwarding as while paused. - #[moq_clock::test] + #[kio::test] async fn a_pausing_new_group_is_refused() { for version in [Version::Draft18, Version::Draft22] { let mut h = harness(version); @@ -2270,7 +2270,7 @@ mod tests { } /// An update taken while forwarding outlives a pause: the next resume keeps it. - #[moq_clock::test] + #[kio::test] async fn a_forwarding_update_outlives_a_pause() { for version in [Version::Draft18, Version::Draft22] { let mut h = harness(version); @@ -2302,7 +2302,7 @@ mod tests { /// On draft-18 a track the peer already SUBSCRIBEd to is skipped rather than PUBLISHed /// a second time; later drafts PUBLISH it. - #[moq_clock::test] + #[kio::test] async fn a_subscribed_track_is_skipped_on_draft_18() { let version = Version::Draft18; let mut h = harness(version); @@ -2348,7 +2348,7 @@ mod tests { /// From draft-22 each PUBLISH states the listing's subscription parameters, which the /// subscriber otherwise takes as the defaults; earlier drafts carry them on PUBLISH_OK. /// Draft-22 sends none of them on SUBSCRIBE_TRACKS. - #[moq_clock::test] + #[kio::test] async fn a_listing_states_its_parameters_on_each_publish() { for version in DRAFTS.into_iter().filter(|version| *version != Version::Draft22) { let mut h = harness(version); @@ -2382,7 +2382,7 @@ mod tests { /// An omitted SUBSCRIBER_PRIORITY is the drafts' 128, so each PUBLISH restates 128 rather /// than this stack's unset 127. - #[moq_clock::test] + #[kio::test] async fn a_listing_without_a_priority_states_the_default() { for version in DRAFTS.into_iter().filter(|version| Filter::is_draft22(*version)) { let mut h = harness(version); @@ -2399,7 +2399,7 @@ mod tests { /// A forwarding PUBLISH ends with PUBLISH_DONE once its track is no longer listed, here /// because its broadcast's route went, even while the track itself goes on. The track /// has not ended, so neither does the PUBLISH cleanly. - #[moq_clock::test] + #[kio::test] async fn an_unlisted_forwarding_publish_ends() { for version in [Version::Draft18, Version::Draft22] { let mut h = harness(version); @@ -2429,7 +2429,7 @@ mod tests { /// A paused PUBLISH ends in error once its track is unlisted, here because its /// broadcast's route went, never with the clean end that says the track is over. - #[moq_clock::test] + #[kio::test] async fn an_unlisted_paused_publish_ends_in_error() { for version in DRAFTS { let mut h = harness(version); @@ -2448,7 +2448,7 @@ mod tests { /// A listing ending through a refused update still unlists its tracks while the peer /// withholds the credit its REQUEST_ERROR needs. - #[moq_clock::test] + #[kio::test] async fn a_closing_listing_still_unlists() { for version in [Version::Draft18, Version::Draft22] { let config = memory::Config { @@ -2466,7 +2466,7 @@ mod tests { ..update(2, false) }; send(&mut request, &refused).await; - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; // A new instance takes the path while the old one goes on: only its route ends. let _restarted = h._origin.publish("room/cam", crate::origin::Route::default()).unwrap(); @@ -2482,7 +2482,7 @@ mod tests { /// With MoQ Auth, no track is listed until the peer answers our setup credential, whose /// grant may narrow what the listing shows, and a listing cancelled while waiting frees /// its prefix. - #[moq_clock::test] + #[kio::test] async fn a_listing_waits_for_the_setup_answer() { for version in [Version::Draft18, Version::Draft22] { let mut h = harness(version); @@ -2505,7 +2505,7 @@ mod tests { .with_auth(auth.clone()); let first = h.request(&listing(false)).await; - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let opened = futures::poll!(std::pin::pin!(Stream::accept( &mut crate::driver::Transport::new(h.peer.clone()), version @@ -2513,7 +2513,7 @@ mod tests { assert!(opened.is_pending(), "{version}: listed a track before the setup answer"); first.writer.abort(&Error::Cancel); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let mut again = listing(false); again.request_id = RequestId(2); let mut request = h.request(&again).await; @@ -2527,7 +2527,7 @@ mod tests { /// Tracks under a namespace our grant does not cover are not listed until it does, and /// a grant that stops covering them ends their PUBLISHes. - #[moq_clock::test] + #[kio::test] async fn a_listing_follows_the_publish_grant() { let nothing = || crate::auth::Grant { publish: crate::Patterns::new(), @@ -2542,7 +2542,7 @@ mod tests { let mut request = h.request(&listing(false)).await; assert_eq!(next(&mut request).await.0, ietf::RequestOk::ID, "{version}"); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let opened = futures::poll!(std::pin::pin!(Stream::accept( &mut crate::driver::Transport::new(h.peer.clone()), version diff --git a/rs/moq-net/src/ietf/request_stream.rs b/rs/moq-net/src/ietf/request_stream.rs index da4c6813a86..6e54825ef04 100644 --- a/rs/moq-net/src/ietf/request_stream.rs +++ b/rs/moq-net/src/ietf/request_stream.rs @@ -385,7 +385,7 @@ impl<'a, const TRACKS: bool> Decode<'a, Version> for NamespaceUpdate { mod tests { use super::*; - #[moq_clock::test] + #[kio::test] async fn request_messages_keep_goaway_state_across_response_phases() { use crate::lite::test_transport::ScriptedSession; for version in [Version::Draft18, Version::Draft22] { @@ -407,7 +407,7 @@ mod tests { /// A request-stream message counts as its sender counts it: the length and body, not the /// type that selects it, including a GOAWAY read ahead of the response. - #[moq_clock::test] + #[kio::test] async fn request_stream_messages_count_without_their_type() { use crate::lite::test_transport::ScriptedSession; use crate::stats::{Message, Registry, Tier}; @@ -429,7 +429,7 @@ mod tests { assert_eq!(rx(Message::Other), Some(2)); } - #[moq_clock::test] + #[kio::test] async fn a_goaway_does_not_cancel_a_pending_request() { use crate::lite::test_transport::ScriptedSession; for version in [Version::Draft18, Version::Draft22] { diff --git a/rs/moq-net/src/ietf/session.rs b/rs/moq-net/src/ietf/session.rs index 98820332f27..41a0f97a080 100644 --- a/rs/moq-net/src/ietf/session.rs +++ b/rs/moq-net/src/ietf/session.rs @@ -1369,7 +1369,7 @@ mod tests { assert!(decode_peer_setup(encode(Some(&[0xff])), version, true).is_err()); } - #[moq_clock::test] + #[kio::test] async fn announce_interest_without_credit_keeps_the_session_alive() { use std::sync::atomic::Ordering; for version in [Version::Draft18] { @@ -1411,7 +1411,7 @@ mod tests { 1, "{version}: interest was attempted" ); - moq_clock::sleep(std::time::Duration::from_secs(20)).await; + kio::clock::sleep(std::time::Duration::from_secs(20)).await; assert!( futures::poll!(driver.as_mut()).is_pending(), "{version}: local refusal ended the session" @@ -1426,7 +1426,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn auth_ids_need_the_peers_parity() { for version in [Version::Draft18, Version::Draft22] { for client in [false, true] { @@ -1494,7 +1494,7 @@ mod tests { extensions: Default::default(), }) .unwrap(); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect("invalid AUTH ID left the session open") .expect_err("invalid request ID must be fatal"); @@ -1508,7 +1508,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn malformed_auth_replies_close_the_session() { for version in [Version::Draft22] { for (id, body) in [ @@ -1551,7 +1551,7 @@ mod tests { extensions: Default::default(), }) .unwrap(); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect("the session outlived a malformed AUTH reply") .expect_err("malformed AUTH is fatal"); @@ -1563,7 +1563,7 @@ mod tests { /// A granted token whose Auth request the peer resets is presented again on the same /// session, backing off while each attempt is lost before a reply: at 0s, 1s, and 3s. - #[moq_clock::test] + #[kio::test] async fn a_lost_auth_request_is_presented_again() { let version = Version::Draft18; let mut grant = Vec::new(); @@ -1605,7 +1605,7 @@ mod tests { .unwrap(); let token = handle.present(bytes::Bytes::from_static(b"token")).unwrap(); - let res = moq_clock::timeout(std::time::Duration::from_secs(5), driver).await; + let res = kio::clock::timeout(std::time::Duration::from_secs(5), driver).await; assert!(res.is_err(), "the session ended: {res:?}"); assert_eq!(occurrences(&log, b"token"), 3); assert!( @@ -1616,7 +1616,7 @@ mod tests { /// A peer that negotiated MoQ Auth but resets a token's request before any reply gave it /// nothing: the token fails as unsupported rather than being presented again. - #[moq_clock::test] + #[kio::test] async fn an_auth_request_reset_before_its_reply_is_unsupported() { let version = Version::Draft18; let mut grant = Vec::new(); @@ -1659,14 +1659,14 @@ mod tests { .unwrap(); let token = handle.present(bytes::Bytes::from_static(b"token")).unwrap(); - let res = moq_clock::timeout(std::time::Duration::from_secs(5), driver).await; + let res = kio::clock::timeout(std::time::Duration::from_secs(5), driver).await; assert!(res.is_err(), "the session ended: {res:?}"); assert_eq!(occurrences(&log, b"token"), 1, "presented again"); let err = futures::FutureExt::now_or_never(token.closed()).expect("the token is still open"); assert!(matches!(err, Error::Unsupported), "{err:?}"); } - #[moq_clock::test] + #[kio::test] async fn malformed_presenter_auth_closes_the_session() { for version in [Version::Draft22] { for body in [vec![0, 2], vec![0, 0, 0]] { @@ -1704,7 +1704,7 @@ mod tests { extensions: Default::default(), }) .unwrap(); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect("malformed presenter AUTH was ignored") .expect_err("malformed AUTH is fatal"); @@ -1769,7 +1769,7 @@ mod tests { /// Driven through `start` rather than `run_subscribe_namespace` directly: the /// stream surfaces the error either way, so only this loop's handling of it decides /// between a close and a warning, and a test below the loop would pass regardless. - #[moq_clock::test] + #[kio::test] async fn a_namespace_without_a_hop_path_closes_the_session() { const VERSION: Version = Version::Draft18; @@ -1814,7 +1814,7 @@ mod tests { }) .expect("start the session"); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect("the session ended rather than carrying on") .expect_err("a malformed NAMESPACE fails the session"); @@ -1832,7 +1832,7 @@ mod tests { /// Driven through `start` so the per-prefix fan-out is exercised, not just one stream /// in isolation: a loop that opened a single stream would still satisfy a test that /// called `run_subscribe_namespace` itself. - #[moq_clock::test] + #[kio::test] async fn every_permitted_prefix_gets_its_own_subscribe_namespace() { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let scope: crate::Patterns = ["cam", "mic"] @@ -1872,14 +1872,14 @@ mod tests { extensions: Default::default(), }) .expect("start the session"); - let _driver = moq_clock::sim::spawn(driver); + let _driver = kio::clock::sim::spawn(driver); // Both requests are written before either peer response, which never comes. for _ in 0..100 { if occurrences(&log, b"cam") > 0 && occurrences(&log, b"mic") > 0 { break; } - moq_clock::sleep(std::time::Duration::from_millis(5)).await; + kio::clock::sleep(std::time::Duration::from_millis(5)).await; } assert_eq!(occurrences(&log, b"cam"), 1, "one SUBSCRIBE_NAMESPACE for cam"); @@ -1921,7 +1921,7 @@ mod tests { solicit: Option, ) -> ( crate::lite::test_transport::Log, - moq_clock::sim::JoinHandle>, + kio::clock::sim::JoinHandle>, ) { let gate = kio::Producer::new(true); let session = crate::lite::test_transport::SinkSession::gated_bi(gate.consume()); @@ -1936,7 +1936,7 @@ mod tests { solicit: Option, ) -> ( crate::lite::test_transport::Log, - moq_clock::sim::JoinHandle>, + kio::clock::sim::JoinHandle>, ) { let log = session.log.clone(); let session = crate::driver::Transport::new(session); @@ -1967,7 +1967,7 @@ mod tests { extensions: Default::default(), }) .expect("start the session"); - (log, moq_clock::sim::spawn(driver)) + (log, kio::clock::sim::spawn(driver)) } /// Let the driver run until `needle` reaches the wire, or give up after a while. @@ -1976,13 +1976,13 @@ mod tests { if occurrences(log, needle) > 0 { return true; } - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } false } /// A client asks nothing until something is watched, then only about what is. - #[moq_clock::test] + #[kio::test] async fn a_client_asks_only_about_what_is_watched() { for version in [Version::Draft18] { let subscribe = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -2006,7 +2006,7 @@ mod tests { /// Each request has a stream of its own, so at a foreign peer the broader one waits for /// the peer to close the narrower one's, which ends with a FIN on draft-18 and a /// reset on draft-22: a peer that never closes it never sees the two overlap. - #[moq_clock::test] + #[kio::test] async fn a_broader_watch_waits_for_the_narrower_to_leave_the_wire() { for version in [Version::Draft18, Version::Draft22] { let subscribe = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -2017,7 +2017,7 @@ mod tests { let _cam = watch(&subscribe, "cam"); for _ in 0..ANNOUNCE_TURNS { - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } assert_eq!(log.bi_opens(), opened, "{version:?} overlapped the narrower request"); let ended = log.trail().into_iter().any(|(_, sent)| match sent { @@ -2031,7 +2031,7 @@ mod tests { /// A request ended while it waits on the peer for stream credit holds nothing: the /// broader request that replaced it goes out alone once the credit arrives. - #[moq_clock::test] + #[kio::test] async fn a_request_ended_before_it_opened_does_not_block_the_broader_one() { for version in [Version::Draft22] { let subscribe = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -2045,11 +2045,11 @@ mod tests { let _front = watch(&subscribe, "cam/front"); for _ in 0..ANNOUNCE_TURNS { - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } let _cam = watch(&subscribe, "cam"); for _ in 0..ANNOUNCE_TURNS { - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } *credit.write().ok().unwrap() = true; assert!(sent(&log, b"cam").await, "{version:?} never asked the broader prefix"); @@ -2061,7 +2061,7 @@ mod tests { /// A peer that declared MoQ Solicit is ours and holds overlapping requests, so a broader /// watch leaves the narrower request open, as on moq-lite: neither takes the other's /// routes over before it has synced. - #[moq_clock::test] + #[kio::test] async fn a_broader_watch_keeps_the_narrower_open_at_our_peer() { for version in [Version::Draft18] { let subscribe = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -2123,14 +2123,14 @@ mod tests { extensions: Default::default(), }) .expect("start the session"); - let _driver = moq_clock::sim::spawn(driver); + let _driver = kio::clock::sim::spawn(driver); // Drive until the announce lands, rather than betting on one fixed window. for _ in 0..ANNOUNCE_TURNS { if occurrences(&log, b"solo-cam") > 0 { break; } - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } occurrences(&log, b"solo-cam") @@ -2138,7 +2138,7 @@ mod tests { /// The peer's SETUP decides whether an advertisement may go out unasked, so nothing /// can be sent before it arrives. - #[moq_clock::test] + #[kio::test] async fn no_announce_before_the_peer_setup() { assert_eq!( announce_occurrences(None).await, @@ -2149,7 +2149,7 @@ mod tests { /// A peer that requires solicitation hears nothing until it asks, which is the /// behavior the IETF draft describes for a relay. - #[moq_clock::test] + #[kio::test] async fn a_peer_requiring_solicitation_is_not_told_unasked() { let declared = peer::Peer { solicit: Some(true), @@ -2166,7 +2166,7 @@ mod tests { /// A peer that declared nothing is told without being asked. Every relay that never /// sends SUBSCRIBE_NAMESPACE depends on this, and the session is what wires the /// unsolicited loop up at all. - #[moq_clock::test] + #[kio::test] async fn a_peer_declaring_nothing_is_told_unasked() { assert_eq!( announce_occurrences(Some(peer::Peer::default())).await, @@ -2193,7 +2193,7 @@ mod tests { _cam: crate::AnnounceProducer, _gate: kio::Producer, _goaway: crate::goaway::Handle, - _driver: moq_clock::sim::JoinHandle>, + _driver: kio::clock::sim::JoinHandle>, } fn auth_session(auth: bool) -> AuthSession { @@ -2238,19 +2238,19 @@ mod tests { _cam: cam, _gate: gate, _goaway: goaway, - _driver: moq_clock::sim::spawn(driver), + _driver: kio::clock::sim::spawn(driver), } } /// A peer that never offered MoQ Auth sees no Auth request and the session keeps /// working. A token resolves promptly rather than hanging, kept with an unknown grant /// for the requests that name it. - #[moq_clock::test] + #[kio::test] async fn a_peer_without_auth_sees_no_auth_request() { let session = auth_session(false); let (handle, log) = (&session.handle, &session.log); - let (auth, answer) = moq_clock::timeout(std::time::Duration::from_secs(1), handle.handle().add("token")) + let (auth, answer) = kio::clock::timeout(std::time::Duration::from_secs(1), handle.handle().add("token")) .await .expect("resolved promptly") .expect("kept for requests"); @@ -2262,7 +2262,7 @@ mod tests { if occurrences(log, b"solo-cam") > 0 { break; } - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } assert_eq!(occurrences(log, b"solo-cam"), 1, "the session stopped advertising"); assert_eq!( @@ -2273,7 +2273,7 @@ mod tests { } /// A peer that offered it gets the connection's own credential right away. - #[moq_clock::test] + #[kio::test] async fn a_negotiating_peer_gets_the_setup_token() { let session = auth_session(true); let log = &session.log; @@ -2281,7 +2281,7 @@ mod tests { if occurrences(log, &auth_type()) > 0 { break; } - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } assert_eq!(occurrences(log, &auth_type()), 1, "one AUTH for the setup token"); } @@ -2317,7 +2317,7 @@ mod tests { .expect("start the session"); // The driver parks once SETUP is out. - moq_clock::timeout(std::time::Duration::from_secs(10), driver) + kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect_err("the session ended instead of parking after SETUP"); @@ -2331,7 +2331,7 @@ mod tests { } /// Each extension reaches our SETUP only while this side offers it. - #[moq_clock::test] + #[kio::test] async fn a_declined_extension_stays_out_of_setup() { let all = crate::setup::Extensions::default(); let mut no_auth = all; @@ -2353,7 +2353,7 @@ mod tests { /// A server's handle supports AUTH only when the client offered it too, so a server /// answering a client that did not offer it leaves the option out, whatever it offers. - #[moq_clock::test] + #[kio::test] async fn a_server_offers_auth_only_to_a_client_that_did() { let all = crate::setup::Extensions::default(); assert_eq!(our_setup(false, crate::auth::Link::new(true), all).await, (true, true)); @@ -2418,7 +2418,7 @@ mod tests { }) .expect("start the session"); - let res = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let res = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .ok(); (res, log.closes()) @@ -2426,7 +2426,7 @@ mod tests { /// The Auth draft negotiates the extension only when both sides offer it, so an Auth /// request reaching a side that declined it is a protocol violation, not a token to grant. - #[moq_clock::test] + #[kio::test] async fn an_auth_request_to_a_side_that_declined_it_is_refused() { let (res, closes) = serve_auth_request(true).await; assert!(res.is_none(), "both offered: the request is served, {res:?}"); @@ -2507,7 +2507,7 @@ mod tests { }) .expect("start the session"); - moq_clock::timeout(std::time::Duration::from_secs(10), driver) + kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect_err("the session ended over one dead stream"); @@ -2516,7 +2516,7 @@ mod tests { /// A client advertises its AUTHORITY and connection credential in the SETUP it writes on /// its uni stream. - #[moq_clock::test] + #[kio::test] async fn setup_carries_the_authority_and_token() { const AUTHORITY: &[u8] = b"relay.example.com:4443"; const TOKEN: &[u8] = b"connection-credential"; @@ -2555,7 +2555,7 @@ mod tests { }) .expect("start the session"); - moq_clock::timeout(std::time::Duration::from_secs(10), driver) + kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect_err("the session ended instead of parking after SETUP"); @@ -2571,12 +2571,12 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn a_uni_stream_dead_before_its_type_does_not_end_the_session() { a_dead_incoming_stream_is_not_fatal(crate::lite::test_transport::DeadStreamSession::unis(1)).await; } - #[moq_clock::test] + #[kio::test] async fn a_bidi_stream_dead_before_its_header_does_not_end_the_session() { a_dead_incoming_stream_is_not_fatal(crate::lite::test_transport::DeadStreamSession::bis(1)).await; } @@ -2584,12 +2584,12 @@ mod tests { /// moxygen resets a subgroup stream it opened but never wrote with its own CANCELLED /// (0x1). Over raw QUIC our transport reads that code through the WebTransport space /// and cannot map it, which used to end the session. - #[moq_clock::test] + #[kio::test] async fn a_uni_stream_reset_with_an_unmapped_code_does_not_end_the_session() { a_dead_incoming_stream_is_not_fatal(crate::lite::test_transport::DeadStreamSession::unis(1).unmapped()).await; } - #[moq_clock::test] + #[kio::test] async fn a_bidi_stream_reset_with_an_unmapped_code_does_not_end_the_session() { a_dead_incoming_stream_is_not_fatal(crate::lite::test_transport::DeadStreamSession::bis(1).unmapped()).await; } @@ -2691,14 +2691,14 @@ mod tests { if !log.stops().is_empty() { break; } - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } (log, None) } /// A late group must reach the dispatch loop and stop with CANCELLED. - #[moq_clock::test] + #[kio::test] async fn a_group_for_a_retired_alias_is_stopped_with_cancelled() { let (log, result) = dispatch_uni(Version::Draft18, subgroup_header(Version::Draft18, 7, 0).await, Some(7)).await; @@ -2718,7 +2718,7 @@ mod tests { /// accepted can be one whose bytes the peer has not sent yet, held back by connection /// flow control that the later streams' unread data is using up. Waiting on its type /// before reading them deadlocks the connection. - #[moq_clock::test] + #[kio::test] async fn a_silent_stream_does_not_hold_up_the_next() { let header = subgroup_header(Version::Draft18, 7, 0).await; let session = @@ -2734,7 +2734,7 @@ mod tests { } /// A stalled bidi header must not block a SUBSCRIBE on the next stream. - #[moq_clock::test] + #[kio::test] async fn a_silent_bidi_does_not_hold_up_the_next() { const VERSION: Version = Version::Draft18; let mut subscribe = Vec::new(); @@ -2769,7 +2769,7 @@ mod tests { .with_incoming_bidis(vec![stalled, subscribe.clone()]); let driver = bidi_driver(session, Some(origin.consume())); let subscribed = Box::pin(async { while track.subscription_changed().await.unwrap().is_none() {} }); - let result = moq_clock::timeout( + let result = kio::clock::timeout( std::time::Duration::from_secs(10), futures::future::select(driver, subscribed), ) @@ -2783,7 +2783,7 @@ mod tests { } /// Child tasks must report malformed and unknown requests to the session driver. - #[moq_clock::test] + #[kio::test] async fn invalid_bidi_requests_still_end_the_session() { for id in [ietf::Subscribe::ID, 0x3f] { let mut header = Vec::new(); @@ -2792,7 +2792,7 @@ mod tests { encoder.slice(&[0, 0]); // Complete, empty body: malformed for SUBSCRIBE. let session = crate::lite::test_transport::ScriptedSession::new(Vec::new()).with_incoming_bidis(vec![header]); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), bidi_driver(session, None)) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), bidi_driver(session, None)) .await .expect("invalid request did not end the session") .expect_err("invalid request was accepted"); @@ -2833,7 +2833,7 @@ mod tests { } /// A non-zero subgroup is refused on its own stream, never by closing the session. - #[moq_clock::test] + #[kio::test] async fn a_non_zero_subgroup_is_stopped_without_closing_the_session() { let (log, result) = dispatch_uni(Version::Draft18, subgroup_header(Version::Draft18, 7, 1).await, None).await; @@ -2852,7 +2852,7 @@ mod tests { } /// Padding is read and dropped: no STOP_SENDING, and the session stays up. - #[moq_clock::test] + #[kio::test] async fn a_padding_stream_is_discarded() { for version in [Version::Draft18, Version::Draft22] { let (log, result) = dispatch_uni(version, uni_stream(version, PADDING), None).await; @@ -2870,7 +2870,7 @@ mod tests { /// A server waiting on the client's SETUP holds the padding and group streams that beat /// it, then classifies them once the session starts. The drafts say to buffer early /// data; rejecting it reached the wire as INTERNAL_ERROR. - #[moq_clock::test] + #[kio::test] async fn uni_streams_before_setup_are_held_until_it_lands() { const VERSION: Version = Version::Draft18; @@ -2905,7 +2905,7 @@ mod tests { /// An unknown or invalid stream type MUST close the session, so it stops nothing on its own: /// the session close takes the stream with it. - #[moq_clock::test] + #[kio::test] async fn an_unknown_uni_type_closes_the_session() { for (version, kind) in [ (Version::Draft18, 0), @@ -2923,7 +2923,7 @@ mod tests { } /// The bidi dispatcher closes the session for an unknown full-width message type. - #[moq_clock::test] + #[kio::test] async fn an_unknown_bidi_type_closes_the_session() { for version in [Version::Draft18, Version::Draft22] { for kind in [0u64, 1 << 53] { @@ -2958,7 +2958,7 @@ mod tests { }) .unwrap(); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect("unknown bidi type must end the session") .expect_err("unknown bidi type must fail the session"); @@ -2975,7 +2975,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn an_invalid_group_order_closes_the_session() { for version in [Version::Draft18, Version::Draft22] { for (value, nested) in [ @@ -3027,7 +3027,7 @@ mod tests { limits: Default::default(), }) .unwrap(); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .expect("invalid GROUP_ORDER must close the session") .expect_err("invalid GROUP_ORDER must fail"); @@ -3062,7 +3062,7 @@ mod tests { /// A request's AUTHORIZATION TOKEN decodes by the SETUP option's rules, so one this /// endpoint cannot use closes the session with the draft's code. - #[moq_clock::test] + #[kio::test] async fn a_request_token_that_cannot_be_used_closes_the_session() { for version in [Version::Draft22] { for (token, expected, why) in [ @@ -3114,7 +3114,7 @@ mod tests { }) .unwrap(); - let err = moq_clock::timeout(std::time::Duration::from_secs(10), driver) + let err = kio::clock::timeout(std::time::Duration::from_secs(10), driver) .await .unwrap_or_else(|_| panic!("{version:?} {why}: the session stayed up")) .expect_err("the token must fail the session"); @@ -3178,7 +3178,7 @@ mod tests { } /// What a server may not send in its SETUP closes the session with the draft's code. - #[moq_clock::test] + #[kio::test] async fn a_server_setup_with_path_or_authority_closes_the_session() { for version in [Version::Draft18, Version::Draft22] { for (param, expected) in [ @@ -3196,7 +3196,7 @@ mod tests { /// The server's AUTHORIZATION TOKEN is decoded even though a client has no use for it: a /// malformed one closes the session, and a registration overflowing our cache of 0 is /// read as the value it carries (draft-22 section 9.1.4). - #[moq_clock::test] + #[kio::test] async fn a_server_setup_token_decodes_by_the_setup_rules() { for version in [Version::Draft18, Version::Draft22] { for (token, expected) in [ @@ -3215,7 +3215,7 @@ mod tests { /// The SETUP stream carries one GOAWAY and nothing else: anything more, or a GOAWAY that /// is malformed, closes the session as a PROTOCOL_VIOLATION. One GOAWAY leaves it up. - #[moq_clock::test] + #[kio::test] async fn the_setup_stream_carries_at_most_one_goaway() { for version in [Version::Draft18, Version::Draft22] { let request_id = (version == Version::Draft18).then_some(0); @@ -3261,7 +3261,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn a_control_stream_fin_or_reset_is_a_protocol_violation() { use crate::lite::test_transport::{Close, DeadStreamSession, ScriptedSession}; for version in [Version::Draft18, Version::Draft22] { @@ -3294,7 +3294,7 @@ mod tests { /// A second GOAWAY arriving with the first closes the session before the first surfaces, /// so an application leaving over it cannot close first, without our code. - #[moq_clock::test] + #[kio::test] async fn a_goaway_with_more_behind_it_never_surfaces() { for version in [Version::Draft18, Version::Draft22] { let request_id = (version == Version::Draft18).then_some(0); @@ -3325,7 +3325,7 @@ mod tests { /// A fatal error closes the session before its streams drop. A reset of our SETUP stream /// reaching a strict peer first has it close over that, and it never sees our code. - #[moq_clock::test] + #[kio::test] async fn the_session_closes_before_its_streams_reset() { const VERSION: Version = Version::Draft22; let mut params = ietf::Parameters::default(); @@ -3356,7 +3356,7 @@ mod tests { extensions: Default::default(), }) .unwrap(); - let _ = moq_clock::timeout(std::time::Duration::from_secs(10), driver).await; + let _ = kio::clock::timeout(std::time::Duration::from_secs(10), driver).await; let closes = log.closes(); assert_eq!(closes.len(), 1, "{closes:?}"); @@ -3375,7 +3375,7 @@ mod tests { /// A draft-18 GOAWAY names one of the receiver's own Request IDs, so one with the sender's /// parity closes the session with INVALID_REQUEST_ID rather than redirecting it, and one /// without a Request ID closes it as a PROTOCOL_VIOLATION. - #[moq_clock::test] + #[kio::test] async fn a_draft18_goaway_request_id_has_the_receivers_parity() { const VERSION: Version = Version::Draft18; // The loop runs as a client, whose Request IDs are even. @@ -3395,7 +3395,7 @@ mod tests { /// Draft-18 GOAWAY names the first peer ID past every one used, preserving the peer's /// parity, and still admits one a reordered stream skipped below it. - #[moq_clock::test] + #[kio::test] async fn our_draft18_goaway_names_the_admitted_request_cutoff() { const VERSION: Version = Version::Draft18; for client in [false, true] { @@ -3463,7 +3463,7 @@ mod tests { extensions: Default::default(), }) .unwrap(); - let _ = moq_clock::timeout(std::time::Duration::from_secs(10), driver).await; + let _ = kio::clock::timeout(std::time::Duration::from_secs(10), driver).await; let closes = log.closes(); // A request stream closes at the source and its task may close again; the transport // keeps the first, so only a disagreeing code would reach the peer. @@ -3477,7 +3477,7 @@ mod tests { /// A request past our GOAWAY cutoff is refused in the answer its kind reads: an AUTH /// with AUTH_ERROR carrying GOING_AWAY, since its presenter takes anything else as a /// violation, and the rest with REQUEST_ERROR. - #[moq_clock::test] + #[kio::test] async fn a_request_past_our_goaway_is_refused_in_its_own_answer() { const VERSION: Version = Version::Draft18; let reason = b"going away"; @@ -3502,7 +3502,7 @@ mod tests { /// A malformed request closes the session with the draft's code: a Request ID of the /// wrong parity, a namespace or name outside its bounds, or a body that does not fill /// its length. - #[moq_clock::test] + #[kio::test] async fn a_malformed_request_closes_the_session() { for version in [Version::Draft18, Version::Draft22] { let subscribe = |body: &[u8]| frame(version, ietf::Subscribe::ID, body); @@ -3573,7 +3573,7 @@ mod tests { /// A request stream may carry one GOAWAY, migrating that request alone: it leaves the /// session up, even on two streams at once. A second on one stream, or an unknown /// message, closes the session as a PROTOCOL_VIOLATION. - #[moq_clock::test] + #[kio::test] async fn a_request_stream_carries_at_most_one_goaway() { for version in [Version::Draft18, Version::Draft22] { let one = goaway(version, None); @@ -3602,7 +3602,7 @@ mod tests { /// Only a server may name a new session in a request stream GOAWAY: a client that does /// closes the session as a PROTOCOL_VIOLATION. - #[moq_clock::test] + #[kio::test] async fn a_request_stream_goaway_redirects_only_from_a_server() { for version in [Version::Draft18, Version::Draft22] { let mut body = Vec::new(); diff --git a/rs/moq-net/src/ietf/subscriber.rs b/rs/moq-net/src/ietf/subscriber.rs index 54cebefe420..5ed4f057c9c 100644 --- a/rs/moq-net/src/ietf/subscriber.rs +++ b/rs/moq-net/src/ietf/subscriber.rs @@ -6058,7 +6058,7 @@ mod tests { (live, consumer) } - #[moq_clock::test] + #[kio::test] async fn internal_alias_resolution_ends_with_its_session() { let aliases = TrackAliases::default(); let consumer = aliases.consume(); @@ -6111,14 +6111,14 @@ mod tests { responses } - #[moq_clock::test] + #[kio::test] async fn bare_fin_requires_publish_done() { for clean in [false, true] { check_publish_fin(fin_responses(clean), clean).await; } } - #[moq_clock::test] + #[kio::test] #[ignore = "requires Bun; run by just test bare-fin in interop CI"] async fn bare_fin_interop() { for clean in [false, true] { @@ -6127,7 +6127,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn track_alias_waits_for_control_message() { let runtime = crate::time::sim(); let aliases = TrackAliases::default(); @@ -6143,7 +6143,7 @@ mod tests { /// SUBSCRIBE_OK has not accepted the track, so the map holds no producer. /// Abort still has to reject the parked origin request with the session error. - #[moq_clock::test] + #[kio::test] async fn session_death_rejects_a_subscribe_still_setting_up() { let broadcast = crate::broadcast::Info::new().produce(); let mut dynamic = broadcast.requests(); @@ -6179,7 +6179,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn unknown_track_alias_times_out() { let aliases = TrackAliases::default(); assert!(matches!( @@ -6189,7 +6189,7 @@ mod tests { } async fn settle() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } fn occurrences(log: &crate::lite::test_transport::Log, needle: &[u8]) -> usize { @@ -6233,7 +6233,7 @@ mod tests { /// A side that declined MoQ Solicit invited unsolicited advertisements, so one is /// expected even from a peer that implements the extension. - #[moq_clock::test] + #[kio::test] async fn an_announce_to_a_side_that_declined_solicit_is_fine() { for solicit in [Some(true), Some(false), None] { assert!( @@ -6249,7 +6249,7 @@ mod tests { /// /// Writing the option is the proof of support, whichever value it carries: an explicit /// 0 says "no requirement of my own" and still says "I read yours". - #[moq_clock::test] + #[kio::test] async fn an_announce_from_a_peer_that_implements_solicit_is_fatal() { assert!( unsolicited_is_a_violation(Some(true), Version::Draft18), @@ -6264,7 +6264,7 @@ mod tests { /// A peer that declared nothing has never heard of the extension, so it cannot have /// honored ours. Announcing at us is what it is supposed to do, and #2730 is what /// happens when nobody does. - #[moq_clock::test] + #[kio::test] async fn an_announce_from_a_peer_that_declared_nothing_is_fine() { assert!(!unsolicited_is_a_violation(None, Version::Draft18)); } @@ -6272,7 +6272,7 @@ mod tests { /// A rooted subscriber asks the peer for its permitted SCOPE. The root names where /// replies mount on our side, which is meaningless to a peer outside our namespace, /// so sending it asks for a prefix that matches nothing there. - #[moq_clock::test] + #[kio::test] async fn a_rooted_subscriber_asks_for_its_scope_not_its_root() { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let scope = crate::Patterns::from(crate::Pattern::subtree("cam").unwrap()); @@ -6358,7 +6358,7 @@ mod tests { /// Driven through the real response stream rather than by recomputing the join /// here: a test that did its own `prefix.join(suffix)` would still pass if the /// NAMESPACE arm went back to joining the root. - #[moq_clock::test] + #[kio::test] async fn a_rooted_subscriber_mounts_a_reply_under_its_root_once() { const VERSION: Version = Version::Draft18; @@ -6421,7 +6421,7 @@ mod tests { /// A NAMESPACE that loops back through us detaches its route, but the advertisement /// stays live on the wire until its NAMESPACE_DONE: a repeat that restores a clean path /// while gaining or losing an epoch is still the violation it would be without the loop. - #[moq_clock::test] + #[kio::test] async fn a_reflected_namespace_keeps_its_epoch_live() { const VERSION: Version = Version::Draft18; let us = crate::Hop::new(5).unwrap(); @@ -6516,7 +6516,7 @@ mod tests { /// A namespace the peer holds on a SUBSCRIBE_NAMESPACE stream takes an announce slot /// whatever we make of it, so reflected ones the origin never sees still exhaust the /// session's budget, and a NAMESPACE_DONE gives the slot back. - #[moq_clock::test] + #[kio::test] async fn a_reflected_namespace_holds_an_announce_slot() { const VERSION: Version = Version::Draft18; let us = crate::Hop::new(5).unwrap(); @@ -6608,7 +6608,7 @@ mod tests { /// MoQ Active Count is negotiated, so a REQUEST_OK that breaks the negotiation /// either way is the peer's fault: a count we cannot rely on, or one missing where we /// would otherwise wait on it forever. - #[moq_clock::test] + #[kio::test] async fn a_count_the_negotiation_did_not_promise_is_a_violation() { const VERSION: Version = Version::Draft18; @@ -6739,7 +6739,7 @@ mod tests { } /// With MoQ Active Count, the origin syncs once the counted NAMESPACEs are in. - #[moq_clock::test] + #[kio::test] async fn counted_namespaces_catch_up() { const VERSION: Version = Version::Draft18; for (entries, synced) in [(&["a"][..], false), (&["a", "b"][..], true)] { @@ -6769,7 +6769,7 @@ mod tests { } /// Without MoQ Active Count, REQUEST_OK is the best boundary there is. - #[moq_clock::test] + #[kio::test] async fn an_uncounted_answer_catches_up_on_the_ok() { const VERSION: Version = Version::Draft18; let session = crate::lite::test_transport::ScriptedSession::new(counted_response(VERSION, None, &[]).await); @@ -6790,7 +6790,7 @@ mod tests { } /// A counted set cut short, by a NAMESPACE_DONE or the stream ending, is the peer's fault. - #[moq_clock::test] + #[kio::test] async fn a_counted_set_cut_short_is_a_violation() { const VERSION: Version = Version::Draft18; for (entries, fin) in [(&["a", "-a"][..], false), (&["a"][..], true)] { @@ -6823,7 +6823,7 @@ mod tests { /// A cancelled subscription leaves its alias behind, so the groups the publisher is /// still sending are discarded at once instead of stalling out the timeout and being /// reported as unknown. - #[moq_clock::test] + #[kio::test] async fn retired_alias_drops_late_groups_immediately() { let aliases = TrackAliases::default(); insert_track_alias(&aliases, 7, RequestId(11)).unwrap(); @@ -6847,7 +6847,7 @@ mod tests { /// Covers the error this path produces and the code it maps to, not the dispatch loop /// that sends it. `session::a_group_for_a_retired_alias_is_stopped_with_cancelled` /// drives that loop over a real receive stream. - #[moq_clock::test] + #[kio::test] async fn a_retired_alias_maps_to_the_cancelled_code() { let aliases = TrackAliases::default(); insert_track_alias(&aliases, 7, RequestId(11)).unwrap(); @@ -6941,7 +6941,7 @@ mod tests { /// same alias. Our filters are all LargestObject, so we cannot re-apply them to tell the /// groups apart, but that is one subscription's problem. Killing the session over a /// legal choice would take every other broadcast down with it. - #[moq_clock::test] + #[kio::test] async fn a_shared_alias_for_one_track_costs_only_that_subscription() { let subscriber = subscriber_with_tracks(&[(RequestId(11), "cam", "video"), (RequestId(13), "cam", "video")]); @@ -6955,7 +6955,7 @@ mod tests { /// Relays keep datagram Object IDs, while plain readers see only normal object 0. /// An unbound alias is dropped, and a malformed datagram is the peer's violation. - #[moq_clock::test] + #[kio::test] async fn an_object_datagram_is_a_datagram_group() { use crate::coding::Encode as _; use futures::FutureExt as _; @@ -7028,7 +7028,7 @@ mod tests { /// A datagram that lands before SUBSCRIBE_OK binds its alias is dropped, not held for the /// subscription to replay once it is bound. The reader was already subscribed, so only the /// missing alias can have dropped it. - #[moq_clock::test] + #[kio::test] async fn a_datagram_before_its_alias_is_dropped() { use crate::coding::Encode as _; use futures::FutureExt as _; @@ -7074,7 +7074,7 @@ mod tests { } /// One alias naming two different tracks is the collision section 11.1 makes fatal. - #[moq_clock::test] + #[kio::test] async fn an_alias_reused_for_another_track_is_fatal() { let subscriber = subscriber_with_tracks(&[(RequestId(11), "cam", "video"), (RequestId(13), "cam", "audio")]); @@ -7088,7 +7088,7 @@ mod tests { /// Same track name under a different broadcast is a different full track name, so it is /// a collision too. - #[moq_clock::test] + #[kio::test] async fn an_alias_reused_across_broadcasts_is_fatal() { let subscriber = subscriber_with_tracks(&[(RequestId(11), "cam", "video"), (RequestId(13), "screen", "video")]); @@ -7105,7 +7105,7 @@ mod tests { /// until STOP_SENDING arrives on the direction it writes (section 6.4.2.3), /// so a subscriber that only finishes leaves it feeding an alias forever. That is what /// turns a routine unsubscribe into an endless "unknown track alias" stream. - #[moq_clock::test] + #[kio::test] async fn cancelling_a_subscription_stops_the_publisher() { for version in [Version::Draft22] { let log = cancel_a_subscription(version).await; @@ -7128,7 +7128,7 @@ mod tests { /// polled. The publisher destroyed the request when it sent the error, so treating that /// as abandonment would cancel a request that no longer exists and name a dead id back at /// a peer entitled to object. The answer wins. - #[moq_clock::test] + #[kio::test] async fn a_ready_rejection_beats_local_abandonment() { const VERSION: Version = Version::Draft18; @@ -7185,13 +7185,13 @@ mod tests { drop(track); drop(consumer); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; }); - moq_clock::timeout(std::time::Duration::from_secs(1), serving) + kio::clock::timeout(std::time::Duration::from_secs(1), serving) .await .expect("run_subscribe did not finish") .unwrap(); @@ -7239,7 +7239,7 @@ mod tests { /// A subscribe whose readers leave while it waits on a token ends, rather than holding /// its task and track until a token that may never be answered. - #[moq_clock::test] + #[kio::test] async fn an_abandoned_subscribe_stops_waiting_for_auth() { const VERSION: Version = Version::Draft18; let (mut subscriber, log, _auth, _tokens, _task_set) = waiting_on_auth(VERSION); @@ -7251,13 +7251,13 @@ mod tests { let subscription = track.subscribe(None); let request = dynamic.requested_track().await.expect("no track requested"); - let mut serving = moq_clock::sim::spawn(async move { + let mut serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; }); assert!( - moq_clock::timeout(std::time::Duration::from_secs(1), &mut serving) + kio::clock::timeout(std::time::Duration::from_secs(1), &mut serving) .await .is_err(), "finished while the track was wanted" @@ -7266,7 +7266,7 @@ mod tests { drop(subscription); drop(track); drop(consumer); - moq_clock::timeout(std::time::Duration::from_secs(1), serving) + kio::clock::timeout(std::time::Duration::from_secs(1), serving) .await .expect("an abandoned subscribe kept waiting on its token") .unwrap(); @@ -7278,7 +7278,7 @@ mod tests { /// A subscribe under an announced route that is withdrawn while it waits on a token /// ends, judged against the union as it stands, so routing can recover. - #[moq_clock::test] + #[kio::test] async fn a_withdrawn_route_ends_a_subscribe_waiting_for_auth() { const VERSION: Version = Version::Draft18; let (mut subscriber, log, _auth, _tokens, _task_set) = waiting_on_auth(VERSION); @@ -7292,20 +7292,20 @@ mod tests { let route = kio::Producer::<()>::default(); let live = route.consume(); - let mut serving = moq_clock::sim::spawn(async move { + let mut serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, Some(live), request) .await; }); assert!( - moq_clock::timeout(std::time::Duration::from_secs(1), &mut serving) + kio::clock::timeout(std::time::Duration::from_secs(1), &mut serving) .await .is_err(), "finished while the route stood" ); drop(route); - moq_clock::timeout(std::time::Duration::from_secs(1), serving) + kio::clock::timeout(std::time::Duration::from_secs(1), serving) .await .expect("a withdrawn route kept the subscribe waiting on its token") .unwrap(); @@ -7320,7 +7320,7 @@ mod tests { /// independent of the request stream. If the last consumer leaves in that window, the /// subscriber still owes it a cancellation: walking away silently is what leaves it /// serving a track nobody reads. - #[moq_clock::test] + #[kio::test] async fn abandoning_before_subscribe_ok_still_cancels() { const VERSION: Version = Version::Draft18; @@ -7351,7 +7351,7 @@ mod tests { let request = dynamic.requested_track().await.expect("no track requested"); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -7365,7 +7365,7 @@ mod tests { drop(track); drop(consumer); - moq_clock::timeout(std::time::Duration::from_secs(1), serving) + kio::clock::timeout(std::time::Duration::from_secs(1), serving) .await .expect("run_subscribe parked waiting for a response that never came") .unwrap(); @@ -7388,7 +7388,7 @@ mod tests { /// A grant revoked while the SUBSCRIBE waits for its answer refuses the request and /// cancels the subscribe at once, not once the peer answers or acknowledges the cancel. - #[moq_clock::test] + #[kio::test] async fn a_revocation_never_waits_behind_subscribe_ok() { for version in [Version::Draft18, Version::Draft22] { // A peer that accepts the stream and then says nothing at all, not even @@ -7419,7 +7419,7 @@ mod tests { let subscription = track.subscribe(None); let request = dynamic.requested_track().await.expect("no track requested"); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -7429,7 +7429,7 @@ mod tests { assert!(occurrences(&log, &[ietf::Subscribe::ID as u8]) > 0, "{version}"); auth.ended(0, Error::Session(SessionError::Unauthorized)); - let result = moq_clock::timeout(Duration::from_secs(1), subscription) + let result = kio::clock::timeout(Duration::from_secs(1), subscription) .await .unwrap_or_else(|_| panic!("{version}: the revocation waited behind SUBSCRIBE_OK")); assert!( @@ -7449,7 +7449,7 @@ mod tests { /// An unanswered epochless request cannot prove which instance the peer resolved. /// Retiring its source cancels it even while the caller keeps its demand. - #[moq_clock::test] + #[kio::test] async fn a_retirement_before_subscribe_ok_refuses_the_subscription() { const VERSION: Version = Version::Draft18; @@ -7483,7 +7483,7 @@ mod tests { let request = dynamic.requested_track().await.expect("no track requested"); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -7666,7 +7666,7 @@ mod tests { macro_rules! setup_wait_test { ($name:ident, $stage:ident, [$($version:ident),+]) => { - #[moq_clock::test] + #[kio::test] async fn $name() { for version in [$(Version::$version),+] { for cause in [Invalidated::Retired, Invalidated::Revoked, Invalidated::Narrowed, Invalidated::Expired] { @@ -7718,7 +7718,7 @@ mod tests { /// finished is still retransmitting, so the writer's Drop reset would discard the message /// before the peer read it. Closing consumes the writer, which is what removes that /// fallback, so a reset here means the cancellation never landed. - #[moq_clock::test] + #[kio::test] async fn cancelling_does_not_reset_away_the_unsubscribe() { for version in [Version::Draft22] { let log = cancel_a_subscription(version).await; @@ -7804,7 +7804,7 @@ mod tests { // subscription reached Established rather than assume it. let probe = subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -7827,7 +7827,7 @@ mod tests { drop(track); drop(consumer); - moq_clock::timeout(crate::track::IDLE_LINGER * 2, serving) + kio::clock::timeout(crate::track::IDLE_LINGER * 2, serving) .await .expect("run_subscribe did not finish") .unwrap(); @@ -7886,7 +7886,7 @@ mod tests { let request = dynamic.requested_track().await.expect("no track requested"); let probe = subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -7938,7 +7938,7 @@ mod tests { /// Serve the front's request on its wake, before the requesting call can return. /// A peer that refuses TRACK_STATUS must still receive SUBSCRIBE for a catalog reader. - #[moq_clock::test] + #[kio::test] async fn a_catalog_subscription_never_requests_track_status() { use std::sync::{Arc, Mutex}; use std::task::{Context, Wake, Waker}; @@ -8014,7 +8014,7 @@ mod tests { // Run the request classification before the front can add demand after // its query. The simulator takes over only once the wire work parks. if std::future::Future::poll(serving.as_mut(), &mut Context::from_waker(Waker::noop())).is_pending() { - drop(moq_clock::sim::spawn(serving)); + drop(kio::clock::sim::spawn(serving)); } } } @@ -8043,7 +8043,7 @@ mod tests { /// Query-only and fetch-only demand fail with the peer's TRACK_STATUS refusal, /// including NOT_SUPPORTED and undefined codes, without opening a subscription. - #[moq_clock::test] + #[kio::test] async fn a_refused_track_status_never_subscribes() { for version in [Version::Draft18, Version::Draft22] { for code in [3, u64::from(u32::MAX)] { @@ -8111,7 +8111,7 @@ mod tests { /// A copy that already knows its track, here from TRACK_STATUS_OK, opts out of the /// properties when a subscriber returns, and keeps the units it learned rather than /// taking the empty block the opted-out SUBSCRIBE_OK carries. - #[moq_clock::test] + #[kio::test] async fn a_resumed_subscribe_opts_out_of_known_properties() { let declared = Timescale::new(90_000).unwrap(); for version in [Version::Draft18, Version::Draft22] { @@ -8168,7 +8168,7 @@ mod tests { let request = dynamic.requested_track().await.expect("no track requested"); let probe = subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -8219,7 +8219,7 @@ mod tests { /// The publisher opens no fetch stream for an empty range, so a fill against a track /// with no content is owed nothing. Leaving it outstanding would withhold every later /// group behind a head that is never coming. - #[moq_clock::test] + #[kio::test] async fn an_empty_track_settles_the_fill() { assert!( !fill_after_subscribe_ok(None, Some(37)).await, @@ -8229,7 +8229,7 @@ mod tests { /// A track with content does owe one, so the fill stays outstanding until its fetch /// stream arrives. - #[moq_clock::test] + #[kio::test] async fn a_track_with_content_still_awaits_its_fill() { assert!( fill_after_subscribe_ok(Some(ietf::Location { group: 3, object: 4 }), Some(37)).await, @@ -8237,7 +8237,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn an_older_peer_without_priority_property_uses_wire_default() { assert!(!fill_after_subscribe_ok(None, None).await); } @@ -8261,7 +8261,7 @@ mod tests { /// A namespace past the session's cap closes the session with TOO_MANY_REQUESTS, a /// repeat of a held namespace costs nothing, and a retraction frees its slot. - #[moq_clock::test] + #[kio::test] async fn namespaces_past_the_cap_close_the_session() { let session = crate::lite::test_transport::SinkSession::new(Default::default()); let log = session.log.clone(); @@ -8317,7 +8317,7 @@ mod tests { /// moq-transport carries no hop ids, so a peer's broadcasts are marked /// anonymous (hop 0). An identity assigned via `Client::with_peer_hop` is /// stored as `via` for split-horizon and never written into the chain. - #[moq_clock::test] + #[kio::test] async fn assigned_peer_hop_attributes_announces() { let session = crate::lite::test_transport::SinkSession::new(Default::default()); let assigned = crate::Hop::new(777).unwrap(); @@ -8360,7 +8360,7 @@ mod tests { /// claiming the path: taking it over would leave only a route we refuse to /// advertise back to the peer, and the publish direction would withdraw the /// announce it just made. - #[moq_clock::test] + #[kio::test] async fn reflected_announce_does_not_evict_the_source_we_publish() { let session = crate::lite::test_transport::SinkSession::new(Default::default()); let peer = crate::Hop::new(777).unwrap(); @@ -8414,7 +8414,7 @@ mod tests { /// Two sessions assigned the same identity announce the same anonymous chain. /// Without an epoch the fresh session is another source, so consumers restart /// once, and retracting the stale session leaves the fresh route standing quietly. - #[moq_clock::test] + #[kio::test] async fn reconnecting_peer_restarts_the_route() { let peer = crate::Hop::new(777).unwrap(); let self_origin = crate::Hop::new(1).unwrap(); @@ -8447,13 +8447,13 @@ mod tests { }; let first = connect(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; announced.expect_next_active("room/host").await; // The peer reconnects before the old session is retired: an identical route // from the fresh session wins at once, as another source. let _second = connect(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; announced.expect_next_restarted("room/host").await; announced.assert_next_wait(); @@ -8462,7 +8462,7 @@ mod tests { // The stale session finally retracting leaves the fresh route standing. drop(first); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; announced.assert_next_wait(); assert!(routed_now(&consumer, "room/host").is_some()); } @@ -8505,7 +8505,7 @@ mod tests { /// A negotiated advertisement carries the whole path and its accumulated cost, and /// the receiving relay charges its own link on top (saturating, so an absurd /// upstream value ranks last rather than wrapping to best). - #[moq_clock::test] + #[kio::test] async fn cluster_advert_becomes_a_route_with_the_link_charged() { let (subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -8541,7 +8541,7 @@ mod tests { /// An advertisement whose path already contains our own Hop ID looped back: /// forwarding it would extend the loop and subscribing through it would route us /// back to ourselves. Hop ID 0 identifies nothing, so it is never a loop. - #[moq_clock::test] + #[kio::test] async fn cluster_advert_loop_is_discarded() { let (subscriber, _origin) = cluster_subscriber(crate::Hop::new(5).unwrap()); let peer = cluster::Peer { @@ -8564,7 +8564,7 @@ mod tests { /// An unpriced link costs 1, so an unpriced mesh accumulates a cost equal to the /// hop count and degenerates to shortest-path routing. - #[moq_clock::test] + #[kio::test] async fn unpriced_link_costs_one() { let (subscriber, _origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let peer = cluster::Peer { @@ -8593,7 +8593,7 @@ mod tests { /// /// Driven through the real exit path rather than by calling `stop_announce`: a test /// that picked the detach itself would still pass if the stream stopped using it. - #[moq_clock::test] + #[kio::test] async fn a_lost_namespace_stream_closes_the_broadcast() { const VERSION: Version = Version::Draft18; @@ -8647,7 +8647,7 @@ mod tests { /// NAMESPACE has no REQUEST_UPDATE, so a peer reprices one by re-sending it on the /// SUBSCRIBE_NAMESPACE stream. The repeat is neither a duplicate nor a violation: it /// replaces the advertisement in place, and the route is never retracted for it. - #[moq_clock::test] + #[kio::test] async fn a_re_sent_namespace_reprices_in_place() { const VERSION: Version = Version::Draft18; @@ -8740,7 +8740,7 @@ mod tests { /// The peer explicitly retracting a namespace ends the broadcast immediately: it /// said the namespace is gone, so a later create at the path is new content. - #[moq_clock::test] + #[kio::test] async fn an_explicit_namespace_done_closes_the_broadcast() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -8759,7 +8759,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn publish_namespace_requester_fin_keeps_the_route() { for version in [Version::Draft18, Version::Draft22] { for reset in [false, true] { @@ -8817,7 +8817,7 @@ mod tests { /// /// Driven through the real exit path rather than by calling `stop_announce`: a test /// that picked the detach itself would still pass if the stream stopped using it. - #[moq_clock::test] + #[kio::test] async fn a_broken_publish_namespace_stream_closes_the_broadcast() { const VERSION: Version = Version::Draft18; @@ -8882,7 +8882,7 @@ mod tests { /// which is what these advertisements would be had they arrived on two sessions. The /// refcount is a detail of sharing one `SourceGuard` per session; it must not change /// what the origin sees. - #[moq_clock::test] + #[kio::test] async fn the_last_owner_out_decides_the_detach() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -8920,7 +8920,7 @@ mod tests { /// A source minted under a namespace goes once nothing holds it, so the session keeps /// nothing for a path its fronts let go of, and goes at once as the namespace is /// retracted, held or not. - #[moq_clock::test] + #[kio::test] async fn a_minted_source_closes_unheld_or_retracted() { let (subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let run = |route: &kio::Producer<()>| { @@ -8929,7 +8929,7 @@ mod tests { ); let (holder, dynamic) = (source.consume(), source.requests()); let (this, route) = (subscriber.clone(), route.consume()); - let task = moq_clock::sim::spawn(async move { + let task = kio::clock::sim::spawn(async move { this.run_broadcast(crate::Path::from_static("pool/p"), source, dynamic, Some(route)) .await }); @@ -8955,7 +8955,7 @@ mod tests { /// An advertisement with no path of its own (a peer that did not negotiate the /// extension) still pays for the link it arrived over. Forwarding it as free would /// advertise a paid upstream as the cheapest route in the mesh. - #[moq_clock::test] + #[kio::test] async fn a_pathless_advert_still_pays_for_its_link() { let (unpriced, _origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let peer = cluster::Peer::default(); @@ -8981,7 +8981,7 @@ mod tests { /// An update replaces the advertisement in place: the route moves, the refcount does /// not, and the source is not torn down. - #[moq_clock::test] + #[kio::test] async fn cluster_update_replaces_in_place() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -9022,7 +9022,7 @@ mod tests { /// relay signals that it started carrying the namespace), so the source and every /// live subscription on it must survive. Reading the repeat as a new publisher /// detached the source milliseconds after SUBSCRIBE went out. - #[moq_clock::test] + #[kio::test] async fn anonymous_publisher_survives_a_repricing_update() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -9072,7 +9072,7 @@ mod tests { /// another, on separate streams that arrive in either order. The newest advertisement /// stands, so neither the old one's late update nor its withdrawal reverts the route /// to the instance it named. - #[moq_clock::test] + #[kio::test] async fn a_reordered_replacement_keeps_the_new_instance() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -9120,7 +9120,7 @@ mod tests { /// MoQ Epoch: a namespace advertised both inline and by a later PUBLISH_NAMESPACE takes /// another epoch from either. An inline repeat under the new epoch is the newest /// advertisement, not an update to the older of the two. - #[moq_clock::test] + #[kio::test] async fn a_repeat_under_another_epoch_becomes_the_newest() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -9162,7 +9162,7 @@ mod tests { /// Two *separate* advertisements for one namespace refcount a single route: /// it takes both retractions to retract it. - #[moq_clock::test] + #[kio::test] async fn separate_adverts_refcount_the_route() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -9200,7 +9200,7 @@ mod tests { /// one namespace are then two messages about a single source, and treating the /// second as a different publisher would tear down what the first attached, right /// as a subscriber is resolving a track through it. - #[moq_clock::test] + #[kio::test] async fn pathless_adverts_never_replace_the_source() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -9231,7 +9231,7 @@ mod tests { /// An update replaces the advertisement it repeats. When the replacement loops back /// through us it is a retraction, so the route we were holding must go: keeping it /// would leave subscriptions on a path the peer no longer offers. - #[moq_clock::test] + #[kio::test] async fn reflected_replacement_retracts_the_route() { let self_origin = crate::Hop::new(5).unwrap(); let (mut subscriber, origin) = cluster_subscriber(self_origin); @@ -9412,7 +9412,7 @@ mod tests { /// namespace even when the peer's path goes clean again. It is also not ours to /// close: a peer MAY legitimately send a path carrying our Hop ID when a redundant /// sibling shares it, which the draft answers with "discard", not PROTOCOL_VIOLATION. - #[moq_clock::test] + #[kio::test] async fn a_reflected_update_detaches_but_keeps_the_stream() { let self_origin = crate::Hop::new(5).unwrap(); let peer = peer_9(); @@ -9462,7 +9462,7 @@ mod tests { /// Having kept the stream, a later usable path re-attaches on it. This is the whole /// reason the stream stays open. - #[moq_clock::test] + #[kio::test] async fn a_clean_update_after_a_reflection_reattaches() { let self_origin = crate::Hop::new(5).unwrap(); let peer = peer_9(); @@ -9505,7 +9505,7 @@ mod tests { /// A token-authorized announce re-attaching after a reflection reuses the slot its grant /// still holds: with a cap of one, taking a second would close the session. - #[moq_clock::test] + #[kio::test] async fn a_token_announce_reattaches_on_its_own_slot() { let self_origin = crate::Hop::new(5).unwrap(); let peer = peer_9(); @@ -9595,7 +9595,7 @@ mod tests { /// The expected update: a relay that started carrying the namespace reprices it to /// 0. REQUEST_UPDATE keeps an omitted parameter, so the 0 arrives explicit and alone, /// lands on the path already held, and is answered REQUEST_OK. - #[moq_clock::test] + #[kio::test] async fn an_explicit_zero_reprices_the_held_path() { const VERSION: Version = Version::Draft18; let self_origin = crate::Hop::new(5).unwrap(); @@ -9667,7 +9667,7 @@ mod tests { /// closed, which withdraws the advertisement (moq-transport Section 9.5.1). The /// caller releases the route, so the loop must return cleanly rather than fault the /// session. - #[moq_clock::test] + #[kio::test] async fn a_failed_update_withdraws_the_advertisement() { let self_origin = crate::Hop::new(5).unwrap(); let peer = peer_9(); @@ -9725,7 +9725,7 @@ mod tests { /// An update whose first Hop ID differs names a different publisher. It still /// replaces the advertisement in place and the stream stays open: the origin, not the /// session, keeps the two publishers' content apart. - #[moq_clock::test] + #[kio::test] async fn an_update_that_changes_the_publisher_applies_in_place() { let self_origin = crate::Hop::new(5).unwrap(); let peer = peer_9(); @@ -9773,7 +9773,7 @@ mod tests { /// A second PUBLISH_NAMESPACE on the stream that already carries one is not an /// update any more: it is the base draft's duplicate request, a protocol violation. - #[moq_clock::test] + #[kio::test] async fn a_repeated_publish_namespace_is_a_duplicate() { const VERSION: Version = Version::Draft18; let self_origin = crate::Hop::new(5).unwrap(); @@ -9840,7 +9840,7 @@ mod tests { /// without a NAMESPACE_DONE for each, those refcounts must still be released, or the /// source stays attached for the rest of the session (the stream can die while the /// session keeps running). - #[moq_clock::test] + #[kio::test] async fn namespace_stream_close_releases_live_paths() { let (mut subscriber, origin) = cluster_subscriber(crate::Hop::new(1).unwrap()); let consumer = origin.consume(); @@ -9870,7 +9870,7 @@ mod tests { /// PUBLISH offers one track, but a source attaches per namespace and serves every /// track under it. Rather than invent a namespace-level source from a track-level /// offer, decline the request with NOT_SUPPORTED and leave the session running. - #[moq_clock::test] + #[kio::test] async fn publish_is_rejected_without_announcing() { for version in [Version::Draft18] { // An open gate, so the rejection actually reaches the wire. @@ -9913,7 +9913,7 @@ mod tests { // Errors are surfaced to the peer on the stream, not raised as a session error. subscriber.run_publish_stream(stream, msg).await.unwrap(); - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; assert!( routed_now(&consumer, "room/host").is_none(), @@ -10099,7 +10099,7 @@ mod tests { /// A request token on a PUBLISH_NAMESPACE the session grant does not cover authorizes /// the announce: the subscriber verifies it through the acceptor and attaches the route. - #[moq_clock::test] + #[kio::test] async fn a_publish_namespace_token_authorizes_an_uncovered_announce() { const VERSION: Version = Version::Draft18; let (mut subscriber, mut requests, _cred, consumer, session) = auth_announce_harness(VERSION, Vec::new()); @@ -10138,7 +10138,7 @@ mod tests { /// An announce's grant ending while its first answer waits on a peer that stopped /// reading retracts the route at once, not once the answer drains: the peer is told /// only afterwards. - #[moq_clock::test] + #[kio::test] async fn a_revoked_token_retracts_an_announce_whose_ok_is_blocked() { for version in [Version::Draft18, Version::Draft22] { let gate = kio::Producer::new(false); @@ -10189,7 +10189,7 @@ mod tests { }; *open = true; drop(open); - let _ = moq_clock::timeout(std::time::Duration::from_secs(1), run.as_mut()) + let _ = kio::clock::timeout(std::time::Duration::from_secs(1), run.as_mut()) .await .unwrap_or_else(|_| panic!("{version}: outlived its grant")); @@ -10218,7 +10218,7 @@ mod tests { /// A refused request token is answered UNAUTHORIZED and the announce is not attached; the /// session is untouched. - #[moq_clock::test] + #[kio::test] async fn a_refused_publish_namespace_token_is_not_announced() { const VERSION: Version = Version::Draft18; let (mut subscriber, mut requests, _cred, consumer, session) = auth_announce_harness(VERSION, Vec::new()); @@ -10258,7 +10258,7 @@ mod tests { /// What the peer's AUTH_OK grants us never authorizes what the peer asks of us: with a /// covering peer grant and no limit, the application still verifies the announce's token, /// and its refusal refuses the announce. - #[moq_clock::test] + #[kio::test] async fn a_covering_peer_grant_never_skips_the_verifier() { const VERSION: Version = Version::Draft18; let auth = crate::auth::Link::new(true); @@ -10308,7 +10308,7 @@ mod tests { /// one stands outside the limit: narrowing the limit away from it leaves it attached, as the /// publisher, which counts it token-backed, expects. Admitted on the limit instead, the /// narrowing would withhold a route the publisher still believes its token backs. - #[moq_clock::test] + #[kio::test] async fn a_covering_limit_still_verifies_the_token() { const VERSION: Version = Version::Draft18; let limit = |subtree: &str| crate::auth::Grant { @@ -10370,7 +10370,7 @@ mod tests { /// A token-authorized announce stands outside the limit while it lasts: a narrower limit /// leaves it attached, and only its own end retracts it. - #[moq_clock::test] + #[kio::test] async fn a_token_authorized_announce_is_exempt_from_the_limit() { const VERSION: Version = Version::Draft18; let auth = crate::auth::Link::new(false); @@ -10421,7 +10421,7 @@ mod tests { /// A token-authorized announce authorizes the tracks subscribed under it, outside the /// limit, and only while its token lasts. - #[moq_clock::test] + #[kio::test] async fn a_token_authorized_announce_admits_its_subscriptions() { const VERSION: Version = Version::Draft18; let auth = crate::auth::Link::new(false); @@ -10519,7 +10519,7 @@ mod tests { /// A REQUEST_UPDATE the acceptor renews keeps a token-authorized announce alive past the /// old grant's expiry: the subscriber re-verifies the token off the announce stream and /// re-arms the deadline. - #[moq_clock::test] + #[kio::test] async fn a_publish_namespace_renewal_extends_past_the_old_expiry() { for version in [Version::Draft18] { let (mut subscriber, mut requests, _cred, consumer, session) = @@ -10577,7 +10577,7 @@ mod tests { // Past the original 60s expiry: the renewal re-armed the deadline, so the announce // stays attached. - moq_clock::sim::advance(std::time::Duration::from_secs(120)).await; + kio::clock::sim::advance(std::time::Duration::from_secs(120)).await; for _ in 0..50 { let _ = futures::poll!(acceptor.as_mut()); assert!( @@ -10595,7 +10595,7 @@ mod tests { /// A lapsed grant retracts its announce at once, even while the withdrawal waits on a peer /// that never acknowledges the closed stream. - #[moq_clock::test] + #[kio::test] async fn a_lapsed_announce_grant_retracts_before_the_peer_reads() { const VERSION: Version = Version::Draft18; let session = crate::lite::test_transport::ScriptedSession::per_stream(vec![Vec::new()]).with_unacked_fin(); @@ -10631,7 +10631,7 @@ mod tests { } assert!(routed, "the token must authorize the announce"); - moq_clock::sim::advance(std::time::Duration::from_secs(120)).await; + kio::clock::sim::advance(std::time::Duration::from_secs(120)).await; let mut retracted = false; for _ in 0..50 { let _ = futures::poll!(acceptor.as_mut()); @@ -10653,7 +10653,7 @@ mod tests { /// An update repeating its token withdraws a token-authorized announce, retracting the route /// at once even while the withdrawal waits on a peer that never acknowledges it. - #[moq_clock::test] + #[kio::test] async fn a_repeated_token_update_retracts_before_the_peer_reads() { const VERSION: Version = Version::Draft18; const TOKEN: &[u8] = &[0x03, 0x00, 0xAA]; @@ -10705,7 +10705,7 @@ mod tests { /// Per draft-18 section 10.9.1, a refused PUBLISH_NAMESPACE /// renewal ends only that announce at once, by closing its stream, not by waiting for /// the old 60s grant to lapse. The session stays up. - #[moq_clock::test] + #[kio::test] async fn a_refused_publish_namespace_renewal_ends_the_announce() { for version in [Version::Draft18] { let (mut subscriber, mut requests, _cred, _consumer, session) = @@ -10767,7 +10767,7 @@ mod tests { /// Where tokens decide, a token arriving on an update for an announce the limit admitted /// without one is refused rather than taken unread: it ends only that announce, unverified. - #[moq_clock::test] + #[kio::test] async fn a_token_on_an_announce_admitted_without_one_is_refused() { for version in [Version::Draft18] { let (mut subscriber, mut requests, _cred, consumer, session) = @@ -10813,7 +10813,7 @@ mod tests { /// renewal re-arms the grant and the HOP_PATH/ROUTE_COST re-route the advertisement, /// answered with the renewal's single response. Before the fix the token branch /// short-circuited the loop and the cluster parameters on the same update were dropped. - #[moq_clock::test] + #[kio::test] async fn an_update_applies_both_a_renewal_and_cluster_params() { const VERSION: Version = Version::Draft18; let (mut subscriber, mut requests, _cred, consumer, session) = @@ -10894,7 +10894,7 @@ mod tests { /// (0x05) changes only ROUTE_COST (4 to 1) and the last (0x07) only HOP_PATH, so the final /// cost shows the middle delta survived; the single slot this replaced dropped 0x05, /// leaving the cost at the initial 4 and never verifying its token. - #[moq_clock::test] + #[kio::test] async fn two_announce_renewals_buffered_behind_a_pending_verdict_each_apply_and_answer() { const VERSION: Version = Version::Draft18; @@ -10974,7 +10974,7 @@ mod tests { /// an announce stream broke the negotiated limit: draft-22 section 9.1.7 closes the session /// with TOO_MANY_REQUEST_UPDATES. run_publish_namespace_updates must close explicitly (the /// dispatcher does not close on an Error::Session), and surface that error too. - #[moq_clock::test] + #[kio::test] async fn announce_renewals_past_the_advertised_limit_close_the_session() { const VERSION: Version = Version::Draft22; @@ -11035,7 +11035,7 @@ mod tests { /// Exactly MAX_REQUEST_UPDATES outstanding (the one being verified plus the queue) is within /// the advertised limit, so a draft-22 peer holding that many is not faulted: the announce /// keeps running and the session stays up. - #[moq_clock::test] + #[kio::test] async fn announce_renewals_at_the_advertised_limit_keep_the_announce() { const VERSION: Version = Version::Draft18; @@ -11081,7 +11081,7 @@ mod tests { /// Drafts below 19 carry no MAX_REQUEST_UPDATES option, so a peer there agreed to no ceiling: /// the same flood that closes a draft-22 session must neither end the announce nor close the /// session on draft-18, because a conforming peer must not be stranded for a limit it never saw. - #[moq_clock::test] + #[kio::test] async fn older_drafts_do_not_strand_an_announce_flood() { const VERSION: Version = Version::Draft18; @@ -11124,7 +11124,7 @@ mod tests { /// On drafts without the option the guard is a memory backstop, not a protocol limit: a flood /// past it ends the one announce by finishing the stream, never the session. - #[moq_clock::test] + #[kio::test] async fn an_older_draft_announce_flood_past_the_guard_ends_the_announce() { const VERSION: Version = Version::Draft18; @@ -11173,7 +11173,7 @@ mod tests { /// A flood past the guard retracts the announce at once, even while the withdrawal waits on /// a peer that never acknowledges the finished stream. - #[moq_clock::test] + #[kio::test] async fn a_flood_past_the_guard_retracts_before_the_peer_reads() { const VERSION: Version = Version::Draft18; @@ -11295,7 +11295,7 @@ mod tests { /// On a session without the AUTH extension, a token-bearing PUBLISH_NAMESPACE the limit /// does not cover is verified by the application. Admitted on a covering grant; refused /// UNAUTHORIZED (not admitted) on refusal. This is the standard moq-transport peer shape. - #[moq_clock::test] + #[kio::test] async fn a_request_token_on_a_no_auth_session_is_verified() { const VERSION: Version = Version::Draft18; @@ -11388,7 +11388,7 @@ mod tests { /// A peer that ends the announce while a renewal is still being verified ends it here too: /// with a grant that never expires and an acceptor that never answers the renewal, only /// the stream closing can end the request, and it must. - #[moq_clock::test] + #[kio::test] async fn a_closed_announce_ends_while_a_renewal_is_pending() { const VERSION: Version = Version::Draft18; let session = crate::lite::test_transport::ScriptedSession::per_stream_eof(vec![ @@ -11443,7 +11443,7 @@ mod tests { /// An update queued behind a pending renewal spends its request ID on arrival, so the /// announce ending before the queue drains leaves no ID the peer could reuse. - #[moq_clock::test] + #[kio::test] async fn a_queued_update_spends_its_request_id_when_the_announce_ends() { const VERSION: Version = Version::Draft18; let queued = { @@ -11505,7 +11505,7 @@ mod tests { /// An update queued behind a pending renewal is decoded on arrival, so a session-fatal one /// still closes the session when the peer withdraws before the queue drains. - #[moq_clock::test] + #[kio::test] async fn a_queued_malformed_update_is_fatal_despite_a_withdrawal() { const VERSION: Version = Version::Draft18; let queued = { @@ -11585,7 +11585,7 @@ mod tests { /// An announcing peer's token grant is checked on its `publish` patterns: a read-only grant /// does not admit a PUBLISH_NAMESPACE, a write-only one does. - #[moq_clock::test] + #[kio::test] async fn an_announce_token_needs_a_publish_grant() { const VERSION: Version = Version::Draft18; let read_only = crate::auth::Grant { @@ -11639,7 +11639,7 @@ mod tests { /// The additive constraint: a token-LESS PUBLISH_NAMESPACE on a no-auth session (None union) /// is admitted by the origin model exactly as before; the token path is never entered. - #[moq_clock::test] + #[kio::test] async fn a_token_less_request_on_a_no_auth_session_is_unchanged() { const VERSION: Version = Version::Draft18; let (mut subscriber, _requests, consumer, session) = auth_announce_harness_no_ext(VERSION, None); @@ -12289,7 +12289,7 @@ mod stitch_tests { /// The tail is read first, so it has to wait for the head rather than start a group of /// its own: with newest-first group order the publisher can prioritize the tail's stream /// ahead of the fill's. - #[moq_clock::test] + #[kio::test] async fn a_fill_and_its_tail_stitch_into_one_group() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -12324,7 +12324,7 @@ mod stitch_tests { /// History groups finish at the next group's header; only the newest head waits /// for the live tail. A gap in group numbering is not a missing object. - #[moq_clock::test] + #[kio::test] async fn a_multi_group_fill_finishes_history_before_stitching_the_tail() { let history: &[&[u8]] = &[b"history"]; let head: &[&[u8]] = &[b"head"]; @@ -12367,7 +12367,7 @@ mod stitch_tests { /// Cancelling an update fill in a partial payload releases its tail without /// cancelling the live subscription: its next whole group still arrives. - #[moq_clock::test] + #[kio::test] async fn cancelling_an_update_fill_does_not_park_the_live_tail() { const UPDATE: RequestId = RequestId(99); let h = Harness::new( @@ -12392,7 +12392,7 @@ mod stitch_tests { assert!(futures::poll!(filling.as_mut()).is_pending()); } let mut tail = h.stream().await; - let result = moq_clock::timeout(Duration::from_secs(1), h.subscriber.clone().recv_group(&mut tail)) + let result = kio::clock::timeout(Duration::from_secs(1), h.subscriber.clone().recv_group(&mut tail)) .await .expect("cancelled fill left its tail parked"); result.expect("the live tail still supports passthrough delivery"); @@ -12408,7 +12408,7 @@ mod stitch_tests { /// A tail parked on its head stops holding the end open, so the finished fill does until /// the head is claimed: otherwise the subscription looks settled between the fill /// finishing and the tail waking, and ends before the tail is read. - #[moq_clock::test] + #[kio::test] async fn an_unclaimed_fill_holds_the_end_open() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -12648,7 +12648,7 @@ mod stitch_tests { relay_passthrough(script, ingress, egress, None).await } - #[moq_clock::test] + #[kio::test] async fn passthrough_preserves_object_properties_through_dispatch() { for version in [Version::Draft22] { let mut script = Vec::new(); @@ -12684,7 +12684,7 @@ mod stitch_tests { /// A relayed Timestamp leaves in the units the publisher declared: the cache holds the /// track on the publisher's grid, so a copy of the same instance over another route /// matches it, including across a moq-lite hop that negotiated the `ietf` extension. - #[moq_clock::test] + #[kio::test] async fn passthrough_keeps_the_publishers_timestamp_units() { let version = Version::Draft22; // Timestamp 42 (ms), then an unknown property that must survive beside it. @@ -12742,7 +12742,7 @@ mod stitch_tests { bytes } - #[moq_clock::test] + #[kio::test] async fn passthrough_fetch_requires_marked_gaps_and_preserves_fields() { for version in [Version::Draft22] { for marked in [false, true] { @@ -12800,7 +12800,7 @@ mod stitch_tests { /// A relayed FETCH ends its answer at the last frame rather than carrying the /// END_OF_GROUP object, and the next relay fills its cache from that answer. - #[moq_clock::test] + #[kio::test] async fn passthrough_fetch_ends_at_the_last_frame() { for version in [Version::Draft22] { let objects = [ @@ -12840,7 +12840,7 @@ mod stitch_tests { /// Only a Normal object may carry properties: a status object with them is refused on /// ingest. - #[moq_clock::test] + #[kio::test] async fn passthrough_keeps_properties_off_status_objects() { for version in [Version::Draft22] { for status in [END_OF_GROUP, END_OF_TRACK] { @@ -12857,7 +12857,7 @@ mod stitch_tests { } } - #[moq_clock::test] + #[kio::test] async fn passthrough_refuses_contradictory_gap_properties() { for properties in [vec![0x3e, 2], vec![0x3e, 3], vec![0x3e, 1, 0, 1]] { let script = object_stream(VERSION, true, &[(0, &[], None), (2, &properties, None)]); @@ -12870,7 +12870,7 @@ mod stitch_tests { } } - #[moq_clock::test] + #[kio::test] async fn passthrough_fetch_ingest_keeps_marked_gaps_and_stitches_its_tail() { for version in [Version::Draft22] { let mut objects = Vec::new(); @@ -12936,7 +12936,7 @@ mod stitch_tests { } } - #[moq_clock::test] + #[kio::test] async fn passthrough_preserves_ids_first_object_and_end_status() { for version in [Version::Draft22] { for first in [false, true] { @@ -12966,7 +12966,7 @@ mod stitch_tests { } } - #[moq_clock::test] + #[kio::test] async fn passthrough_preserves_immutable_bytes() { for ingress in [Version::Draft18, Version::Draft22] { let mut inner = Vec::new(); @@ -12995,7 +12995,7 @@ mod stitch_tests { /// dropped on its way to draft 22 when mutable, and refused when sealed, through a /// moq-lite hop too: drafts 18 and 22 serialize a block alike, so only the track's /// carried ingress draft tells them apart. - #[moq_clock::test] + #[kio::test] async fn passthrough_keeps_0x06_from_crossing_to_draft_22() { let (ingress, egress) = (Version::Draft18, Version::Draft22); // 0x06 = 42 and 0x20 = 7, mutable. @@ -13026,7 +13026,7 @@ mod stitch_tests { } } - #[moq_clock::test] + #[kio::test] async fn passthrough_preserves_datagram_objects_through_dispatch() { // Also through a second relay behind a moq-lite hop with the `ietf` extension. for (version, ranged, hop) in [Version::Draft22] @@ -13140,7 +13140,7 @@ mod stitch_tests { } } - #[moq_clock::test] + #[kio::test] async fn passthrough_translates_mutable_property_encodings() { for ingress in [Version::Draft22] { let mut properties = Vec::new(); @@ -13166,7 +13166,7 @@ mod stitch_tests { } } - #[moq_clock::test] + #[kio::test] async fn passthrough_accepts_nonzero_first_objects_and_gaps() { for version in [Version::Draft22] { let mut script = Vec::new(); @@ -13195,7 +13195,7 @@ mod stitch_tests { } /// Relays retain a datagram's Object ID; a plain reader skips it until object 0 arrives. - #[moq_clock::test] + #[kio::test] async fn passthrough_accepts_datagrams_past_object_zero() { let version = Version::Draft22; let mut h = Harness::with_timescale(Fill::Done, vec![], None); @@ -13233,7 +13233,7 @@ mod stitch_tests { ); } - #[moq_clock::test] + #[kio::test] async fn an_overflowing_object_id_reaches_session_teardown() { let mut bytes = tail_stream(SEQUENCE, 0, &[b"head"]); crate::coding::Encoder::new(&mut bytes, VERSION.into()) @@ -13249,7 +13249,7 @@ mod stitch_tests { } /// A subgroup 1 stream costs only itself: the track's subgroup 0 stream still arrives. - #[moq_clock::test] + #[kio::test] async fn a_non_zero_subgroup_leaves_the_track_flowing() { let mut refused = Vec::new(); ietf::GroupHeader { @@ -13286,7 +13286,7 @@ mod stitch_tests { /// 2 is subgroup 2: refused like an explicit one, never taken as subgroup 0, even when the /// rest of that object is cut off. A compact stream with no objects names no subgroup and /// is subgroup 0. - #[moq_clock::test] + #[kio::test] async fn a_compact_non_zero_subgroup_is_refused() { for version in [Version::Draft22] { let compact = |sequence: u64, first: Option| { @@ -13377,7 +13377,7 @@ mod stitch_tests { } /// A truncated property inside a later object's extension block is a malformed group. - #[moq_clock::test] + #[kio::test] async fn a_malformed_extension_block_is_refused() { // Delta 0, then a 1-byte extension block holding half of a 2-byte varint. let mut stream = tail_stream(SEQUENCE, 0, &[b"ok"]); @@ -13387,14 +13387,14 @@ mod stitch_tests { } /// A FIN before the declared payload ends. - #[moq_clock::test] + #[kio::test] async fn a_payload_cut_short_is_refused() { let h = Harness::with_timescale(Fill::Done, vec![raw_stream(SEQUENCE, &[0, 4], &[1, 2])], None); h.dispatch_refused().await; } /// A declared object size past what a group may hold. - #[moq_clock::test] + #[kio::test] async fn an_oversized_frame_is_refused() { let size = crate::group::MAX_CACHE_BYTES + 1; let h = Harness::with_timescale(Fill::Done, vec![raw_stream(SEQUENCE, &[0, size], &[])], None); @@ -13402,7 +13402,7 @@ mod stitch_tests { } /// More objects than a group may hold. - #[moq_clock::test] + #[kio::test] async fn an_oversized_group_is_refused() { // Each empty object is its delta, a zero size, and the Normal status. let objects = vec![0u64; 3 * (crate::group::MAX_GROUP_FRAMES + 1)]; @@ -13411,7 +13411,7 @@ mod stitch_tests { } /// A second stream for a group the track already holds. - #[moq_clock::test] + #[kio::test] async fn a_second_stream_for_a_group_is_refused() { let whole = raw_stream(SEQUENCE, &[0, 1], &[42]); let h = Harness::with_timescale(Fill::Done, vec![whole.clone(), whole], None); @@ -13420,7 +13420,7 @@ mod stitch_tests { h.dispatch_refused().await; } - #[moq_clock::test] + #[kio::test] async fn object_extension_limit() { for size in [65536usize, 65537] { for first in [true, false] { @@ -13494,7 +13494,7 @@ mod stitch_tests { /// A fill object without a Timestamp on a timed track ends the track, as a subgroup /// object does: the fill is the head of a group the subscription carries. - #[moq_clock::test] + #[kio::test] async fn an_unstamped_fill_object_ends_the_track() { use futures::FutureExt; @@ -13531,7 +13531,7 @@ mod stitch_tests { /// A subgroup object without a Timestamp on a timed track makes the whole track /// malformed, so the track ends rather than only its group. - #[moq_clock::test] + #[kio::test] async fn an_unstamped_subgroup_object_ends_the_track() { use futures::FutureExt; @@ -13562,7 +13562,7 @@ mod stitch_tests { } /// END_OF_TRACK after a group's last object ends the track right after that group. - #[moq_clock::test] + #[kio::test] async fn an_end_of_track_after_a_group_ends_the_track_after_it() { let h = Harness::new( Fill::Done, @@ -13586,7 +13586,7 @@ mod stitch_tests { assert!(consumer.recv_group().await.unwrap().is_none(), "then the track ends"); } - #[moq_clock::test] + #[kio::test] async fn a_standalone_end_of_track_preserves_a_nonzero_object() { let mut marker = tail_stream(5, 5, &[]); for value in [5u64, 0, 0, END_OF_TRACK] { @@ -13605,7 +13605,7 @@ mod stitch_tests { /// A group at or past the end an END_OF_TRACK declared contradicts that end, which no /// later stream can repair, so the whole track fails rather than ending clean without it. - #[moq_clock::test] + #[kio::test] async fn a_group_past_the_declared_end_aborts_the_track() { use futures::FutureExt; @@ -13623,7 +13623,7 @@ mod stitch_tests { /// END_OF_TRACK at object 0 says the group does not exist, so the track ends before it /// and no group is created for it. - #[moq_clock::test] + #[kio::test] async fn an_end_of_track_at_object_zero_creates_no_group() { let h = Harness::new( Fill::Done, @@ -13638,7 +13638,7 @@ mod stitch_tests { /// The group ended exactly where we joined it, so the subscription's stream carries no /// objects at all. That still ends the group, which is what publishes the head. - #[moq_clock::test] + #[kio::test] async fn an_empty_tail_finishes_the_filled_group() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -13664,7 +13664,7 @@ mod stitch_tests { /// cannot reach a producer the fetch stream still owns. The handoff has to settle it, or /// the head outlives the subscription unfinished and a consumer blocks on it. It is /// cancelled rather than finished, since nothing says the group ended there. - #[moq_clock::test] + #[kio::test] async fn a_head_finishing_after_teardown_is_cancelled_not_installed() { let track = track::Producer::new( std::sync::Arc::new(crate::broadcast::Info::default()), @@ -13690,7 +13690,7 @@ mod stitch_tests { /// Leaving a track while its head waits for the tail cancels that group rather than /// finishing it: the group may still be open upstream, and a finished copy would cut it /// short for a rejoin. - #[moq_clock::test] + #[kio::test] async fn an_unclaimed_head_is_cancelled_when_the_subscription_goes() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -13708,7 +13708,7 @@ mod stitch_tests { } /// Closing locally cancels a filled head whose live tail never arrived. - #[moq_clock::test] + #[kio::test] async fn an_unclaimed_head_is_cancelled_when_the_session_closes() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -13736,7 +13736,7 @@ mod stitch_tests { /// A publisher that serves a head and then opens a whole group for the same sequence /// has contradicted its own fill. The model holds one producer per group, so the /// duplicate stream and unfinished head are refused without caching a cut group. - #[moq_clock::test] + #[kio::test] async fn a_whole_group_for_a_headed_sequence_is_refused() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -13763,7 +13763,7 @@ mod stitch_tests { /// A fill head parked waiting for its tail is still a live group producer. Dropping the /// session has to end it, or the consumer waits on a group nobody will ever write again. /// The guard is `State`'s own `Drop`, so it runs however the driver was torn down. - #[moq_clock::test] + #[kio::test] async fn a_cancelled_session_aborts_a_waiting_fill_head() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -13789,7 +13789,7 @@ mod stitch_tests { ); } - #[moq_clock::test] + #[kio::test] async fn session_death_keeps_a_waiting_fill_heads_resume_position() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -13821,7 +13821,7 @@ mod stitch_tests { /// group lands before the fill has written its head. The model holds one producer per /// live sequence, so the fill loses the race to create it and gives up, rather than a /// second producer appearing and the objects being delivered twice. - #[moq_clock::test] + #[kio::test] async fn a_whole_group_that_precedes_the_head_wins_the_sequence() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -13852,7 +13852,7 @@ mod stitch_tests { } /// A standalone subgroup tail keeps its identity while plain readers see its payload. - #[moq_clock::test] + #[kio::test] async fn a_tail_without_a_fill_is_preserved() { let h = Harness::new(Fill::Done, vec![tail_stream(SEQUENCE, 2, &[b"tail-2"])]); let mut consumer = h.track.subscribe(None); @@ -13864,7 +13864,7 @@ mod stitch_tests { /// Object IDs are absolute whatever FIRST_OBJECT says, and they start at 0, so a /// draft-18 stream that leaves the bit clear and starts at object 0 is the whole /// group. The publisher is out of spec on the bit, not missing a head. - #[moq_clock::test] + #[kio::test] async fn a_clear_first_object_at_zero_delivers_the_group() { let bytes = draft18_subgroup(SEQUENCE, false, 0, &[b"whole", b"next"]); assert_eq!( @@ -13889,7 +13889,7 @@ mod stitch_tests { /// The END_OF_GROUP header bit only lets a FIN imply the group's end, so an explicit /// END_OF_GROUP status on the same stream ends the group there rather than failing it. - #[moq_clock::test] + #[kio::test] async fn an_end_of_group_status_on_a_marked_stream_finishes_the_group() { use futures::FutureExt; @@ -13917,7 +13917,7 @@ mod stitch_tests { } /// FIRST_OBJECT and the starting ID are independent relay metadata. - #[moq_clock::test] + #[kio::test] async fn a_clear_first_object_past_zero_is_preserved() { let partial = draft18_subgroup(SEQUENCE, false, 3, &[b"tail-3"]); let whole = draft18_subgroup(SEQUENCE + 1, true, 0, &[b"next"]); @@ -13948,7 +13948,7 @@ mod stitch_tests { /// A received group whose first object rewinds past the group before it is accepted: a /// moq-transport peer may stamp arrival times, so its timed tracks are unchecked. - #[moq_clock::test] + #[kio::test] async fn a_received_rewind_is_accepted() { use futures::FutureExt; @@ -13979,7 +13979,7 @@ mod stitch_tests { /// A head that stops short of where the tail starts would leave a hole in the middle of /// the group. Refusing it aborts the incomplete group instead of caching a cut prefix. - #[moq_clock::test] + #[kio::test] async fn a_head_that_misses_the_tail_is_refused() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -14003,7 +14003,7 @@ mod stitch_tests { assert!(matches!(head.read_frame().await, Err(Error::Unsupported))); } - #[moq_clock::test] + #[kio::test] async fn receive_drain_keeps_bound_aliases_and_ends_unknown_alias_waits() { let h = Harness::new(Fill::Done, vec![]); let aliases = h.subscriber.state.lock().aliases.consume(); @@ -14017,7 +14017,7 @@ mod stitch_tests { assert!(matches!(resolve_track_alias(&h.subscriber.runtime, aliases, ALIAS).await, Ok(id) if id == REQUEST)); } - #[moq_clock::test] + #[kio::test] async fn receive_drain_ends_a_fill_waiting_for_subscribe_ok() { let h = Harness::new(Fill::Requested, vec![fill_stream(SEQUENCE, &[b"head"])]); let mut stream = h.stream().await; @@ -14031,7 +14031,7 @@ mod stitch_tests { )); } - #[moq_clock::test] + #[kio::test] async fn receive_drain_ends_a_tail_waiting_for_a_missing_fill() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -14045,7 +14045,7 @@ mod stitch_tests { assert!(futures::FutureExt::now_or_never(receiving).is_some()); } - #[moq_clock::test] + #[kio::test] async fn receive_drain_preserves_a_buffered_fill_and_tail() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -14072,7 +14072,7 @@ mod stitch_tests { ); } - #[moq_clock::test] + #[kio::test] async fn receive_drain_ends_a_group_fetch_waiting_for_fetch_ok() { let h = Harness::new(Fill::Done, vec![fill_stream(SEQUENCE, &[b"head"])]); h.subscriber @@ -14093,7 +14093,7 @@ mod stitch_tests { /// A fetch stream can arrive before SUBSCRIBE_OK commits the pending track. It waits /// for that response instead of looking up a producer that does not exist yet. - #[moq_clock::test] + #[kio::test] async fn an_early_fill_waits_for_subscribe_ok() { let h = Harness::new(Fill::Requested, vec![fill_stream(SEQUENCE, &[b"head-0"])]); { @@ -14115,7 +14115,7 @@ mod stitch_tests { /// A fetch stream answering a subscription that asked for no fill duplicates a group the /// subscription itself is delivering, so it is refused rather than written. - #[moq_clock::test] + #[kio::test] async fn an_unsolicited_fill_is_refused() { let h = Harness::new(Fill::Done, vec![fill_stream(SEQUENCE, &[b"head-0"])]); let mut fill = h.stream().await; @@ -14130,7 +14130,7 @@ mod stitch_tests { /// A mid-group subscribe stream waits for the joining FETCH's head and stitches onto it, /// the same rendezvous a draft-22 fill uses. The FETCH is named by its own request id. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_stitches_a_mid_group_tail() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -14161,7 +14161,7 @@ mod stitch_tests { /// A subscribe stream that starts at object 0 stands alone; the joining FETCH's answer /// is discarded rather than delivered twice. - #[moq_clock::test] + #[kio::test] async fn a_whole_group_stream_discards_the_joining_fetch() { let h = Harness::new( Fill::Serving(Some(Timescale::MICRO)), @@ -14201,7 +14201,7 @@ mod stitch_tests { /// A joining FETCH carries the one group its subscription joins, so a second group on /// it is refused rather than published as a head no tail continues. - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_spanning_several_groups_is_refused() { let groups: &[(u64, &[&[u8]])] = &[(9, &[b"g9-0"]), (10, &[b"g10-0"])]; let h = Harness::new( @@ -14218,7 +14218,7 @@ mod stitch_tests { /// The first object on a fetch stream has no prior object, so leaving any field to /// the prior one is a violation, not "the requested group, from its start". - #[moq_clock::test] + #[kio::test] async fn a_group_fetch_refuses_a_first_object_that_inherits() { use ietf::FetchSubgroup::{Prior, Zero}; let header = |group, object, subgroup, priority| ietf::FetchObject::Object { @@ -14259,7 +14259,7 @@ mod stitch_tests { /// On a timed track every Normal object carries a Timestamp, so one without is /// malformed rather than stamped with its arrival time. - #[moq_clock::test] + #[kio::test] async fn an_unstamped_object_on_a_timed_track_is_malformed() { let mut run = GroupFetchRun::new(VERSION, group_fetch_objects(SEQUENCE, 0, &[b"a"])).await; let track = track::Producer::new( @@ -14281,7 +14281,7 @@ mod stitch_tests { /// fails the group instead of caching it. Before draft-22 the End Location also promises /// every object before it, so a stream that FINs short fails too. From draft-22 it is the /// range covered, and the objects missing before it do not exist (section 9.11). - #[moq_clock::test] + #[kio::test] async fn a_group_fetch_stays_within_its_end_location() { const END: u64 = 3; for version in [Version::Draft18, VERSION] { @@ -14317,7 +14317,7 @@ mod stitch_tests { /// A stream that FINs before the group its End Location bounds, with no objects or after /// an earlier group, is short before draft-22. From draft-22 the bounded group is refused /// for now, since objects past the bound may still be written. - #[moq_clock::test] + #[kio::test] async fn a_range_fetch_must_reach_its_bounded_group() { let last = SEQUENCE + 2; for version in [Version::Draft18, VERSION] { @@ -14346,7 +14346,7 @@ mod stitch_tests { ), true => { assert!(res.is_ok(), "{version} empty={empty}: {res:?}"); - let bounded = moq_clock::timeout(Duration::from_secs(1), bounded) + let bounded = kio::clock::timeout(Duration::from_secs(1), bounded) .await .expect("refused"); assert!( @@ -14382,7 +14382,7 @@ mod stitch_tests { /// A datagram group is never fetchable, so a group fetch answered with one names it /// dropped as not fetchable, caching nothing, and reads on past its payload. - #[moq_clock::test] + #[kio::test] async fn a_group_fetch_drops_a_datagram_group() { let mut run = GroupFetchRun::new(VERSION, datagram_object(SEQUENCE)).await; let (slot, fetch) = run.slot(None, None).await; @@ -14396,7 +14396,7 @@ mod stitch_tests { /// A run of missing groups goes upstream as one FETCH, whose single stream our publisher /// answers with every group it holds. The next relay caches those, and answers the readers /// of the groups between them, which do not exist, with a miss. - #[moq_clock::test] + #[kio::test] async fn a_range_fetch_round_trips_with_the_groups_between_dropped() { use crate::lite::test_transport::Sent; for version in [Version::Draft18, Version::Draft22] { @@ -14462,7 +14462,7 @@ mod stitch_tests { let stream = Stream::open(&mut crate::driver::Transport::new(downstream.clone()), version) .await .unwrap(); - moq_clock::timeout( + kio::clock::timeout( Duration::from_secs(1), publisher .handle_stream(ietf::Fetch::ID, ietf::Body(body.into()), stream, false) @@ -14506,14 +14506,14 @@ mod stitch_tests { start: 0, end: None, })); - let res = moq_clock::timeout( + let res = kio::clock::timeout( Duration::from_secs(1), run.subscriber.recv_group_fetch(&mut run.stream, slot), ) .await .expect("recv"); assert!(res.is_ok(), "{version}: {res:?}"); - let _filled = moq_clock::timeout(Duration::from_secs(1), filling) + let _filled = kio::clock::timeout(Duration::from_secs(1), filling) .await .expect("filled"); assert_eq!(consumer.cached_groups(0..10), [4, 6], "{version}"); @@ -14530,7 +14530,7 @@ mod stitch_tests { assert!(group.read_frame().await.unwrap().is_none(), "{version}"); } for fetched in missing { - let fetched = moq_clock::timeout(Duration::from_secs(1), fetched) + let fetched = kio::clock::timeout(Duration::from_secs(1), fetched) .await .expect("dropped"); assert!( @@ -14544,7 +14544,7 @@ mod stitch_tests { /// A fill answered with a datagram Object is refused the same way. Only the fill goes: /// the subscription keeps delivering the groups after it. - #[moq_clock::test] + #[kio::test] async fn a_datagram_fill_fails_only_the_fill() { let mut fill = Vec::new(); crate::coding::Encoder::new(&mut fill, VERSION.into()) @@ -14604,7 +14604,7 @@ mod stitch_tests { /// A group aborted under a stalled fetch stream, as by eviction, ends the run with its /// error instead of leaving the run's readers waiting on the stream. - #[moq_clock::test] + #[kio::test] async fn a_group_aborted_under_a_stalled_fetch_ends_the_run() { let mut run = GroupFetchRun::stalled(VERSION, group_fetch_objects(SEQUENCE, 0, &[b"0"])).await; let (slot, _fetch) = run.slot(None, None).await; @@ -14619,7 +14619,7 @@ mod stitch_tests { assert!(matches!(receive.await, Err(Error::Evicted))); } - #[moq_clock::test] + #[kio::test] async fn internal_group_fetch_setup_cancellation_is_cancel() { let mut run = GroupFetchRun::new(VERSION, Vec::new()).await; let slot = kio::Producer::new(GroupFetch::Pending); @@ -14740,7 +14740,7 @@ mod joining_fetch_tests { const JOINING_DRAFTS: [Version; 1] = [Version::Draft18]; async fn settle() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } fn message_bytes<'m, M: Message<'m>>(id: u64, msg: &M, version: Version) -> Vec { @@ -14816,7 +14816,7 @@ mod joining_fetch_tests { kio::Pending, ), _tasks: (Tasks, TaskSet), - serving: moq_clock::sim::JoinHandle<()>, + serving: kio::clock::sim::JoinHandle<()>, } impl JoinRun { @@ -14857,7 +14857,7 @@ mod joining_fetch_tests { let request = dynamic.requested_track().await.expect("no track requested"); let mut serving_subscriber = subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { serving_subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -14983,12 +14983,12 @@ mod joining_fetch_tests { } } - #[moq_clock::test] + #[kio::test] async fn revocation_cancels_a_group_fetch_before_the_subscribe_fin_is_acked() { revoked_child_fetch(false).await; } - #[moq_clock::test] + #[kio::test] async fn revocation_cancels_an_answered_fetch_before_the_subscribe_fin_is_acked() { revoked_child_fetch(true).await; } @@ -14996,7 +14996,7 @@ mod joining_fetch_tests { /// From draft 18 the joining FETCH's request stays open after FETCH_OK. Its failure while /// the head is still being written settles the fill, so a mid-group tail is not parked /// on a head that may never finish. - #[moq_clock::test] + #[kio::test] async fn a_request_failing_mid_head_settles_the_fill() { let version = Version::Draft18; let session = ScriptedSession::per_stream_reset(vec![fetch_ok(version)]); @@ -15014,7 +15014,7 @@ mod joining_fetch_tests { assert!(matches!(*fill.read(), Fill::Done), "{version}: the head is released"); } - #[moq_clock::test] + #[kio::test] async fn invalid_joining_open_is_refused() { for version in JOINING_DRAFTS { for retired in [false, true] { @@ -15042,7 +15042,7 @@ mod joining_fetch_tests { } } - #[moq_clock::test] + #[kio::test] async fn a_joining_fetch_waits_for_stream_credit() { for version in JOINING_DRAFTS { let session = ScriptedSession::new(Vec::new()).without_credit(); @@ -15060,7 +15060,7 @@ mod joining_fetch_tests { } /// Abandoning a blocked open leaves the next sequential ID available to unrelated work. - #[moq_clock::test] + #[kio::test] async fn cancelling_a_joining_fetch_open_spends_no_id() { for version in JOINING_DRAFTS { let gate = kio::Producer::new(false); @@ -15079,7 +15079,7 @@ mod joining_fetch_tests { /// Every draft-18 live join is Largest Object on the SUBSCRIBE and a relative /// joining FETCH at offset 0 that names the subscribe's request id. - #[moq_clock::test] + #[kio::test] async fn a_live_join_is_spelled_as_largest_object_plus_relative_fetch() { let largest = Some(ietf::Location { group: 4, object: 1 }); for version in JOINING_DRAFTS { @@ -15111,7 +15111,7 @@ mod joining_fetch_tests { /// A start below, at, or past the Largest group joins that group alone: a group below it /// is left to the copy's fills. - #[moq_clock::test] + #[kio::test] async fn a_join_from_any_start_fetches_only_the_largest_group() { let largest = Some(ietf::Location { group: 9, object: 0 }); for version in JOINING_DRAFTS { @@ -15138,7 +15138,7 @@ mod joining_fetch_tests { /// the Largest group and nothing more, as a failed draft-22 fill does: the fill settles, /// so a stream starting mid-group no longer waits on it, and the subscription keeps /// delivering whole groups. - #[moq_clock::test] + #[kio::test] async fn a_refused_fetch_joins_at_the_next_whole_group() { let largest = Some(ietf::Location { group: 4, object: 1 }); for version in JOINING_DRAFTS { @@ -15158,7 +15158,7 @@ mod joining_fetch_tests { /// A malformed answer to the joining FETCH is not a refusal: the peer broke the /// protocol, so the session closes. - #[moq_clock::test] + #[kio::test] async fn a_malformed_fetch_answer_closes_the_session() { let largest = Some(ietf::Location { group: 4, object: 1 }); for version in JOINING_DRAFTS { @@ -15180,7 +15180,7 @@ mod joining_fetch_tests { /// A joining FETCH is not one of the subscription's counted streams, so a clean /// PUBLISH_DONE can settle while its head is still being written. The head is then the /// whole group, as it is when it lands first, rather than cut short as on a leave. - #[moq_clock::test] + #[kio::test] async fn a_head_landing_after_a_clean_end_finishes_its_group() { let largest = Some(ietf::Location { group: 4, object: 0 }); for version in JOINING_DRAFTS { @@ -15234,7 +15234,7 @@ mod joining_fetch_tests { // The grace runs out with the head still being written, ending the subscription. // The finished copy lingers for fills while the reader holds it. while !run.subscriber.state.lock().subscribes.is_empty() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } assert!(!run.serving.is_finished(), "{version}: the finished copy lingers"); @@ -15252,7 +15252,7 @@ mod joining_fetch_tests { /// for a later reader to subscribe afresh rather than lingering as if the track ended. Its /// reader sees an error, not a clean end: the fresh copy's groups continue past this one's, /// so an end here would be one the track runs past. - #[moq_clock::test] + #[kio::test] async fn a_subscription_ended_copy_does_not_linger() { for version in JOINING_DRAFTS { let mut ok = subscribe_ok(version, None); @@ -15476,35 +15476,35 @@ mod joining_fetch_tests { assert!(subscriber.state.lock().group_fetches.is_empty(), "request retired"); } - #[moq_clock::test] + #[kio::test] async fn a_retired_group_fetch_before_fetch_ok_is_cancelled() { for version in JOINING_DRAFTS { abandon_group_fetch(version, FetchStage::Retired).await; } } - #[moq_clock::test] + #[kio::test] async fn an_abandoned_group_fetch_before_fetch_ok_is_cancelled() { for version in JOINING_DRAFTS { abandon_group_fetch(version, FetchStage::Unanswered).await; } } - #[moq_clock::test] + #[kio::test] async fn an_abandoned_group_fetch_after_fetch_ok_is_cancelled() { for version in JOINING_DRAFTS { abandon_group_fetch(version, FetchStage::Accepted).await; } } - #[moq_clock::test] + #[kio::test] async fn an_abandoned_partial_group_fetch_is_cancelled() { for version in JOINING_DRAFTS { abandon_group_fetch(version, FetchStage::Receiving).await; } } - #[moq_clock::test] + #[kio::test] async fn a_complete_group_fetch_is_cached_when_the_reader_leaves() { for version in JOINING_DRAFTS { abandon_group_fetch(version, FetchStage::Complete).await; @@ -15512,14 +15512,14 @@ mod joining_fetch_tests { } /// A request reset after the group is written must not abort the cached group. - #[moq_clock::test] + #[kio::test] async fn a_complete_group_fetch_survives_a_request_reset() { for version in JOINING_DRAFTS { abandon_group_fetch(version, FetchStage::CompleteReset).await; } } - #[moq_clock::test] + #[kio::test] async fn a_claimed_fetch_waits_only_while_wanted() { for version in JOINING_DRAFTS { for stage in [FetchStage::Credit, FetchStage::CreditRetired, FetchStage::CreditGranted] { @@ -15531,7 +15531,7 @@ mod joining_fetch_tests { /// A publisher that resets the request after FETCH_OK owes no fetch stream, so the /// group it accepted is aborted instead of left open for every reader to wait on. /// Without that, `run_group_fetch` never returns. - #[moq_clock::test] + #[kio::test] async fn a_group_fetch_reset_after_fetch_ok_aborts_the_group() { const VERSION: Version = Version::Draft18; const GROUP: u64 = 4; @@ -15586,7 +15586,7 @@ mod joining_fetch_tests { /// From draft-22 an End Location outside the FETCH's range is malformed: /// the session closes with PROTOCOL_VIOLATION rather than reading it as an empty answer. - #[moq_clock::test] + #[kio::test] async fn a_draft22_end_location_outside_the_range_closes_the_session() { const GROUP: u64 = 4; const START: u64 = 3; @@ -15669,7 +15669,7 @@ mod joining_fetch_tests { /// A cache miss for a group's tail asks upstream from the frame the reader wants and /// numbers what arrives from there, so a publisher that evicted the prefix can answer. - #[moq_clock::test] + #[kio::test] async fn a_group_fetch_asks_from_the_wanted_frame() { for version in JOINING_DRAFTS.into_iter().chain([Version::Draft22]) { for ended in [false, true] { @@ -15679,7 +15679,7 @@ mod joining_fetch_tests { } /// Legacy moxygen/cache answers one group past the requested group remain readable. - #[moq_clock::test] + #[kio::test] async fn a_legacy_group_fetch_answer_still_covers_the_requested_group() { for version in JOINING_DRAFTS { for ended in [false, true] { @@ -15776,7 +15776,7 @@ mod joining_fetch_tests { assert!(futures::poll!(fetch.as_mut()).is_pending()); let request = dynamic.requested_fill().await.expect("no group requested"); - let serving = moq_clock::sim::spawn(subscriber.clone().run_group_fetch( + let serving = kio::clock::sim::spawn(subscriber.clone().run_group_fetch( Path::from_static("broadcast"), "video".into(), request, @@ -15849,7 +15849,7 @@ mod new_group_tests { use crate::{model::ProduceTest, transport::memory}; async fn settle() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } const VERSION: Version = Version::Draft22; @@ -15860,7 +15860,7 @@ mod new_group_tests { track: track::Consumer, probe: Subscriber, peer: memory::Session, - serving: moq_clock::sim::JoinHandle<()>, + serving: kio::clock::sim::JoinHandle<()>, /// Landed groups stay open, as a live publisher's would. landed: Vec, _broadcast: crate::broadcast::Producer, @@ -15890,7 +15890,7 @@ mod new_group_tests { let first = track.subscribe(None); let request = dynamic.requested_track().await.expect("no track requested"); let probe = subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -15912,7 +15912,7 @@ mod new_group_tests { let id = stream.reader.varint().await.unwrap(); (id, stream.reader.decode::().await.unwrap()) }; - moq_clock::timeout(Duration::from_secs(1), read) + kio::clock::timeout(Duration::from_secs(1), read) .await .expect("the relay sent nothing") } @@ -16004,7 +16004,7 @@ mod new_group_tests { /// A copy with nothing cached has no group to judge a join by, so its SUBSCRIBE asks for /// none. - #[moq_clock::test] + #[kio::test] async fn a_first_subscribe_asks_for_no_group() { let (mut relay, _first) = relay().await; let (_stream, sent) = relay.accept().await; @@ -16014,7 +16014,7 @@ mod new_group_tests { /// A join over the ratio goes upstream in a REQUEST_UPDATE for the group past the /// newest. Joins until that group lands ask for the same one and go no further. - #[moq_clock::test] + #[kio::test] async fn a_join_over_the_ratio_requests_a_group() { let (mut relay, _first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16036,7 +16036,7 @@ mod new_group_tests { } /// A join under the ratio reads the current group and asks for nothing. - #[moq_clock::test] + #[kio::test] async fn a_join_under_the_ratio_asks_nothing() { let (mut relay, _first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16049,7 +16049,7 @@ mod new_group_tests { } /// One REQUEST_UPDATE is in flight at a time; a join meanwhile goes up once it is answered. - #[moq_clock::test] + #[kio::test] async fn a_join_behind_an_unanswered_update_waits() { let (mut relay, _first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16071,7 +16071,7 @@ mod new_group_tests { /// A refused update ends the subscription, so nothing more goes up while PUBLISH_DONE /// is on its way, even for a join that waited behind it. - #[moq_clock::test] + #[kio::test] async fn a_refused_update_sends_no_more() { let (mut relay, _first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16098,7 +16098,7 @@ mod new_group_tests { /// A group the publisher already has is on its way, so a join asking for it goes no /// further. - #[moq_clock::test] + #[kio::test] async fn a_group_upstream_has_is_not_requested() { let (mut relay, _first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16112,7 +16112,7 @@ mod new_group_tests { /// A publisher that did not advertise DYNAMIC_GROUPS refreshes on no join, so it never /// hears a REQUEST_UPDATE carrying one. - #[moq_clock::test] + #[kio::test] async fn a_publisher_without_dynamic_groups_hears_no_updates() { let (mut relay, _first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16126,7 +16126,7 @@ mod new_group_tests { /// A group still wanted when the copy goes idle rides the SUBSCRIBE that resumes it, and /// is outstanding from there. - #[moq_clock::test] + #[kio::test] async fn a_resumed_copy_carries_its_request() { let (mut relay, first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16150,7 +16150,7 @@ mod new_group_tests { /// A fill whose stream reset before its header never settles. It holds back only a /// widening, whose own fill would take the head; a narrowing still goes up. - #[moq_clock::test] + #[kio::test] async fn an_unsettled_fill_holds_back_only_a_widening() { let (mut relay, mut first) = relay().await; let (mut stream, _) = relay.accept().await; @@ -16228,7 +16228,7 @@ mod track_property_tests { let subscribing = track.subscribe(None); let request = dynamic.requested_track().await.expect("no track requested"); let probe = subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -16258,10 +16258,10 @@ mod track_property_tests { frame.extend(body); stream.writer.write_all(&mut bytes::Bytes::from(frame)).await.unwrap(); - let subscribed = moq_clock::timeout(Duration::from_secs(1), subscribing) + let subscribed = kio::clock::timeout(Duration::from_secs(1), subscribing) .await .expect("the subscription was never answered"); - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; serving.abort(); (subscribed, probe) } @@ -16285,7 +16285,7 @@ mod track_property_tests { /// An even property the draft defines but moq-net does not implement /// (OBJECT_DELIVERY_TIMEOUT) and an odd one from the application range reach the track /// unchanged, for the relay's own answers downstream to forward. - #[moq_clock::test] + #[kio::test] async fn unknown_properties_reach_the_track() { for version in VERSIONS { let unknown = vec![ @@ -16312,7 +16312,7 @@ mod track_property_tests { /// A Mandatory Track Property we do not understand, mutable or sealed, refuses the /// track with UNSUPPORTED_EXTENSION instead of forwarding it. - #[moq_clock::test] + #[kio::test] async fn a_mandatory_property_refuses_the_track() { for version in VERSIONS { let mandatory = Property { @@ -16340,7 +16340,7 @@ mod track_property_tests { /// A sealed DEFAULT_PUBLISHER_GROUP_ORDER is advisory: the relay accepts the track, serves /// its own order, and keeps the sealed block to forward unchanged. - #[moq_clock::test] + #[kio::test] async fn a_sealed_group_order_the_relay_does_not_serve_is_accepted() { for version in VERSIONS { for order in [2, 1] { @@ -16371,7 +16371,7 @@ mod track_property_tests { /// A TIMESCALE keeps the publisher's units, mutable or sealed: a sealed one travels /// downstream unchanged, and a mutable one matches a copy that arrived over another route. - #[moq_clock::test] + #[kio::test] async fn a_timescale_keeps_its_units() { for version in VERSIONS { let timescale = Property { @@ -16398,7 +16398,7 @@ mod full_track_name_tests { /// A Full Track Name too long for the wire fails only its own subscription, and the /// session carries the next one. - #[moq_clock::test] + #[kio::test] async fn an_unencodable_track_name_fails_only_its_subscription() { for version in [Version::Draft18, Version::Draft22] { let (session, peer) = memory::pair(memory::Config::default()); @@ -16425,7 +16425,7 @@ mod full_track_name_tests { let mut subscribing = std::pin::pin!(track.subscribe(None)); let request = dynamic.requested_track().await.expect("no track requested"); let mut subscriber = subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("broadcast"), dynamic, None, request) .await; @@ -16442,7 +16442,7 @@ mod full_track_name_tests { }; assert_eq!(id, ietf::Subscribe::ID, "{version}"); } else { - let refused = moq_clock::timeout(Duration::from_secs(1), &mut subscribing) + let refused = kio::clock::timeout(Duration::from_secs(1), &mut subscribing) .await .expect("the subscription was never refused"); assert!( diff --git a/rs/moq-net/src/ietf/subscriber/tracks.rs b/rs/moq-net/src/ietf/subscriber/tracks.rs index f2d5ac2b8ad..851b0e4b1a8 100644 --- a/rs/moq-net/src/ietf/subscriber/tracks.rs +++ b/rs/moq-net/src/ietf/subscriber/tracks.rs @@ -1248,17 +1248,17 @@ mod tests { listening: Listening, version: Version, _broadcast: crate::broadcast::Producer, - _driver: moq_clock::sim::JoinHandle<()>, + _driver: kio::clock::sim::JoinHandle<()>, } async fn settle() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } fn harness(version: Version) -> Harness { let (session, peer) = memory::pair(memory::Config::default()); let (tasks, mut task_set) = TaskSet::new(); - let driver = moq_clock::sim::spawn(async move { kio::wait(|waiter| task_set.poll(waiter)).await }); + let driver = kio::clock::sim::spawn(async move { kio::wait(|waiter| task_set.poll(waiter)).await }); let subscriber = Subscriber::new( crate::time::sim(), crate::driver::Transport::new(session.clone()), @@ -1292,7 +1292,7 @@ mod tests { let id = stream.reader.varint().await.unwrap(); (id, stream.reader.decode::().await.unwrap()) }; - moq_clock::timeout(TIMEOUT, read) + kio::clock::timeout(TIMEOUT, read) .await .expect("the subscriber sent nothing") } @@ -1318,7 +1318,7 @@ mod tests { impl Harness { /// Accept the SUBSCRIBE_TRACKS and establish it. async fn establish(&mut self) -> PeerStream { - let mut stream = moq_clock::timeout( + let mut stream = kio::clock::timeout( TIMEOUT, Stream::accept(&mut crate::driver::Transport::new(self.peer.clone()), self.version), ) @@ -1356,14 +1356,14 @@ mod tests { ) -> ( crate::track::Consumer, kio::Pending, - moq_clock::sim::JoinHandle<()>, + kio::clock::sim::JoinHandle<()>, ) { let mut dynamic = self._broadcast.requests(); let track = self._broadcast.consume().track(name).unwrap(); let reader = track.subscribe(None); let request = dynamic.requested_track().await.expect("no track requested"); let mut subscriber = self.subscriber.clone(); - let serving = moq_clock::sim::spawn(async move { + let serving = kio::clock::sim::spawn(async move { subscriber .run_subscribe(Path::from_static("bcast"), dynamic, None, request) .await; @@ -1378,7 +1378,7 @@ mod tests { ) -> ( crate::track::Consumer, crate::track::Subscriber, - moq_clock::sim::JoinHandle<()>, + kio::clock::sim::JoinHandle<()>, ) { let (track, reader, serving) = self.read_track("video").await; let (id, body) = read(video).await; @@ -1390,7 +1390,7 @@ mod tests { largest: None, }; write(video, ietf::RequestOk::ID, &ok).await; - let reader = moq_clock::timeout(TIMEOUT, reader) + let reader = kio::clock::timeout(TIMEOUT, reader) .await .expect("never accepted") .unwrap(); @@ -1401,7 +1401,7 @@ mod tests { async fn resume_and_pause( &mut self, video: &mut PeerStream, - ) -> (crate::track::Consumer, moq_clock::sim::JoinHandle<()>) { + ) -> (crate::track::Consumer, kio::clock::sim::JoinHandle<()>) { let (track, reader, serving) = self.resume(video).await; drop(reader); let (id, body) = read(video).await; @@ -1428,7 +1428,7 @@ mod tests { let body: ietf::Body = ours.reader.decode().await.unwrap(); let mut subscriber = self.subscriber.clone(); let version = self.version; - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { let msg = body.message::(version).unwrap().into_owned(); let _ = subscriber.serve_publish(ours, msg).await; }); @@ -1462,7 +1462,7 @@ mod tests { /// A PUBLISH no listing asked for stays refused, and one for a track already held is /// redundant: DUPLICATE_SUBSCRIPTION on draft-18, which allows one subscription per /// track, and UNINTERESTED after. - #[moq_clock::test] + #[kio::test] async fn an_unasked_or_redundant_publish_is_refused() { for (version, duplicate) in [(Version::Draft18, 0x19), (Version::Draft22, 0x20)] { let mut h = harness(version); @@ -1476,7 +1476,7 @@ mod tests { } /// A PUBLISH_DONE with TRACK_ENDED unlists the track as finished, and the listing stands. - #[moq_clock::test] + #[kio::test] async fn a_track_ended_publish_finishes_the_track() { let version = Version::Draft22; let mut h = harness(version); @@ -1496,7 +1496,7 @@ mod tests { /// Any other PUBLISH_DONE, INTERNAL_ERROR included, fails the listing rather than hide a /// track that may be live. - #[moq_clock::test] + #[kio::test] async fn another_publish_done_fails_the_listing() { let version = Version::Draft22; for (status, expected) in [ @@ -1523,7 +1523,7 @@ mod tests { /// A resumed listed track ending any way but TRACK_ENDED fails the listing, even a /// clean SUBSCRIPTION_ENDED (draft 18), which says nothing of the track itself. - #[moq_clock::test] + #[kio::test] async fn a_resumed_track_ending_otherwise_fails_the_listing() { let version = Version::Draft18; let mut h = harness(version); @@ -1542,12 +1542,12 @@ mod tests { }; write(&mut video, ietf::PublishDone::ID, &done).await; // The subscription waits out its data streams before it ends. - moq_clock::sleep(Duration::from_secs(5)).await; + kio::clock::sleep(Duration::from_secs(5)).await; assert!(h.listening.poll_failed(&kio::Waiter::noop()).is_ready()); } /// A skipped track is listed through a paused SUBSCRIBE of ours, once it answers. - #[moq_clock::test] + #[kio::test] async fn a_skipped_track_lists_once_its_paused_subscribe_answers() { for version in [Version::Draft18, Version::Draft22] { let mut h = harness(version); @@ -1559,7 +1559,7 @@ mod tests { write(&mut listing, ietf::PublishSkipped::ID, &skipped).await; assert_eq!(event(&mut h.tracks), None, "{version}: listed before it answered"); - let mut stream = moq_clock::timeout( + let mut stream = kio::clock::timeout( TIMEOUT, Stream::accept(&mut crate::driver::Transport::new(h.peer.clone()), version), ) @@ -1591,7 +1591,7 @@ mod tests { } /// A refused paused SUBSCRIBE fails the listing. - #[moq_clock::test] + #[kio::test] async fn a_refused_paused_subscribe_fails_the_listing() { let version = Version::Draft22; let mut h = harness(version); @@ -1601,7 +1601,7 @@ mod tests { track_name: "audio".into(), }; write(&mut listing, ietf::PublishSkipped::ID, &skipped).await; - let mut stream = moq_clock::timeout( + let mut stream = kio::clock::timeout( TIMEOUT, Stream::accept(&mut crate::driver::Transport::new(h.peer.clone()), version), ) @@ -1623,7 +1623,7 @@ mod tests { /// A listed PUBLISH whose properties we cannot take fails the listing: the peer sends /// nothing else for that track, so a listing left standing would silently miss it. - #[moq_clock::test] + #[kio::test] async fn an_unsupported_publish_fails_the_listing() { let version = Version::Draft22; let mut h = harness(version); @@ -1646,7 +1646,7 @@ mod tests { /// On draft-22 a PUBLISH that forwards contradicts the paused listing it answers, and /// nothing we send can pause it: it is refused and the listing fails, rather than have its /// objects refused unseen. On draft-18 our PUBLISH_OK pauses it. - #[moq_clock::test] + #[kio::test] async fn a_forwarding_publish_fails_the_listing_on_draft_22() { for version in [Version::Draft18, Version::Draft22] { let mut h = harness(version); @@ -1676,7 +1676,7 @@ mod tests { /// A listed track that finishes before its resume is answered goes back to lingering, and /// its waiting reader SUBSCRIBEs: the idle copy cannot place the end, which the SUBSCRIBE /// learns, rather than abort a clean finish. - #[moq_clock::test] + #[kio::test] async fn a_track_ending_before_its_resume_resubscribes() { let version = Version::Draft22; let mut h = harness(version); @@ -1702,7 +1702,7 @@ mod tests { "TRACK_ENDED failed the listing" ); - let mut stream = moq_clock::timeout( + let mut stream = kio::clock::timeout( TIMEOUT, Stream::accept(&mut crate::driver::Transport::new(h.peer.clone()), version), ) @@ -1715,7 +1715,7 @@ mod tests { /// A paused track's upstream failing aborts the copy a reader left lingering, rather /// than leave it open with nothing upstream. - #[moq_clock::test] + #[kio::test] async fn a_paused_track_failing_aborts_its_lingering_copy() { let version = Version::Draft22; let mut h = harness(version); @@ -1736,7 +1736,7 @@ mod tests { /// The answer a pause owes is decoded like any other, so a malformed one closes the /// session rather than count as an answer. - #[moq_clock::test] + #[kio::test] async fn a_malformed_pause_answer_closes_the_session() { let version = Version::Draft22; let mut h = harness(version); @@ -1754,19 +1754,19 @@ mod tests { let mut peer = h.peer.clone(); let closed = kio::wait(move |waiter| crate::transport::poll::Session::poll_closed(&mut peer, &mut waiter.context())); - moq_clock::timeout(TIMEOUT, closed) + kio::clock::timeout(TIMEOUT, closed) .await .expect("the session stayed up"); } /// A peer that refuses SUBSCRIBE_TRACKS, resets it, or never answers it fails at most /// that listing: a plain SUBSCRIBE still goes out and is accepted on the session. - #[moq_clock::test] + #[kio::test] async fn a_peer_not_answering_the_listing_still_serves_subscribe() { let version = Version::Draft22; for case in ["refused", "reset", "silent"] { let mut h = harness(version); - let mut listing = moq_clock::timeout( + let mut listing = kio::clock::timeout( TIMEOUT, Stream::accept(&mut crate::driver::Transport::new(h.peer.clone()), version), ) @@ -1804,7 +1804,7 @@ mod tests { } let (_track, reader, _serving) = h.read_track("video").await; - let mut stream = moq_clock::timeout( + let mut stream = kio::clock::timeout( TIMEOUT, Stream::accept(&mut crate::driver::Transport::new(h.peer.clone()), version), ) @@ -1821,7 +1821,7 @@ mod tests { properties: ietf::Properties::default(), }; write(&mut stream, ietf::SubscribeOk::ID, &ok).await; - moq_clock::timeout(TIMEOUT, reader) + kio::clock::timeout(TIMEOUT, reader) .await .expect("never accepted") .unwrap_or_else(|err| panic!("{case}: {err}")); @@ -1830,7 +1830,7 @@ mod tests { /// Dropping the listing cancels its SUBSCRIBE_TRACKS: FIN on draft-18, RESET_STREAM on /// draft-22, where a FIN is no cancel. The held PUBLISHes are let go with it. - #[moq_clock::test] + #[kio::test] async fn dropping_the_listing_cancels_it() { let version = Version::Draft18; let mut h = harness(version); @@ -1838,14 +1838,14 @@ mod tests { let mut video = h.publish("video", 1).await; drop(h.listening); settle().await; - let ended = moq_clock::timeout(TIMEOUT, listing.reader.varint_maybe()) + let ended = kio::clock::timeout(TIMEOUT, listing.reader.varint_maybe()) .await .expect("the listing stayed open"); match version { Version::Draft18 => assert!(matches!(ended, Ok(None)), "{version}: {ended:?}"), _ => assert!(ended.is_err(), "{version}: {ended:?}"), } - let ended = moq_clock::timeout(TIMEOUT, video.reader.varint_maybe()) + let ended = kio::clock::timeout(TIMEOUT, video.reader.varint_maybe()) .await .expect("the PUBLISH stayed held"); assert!(!matches!(ended, Ok(Some(_))), "{version}: {ended:?}"); diff --git a/rs/moq-net/src/lite/ietf.rs b/rs/moq-net/src/lite/ietf.rs index d1a8f9da319..7513baccf42 100644 --- a/rs/moq-net/src/lite/ietf.rs +++ b/rs/moq-net/src/lite/ietf.rs @@ -979,13 +979,13 @@ pub(crate) async fn test_hop( .with_publisher(upstream.consume()); let (client, server) = futures::join!( async { - let (session, driver) = dial.connect(moq_clock::now(), client).await.unwrap(); - drop(moq_clock::sim::spawn(crate::time::run(driver))); + let (session, driver) = dial.connect(kio::clock::now(), client).await.unwrap(); + drop(kio::clock::sim::spawn(crate::time::run(driver))); session }, async { - let (session, driver) = serve.accept(moq_clock::now(), server).await.unwrap(); - drop(moq_clock::sim::spawn(crate::time::run(driver))); + let (session, driver) = serve.accept(kio::clock::now(), server).await.unwrap(); + drop(kio::clock::sim::spawn(crate::time::run(driver))); session }, ); @@ -1062,19 +1062,19 @@ mod hop_tests { } async fn next(group: &mut group::Consumer) -> Option { - moq_clock::timeout(TIMEOUT, kio::wait(|waiter| group.poll_read_object(waiter))) + kio::clock::timeout(TIMEOUT, kio::wait(|waiter| group.poll_read_object(waiter))) .await .expect("no frame") .unwrap() } async fn subscribe(origin: &crate::origin::Producer) -> (track::Consumer, track::Subscriber) { - let broadcast = moq_clock::timeout(TIMEOUT, origin.consume().request_broadcast("room", None)) + let broadcast = kio::clock::timeout(TIMEOUT, origin.consume().request_broadcast("room", None)) .await .expect("no broadcast") .unwrap(); let track = broadcast.track("video").unwrap(); - let subscriber = moq_clock::timeout(TIMEOUT, track.subscribe(None)) + let subscriber = kio::clock::timeout(TIMEOUT, track.subscribe(None)) .await .expect("no subscription") .unwrap(); @@ -1082,7 +1082,7 @@ mod hop_tests { } async fn recv(subscriber: &mut track::Subscriber) -> group::Consumer { - moq_clock::timeout(TIMEOUT, subscriber.recv_group()) + kio::clock::timeout(TIMEOUT, subscriber.recv_group()) .await .expect("no group") .unwrap() @@ -1093,7 +1093,7 @@ mod hop_tests { /// Object IDs, properties, and END_OF_GROUP position, and its track's properties. /// A side that does not offer the extension gets the plain frames alone. The track info /// moq-transport egress restates as Track Properties crosses either way. - #[moq_clock::test] + #[kio::test] async fn relayed_state_crosses_while_the_group_is_open() { for offer in [[true, true], [true, false], [false, true]] { let negotiated = offer == [true, true]; @@ -1172,7 +1172,7 @@ mod hop_tests { let frame = next(&mut received).await.unwrap(); assert_eq!(&frame.payload.contiguous(0)[..], b"b"); assert!(next(&mut received).await.is_none()); - let info = moq_clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); + let info = kio::clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); assert_eq!( (info.max_age, info.timescale, info.priority, info.refresh), ( @@ -1214,11 +1214,11 @@ mod hop_tests { let _track = broadcast.create_track("video", info).unwrap(); let (downstream, _sessions) = test_hop(&upstream, "room", [true, true]).await; - let broadcast = moq_clock::timeout(TIMEOUT, downstream.consume().request_broadcast("room", None)) + let broadcast = kio::clock::timeout(TIMEOUT, downstream.consume().request_broadcast("room", None)) .await .expect("no broadcast") .unwrap(); - moq_clock::timeout(TIMEOUT, broadcast.track("video").unwrap().subscribe(None)) + kio::clock::timeout(TIMEOUT, broadcast.track("video").unwrap().subscribe(None)) .await .expect("no answer") .map(drop) @@ -1227,7 +1227,7 @@ mod hop_tests { /// A track with a Mandatory Track Property, mutable or sealed, is refused across the hop /// as moq-transport ingress refuses it: one we do not understand is neither processed /// nor forwarded. - #[moq_clock::test] + #[kio::test] async fn mandatory_track_properties_are_refused() { let mut sealed = Vec::new(); let e = &mut Encoder::new(&mut sealed, crate::ietf::Version::Draft22.into()); @@ -1250,7 +1250,7 @@ mod hop_tests { /// A sealed TIMESCALE that contradicts TRACK_INFO is refused across the hop: the relay /// times frames by TRACK_INFO, while egress would forward the sealed one. - #[moq_clock::test] + #[kio::test] async fn a_sealed_property_must_match_track_info() { for (timescale, ok) in [(1000, true), (900, false), (0, false)] { let mut sealed = Vec::new(); @@ -1271,7 +1271,7 @@ mod hop_tests { /// A sealed DYNAMIC_GROUPS must match the refresh TRACK_INFO carries across the hop, /// which moq-transport egress restates as DYNAMIC_GROUPS. - #[moq_clock::test] + #[kio::test] async fn a_sealed_dynamic_groups_must_match_track_info() { for (refresh, value, ok) in [ (Some(0), 1, true), @@ -1302,7 +1302,7 @@ mod hop_tests { /// A relay forwards only as many Track Properties as leave room for the ones it /// restates from TRACK_INFO, so one more is refused across the hop. - #[moq_clock::test] + #[kio::test] async fn forwarded_track_properties_leave_room_for_track_info() { let max = crate::ietf::properties::MAX_FORWARDED; for (count, ok) in [(max, true), (max + 1, false)] { @@ -1316,7 +1316,7 @@ mod hop_tests { /// Groups and datagrams from a moq-lite publisher cross a negotiated hop as plain as /// they left: no relay state appears on the way, nor a moq-transport draft. - #[moq_clock::test] + #[kio::test] async fn plain_media_crosses_unchanged() { let upstream = crate::origin::Config::new(crate::Hop::new(2).unwrap()).produce(); let broadcast = upstream.publish("room", crate::origin::Route::default()).unwrap(); @@ -1325,7 +1325,7 @@ mod hop_tests { .unwrap(); let (downstream, sessions) = test_hop(&upstream, "room", [true, true]).await; let (copy, mut subscriber) = subscribe(&downstream).await; - let info = moq_clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); + let info = kio::clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); assert!(info.properties.is_none()); let mut group = track.append_group().unwrap(); @@ -1349,7 +1349,7 @@ mod hop_tests { assert!(received.end_object().is_none()); track.insert_datagram(7, ts(9), b"datagram".to_vec()).unwrap(); - let datagram = moq_clock::timeout(TIMEOUT, kio::wait(|waiter| subscriber.poll_recv_wire_datagram(waiter))) + let datagram = kio::clock::timeout(TIMEOUT, kio::wait(|waiter| subscriber.poll_recv_wire_datagram(waiter))) .await .expect("no datagram") .unwrap() @@ -1362,7 +1362,7 @@ mod hop_tests { /// Only a negotiated hop can preserve several datagram Object IDs. A late or lost /// object 0 never lets another object's payload pose as the whole group. - #[moq_clock::test] + #[kio::test] async fn datagram_objects_cross_only_an_identifying_hop() { for offer in [[false, false], [false, true], [true, false], [true, true]] { for objects in [&[0, 1, 2][..], &[1, 2, 0], &[1, 2]] { @@ -1439,7 +1439,7 @@ mod hop_tests { /// Provenance keeps IETF times unchecked after a hop, while a peer declining the /// extension gets no timeline. SUBSCRIBE, FETCH, and datagrams must agree with TRACK_INFO, /// while a listing stays untimed. - #[moq_clock::test] + #[kio::test] async fn ietf_timestamps_keep_their_provenance_across_a_hop() { for offer in [[true, true], [true, false], [false, true]] { let negotiated = offer == [true, true]; @@ -1459,7 +1459,7 @@ mod hop_tests { // negotiated: a relay re-listing it would otherwise advertise it as native lite. let mut tracks = broadcast.tracks().unwrap(); let listed = loop { - match moq_clock::timeout(TIMEOUT, tracks.next()).await.unwrap().unwrap() { + match kio::clock::timeout(TIMEOUT, tracks.next()).await.unwrap().unwrap() { Some(crate::broadcast::TracksEvent::Added { name, info }) if &*name == "video" => break info, Some(_) => continue, None => panic!("listing ended before the track"), @@ -1467,7 +1467,7 @@ mod hop_tests { }; assert_eq!((listed.timescale, listed.ietf()), (None, None), "{offer:?}"); let copy = broadcast.track("video").unwrap(); - let info = moq_clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); + let info = kio::clock::timeout(TIMEOUT, copy.info()).await.unwrap().unwrap(); assert_eq!(info.timescale, negotiated.then_some(Timescale::MILLI), "{offer:?}"); assert_eq!( info.ietf(), @@ -1476,14 +1476,14 @@ mod hop_tests { ); // Before any subscription, this must fetch the head over the hop, rather // than reading an already subscribed copy's cache. - let mut fetched = moq_clock::timeout(TIMEOUT, copy.fetch_group(0, None)) + let mut fetched = kio::clock::timeout(TIMEOUT, copy.fetch_group(0, None)) .await .unwrap() .unwrap(); assert_eq!(next(&mut fetched).await.unwrap().timestamp, negotiated.then(|| ts(100))); assert!(next(&mut fetched).await.is_none()); let mut subscriber = - moq_clock::timeout(TIMEOUT, copy.subscribe(track::Subscription::default().with_start(1))) + kio::clock::timeout(TIMEOUT, copy.subscribe(track::Subscription::default().with_start(1))) .await .unwrap() .unwrap(); @@ -1499,7 +1499,7 @@ mod hop_tests { assert_eq!(&frame.payload.contiguous(0)[..], b"frame"); assert!(next(&mut received).await.is_none()); track.insert_datagram(2, ts(25), b"datagram".to_vec()).unwrap(); - let datagram = moq_clock::timeout(TIMEOUT, kio::wait(|waiter| subscriber.poll_recv_wire_datagram(waiter))) + let datagram = kio::clock::timeout(TIMEOUT, kio::wait(|waiter| subscriber.poll_recv_wire_datagram(waiter))) .await .unwrap() .unwrap() @@ -1512,7 +1512,7 @@ mod hop_tests { /// A compressed track crosses a negotiated hop as stored: each frame's Inflated Size /// follows its Object Record, and a datagram's follows its Datagram State. - #[moq_clock::test] + #[kio::test] async fn compressed_media_crosses_a_negotiated_hop() { let upstream = crate::origin::Config::new(crate::Hop::new(2).unwrap()).produce(); let broadcast = upstream.publish("room", crate::origin::Route::default()).unwrap(); @@ -1541,7 +1541,7 @@ mod hop_tests { assert!(next(&mut received).await.is_none()); track.insert_datagram(7, ts(9), payload(3)).unwrap(); - let datagram = moq_clock::timeout( + let datagram = kio::clock::timeout( TIMEOUT, kio::wait(|waiter| subscriber.poll_recv_stored_datagram(waiter)), ) diff --git a/rs/moq-net/src/lite/publisher.rs b/rs/moq-net/src/lite/publisher.rs index 100b3626040..0c283971382 100644 --- a/rs/moq-net/src/lite/publisher.rs +++ b/rs/moq-net/src/lite/publisher.rs @@ -2454,7 +2454,7 @@ mod test { /// An unfloored join adopts the first served group: the cursor rises to it, so a /// group created below it is not served. An explicit floor does not; see /// [`explicit_floor_delivers_a_late_lower_group`]. - #[moq_clock::test] + #[kio::test] async fn start_floor_suppresses_late_lower_arrivals() { use futures::FutureExt; @@ -2491,7 +2491,7 @@ mod test { /// The explicit-floor twin of [`start_floor_suppresses_late_lower_arrivals`]. /// The subscription named group 0, so group 5 is still inside the floor when /// it is created after group 7. - #[moq_clock::test] + #[kio::test] async fn explicit_floor_delivers_a_late_lower_group() { let mut producer = track_producer("test"); let mut subscriber = producer.subscribe( @@ -2521,7 +2521,7 @@ mod test { } } - #[moq_clock::test] + #[kio::test] async fn recv_next_drains_datagram_before_finished() { let mut producer = track_producer("test"); let mut subscriber = producer.subscribe(None); @@ -2542,7 +2542,7 @@ mod test { } } - #[moq_clock::test] + #[kio::test] async fn recv_next_reports_future_boundary_before_finished() { let mut producer = track_producer("test"); let mut subscriber = producer.subscribe(None); @@ -2588,7 +2588,7 @@ mod test { /// A relay can ingest back-to-back groups micro-reordered (the upstream leg /// sends newest-first). The older group is cached and in demand, so serving /// must still deliver it; a sequence cursor would skip it permanently. - #[moq_clock::test] + #[kio::test] async fn recv_next_serves_late_arrival_after_newer_group() { use futures::FutureExt; @@ -2938,13 +2938,13 @@ mod announce_test { /// The initial announcement; drop to retract, update to restart. announcement: crate::model::AnnounceProducer, wire: Wire, - task: moq_clock::sim::JoinHandle>, + task: kio::clock::sim::JoinHandle>, } impl Harness { /// Assert the loop is quiet *and* still alive. A panicked announce task /// also writes nothing, so silence alone would pass for the wrong reason - /// (`moq_clock::sim::spawn` parks the panic in the handle until it's joined). + /// (`kio::clock::sim::spawn` parks the panic in the handle until it's joined). fn assert_idle(&self) { self.wire.assert_quiet(); assert!(!self.task.is_finished(), "the announce loop ended unexpectedly"); @@ -2952,7 +2952,7 @@ mod announce_test { } async fn settle() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } /// Announce one route with cost 7 and run the announce loop against it. @@ -2967,7 +2967,7 @@ mod announce_test { /// A relay answers with what it holds now: an upstream still delivering its own /// initial set never delays the ANNOUNCE_OK, so a peer syncs with this relay. - #[moq_clock::test] + #[kio::test] async fn a_silent_upstream_never_delays_the_answer() { let origin = Hop::new(1).unwrap().produce(); let _route = origin.announce("cam", crate::origin::Route::default()).unwrap(); @@ -2982,7 +2982,7 @@ mod announce_test { writer: Writer::new(crate::transport::boxed::SendStream::new(SinkSend::new(log)), VERSION), reader: Reader::new(crate::transport::boxed::RecvStream::new(PendingRecv), VERSION), }; - let _task = moq_clock::sim::spawn(async move { + let _task = kio::clock::sim::spawn(async move { let mut announced = consumer.announced(); let self_origin = consumer.hop(); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, VERSION, None).await @@ -3015,7 +3015,7 @@ mod announce_test { writer: Writer::new(crate::transport::boxed::SendStream::new(SinkSend::new(log)), version), reader: Reader::new(crate::transport::boxed::RecvStream::new(PendingRecv), version), }; - let task = moq_clock::sim::spawn(async move { + let task = kio::clock::sim::spawn(async move { let mut announced = consumer.announced(); let self_origin = consumer.hop(); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, version, auth).await @@ -3055,7 +3055,7 @@ mod announce_test { /// A live announce goes out as an Active with a fresh id; its retraction /// references the id. - #[moq_clock::test] + #[kio::test] async fn announce_and_retract() { let mut h = harness().await; @@ -3080,14 +3080,14 @@ mod announce_test { } /// A metadata update restarts the advertisement in place, keeping its id. - #[moq_clock::test] + #[kio::test] async fn update_restarts_in_place() { let mut h = harness().await; h.announcement .update(crate::origin::Route::default().with_hops(pub_hops()).with_cost(3)) .unwrap(); - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; match h.wire.take_announces().as_slice() { [lite::AnnounceBroadcast::Update { id: 0, hops, cost }] => { @@ -3100,7 +3100,7 @@ mod announce_test { } /// An identical update never reaches the wire: the origin coalesces it away. - #[moq_clock::test] + #[kio::test] async fn identical_update_is_quiet() { let h = harness().await; h.announcement @@ -3114,14 +3114,14 @@ mod announce_test { /// cost) and without an epoch is another source, in either direction: an /// ANNOUNCE_RESTART on lite-07, which may carry an epoch, and an end and a fresh /// start before it. - #[moq_clock::test] + #[kio::test] async fn source_flip_restarts() { for version in [Version::Lite06, Version::Lite07] { let mut h = harness_on(version).await; let route = crate::origin::Route::default().with_hops(pub_hops()).with_cost(7); let newer = h.origin.announce("cam", route.clone()).unwrap(); // A restart waits out the update hold like an update. - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; let restarted = |msgs: Vec| match (version, msgs.as_slice()) { ( @@ -3151,7 +3151,7 @@ mod announce_test { restarted(h.wire.take_announces()); drop(newer); - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; restarted(h.wire.take_announces()); h.assert_idle(); @@ -3159,7 +3159,7 @@ mod announce_test { } /// A newer epoch restarts the advertisement, carrying the epoch on lite-07. - #[moq_clock::test] + #[kio::test] async fn a_newer_epoch_restarts_with_it() { let mut h = harness_on(Version::Lite07).await; let epoch = crate::Epoch::mint(); @@ -3173,7 +3173,7 @@ mod announce_test { .with_cost(7), ) .unwrap(); - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; match h.wire.take_announces().as_slice() { [ @@ -3191,7 +3191,7 @@ mod announce_test { /// A grant that grows while a new instance replaces an advertised one still restarts it, /// whether the instance carries a newer epoch or is an anonymous source: the regrant takes /// in what the old cursor had pending rather than dropping it. - #[moq_clock::test] + #[kio::test] async fn a_restart_pending_when_the_grant_grows_still_restarts() { // The peer's ceiling: what it may subscribe to is what we may announce to it. let grant = |paths: &[&str]| crate::auth::Grant { @@ -3216,7 +3216,7 @@ mod announce_test { }; let _newer = h.origin.announce("cam", route).unwrap(); auth.handle().authorize(&grant(&["cam", "other"])); - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; match h.wire.take_announces().as_slice() { [lite::AnnounceBroadcast::Restart { id: 0, epoch: sent, .. }] => { @@ -3230,24 +3230,24 @@ mod announce_test { /// Costs past the wire ceiling clamp to the same value, so moving between them /// sends nothing. - #[moq_clock::test] + #[kio::test] async fn clamped_cost_change_is_quiet() { let mut h = harness().await; let route = |cost| crate::origin::Route::default().with_hops(pub_hops()).with_cost(cost); h.announcement.update(route(u64::MAX)).unwrap(); - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; assert_eq!(h.wire.take_announces().len(), 1, "expected the clamped restart"); h.announcement.update(route(u64::MAX - 1)).unwrap(); - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; h.assert_idle(); } /// A route whose chain contains the excluded peer is invisible to that peer's /// announce stream (control-plane split horizon via the cursor). - #[moq_clock::test] + #[kio::test] async fn excluded_routes_are_filtered() { let peer = Hop::new(42).unwrap(); let origin = Hop::new(1).unwrap().produce(); @@ -3267,7 +3267,7 @@ mod announce_test { writer: Writer::new(crate::transport::boxed::SendStream::new(SinkSend::new(log)), VERSION), reader: Reader::new(crate::transport::boxed::RecvStream::new(PendingRecv), VERSION), }; - let task = moq_clock::sim::spawn(async move { + let task = kio::clock::sim::spawn(async move { let mut announced = consumer.announced(); let self_origin = consumer.hop(); TestPublisher::run_announce(&mut stream, &consumer, &mut announced, self_origin, VERSION, None).await @@ -3288,7 +3288,7 @@ mod announce_test { } /// A route announced after the initial burst goes out as ANNOUNCE_START. - #[moq_clock::test] + #[kio::test] async fn late_route_emits_announce_start() { let mut h = harness().await; let _late = h @@ -3304,7 +3304,7 @@ mod announce_test { } /// A cost past the wire ceiling is clamped rather than rejected. - #[moq_clock::test] + #[kio::test] async fn cost_clamps_to_the_wire_ceiling() { let mut h = harness().await; h.announcement @@ -3314,7 +3314,7 @@ mod announce_test { .with_cost(u64::MAX), ) .unwrap(); - moq_clock::sleep(crate::origin::Config::default().update_hold).await; + kio::clock::sleep(crate::origin::Config::default().update_hold).await; settle().await; match h.wire.take_announces().as_slice() { [lite::AnnounceBroadcast::Update { cost, .. }] => { @@ -5036,7 +5036,7 @@ mod serve_group_test { /// A track served untimed to lite-05/06 carries its send time, never its frames' own /// timestamps: those of an unchecked track may be moq-transport arrival times. - #[moq_clock::test] + #[kio::test] async fn an_unchecked_track_goes_out_with_send_times() { let runtime = crate::time::sim(); let stamped = Timestamp::from_millis(36_000_000).unwrap(); @@ -5059,7 +5059,7 @@ mod serve_group_test { assert_eq!(stamp.wire(Some(stamped), &runtime).unwrap(), stamped.value()); } - #[moq_clock::test] + #[kio::test] async fn resets_with_the_abort_code() { let log = Log::default(); let session = SinkSession::new(log.clone()); @@ -5106,7 +5106,7 @@ mod serve_group_test { /// A subscription group keeps checking the max delay while a transport write is /// flow-control blocked, so a stalled send cannot pin the stream indefinitely. - #[moq_clock::test] + #[kio::test] async fn blocked_transport_write_expires_with_the_group() { let gate = kio::Producer::new(false); let session = SinkSession::gated_uni(gate.consume()); @@ -5146,7 +5146,7 @@ mod serve_group_test { "transport write is blocked" ); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -5158,7 +5158,7 @@ mod serve_group_test { /// A group parked at its tail when the budget gives up resets with `Old`. A FIN would /// tell the next hop the frames it already has are the whole group. - #[moq_clock::test] + #[kio::test] async fn a_group_parked_at_its_tail_expires_with_old() { let log = Log::default(); let session = SinkSession::new(log.clone()); @@ -5196,7 +5196,7 @@ mod serve_group_test { "parked waiting for the next frame" ); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -5208,7 +5208,7 @@ mod serve_group_test { } /// The final payload remains guarded after its frame has advanced the group cursor. - #[moq_clock::test] + #[kio::test] async fn blocked_final_transport_chunk_expires_with_the_group() { let gate = kio::Producer::new(true); let session = SinkSession::gated_uni(gate.consume()); @@ -5265,7 +5265,7 @@ mod serve_group_test { "the final byte is transport-blocked" ); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -5277,7 +5277,7 @@ mod serve_group_test { /// A subscription group keeps checking the max delay while transport stream credit is /// exhausted, so returning credit is reserved for content that is still live. - #[moq_clock::test] + #[kio::test] async fn blocked_transport_open_expires_with_the_group() { let gate = kio::Producer::new(false); let session = SinkSession::gated_open_uni(gate.consume()); @@ -5316,7 +5316,7 @@ mod serve_group_test { "stream credit is exhausted" ); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -5329,14 +5329,14 @@ mod serve_group_test { /// under the simulator's per-poll limit. async fn settle_run(run: &mut TrackRun, writer: &mut Writer) { while run.poll_step(writer, &kio::Waiter::noop()).is_ready() { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } } /// A peer withholding stream credit makes each subscription hold one group machine, however /// many tracks it subscribes to and groups they publish: the backlog waits in the cache. /// Granting credit then serves every group still worth sending. - #[moq_clock::test] + #[kio::test] async fn withheld_credit_holds_one_group_machine_per_subscription() { for (tracks, groups) in [(1, 1), (1, 64), (16, 1), (16, 64)] { let gate = kio::Producer::new(false); @@ -5377,7 +5377,7 @@ mod serve_group_test { /// A group waiting for stream credit that the cache evicts leaves at once, named with /// SUBSCRIBE_DROP, rather than spending the credit on a reset once it arrives. The next /// group takes its place. - #[moq_clock::test] + #[kio::test] async fn an_evicted_group_waiting_for_credit_leaves_at_once() { let version = Version::Lite07; let gate = kio::Producer::new(false); @@ -5414,7 +5414,7 @@ mod serve_group_test { /// After a stall, the credit goes to the live edge: the group parked when credit ran out /// expires, and the cursor skips the backlog the budget gave up on while it waited. - #[moq_clock::test] + #[kio::test] async fn credit_after_a_stall_serves_the_live_edge() { let version = Version::Lite07; let gate = kio::Producer::new(false); @@ -5429,7 +5429,7 @@ mod serve_group_test { write_group(&mut track, sequence, sequence * 1000); while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} assert!(run.machines() <= 1); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; } *gate.write().ok().unwrap() = true; @@ -5450,7 +5450,7 @@ mod serve_group_test { /// A stream parked on the transport resets once the cache evicts the part of its group /// it has not read: the rest can never be sent, so the buffered bytes are released /// rather than held until the peer grants flow control. - #[moq_clock::test] + #[kio::test] async fn blocked_transport_write_resets_once_the_group_is_evicted() { let gate = kio::Producer::new(false); let session = SinkSession::gated_uni(gate.consume()); @@ -5523,7 +5523,7 @@ mod serve_group_test { /// releases the stream via `poll_close`; leaving the writer to drop after /// `finish()` would fire the Drop fallback and tack a spurious Cancel reset /// onto a stream the peer already acknowledged. - #[moq_clock::test] + #[kio::test] async fn completed_group_does_not_reset() { let log = Log::default(); let session = SinkSession::new(log.clone()); @@ -5574,7 +5574,7 @@ mod serve_group_test { /// A FIN holds the group's bytes until the peer acknowledges it, so a group that /// goes stale while waiting still expires instead of pinning them. - #[moq_clock::test] + #[kio::test] async fn unacknowledged_fin_expires_with_the_group() { let session = SinkSession::new(Log::default()).with_unacked_fin(); let log = session.log.clone(); @@ -5611,7 +5611,7 @@ mod serve_group_test { assert!(futures::poll!(serve.as_mut()).is_pending(), "the FIN is unacknowledged"); assert!(log.resets().is_empty()); - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let mut edge = track.append_group().unwrap(); edge.write_frame(Timestamp::from_millis(1000).unwrap(), b"edge".as_slice()) .unwrap(); @@ -5623,7 +5623,7 @@ mod serve_group_test { /// The transport keeps scheduling a finished stream's retransmissions until the /// FIN is acknowledged, so queue and SUBSCRIBE_UPDATE reorders still reach it. - #[moq_clock::test] + #[kio::test] async fn unacknowledged_fin_follows_priority_changes() { let session = SinkSession::new(Log::default()).with_unacked_fin(); let log = session.log.clone(); @@ -5711,7 +5711,7 @@ mod serve_group_test { (TrackRun::new(ctx, track, bounds, 0, steer), writer, log) } - #[moq_clock::test] + #[kio::test] async fn wanted_updates_ignore_stale_groups_and_recheck_the_ratio() { let track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -5756,7 +5756,7 @@ mod serve_group_test { /// group streams join it, ranked newest first by sequence alone: the session-wide queue /// takes no part. A SUBSCRIBE_UPDATE moves the group once, and an order flip re-stamps /// the open streams. - #[moq_clock::test] + #[kio::test] async fn grouped_streams_rank_within_their_subscription() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -5807,7 +5807,7 @@ mod serve_group_test { } /// The encoded body must fit both the wire cap and the transport's smaller limit. - #[moq_clock::test] + #[kio::test] async fn datagrams_fit_the_wire_and_transport_limits() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { for transport in [900usize, 1200, 1400] { @@ -5841,7 +5841,7 @@ mod serve_group_test { /// A datagram goes in its subscription's send group, ranked like the stream carrying /// its group from the start, so the transport merges it into the group order. - #[moq_clock::test] + #[kio::test] async fn datagrams_rank_within_their_subscription() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -5873,7 +5873,7 @@ mod serve_group_test { /// With `ietf` negotiated, frame bounds cut datagrams by Object ID: a public datagram is frame 0, a /// relayed moq-transport one keeps its own, and both ends are inclusive. - #[moq_clock::test] + #[kio::test] async fn frame_bounds_cut_datagrams_by_object_id() { for (sequence, object_id, served) in [ (5, None, false), @@ -5935,7 +5935,7 @@ mod serve_group_test { /// An object this hop cannot identify is never egress payload. An admitted object's /// existing best-effort accounting still counts a transport-size drop as an attempt. - #[moq_clock::test] + #[kio::test] async fn unidentified_datagram_objects_are_not_metered() { use crate::model::ProduceTest; @@ -6036,7 +6036,7 @@ mod serve_group_test { /// A SUBSCRIBE_UPDATE that flips the group order reranks the next datagram, even with no /// group served in between. - #[moq_clock::test] + #[kio::test] async fn datagrams_follow_an_updated_group_order() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -6080,7 +6080,7 @@ mod serve_group_test { /// A group with more frames ready than one poll's budget drains over several polls, /// so a sibling (the transport's driver, say) runs in between. - #[moq_clock::test] + #[kio::test] async fn a_long_group_drains_within_the_budget() { /// `GroupServe`'s passes per poll; each writes at most one frame. const BUDGET: usize = 32; @@ -6139,7 +6139,7 @@ mod serve_group_test { } /// A skipped sequence is accounted for by DROP rather than a stream count. - #[moq_clock::test] + #[kio::test] async fn lite07_end_drops_skipped_sequences() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -6164,7 +6164,7 @@ mod serve_group_test { /// A relay that holds only the first group of a backlog answers with the largest its /// source reported, so a live joiner downstream starts at the newest group rather than /// the oldest one the budget serves. - #[moq_clock::test] + #[kio::test] async fn lite07_start_reports_the_sources_largest() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -6216,7 +6216,7 @@ mod serve_group_test { /// A stale group already named in SUBSCRIBE_DROP stays dropped once SUBSCRIBE_UPDATE /// widens the max age past it: the subscriber may have settled it already. - #[moq_clock::test] + #[kio::test] async fn a_reported_stale_drop_survives_a_widened_max_age() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut track = track::Producer::new( @@ -6255,7 +6255,7 @@ mod serve_group_test { /// Lite-05 and later name every sequence below the end that the subscription never /// got once the track ends: one skipped between groups, and one past the last. - #[moq_clock::test] + #[kio::test] async fn the_end_drops_the_sequences_never_served() { for version in [Version::Lite05, Version::Lite06] { let mut track = track::Producer::new( @@ -6281,7 +6281,7 @@ mod serve_group_test { /// An upstream DROP is forwarded while the track is still live, and the end sweep /// does not name it again. - #[moq_clock::test] + #[kio::test] async fn an_explicit_drop_is_forwarded_early_once() { for version in [Version::Lite05, Version::Lite06] { let mut track = track::Producer::new( @@ -6312,7 +6312,7 @@ mod serve_group_test { /// A group the publisher cuts is dropped once, while the track is live, and the end /// sweep does not name it again. - #[moq_clock::test] + #[kio::test] async fn a_cut_is_dropped_early_once() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6340,7 +6340,7 @@ mod serve_group_test { /// A wide upstream DROP is held and forwarded as a range, never one entry per sequence, /// and a wider one later forwards only what is new. - #[moq_clock::test] + #[kio::test] async fn a_wide_drop_is_forwarded_as_a_range() { const WIDE: u64 = 1 << 40; let version = Version::Lite06; @@ -6370,7 +6370,7 @@ mod serve_group_test { /// An upstream drop below the floor is forwarded once an update lowers the floor to it, /// not only at the end. - #[moq_clock::test] + #[kio::test] async fn a_lowered_start_forwards_a_drop_held_below_it() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6403,7 +6403,7 @@ mod serve_group_test { } /// A group the publisher cuts and then re-creates is served, not dropped. - #[moq_clock::test] + #[kio::test] async fn a_recreated_cut_is_not_dropped() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6428,7 +6428,7 @@ mod serve_group_test { /// A cut this run already dropped stays dropped: the subscriber accounted for it, so a /// group the publisher re-creates under it afterwards is not served. - #[moq_clock::test] + #[kio::test] async fn a_cut_dropped_then_recreated_is_not_served() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6462,7 +6462,7 @@ mod serve_group_test { /// A late group the cursor skips as stale is dropped at once, even when it is the only /// unread group and nothing else wakes the run. - #[moq_clock::test] + #[kio::test] async fn a_late_stale_group_is_dropped_early() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6479,7 +6479,7 @@ mod serve_group_test { assert_eq!(drops(&mut writer, &log, version).await, []); // Its successor arrived a full budget ago, so group 1 is stale on the wall clock. - moq_clock::sim::advance(Duration::from_secs(2)).await; + kio::clock::sim::advance(Duration::from_secs(2)).await; write_group(&mut track, 1, 1); while run.poll_step(&mut writer, &kio::Waiter::noop()).is_ready() {} assert_eq!( @@ -6492,7 +6492,7 @@ mod serve_group_test { /// A group skipped for a missing head after SUBSCRIBE_START is dropped at once, not /// left for the end sweep. - #[moq_clock::test] + #[kio::test] async fn a_missing_head_is_dropped_early() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6527,7 +6527,7 @@ mod serve_group_test { } /// A missing head at the model's largest sequence has no successor to name. - #[moq_clock::test] + #[kio::test] async fn a_missing_head_at_the_maximum_sequence_does_not_panic() { let track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -6548,10 +6548,10 @@ mod serve_group_test { } /// A long-budget reader warms the relay without changing a live reader's resolved start. - #[moq_clock::test] + #[kio::test] async fn cold_and_warm_relays_resolve_the_same_start() { fn drive(mut driver: D) { - drop(moq_clock::sim::spawn(moq_clock::drive(move |now, waiter| { + drop(kio::clock::sim::spawn(kio::clock::drive(move |now, waiter| { crate::time::Driver::poll(&mut driver, now, waiter) }))); } @@ -6581,12 +6581,12 @@ mod serve_group_test { .with_publisher(publisher); futures::join!( async { - let (session, driver) = client.connect(moq_clock::now(), client_transport).await.unwrap(); + let (session, driver) = client.connect(kio::clock::now(), client_transport).await.unwrap(); drive(driver); session }, async { - let (session, driver) = server.accept(moq_clock::now(), server_transport).await.unwrap(); + let (session, driver) = server.accept(kio::clock::now(), server_transport).await.unwrap(); drive(driver); session } @@ -6625,7 +6625,7 @@ mod serve_group_test { assert_eq!(keeper.recv_group().await.unwrap().unwrap().sequence, sequence); } } - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let subscriber = origin(3); let _downstream = connect(version, &relay, &subscriber).await; let remote = subscriber.consume().routed_broadcast("room").await.unwrap(); @@ -6647,7 +6647,7 @@ mod serve_group_test { } /// A relay's retained stale groups must not change the start it answers downstream. - #[moq_clock::test] + #[kio::test] async fn the_start_names_past_the_stale_groups_it_skips() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut starts = Vec::new(); @@ -6661,7 +6661,7 @@ mod serve_group_test { for sequence in (if warm { 0 } else { 2 })..3 { write_group(&mut track, sequence, sequence * 10); } - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; let subscriber = track.subscribe(track::Subscription::default()); let (mut run, mut writer, log) = lite_run(version, SinkSession::new(Log::default()), subscriber); assert!( @@ -6684,7 +6684,7 @@ mod serve_group_test { } /// Upstream drops received before the start exclude the entire range, even on lite-07. - #[moq_clock::test] + #[kio::test] async fn the_start_names_past_the_upstream_dropped_range() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut track = track::Producer::new( @@ -6715,7 +6715,7 @@ mod serve_group_test { } /// A range given up before the start resolves, but above it, is still named promptly. - #[moq_clock::test] + #[kio::test] async fn a_range_skipped_above_the_start_is_dropped() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut track = track::Producer::new( @@ -6741,7 +6741,7 @@ mod serve_group_test { /// A SUBSCRIBE_UPDATE that lowers the start below SUBSCRIBE_START asks for those groups /// too, so the drops at the end count from there. - #[moq_clock::test] + #[kio::test] async fn the_end_drops_below_a_lowered_start() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6784,7 +6784,7 @@ mod serve_group_test { /// A lowered start restarts the age of the gaps it newly asks for, as the subscriber does, /// so a gap below the old start isn't folded away on the time before the update. - #[moq_clock::test] + #[kio::test] async fn the_end_drops_below_a_lowered_start_after_the_grace() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6803,7 +6803,7 @@ mod serve_group_test { assert!(step.is_ready(), "the start never resolved"); } - moq_clock::sim::advance(Duration::from_secs(2)).await; + kio::clock::sim::advance(Duration::from_secs(2)).await; run.update(lite::SubscribeUpdate { wanted_group: None, order: crate::track::Order::Descending, @@ -6830,7 +6830,7 @@ mod serve_group_test { /// After a raised start, lowering it again restarts the gaps below the raised floor, not /// only those below the lowest start ever asked for. - #[moq_clock::test] + #[kio::test] async fn the_end_drops_below_a_start_raised_then_lowered() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6863,9 +6863,9 @@ mod serve_group_test { assert!(futures::poll!(run.as_mut()).is_pending()); } - moq_clock::sim::advance(Duration::from_millis(900)).await; + kio::clock::sim::advance(Duration::from_millis(900)).await; run.update(update(2)); - moq_clock::sim::advance(Duration::from_millis(200)).await; + kio::clock::sim::advance(Duration::from_millis(200)).await; track.finish_at(track::Position::group(6)).unwrap(); drop(track); kio::wait(|waiter| run.poll(&mut writer, waiter)).await.unwrap(); @@ -6875,7 +6875,7 @@ mod serve_group_test { /// A raised floor sends no early drop: a later update may lower it again, and the /// subscriber cannot take back a drop for the groups that reopens. - #[moq_clock::test] + #[kio::test] async fn a_raised_floor_is_not_dropped_early() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -6916,7 +6916,7 @@ mod serve_group_test { /// Pre-06 an absent Group Start is the latest group, so an update that drops a named /// floor re-pins the cursor there: a group created below it afterwards is not served. - #[moq_clock::test] + #[kio::test] async fn a_pre06_update_dropping_the_floor_repins_to_the_latest_group() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -6954,7 +6954,7 @@ mod serve_group_test { /// On an empty track the re-pin has no latest group to name, so the first group the /// track produces is served, even below the dropped floor. - #[moq_clock::test] + #[kio::test] async fn a_pre06_update_dropping_the_floor_on_an_empty_track_serves_the_next_group() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -6987,7 +6987,7 @@ mod serve_group_test { /// A never-arrived gap remains owed after the publisher's grace: only the subscriber /// may age it out, and the end sweep must still name it before the FIN. - #[moq_clock::test] + #[kio::test] async fn the_end_drops_a_never_arrived_gap_past_the_grace() { let version = Version::Lite06; let mut track = track::Producer::new( @@ -7004,7 +7004,7 @@ mod serve_group_test { write_group(&mut track, 2, 0); assert!(futures::poll!(run.as_mut()).is_pending()); - moq_clock::sim::advance(Duration::from_secs(2)).await; + kio::clock::sim::advance(Duration::from_secs(2)).await; write_group(&mut track, 4, 0); assert!(futures::poll!(run.as_mut()).is_pending()); track.finish_at(track::Position::group(5)).unwrap(); @@ -7089,7 +7089,7 @@ mod serve_group_test { /// A resume past the only finished group leaves that group below the cursor. /// Widening to no floor serves it: it is the live edge until a newer group /// exists, and a catalog never publishes the next one. - #[moq_clock::test] + #[kio::test] async fn a_widening_update_serves_the_finished_group_it_had_skipped() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -7114,7 +7114,7 @@ mod serve_group_test { /// Widening the floor serves a cached group below the old one, even though it arrived /// before the groups already served, and serves those only once. - #[moq_clock::test] + #[kio::test] async fn a_widening_update_serves_a_cached_group_below_the_old_floor() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -7143,7 +7143,7 @@ mod serve_group_test { /// A SUBSCRIBE_UPDATE landing while the first group waits on the source's start keeps /// the floor it raised: resolving the start from the held group must not lower it. - #[moq_clock::test] + #[kio::test] async fn held_first_group_keeps_an_updated_floor() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -7178,7 +7178,7 @@ mod serve_group_test { /// A source whose feed starts below the subscriber's floor serves the floor's group, so /// a newer group arriving first must not resolve the start past it. - #[moq_clock::test] + #[kio::test] async fn held_first_group_resolves_to_the_floor_under_the_source() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -7201,7 +7201,7 @@ mod serve_group_test { /// A group skipped for a missing head before the start resolves is never served, so /// SUBSCRIBE_START must not name it, even where the source's feed starts. - #[moq_clock::test] + #[kio::test] async fn held_first_group_starts_past_a_skipped_head() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -7228,7 +7228,7 @@ mod serve_group_test { /// Adjacent ranges skipped with different errors before the start resolves are all /// passed over, so SUBSCRIBE_START names neither. - #[moq_clock::test] + #[kio::test] async fn held_first_group_starts_past_adjacent_skips() { let mut track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -7255,7 +7255,7 @@ mod serve_group_test { } /// A track that ends without a group still ends the subscription, with no stream owed. - #[moq_clock::test] + #[kio::test] async fn lite07_empty_track_ends_without_a_start() { let track = track::Producer::new( Arc::new(broadcast::Info::default()), @@ -7271,7 +7271,7 @@ mod serve_group_test { } /// A declared end is sent before stream credit, and a group that expires first is dropped. - #[moq_clock::test] + #[kio::test] async fn lite07_end_precedes_blocked_streams_and_reports_expiry() { let gate = kio::Producer::new(false); let mut track = track::Producer::new( @@ -7287,7 +7287,7 @@ mod serve_group_test { assert!(futures::poll!(run.as_mut()).is_pending()); // Group 1 lands a second later, expiring group 0 before it ever opened. - moq_clock::sim::advance(Duration::from_secs(1)).await; + kio::clock::sim::advance(Duration::from_secs(1)).await; write_group(&mut track, 1, 1000); track.finish().unwrap(); assert!(futures::poll!(run.as_mut()).is_pending(), "group 1 is still opening"); @@ -7320,7 +7320,7 @@ mod tests { /// the caller assigned it, on the data plane and not just the announce filter. /// Otherwise it can subscribe its way back to content that already flowed through /// it, which is the loop the announce filter exists to prevent. - #[moq_clock::test] + #[kio::test] async fn serving_origin_falls_back_to_the_assigned_identity() { let assigned = crate::Hop::new(777).unwrap(); let upstream = crate::Hop::new(778).unwrap(); @@ -7383,7 +7383,7 @@ mod tests { /// same per-peer route selection as the live loop: a broadcast whose only /// route flows through the excluded hop (here the peer's assigned identity, /// `Client::with_peer_hop`) is filtered from the initial set too. - #[moq_clock::test] + #[kio::test] async fn announce_init_applies_route_selection() { let assigned = crate::Hop::new(777).unwrap(); let clean_publisher = crate::Hop::new(778).unwrap(); @@ -7439,7 +7439,7 @@ mod tests { /// A broadcast sent in ANNOUNCE_INIT is live like any other, so its end reaches /// the peer instead of being treated as never advertised. - #[moq_clock::test] + #[kio::test] async fn announce_init_broadcast_ends() { let self_origin = crate::Hop::new(1).unwrap(); let origin = crate::origin::Config::new(self_origin).produce(); @@ -7463,10 +7463,10 @@ mod tests { )); assert!(futures::poll!(run.as_mut()).is_pending()); drop(cam); - moq_clock::timeout(std::time::Duration::from_secs(10), async { + kio::clock::timeout(std::time::Duration::from_secs(10), async { while log.writes.lock().unwrap().windows(3).filter(|w| *w == b"cam").count() < 2 { assert!(futures::poll!(run.as_mut()).is_pending()); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } }) .await @@ -7475,7 +7475,7 @@ mod tests { /// A close that lands before the initial burst still sends it, then ends every /// broadcast, so the peer never sees a FIN in place of ANNOUNCE_INIT. - #[moq_clock::test] + #[kio::test] async fn withdraw_before_init_sends_the_initial_burst() { let self_origin = crate::Hop::new(1).unwrap(); let origin = crate::origin::Config::new(self_origin).produce(); @@ -7541,7 +7541,7 @@ mod tests { ProbeServe::new(publisher.shared.clone(), publisher.runtime.clone(), stream) } - #[moq_clock::test] + #[kio::test] async fn malformed_complete_goaway_closes_the_session() { use kio::Task; for version in [Version::Lite04, Version::Lite05, Version::Lite06, Version::Lite07] { @@ -7568,7 +7568,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn unknown_control_types_reset_only_their_stream() { use kio::Task; // An unassigned type everywhere, then types a version predates: PROBE before lite-03, @@ -7647,7 +7647,7 @@ mod tests { async fn reports(&mut self, after: Duration) -> Vec { let server = &mut self.server; let run = kio::wait(|waiter| server.poll_probe(waiter)); - assert!(moq_clock::timeout(after, run).await.is_err(), "the stream never ends"); + assert!(kio::clock::timeout(after, run).await.is_err(), "the stream never ends"); decode_probes(&self.log.writes.lock().unwrap(), self.version) } } @@ -7671,7 +7671,7 @@ mod tests { /// The two PROBE fields are independent, each using 0 for unknown, so discarding /// the whole message for want of a bitrate leaves a subscriber with no RTT at /// all. That is what pins a qmux viewer to its fallback jitter buffer. - #[moq_clock::test] + #[kio::test] async fn reports_rtt_without_a_bitrate() { let stats = crate::lite::test_transport::SinkStats::default().with_rtt(std::time::Duration::from_millis(40)); let probes = probe_writes(stats).await; @@ -7682,7 +7682,7 @@ mod tests { } /// The mirror case: a send rate with no RTT still reports. - #[moq_clock::test] + #[kio::test] async fn reports_bitrate_without_an_rtt() { let stats = crate::lite::test_transport::SinkStats::default().with_send_rate(1_000_000); let probes = probe_writes(stats).await; @@ -7694,7 +7694,7 @@ mod tests { /// A transport measuring neither has nothing to say, and must not emit a report /// claiming two zeroes. - #[moq_clock::test] + #[kio::test] async fn reports_nothing_when_nothing_is_measurable() { let probes = probe_writes(crate::lite::test_transport::SinkStats::default()).await; assert!(probes.is_empty(), "expected no report, got {probes:?}"); @@ -7703,7 +7703,7 @@ mod tests { /// Lite03's PROBE carries no RTT field, so an RTT-only report has nothing to /// say there. Sending one anyway would serialize as a bare "bitrate unknown" /// and, worse, fire again on every RTT movement. - #[moq_clock::test] + #[kio::test] async fn lite03_sends_nothing_for_an_rtt_only_report() { let stats = crate::lite::test_transport::SinkStats::default().with_rtt(std::time::Duration::from_millis(40)); let probes = probe_writes_version(stats, Version::Lite03).await; @@ -7711,7 +7711,7 @@ mod tests { } /// Lite03 still reports the half it can carry. - #[moq_clock::test] + #[kio::test] async fn lite03_reports_the_bitrate() { let stats = crate::lite::test_transport::SinkStats::default() .with_send_rate(1_000_000) @@ -7725,7 +7725,7 @@ mod tests { /// A bitrate that becomes unknown is worth one report: the peer is still /// holding the last value we sent. But only one, however long the stream runs. - #[moq_clock::test] + #[kio::test] async fn a_bitrate_going_unknown_is_retracted_once() { let stats = crate::lite::test_transport::SinkStats::default().with_send_rate(1_000_000); let mut probing = Probing::new(stats, Version::Lite05).await; @@ -7747,7 +7747,7 @@ mod tests { /// An estimate that never moves is refreshed once per PROBE_MAX_AGE, and costs /// nothing in between. - #[moq_clock::test] + #[kio::test] async fn an_unchanged_estimate_refreshes_at_max_age() { let stats = crate::lite::test_transport::SinkStats::default().with_send_rate(1_000_000); let mut probing = Probing::new(stats, Version::Lite05).await; @@ -7758,7 +7758,7 @@ mod tests { } /// A move past PROBE_MAX_DELTA is reported as soon as the estimate changes. - #[moq_clock::test] + #[kio::test] async fn a_large_move_reports_at_once() { let stats = crate::lite::test_transport::SinkStats::default().with_send_rate(1_000_000); let mut probing = Probing::new(stats, Version::Lite05).await; @@ -7772,7 +7772,7 @@ mod tests { /// A smaller move waits for the threshold to decay to it, even though the /// estimate does not change again. - #[moq_clock::test] + #[kio::test] async fn a_small_move_waits_for_the_threshold() { let stats = crate::lite::test_transport::SinkStats::default().with_send_rate(1_000_000); let mut probing = Probing::new(stats, Version::Lite05).await; @@ -7798,7 +7798,7 @@ mod tests { /// Drive `serve` until it ends, or everything parks: whether it ended. async fn drive(serve: &mut RequestServe) -> bool { - moq_clock::timeout(Duration::from_millis(1), kio::wait(|waiter| serve.poll(waiter))) + kio::clock::timeout(Duration::from_millis(1), kio::wait(|waiter| serve.poll(waiter))) .await .is_ok() } @@ -7872,7 +7872,7 @@ mod tests { drop(serve); if let Some(track) = track { let mut demand = track.demand(); - let unused = moq_clock::timeout( + let unused = kio::clock::timeout( Duration::from_millis(1), kio::wait(|waiter| crate::util::poll_unwanted(&mut demand, waiter)), ); @@ -7894,7 +7894,7 @@ mod tests { /// transaction (moq-lite: closing the send direction ends the stream), however the /// answer is waiting. The lookup ends then, rather than pinning an upstream request /// nobody will read. - #[moq_clock::test] + #[kio::test] async fn a_request_ends_when_the_requester_leaves() { let broadcast = crate::Path::from_static("room"); for version in [Version::Lite05, Version::Lite06, Version::Lite07] { @@ -7937,7 +7937,7 @@ mod tests { /// A broadcast that overflows `Path::MAX_BYTES` under a deep root is refused on its own /// stream, never by closing the session. - #[moq_clock::test] + #[kio::test] async fn a_broadcast_too_long_under_the_root_is_refused_per_request() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -7989,7 +7989,7 @@ mod tests { reader: crate::coding::Reader::new(crate::transport::boxed::RecvStream::new(recv), version), }; let mut serve = RequestServe::::new(publisher.shared.clone(), stream); - let served = moq_clock::timeout(Duration::from_millis(1), kio::wait(|waiter| serve.poll(waiter))) + let served = kio::clock::timeout(Duration::from_millis(1), kio::wait(|waiter| serve.poll(waiter))) .await .expect("the request was left waiting"); assert!(served.is_ok(), "{version:?}: the session closed: {served:?}"); @@ -8003,7 +8003,7 @@ mod tests { /// An answered TRACK stream holds its track until the requester closes its side, by /// FIN or reset, and the hold owes nothing a draining close would wait for. A requester /// that leaves while the reply is still blocked on flow control lets the track go too. - #[moq_clock::test] + #[kio::test] async fn an_answered_track_stream_holds_the_track_until_the_requester_closes() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { for close in [Close::Fin, Close::Reset] { @@ -8079,7 +8079,7 @@ mod tests { session.close(close); assert!(drive(&mut serve).await, "{case}: still holding"); let mut demand = track.demand(); - moq_clock::timeout( + kio::clock::timeout( Duration::from_millis(1), kio::wait(|waiter| crate::util::poll_unwanted(&mut demand, waiter)), ) @@ -8101,7 +8101,7 @@ mod tests { /// resolves keeps it waiting, and the latest applies once it starts. Its wanted group /// is state each update restates: past the largest it joins, and once that group /// exists the same value asks for nothing more. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_update_is_not_a_close() { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let broadcast = origin.create_broadcast("room").unwrap(); @@ -8205,7 +8205,7 @@ mod tests { /// sibling (the transport's driver, say) runs between its polls. Without it, one poll /// served every group the producer kept appending and starved the rest of the runtime /// (a go publisher's 2.5 ms audio groups timed its session out). - #[moq_clock::test] + #[kio::test] async fn a_busy_subscription_yields_to_its_siblings() { /// `RequestServe`'s passes per poll; each serves at most one group. const BUDGET: u64 = 32; @@ -8334,7 +8334,7 @@ mod tests { /// A cold relay fills a bounded request from the group's head, so its cache does not /// store an undecodable tail merely because that was the downstream reader's floor. - #[moq_clock::test] + #[kio::test] async fn a_cold_bounded_fetch_requests_the_prefix() { let origin = crate::origin::Config::new(Hop::new(1).unwrap()).produce(); let broadcast = origin.create_broadcast("room").unwrap(); @@ -8379,7 +8379,7 @@ mod tests { /// A FETCH whose own budget gives up on its group partway resets as too old: a FIN /// would tell the requester the prefix it got is the whole group. - #[moq_clock::test] + #[kio::test] async fn an_expired_fetch_resets_rather_than_finishing() { const VERSION: Version = Version::Lite07; let origin = crate::origin::Config::new(Hop::new(1).unwrap()).produce(); @@ -8444,7 +8444,7 @@ mod tests { assert_eq!(session.log.resets(), vec![crate::StreamError::Old.to_code()]); } - #[moq_clock::test] + #[kio::test] async fn report_consumes_probe_targets_until_fin() { for version in [ Version::Lite03, @@ -8488,7 +8488,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn draining_probe_targets_yields() { const TARGETS: usize = 100; let version = Version::Lite07; @@ -8521,7 +8521,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn malformed_subscribe_update_closes_after_request_setup() { use kio::Task; for version in [Version::Lite05, Version::Lite06, Version::Lite07] { @@ -8579,7 +8579,7 @@ mod tests { /// A second listing of a broadcast on one session replaces the first, so a peer cannot /// multiply the listed set's memory and fanout by listing it again. - #[moq_clock::test] + #[kio::test] async fn a_newer_listing_of_a_broadcast_replaces_the_older() { use kio::Task; let version = Version::Lite07; @@ -8617,7 +8617,7 @@ mod tests { // Whether the control is still serving after the runtime settles. async fn serving(control: &mut Control) -> bool { - moq_clock::timeout(Duration::from_millis(1), kio::wait(|waiter| control.poll(waiter))) + kio::clock::timeout(Duration::from_millis(1), kio::wait(|waiter| control.poll(waiter))) .await .is_err() } @@ -8632,7 +8632,7 @@ mod tests { assert!(serving(&mut newer).await, "the newer listing ended"); } - #[moq_clock::test] + #[kio::test] async fn a_producer_decode_error_stays_on_its_request() { use kio::Task; for version in [Version::Lite05, Version::Lite06, Version::Lite07] { @@ -8670,7 +8670,7 @@ mod tests { runtime: crate::time::sim(), state: ControlState::Subscribe(RequestServe::new(shared, probe.stream.unwrap())), }; - let pending = moq_clock::timeout(Duration::from_millis(1), kio::wait(|waiter| control.poll(waiter))).await; + let pending = kio::clock::timeout(Duration::from_millis(1), kio::wait(|waiter| control.poll(waiter))).await; assert!(pending.is_err(), "{version}: request did not wait for its track"); // The local producer fails with the same error type a malformed peer message // would; it is still not the peer's fault. @@ -8680,7 +8680,7 @@ mod tests { .expect("track requested") .unwrap(); track.reject(Error::Decode(crate::DecodeError::InvalidValue)); - let ended = moq_clock::timeout(Duration::from_millis(1), kio::wait(|waiter| control.poll(waiter))).await; + let ended = kio::clock::timeout(Duration::from_millis(1), kio::wait(|waiter| control.poll(waiter))).await; assert!(ended.is_ok(), "{version}: the request did not end"); assert!( log.closes().is_empty(), @@ -8690,7 +8690,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn goaway_roles_limits_and_transport_termination() { use kio::Task; for version in [Version::Lite04, Version::Lite05, Version::Lite06, Version::Lite07] { @@ -8818,7 +8818,7 @@ mod tests { /// A subscription's send group ranks by the peer's subscriber priority first, and the /// publisher's track priority breaks a tie between two at one subscriber priority. - #[moq_clock::test] + #[kio::test] async fn send_group_ranks_by_the_subscriber_then_the_publisher() { let origin = crate::origin::Config::new(Hop::new(1).unwrap()).produce(); let broadcast = origin.create_broadcast("a").unwrap(); diff --git a/rs/moq-net/src/lite/session.rs b/rs/moq-net/src/lite/session.rs index 41c53bf82b9..ef44269fe05 100644 --- a/rs/moq-net/src/lite/session.rs +++ b/rs/moq-net/src/lite/session.rs @@ -934,7 +934,7 @@ mod tests { use crate::coding::Encode; use crate::lite::test_transport::ScriptedSession; - #[moq_clock::test] + #[kio::test] async fn malformed_auth_replies_close_the_session() { // Unknown reply, invalid code, truncated error, and trailing body bytes. for script in [ @@ -949,7 +949,7 @@ mod tests { /// A protocol error on a live connection must end partial receive reads before /// waiting for them, otherwise receive draining could wait for new peer data. - #[moq_clock::test] + #[kio::test] async fn malformed_auth_closes_before_draining_a_partial_group_header() { assert_session_closes( ScriptedSession::per_stream(vec![vec![99]]).with_incoming_unis(vec![vec![0]]), @@ -960,7 +960,7 @@ mod tests { /// After close, no stream can deliver the peer SETUP a GROUP stream waits on to read /// its header, whether the SETUP stream was truncated or never opened. - #[moq_clock::test] + #[kio::test] async fn drain_ends_when_groups_wait_on_an_undeliverable_setup() { let version = Version::Lite07; let mut group = Vec::new(); @@ -1007,7 +1007,7 @@ mod tests { .unwrap(); let mut driver = start.driver; - let res = moq_clock::timeout( + let res = kio::clock::timeout( std::time::Duration::from_secs(10), kio::wait(|waiter| driver.poll(waiter)), ) @@ -1053,7 +1053,7 @@ mod tests { let mut driver = start.driver; let token = handle.present(bytes::Bytes::from_static(b"token")).unwrap(); - let res = moq_clock::timeout( + let res = kio::clock::timeout( std::time::Duration::from_secs(5), kio::wait(|waiter| driver.poll(waiter)), ) @@ -1064,7 +1064,7 @@ mod tests { /// A granted token whose stream the peer resets is presented again on the same session, /// backing off while each attempt is lost before a reply: at 0s, 1s, and 3s. - #[moq_clock::test] + #[kio::test] async fn a_lost_stream_is_presented_again() { let grant = empty_grant(Version::Lite07); let transport = ScriptedSession::per_stream(vec![grant.clone(), grant]); @@ -1085,7 +1085,7 @@ mod tests { /// A retry's stream that ends before its reply is lost, not a peer without AUTH: the /// peer already answered the token, so it is presented again, backing off from the /// refusal's delay: at 0s, 1s, and 3s. - #[moq_clock::test] + #[kio::test] async fn a_lost_retry_is_presented_again() { let version = Version::Lite07; let mut busy = Vec::new(); @@ -1109,7 +1109,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn malformed_presenter_auth_closes_the_session() { for script in [vec![7, 1, 2], vec![7, 1, 0, 0]] { let transport = ScriptedSession::new(Vec::new()).with_incoming_bidis(vec![script]); @@ -1139,7 +1139,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn malformed_auth_ok_closes_the_session() { for pattern in [ b"*/**".as_slice(), @@ -1171,7 +1171,7 @@ mod tests { /// A reply cut off inside its declared size fails to decode, unlike a peer that /// resets before answering. - #[moq_clock::test] + #[kio::test] async fn truncated_auth_reply_closes_the_session() { let mut script = Vec::new(); let mut w = crate::coding::Encoder::new(&mut script, Version::Lite07.into()); @@ -1181,7 +1181,7 @@ mod tests { assert_session_closes(ScriptedSession::per_stream_eof(vec![script]), Setup::default()).await; } - #[moq_clock::test] + #[kio::test] async fn malformed_auth_error_reasons_close_the_session() { for reason in [vec![0xff], vec![b'a'; 8193]] { let mut script = Vec::new(); @@ -1218,7 +1218,7 @@ mod tests { }) .unwrap(); let mut driver = start.driver; - let res = moq_clock::timeout( + let res = kio::clock::timeout( std::time::Duration::from_secs(10), kio::wait(|waiter| driver.poll(waiter)), ) @@ -1228,7 +1228,7 @@ mod tests { assert_eq!(log.closes()[0].0, SessionError::ProtocolViolation.to_code()); } - #[moq_clock::test] + #[kio::test] async fn accept_setup_does_not_wait_on_an_early_stream_header() { let version = Version::Lite05; let mut setup = Vec::new(); @@ -1246,7 +1246,7 @@ mod tests { assert_eq!(accepted.early.len(), 1); } - #[moq_clock::test] + #[kio::test] async fn accept_setup_refuses_two_incomplete_setup_streams() { use futures::FutureExt; let session = @@ -1257,7 +1257,7 @@ mod tests { )); } - #[moq_clock::test] + #[kio::test] async fn duplicate_setup_closes_the_session() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { for complete in [false, true] { @@ -1302,7 +1302,7 @@ mod tests { /// A SETUP that fails to decode leaves nothing to wait on, since the Setup Stream is /// already claimed. - #[moq_clock::test] + #[kio::test] async fn malformed_setup_closes_the_session() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut truncated = Vec::new(); @@ -1379,7 +1379,7 @@ mod tests { .unwrap() } - #[moq_clock::test] + #[kio::test] async fn server_setup_client_parameters_close_the_session() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { for body in [vec![1, 2, 0], vec![1, 3, 1, 0], vec![1, 3, 1, 1], vec![1, 3, 1, 3]] { @@ -1399,7 +1399,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn unknown_client_role_remains_bidirectional() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let transport = ScriptedSession::new(Vec::new()).with_incoming_unis(vec![vec![1, 4, 1, 3, 1, 3]]); @@ -1414,7 +1414,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn malformed_probe_reports_close_the_session() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let transport = if version.has_auth() { @@ -1448,7 +1448,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn malformed_group_headers_remain_per_stream() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let transport = ScriptedSession::new(Vec::new()).with_incoming_unis(vec![vec![0, 0]]); @@ -1462,7 +1462,7 @@ mod tests { // GOAWAY is not a request: refusing it without credit would leave the peer // unaware that we are draining. - #[moq_clock::test] + #[kio::test] async fn goaway_waits_for_stream_credit() { let transport = ScriptedSession::new(Vec::new()).without_credit(); let log = transport.log.clone(); @@ -1476,7 +1476,7 @@ mod tests { assert!(log.closes().is_empty()); } - #[moq_clock::test] + #[kio::test] async fn clients_never_emit_a_goaway_redirect() { for version in [Version::Lite04, Version::Lite05, Version::Lite06, Version::Lite07] { let client = raw_session(ScriptedSession::new(Vec::new()), version, true, None); diff --git a/rs/moq-net/src/lite/subscriber.rs b/rs/moq-net/src/lite/subscriber.rs index 3e02d35be12..b7902622474 100644 --- a/rs/moq-net/src/lite/subscriber.rs +++ b/rs/moq-net/src/lite/subscriber.rs @@ -2181,7 +2181,7 @@ mod tests { /// A fetch held for a pre-lite-05 feed is released once its caller gives up, rather /// than waiting, track handle and all, for a group the feed may never reach. - #[moq_clock::test] + #[kio::test] async fn an_abandoned_feed_fetch_is_released() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2201,7 +2201,7 @@ mod tests { /// A lite-07 publisher that FINs with no SUBSCRIBE_START served nothing, which covers the /// ranges the SUBSCRIBE asked for but not ones an update it may not have read changed. - #[moq_clock::test] + #[kio::test] async fn a_startless_fin_covers_only_the_subscribed_ranges() { let tail = kio::Producer::new(Tail::default()); let Sub::Active(mut active) = feed_sub(&tail).await else { @@ -2219,7 +2219,7 @@ mod tests { /// QUIC does not order streams, so group 2's header can reach the relay before group 1's. /// A fetch held for group 1 keeps waiting through the grace and is served when it lands. - #[moq_clock::test] + #[kio::test] async fn a_feed_fetch_waits_out_a_reordered_group() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2247,7 +2247,7 @@ mod tests { } /// A group still missing a grace after a later one arrived is a miss, not a hold. - #[moq_clock::test] + #[kio::test] async fn a_feed_fetch_misses_once_the_ledger_gives_up() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2267,7 +2267,7 @@ mod tests { /// A floor lowered by an update, or a fresh SUBSCRIBE starting below earlier arrivals, /// asks for groups only now, so a fetch held for one waits out a fresh grace rather than /// the age of the gap below those arrivals. - #[moq_clock::test] + #[kio::test] async fn a_lowered_floor_restarts_a_held_fetch_gap() { for update in [true, false] { let h = Harness::new(Version::Lite04); @@ -2277,7 +2277,7 @@ mod tests { group.write_frame(None, &b"x"[..]).unwrap(); group.finish().unwrap(); } - moq_clock::sleep(crate::tail::GRACE * 2).await; + kio::clock::sleep(crate::tail::GRACE * 2).await; let lowered = Some(Subscription::default().with_range(2..)); // The SUBSCRIBE in force, already answered. @@ -2350,7 +2350,7 @@ mod tests { (track, callers, requests) } - #[moq_clock::test] + #[kio::test] async fn an_abandoned_feed_fetch_wakes_its_owner_without_an_arrival() { #[derive(Default)] struct Wakes(std::sync::atomic::AtomicUsize); @@ -2396,7 +2396,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn a_feed_arrival_polls_only_its_group() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2417,7 +2417,7 @@ mod tests { assert_eq!(fetches.fold.deadline(), Some(start + crate::tail::GRACE)); } - #[moq_clock::test] + #[kio::test] async fn a_feed_fold_polls_only_its_expired_gap() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2430,7 +2430,7 @@ mod tests { } arrive(&track, &tail, 0, start); arrive(&track, &tail, 2, start); - moq_clock::sleep(crate::tail::GRACE / 2).await; + kio::clock::sleep(crate::tail::GRACE / 2).await; arrive(&track, &tail, 4, start + crate::tail::GRACE / 2); let waiter = kio::Waiter::noop(); fetches.poll(&sub, start, &waiter); @@ -2445,7 +2445,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn feed_boundaries_poll_only_the_groups_they_exclude() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2474,7 +2474,7 @@ mod tests { assert!(fetches.held.is_empty(), "closure releases all remaining held groups"); } - #[moq_clock::test] + #[kio::test] async fn a_feed_drop_polls_only_the_groups_it_excludes() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2503,7 +2503,7 @@ mod tests { /// A peer that starts its feed far past a reader's floor makes the reader's miss wide. /// Holding it settles what the feed gave up by run, in one poll, rather than holding or /// refusing its groups one at a time. - #[moq_clock::test] + #[kio::test] async fn a_wide_feed_fill_settles_by_run() { const WIDE: u64 = 1 << 40; let start = crate::time::Instant::now(); @@ -2538,7 +2538,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn the_feed_track_backstop_refuses_the_next_group() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2559,7 +2559,7 @@ mod tests { assert!(callers.iter_mut().all(|caller| caller.now_or_never().is_none())); } - #[moq_clock::test] + #[kio::test] async fn a_feed_fetch_can_replace_an_abandoned_attempt_before_polling() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2587,7 +2587,7 @@ mod tests { /// A replacement takes the place of the attempt it replaces under the limit, before any /// poll releases that one. - #[moq_clock::test] + #[kio::test] async fn a_feed_fetch_replaces_an_abandoned_attempt_at_the_limit() { let start = crate::time::Instant::now(); let clock = crate::time::Deadlines::new(start); @@ -2617,7 +2617,7 @@ mod tests { } /// Sweep held fetches, unrelated tracks, and live arrival runs independently. - #[moq_clock::test] + #[kio::test] #[ignore = "release benchmark, run by nightly"] async fn benchmark_feed_fetch_wakes() { struct ScanFetches { @@ -2694,7 +2694,7 @@ mod tests { for _ in 0..tracks { // The sim counts ready polls per task poll to catch spinning loops, so // give each track's setup, and the timed loop below, a poll of its own. - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let (track, callers, requests) = feed_batch(1_000_000..1_000_000 + held); let tail = kio::Producer::new(Tail::default()); let sub = feed_sub(&tail).await; @@ -2718,7 +2718,7 @@ mod tests { fixtures.push((track, callers, tail, sub, scan, fetches)); } let (track, _callers, tail, sub, scan, fetches) = &mut fixtures[0]; - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; #[expect(clippy::disallowed_methods, reason = "the scan cost is real elapsed time")] let began = std::time::Instant::now(); for sequence in runs * 2..runs * 2 + EVENTS { @@ -2741,7 +2741,7 @@ mod tests { /// The owed groups start at the floor the demand last asked for, which an update can move /// either way after SUBSCRIBE_START answered the SUBSCRIBE. - #[moq_clock::test] + #[kio::test] async fn the_owed_floor_follows_the_demand() { let session = crate::lite::test_transport::ScriptedSession::new(Vec::new()); let stream = Stream::open(&mut crate::driver::Transport::new(session.clone()), VERSION) @@ -2845,7 +2845,7 @@ mod tests { assert!(log.closes().is_empty()); } - #[moq_clock::test] + #[kio::test] async fn padding_is_discarded_only_on_lite07() { for version in [ Version::Lite01, @@ -2865,7 +2865,7 @@ mod tests { } /// Both runtimes receive the other's encoded padding and keep the session live. - #[moq_clock::test] + #[kio::test] #[ignore = "requires Bun; run by just test interop"] async fn lite_padding_interop() { for (version, alpn) in [ @@ -2889,7 +2889,7 @@ mod tests { /// A GROUP needs no negotiated extension, so it proceeds before SETUP, or after a /// server's gated accept held it. - #[moq_clock::test] + #[kio::test] async fn early_group_is_delivered() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { for pre_read in [false, true] { @@ -2980,7 +2980,7 @@ mod tests { /// A group at or past the end the publisher declared contradicts that end, which no later /// stream can repair, so the whole track fails rather than ending clean without it. lite-05 /// specified an inclusive end, so there it costs only that group's stream. - #[moq_clock::test] + #[kio::test] async fn a_group_past_the_declared_end_aborts_the_track() { use crate::transport::poll::Session as _; @@ -3135,7 +3135,7 @@ mod tests { } /// Object records: `(Skip << 1) | END`, the properties block's length, then the frame. - #[moq_clock::test] + #[kio::test] async fn ietf_records_frame_a_group() { // A plain group: Group State 0, then frame 0 with an empty record. let (res, track, _) = receive_ietf(draft18(None), &[0, 0, 0, 1, u64::from(b'x')]).await; @@ -3155,7 +3155,7 @@ mod tests { } /// A record the Group State does not allow, or bytes past END_OF_GROUP, are refused. - #[moq_clock::test] + #[kio::test] async fn ietf_records_refuse_what_their_group_cannot_hold() { for (body, reason) in [ (&[0x20][..], "an unknown Group State bit"), @@ -3173,7 +3173,7 @@ mod tests { /// A track published over moq-lite has no moq-transport state, so a relayed group on /// one is refused, though its plain groups cross. - #[moq_clock::test] + #[kio::test] async fn ietf_records_need_a_moq_transport_track() { let plain = [0, 0, 0, 1, u64::from(b'x')]; let relayed = [0x1, 0, 0, 1, u64::from(b'x')]; @@ -3187,7 +3187,7 @@ mod tests { /// A relayed group's records carry properties only when its Group State sets EXTENSIONS, /// as the moq-transport subgroup it mirrors could hold none otherwise. - #[moq_clock::test] + #[kio::test] async fn ietf_records_need_extensions_for_properties() { // Object 0 with a draft-18 block holding 0x20 = 1, or an untimed Timestamp. for record in [&[2, 0x20, 1][..], &[2, 0x10, 7]] { @@ -3204,7 +3204,7 @@ mod tests { /// On a timed track, the frame holds an object's time, so a record cannot carry a second, /// mutable Timestamp that could disagree with it. Records that say nothing of time, or /// seal a Timestamp moq-transport egress cannot rewrite, cross beside the frame's. - #[moq_clock::test] + #[kio::test] async fn ietf_records_leave_time_to_their_frame() { let frame = crate::coding::varint::zigzag(500); // Each record after its Object code: Object 0 unless it says otherwise. @@ -3230,7 +3230,7 @@ mod tests { /// A record's properties stay the bytes they arrived as, which the cache charges, rather /// than a decoded list costing many times as much. - #[moq_clock::test] + #[kio::test] async fn ietf_records_hold_properties_at_their_wire_size() { const COUNT: u64 = 1000; // A relayed group's Object 0, whose draft-18 block holds COUNT two-byte properties @@ -3323,7 +3323,7 @@ mod tests { /// Lite-05/06 timestamps may be send times, so a received frame is read past its /// timestamp and lands untimed: nothing rewinds, and the track stays open. - #[moq_clock::test] + #[kio::test] async fn lite06_timestamps_are_dropped() { for version in [Version::Lite05, Version::Lite06] { // Frame 0 at 500ms, before group 4's 1000ms. @@ -3341,7 +3341,7 @@ mod tests { /// Lite-07 timestamps are media time, so a received group is checked like a local /// write and one that rewinds is refused. - #[moq_clock::test] + #[kio::test] async fn a_lite07_rewind_is_refused() { let (res, _track) = receive_group(Version::Lite07, &[500]).await; assert!(matches!(res, Err(Error::TimestampMismatch)), "{res:?}"); @@ -3351,7 +3351,7 @@ mod tests { /// holds one that lite-05/06 could not carry as a group's first frame. lite-06 reaches /// it with a second delta, lite-07 with a first frame its 64-bit varint can encode. /// lite-05/06 drop the timestamp, but a stream carrying one past the bound is still malformed. - #[moq_clock::test] + #[kio::test] async fn a_received_timestamp_past_2_61_is_refused() { let max: i64 = (1 << 61) - 1; for version in [Version::Lite05, Version::Lite06, Version::Lite07] { @@ -3372,7 +3372,7 @@ mod tests { /// An idle copy that resubscribes gets its newest cached group again. That stream only /// duplicates the cache, but lite-07's SUBSCRIBE_END still counts it, so the tail must /// too, or the subscription waits out the grace before it ends. - #[moq_clock::test] + #[kio::test] async fn a_duplicate_group_stream_still_counts_toward_the_end() { use crate::transport::poll::Session as _; @@ -3439,7 +3439,7 @@ mod tests { /// A SUBSCRIBE_END below a group already received contradicts that group. lite-05 /// specified an inclusive end, and `@moq/net` 0.1.3 to 0.1.9 sent one, so there it only /// costs the early boundary; later drafts abort the track. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_end_below_a_received_group() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut responses = Vec::new(); @@ -3583,7 +3583,7 @@ mod tests { /// An answer read only after another instance took the path may be that instance's, /// so the replacement refuses the subscription instead, as does a withdrawal followed /// by a new announcement. - #[moq_clock::test] + #[kio::test] async fn an_answer_read_after_a_replacement_is_refused() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let res = answer_after(version, |selection| selection.replace()).await; @@ -3599,7 +3599,7 @@ mod tests { /// A withdrawal alone leaves the SUBSCRIBE to its answer: the publisher concludes a /// subscription in flight, so a track that finished as its broadcast ended arrives whole. - #[moq_clock::test] + #[kio::test] async fn an_answer_read_after_a_withdrawal_is_kept() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let res = answer_after(version, |selection| selection.withdraw()).await; @@ -3610,7 +3610,7 @@ mod tests { /// Lite-07's SUBSCRIBE_START says where the track is, so a reader knows its largest /// frame before any group arrives. The FIN with no SUBSCRIBE_END then aborts the track, /// and the stream ends with it. - #[moq_clock::test] + #[kio::test] async fn subscribe_start_reports_the_largest() { let version = Version::Lite07; let largest = track::Position { group: 4, frame: 2 }; @@ -3671,7 +3671,7 @@ mod tests { /// A SUBSCRIBE_DROP ends a group still arriving now, with its Error Code on lite-07. /// Earlier versions carry an application code there, so the same bytes read as /// OLD. - #[moq_clock::test] + #[kio::test] async fn a_subscribe_drop_ends_an_arriving_group_with_its_code() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut responses = Vec::new(); @@ -3838,7 +3838,7 @@ mod tests { responses } - #[moq_clock::test] + #[kio::test] async fn bare_fin_requires_subscribe_end() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { for (started, clean) in [(false, false), (true, false), (false, true)] { @@ -3847,7 +3847,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] #[ignore = "requires Bun; run by just test bare-fin in interop CI"] async fn bare_fin_interop() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { @@ -3863,7 +3863,7 @@ mod tests { /// Removing a subscription both stops delivery and releases the session's handle /// on the producer, so the track (its cached groups, its stats subscription) ends /// rather than outliving the subscription it belonged to. - #[moq_clock::test] + #[kio::test] async fn unsubscribe_drops_the_datagram_and_releases_the_producer() { let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let subscriber = Subscriber::new(SubscriberConfig { @@ -3949,7 +3949,7 @@ mod tests { /// A lite-05 subscribe still waiting on TRACK_INFO is not in the subscribe map. /// Dropping that machine must reject the origin request with the session's error. - #[moq_clock::test] + #[kio::test] async fn session_death_rejects_a_track_waiting_for_info() { let subscriber = Subscriber::new(SubscriberConfig { runtime: crate::time::sim(), @@ -3996,7 +3996,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn announce_interest_without_credit_keeps_the_session_alive() { use std::sync::atomic::Ordering; for version in [Version::Lite04, Version::Lite07] { @@ -4019,7 +4019,7 @@ mod tests { let mut driver = SubscriberDriver::new(subscriber, Vec::new(), false); assert!(driver.poll(&kio::Waiter::noop()).is_pending()); assert_eq!(log.request_attempts.load(Ordering::Relaxed), 1, "{version}"); - moq_clock::sleep(std::time::Duration::from_secs(20)).await; + kio::clock::sleep(std::time::Duration::from_secs(20)).await; assert!(driver.poll(&kio::Waiter::noop()).is_pending()); assert_eq!( log.request_attempts.load(Ordering::Relaxed), @@ -4031,7 +4031,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn a_claimed_fetch_waits_only_while_wanted() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { for end in ["credit", "unused", "retired"] { @@ -4088,7 +4088,7 @@ mod tests { /// send, or its peer never answers. /// Otherwise every request a relay's front abandons (a failover, a reader leaving) /// holds a task, a stream, and the track until the peer answers, which may be never. - #[moq_clock::test] + #[kio::test] async fn an_unused_track_stops_waiting_for_info() { // A closed gate holds the TRACK request in its send; an open one sends it to a // peer that never answers. @@ -4184,7 +4184,7 @@ mod tests { /// A listing is a subscribe: it waits for a token that may cover the broadcast before /// syncing its readers or asking the peer, which would refuse it until then. - #[moq_clock::test] + #[kio::test] async fn a_listing_waits_for_its_token() { let auth = crate::auth::Link::new(true); let token = auth.present(bytes::Bytes::from_static(b"new"), false).unwrap(); @@ -4211,7 +4211,7 @@ mod tests { /// An instance retired while its listing waits for a token lists nothing: a TRACKS /// request without an epoch would list its replacement. The source ends with it. - #[moq_clock::test] + #[kio::test] async fn a_listing_of_a_retired_instance_never_reaches_the_wire() { let auth = crate::auth::Link::new(true); let token = auth.present(bytes::Bytes::from_static(b"new"), false).unwrap(); @@ -4232,7 +4232,7 @@ mod tests { /// A listing on the wire but unanswered when another instance takes the path lists /// nothing: the peer may list that instance. - #[moq_clock::test] + #[kio::test] async fn an_unanswered_listing_of_a_replaced_instance_is_refused() { let open = kio::Producer::new(true); let session = SinkSession::gated_bi(open.consume()); @@ -4255,7 +4255,7 @@ mod tests { } /// A listing outside the session's scope is refused before it reaches the wire. - #[moq_clock::test] + #[kio::test] async fn a_listing_outside_the_scope_is_refused() { let auth = crate::auth::Link::new(false); auth.handle().authorize(&crate::auth::Grant::default()); @@ -4271,7 +4271,7 @@ mod tests { /// A narrower scope resets a live listing with UNAUTHORIZED rather than keep listing /// what the session no longer allows, and leaves the session up. - #[moq_clock::test] + #[kio::test] async fn a_narrower_limit_resets_a_listing() { let auth = crate::auth::Link::new(false); let open = kio::Producer::new(true); @@ -4295,7 +4295,7 @@ mod tests { /// A track waiting on an unanswered token ends once nobody wants it, rather than /// holding its task and track until a token that may never be answered. - #[moq_clock::test] + #[kio::test] async fn an_unused_track_stops_waiting_for_auth() { let auth = crate::auth::Link::new(true); let _token = auth.present(bytes::Bytes::from_static(b"new"), false).unwrap(); @@ -4350,7 +4350,7 @@ mod tests { /// free to serve twice, and a late insert loses the race with a publisher that /// serves its first group the instant it reads the request (`recv_group` drops a /// group whose id isn't in the map yet). - #[moq_clock::test] + #[kio::test] async fn establish_sends_one_registered_subscribe() { // Writes park until this opens, so the assertions below run at the exact moment // the request would hit the wire. @@ -4417,7 +4417,7 @@ mod tests { /// A narrower limit landing while the SUBSCRIBE is still opening resets it with /// UNAUTHORIZED, like a live one, and releases its id. - #[moq_clock::test] + #[kio::test] async fn a_narrower_limit_resets_a_subscribe_still_opening() { // Writes park, so the SUBSCRIBE is on an open stream but not yet flushed. let gate = kio::Producer::new(false); @@ -4528,13 +4528,13 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn internal_cancel_without_a_recorded_session_end_is_cancel() { let h = Harness::new(VERSION); assert!(matches!(h.serve.subscriber.end_reason(), Error::Cancel)); } - #[moq_clock::test] + #[kio::test] async fn internal_serve_preserves_an_abort_from_a_live_clone() { for dynamic_first in [true, false] { let h = Harness::new(VERSION); @@ -4556,7 +4556,7 @@ mod tests { /// A session that dies hands a live track back with the session's error, but finishes one /// whose subscription the publisher already ended, as the driver's cleanup does. - #[moq_clock::test] + #[kio::test] async fn internal_session_end_gives_back_live_and_finishes_ended() { use crate::transport::poll::Session as _; for ended in [false, true] { @@ -4610,7 +4610,7 @@ mod tests { /// A publisher that finishes the track stops reading its subscribe stream, so a /// SUBSCRIBE_UPDATE written then fails. The track still ends with the publisher's /// finish; a reset still hands it back with the reset's error. - #[moq_clock::test] + #[kio::test] async fn an_update_the_publisher_stopped_reading_defers_to_its_end() { use crate::transport::poll::{RecvStream as _, SendStream as _, Session as _}; for reset in [false, true] { @@ -4735,7 +4735,7 @@ mod tests { /// An end of group 0 is the empty range: nothing sorts below it. The wire cannot /// say that, and the nearest thing it can say is "through group 0", which would /// deliver the single group the caller excluded. - #[moq_clock::test] + #[kio::test] async fn an_empty_range_opens_no_subscription() { let mut h = Harness::new(Version::Lite06); let mut sub = Sub::None; @@ -4752,7 +4752,7 @@ mod tests { /// Demand collapsing to nothing cancels the upstream rather than sending a bound /// that means the opposite. - #[moq_clock::test] + #[kio::test] async fn an_empty_range_cancels_a_live_subscription() { let mut h = Harness::new(Version::Lite06); let mut sub = Sub::None; @@ -4780,7 +4780,7 @@ mod tests { /// The wire has no encoding for either: an exclusive end at a group head floors to /// the group below it, so group 5 through group 5 would go out as `start_group = 5`, /// `end_group = 4`, an inverted range the publisher happily parks on. - #[moq_clock::test] + #[kio::test] async fn a_nonzero_empty_range_opens_no_subscription() { let mut h = Harness::new(Version::Lite06); let mut sub = Sub::None; @@ -4797,7 +4797,7 @@ mod tests { /// Demand collapsing to an empty range mid-track cancels the upstream, the same way /// it does at the first position. - #[moq_clock::test] + #[kio::test] async fn a_nonzero_empty_range_cancels_a_live_subscription() { let mut h = Harness::new(Version::Lite06); let mut sub = Sub::None; @@ -4823,7 +4823,7 @@ mod tests { /// sent, such as a lost datagram, never arrived: subscribing again would replay the rest /// and repeat for as long as it stays undeliverable. Ranges an update changed are asked /// again, since the FIN may predate the update. - #[moq_clock::test] + #[kio::test] async fn a_covered_fin_short_of_a_lost_group_resubscribes_only_after_an_update() { for updated in [false, true] { let h = Harness::new(Version::Lite07); @@ -4855,7 +4855,7 @@ mod tests { "{updated}: waits out the grace" ); - moq_clock::sleep(Duration::from_secs(120)).await; + kio::clock::sleep(Duration::from_secs(120)).await; let _ = serving.poll(&h.serve, &kio::Waiter::noop()); assert_eq!(serving.covered.is_some(), !updated, "{updated}"); assert_eq!( @@ -4868,7 +4868,7 @@ mod tests { /// Concurrent joins over the refresh ratio send one SUBSCRIBE_UPDATE upstream, a new /// group past the largest sends the next, and every update restates the latest. - #[moq_clock::test] + #[kio::test] async fn refresh_joins_coalesce_upstream() { let h = Harness::new(Version::Lite07); let request = h._broadcast.reserve_track("refresh").unwrap(); @@ -4925,7 +4925,7 @@ mod tests { /// publisher no longer serves, or clamp one it still does), and an update /// that moves back restores it (the publisher declared that range gone and /// sends no replacement START). - #[moq_clock::test] + #[kio::test] async fn buffered_start_applies_iff_demand_matches() { let mut h = Harness::new(Version::Lite05); let mut sub = Sub::None; @@ -4972,7 +4972,7 @@ mod tests { /// that moves the start forward retires the skipped range (the publisher /// stops serving it and no fresh START says so), one that moves it backward /// reopens it, and dropping to the live edge clears it entirely. - #[moq_clock::test] + #[kio::test] async fn updates_move_the_declared_floor_both_ways() { let mut h = Harness::new(Version::Lite05); let mut sub = Sub::None; @@ -5014,7 +5014,7 @@ mod tests { /// an announce id to it: dropping it silently leaves that id pointing at a path /// owned by the earlier announce, and the `ANNOUNCE_END` that follows retires the /// wrong route. - #[moq_clock::test] + #[kio::test] async fn a_double_announce_is_an_error_even_when_reflected() { let assigned = crate::Hop::new(777).unwrap(); let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -5070,7 +5070,7 @@ mod tests { /// A serve pass polls only the routes whose request queue woke. The driver runs a /// pass on every wake, which is once per group the session carries, so polling /// every announced route there made each group cost the whole announce set. - #[moq_clock::test] + #[kio::test] async fn a_request_readies_only_its_route() { let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let mut subscriber = Subscriber::new(SubscriberConfig { @@ -5109,7 +5109,7 @@ mod tests { assert!(announced.ready.is_empty()); let consumer = origin.consume(); - let request = moq_clock::sim::spawn(async move { consumer.request_broadcast("room/7", None).await }); + let request = kio::clock::sim::spawn(async move { consumer.request_broadcast("room/7", None).await }); let ready = kio::wait(|waiter| announced.ready.poll_pop(waiter)).await.unwrap(); assert_eq!(ready.as_str(), "room/7"); @@ -5124,7 +5124,7 @@ mod tests { /// A source minted under a claim goes once nothing holds it: the front that read it /// ended, so the session keeps nothing for the path, and a later request asks the /// route afresh. Withdrawing the claim still closes a source in use at once. - #[moq_clock::test] + #[kio::test] async fn an_unheld_source_is_retired() { let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let mut subscriber = Subscriber::new(SubscriberConfig { @@ -5161,7 +5161,7 @@ mod tests { announced: &mut Announced, ) -> (crate::broadcast::Consumer, SourceServe) { let consumer = origin.consume(); - let request = moq_clock::sim::spawn(async move { consumer.request_broadcast("pool/p", None).await }); + let request = kio::clock::sim::spawn(async move { consumer.request_broadcast("pool/p", None).await }); let ready = kio::wait(|waiter| announced.ready.poll_pop(waiter)).await.unwrap(); announced.ready.try_push(ready).unwrap(); announced.poll_serve(subscriber, &kio::Waiter::noop()); @@ -5176,7 +5176,7 @@ mod tests { // The requester leaves without reading: its front ends, and the source with it. drop(resolved); - moq_clock::timeout( + kio::clock::timeout( std::time::Duration::from_secs(1), kio::wait(|waiter| kio::Task::poll(&mut serve, waiter)), ) @@ -5193,7 +5193,7 @@ mod tests { /// A track read before the minted source's serve machine first runs queues for that /// machine, rather than the front finding no handler and ending the track `NotFound`. - #[moq_clock::test] + #[kio::test] async fn a_track_read_before_its_source_is_served_queues() { let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let mut subscriber = Subscriber::new(SubscriberConfig { @@ -5223,7 +5223,7 @@ mod tests { announced.poll_serve(&subscriber, &kio::Waiter::noop()); let consumer = origin.consume(); - let request = moq_clock::sim::spawn(async move { consumer.request_broadcast("pool/p", None).await }); + let request = kio::clock::sim::spawn(async move { consumer.request_broadcast("pool/p", None).await }); let ready = kio::wait(|waiter| announced.ready.poll_pop(waiter)).await.unwrap(); announced.ready.try_push(ready).unwrap(); announced.poll_serve(&subscriber, &kio::Waiter::noop()); @@ -5232,7 +5232,7 @@ mod tests { // The front asks the source for the track while its serve machine is still queued. let track = resolved.track("video").unwrap(); let _subscribing = track.subscribe(None); - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; let minted = subscriber.sources.try_pop().unwrap().expect("a source was minted"); let mut serve = SourceServe::new(subscriber.clone(), minted); @@ -5248,7 +5248,7 @@ mod tests { /// the path reads as free, a later announce takes it, and the declined one's /// `ANNOUNCE_END` retires that route instead. This walks a reflection: the chain /// already names this session. - #[moq_clock::test] + #[kio::test] async fn every_declined_announce_is_recorded() { let assigned = crate::Hop::new(777).unwrap(); let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -5306,7 +5306,7 @@ mod tests { } /// A dropped announce still holds its path until the peer retracts it. - #[moq_clock::test] + #[kio::test] async fn a_dropped_announce_still_holds_its_path() { let assigned = crate::Hop::new(777).unwrap(); let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -5364,7 +5364,7 @@ mod tests { /// Appending it again would name one identity twice, which is tolerated in a lite /// chain but is a PROTOCOL_VIOLATION for an IETF peer the route is later forwarded /// to, so the route must never enter the model carrying it. - #[moq_clock::test] + #[kio::test] async fn an_announce_reflected_by_its_sender_is_dropped() { let assigned = crate::Hop::new(777).unwrap(); @@ -5401,7 +5401,7 @@ mod tests { .unwrap(); assert!(!accepted, "a chain naming its own sender must not become a route"); - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; assert!(consumer.get_broadcast("room/host").is_none()); } @@ -5409,7 +5409,7 @@ mod tests { /// origin's hop in the chain is a reflection, not a new path. The announce /// is dropped, the local front keeps serving, and the peer's own /// subscription (split-horizon excluded) still reads from it. - #[moq_clock::test] + #[kio::test] async fn a_reflected_announce_does_not_displace_the_local_front() { let relay = crate::Hop::new(1).unwrap(); let origin = origin::Config::new(relay).produce(); @@ -5490,7 +5490,7 @@ mod tests { /// A peer that declares no identity is marked anonymous (hop 0). The assigned /// identity stays on `via` for split-horizon and is never written into the chain. - #[moq_clock::test] + #[kio::test] async fn assigned_peer_hop_attributes_announces() { let session = SinkSession::new(Default::default()); let assigned = crate::Hop::new(777).unwrap(); @@ -5539,7 +5539,7 @@ mod tests { /// Lite03 hop-count placeholders stay 0 and count as anonymous; they are not /// rewritten with the assigned identity. - #[moq_clock::test] + #[kio::test] async fn lite03_placeholders_stay_anonymous() { let assigned = crate::Hop::new(777).unwrap(); let origin = origin::Config::new(crate::Hop::new(1).unwrap()).produce(); @@ -5583,7 +5583,7 @@ mod tests { /// A publisher that names nobody keeps the anonymous mark, and nothing in front of it: /// identity is the epoch's job, so the relay never names the publisher itself. A /// reprice on the same connection keeps it and updates in place. - #[moq_clock::test] + #[kio::test] async fn an_unnamed_publisher_stays_anonymous() { let (mut subscriber, consumer) = restart_subscriber(SinkSession::new(Default::default())); @@ -5601,7 +5601,7 @@ mod tests { .unwrap(); let mut cursor = consumer.announced(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let route = cursor.expect_next_active("room/host").await; let hops: Vec<_> = route.hops.iter().copied().collect(); assert_eq!(hops, vec![crate::Hop::UNKNOWN]); @@ -5617,7 +5617,7 @@ mod tests { &mut announced, ) .unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let route = cursor.expect_next_active("room/host").await; let hops: Vec<_> = route.hops.iter().copied().collect(); assert_eq!(hops, vec![crate::Hop::UNKNOWN]); @@ -5643,7 +5643,7 @@ mod tests { /// A restart re-prices the announced route in place: consumers observe another /// active update with the new metadata rather than a retract-and-announce. - #[moq_clock::test] + #[kio::test] async fn restart_updates_the_route_in_place() { let (mut subscriber, consumer) = restart_subscriber(SinkSession::new(Default::default())); @@ -5662,7 +5662,7 @@ mod tests { .unwrap(); let mut cursor = consumer.announced(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; cursor.expect_next_active("room/host").await; subscriber @@ -5676,14 +5676,14 @@ mod tests { ) .unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; let route = cursor.expect_next_active("room/host").await; assert_eq!(route.cost, crate::origin::Cost::new(5).charged(0)); } /// A restart is held to the subscribe limit like a start: one the limit no longer /// covers is withheld, ending the old instance rather than attaching the new one. - #[moq_clock::test] + #[kio::test] async fn a_restart_outside_the_limit_is_withheld() { let (mut subscriber, consumer) = restart_subscriber(SinkSession::new(Default::default())); let auth = subscriber.auth.clone(); @@ -5731,7 +5731,7 @@ mod tests { /// This falls out of `Announced` being a local whose announcements drop, /// which is exactly what makes it worth pinning: a refactor that hoisted the map /// to the session (outliving the stream) would leak the announcement instead. - #[moq_clock::test] + #[kio::test] async fn a_lost_announce_stream_retracts_the_route() { let origin = crate::origin::Config::new(crate::Hop::new(1).unwrap()).produce(); let consumer = origin.consume(); @@ -5792,7 +5792,7 @@ mod tests { /// An unknown announce type between two starts is skipped without ending the /// stream. - #[moq_clock::test] + #[kio::test] async fn an_unknown_announce_type_keeps_the_stream() { const VERSION: Version = Version::Lite06; let start = |suffix| lite::AnnounceBroadcast::Active { @@ -5910,7 +5910,7 @@ mod tests { } /// The origin's consumers sync once the counted starts are in and read, never before. - #[moq_clock::test] + #[kio::test] async fn a_counted_initial_set_catches_up() { const VERSION: Version = Version::Lite06; let script = announce_script( @@ -5940,7 +5940,7 @@ mod tests { } /// Part of a counted set is not synced, however much of it was read. - #[moq_clock::test] + #[kio::test] async fn a_partial_initial_set_holds() { const VERSION: Version = Version::Lite06; let script = announce_script(VERSION, &[&announce_ok(VERSION, 2), &announce_start(VERSION, "a")]); @@ -5954,7 +5954,7 @@ mod tests { } /// An empty lite-07 set waits for the ordered SYNCED event. - #[moq_clock::test] + #[kio::test] async fn an_empty_initial_set_catches_up_at_once() { const VERSION: Version = Version::Lite07; let synced = |w: &mut crate::coding::Encoder<'_>| lite::AnnounceBroadcast::Synced.encode(w, VERSION).unwrap(); @@ -5968,7 +5968,7 @@ mod tests { /// A complete body cannot be repaired by bytes from the next announcement. /// Keep the peer stream open: FIN must not be what discovers the malformed body. - #[moq_clock::test] + #[kio::test] async fn malformed_complete_announce_closes_before_more_bytes() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut script = announce_script(version, &[&announce_ok(version, 1)]); @@ -5989,7 +5989,7 @@ mod tests { } /// Only an incomplete outer frame waits, then resumes on its missing byte. - #[moq_clock::test] + #[kio::test] async fn an_incomplete_announce_waits_for_its_body() { for version in [Version::Lite05, Version::Lite06, Version::Lite07] { let mut script = announce_script(version, &[&announce_ok(version, 1), &announce_start(version, "room")]); @@ -6007,7 +6007,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn a_duplicate_synced_is_refused() { const VERSION: Version = Version::Lite07; let synced = |w: &mut crate::coding::Encoder<'_>| lite::AnnounceBroadcast::Synced.encode(w, VERSION).unwrap(); @@ -6018,7 +6018,7 @@ mod tests { } /// Anything but a start inside the counted set cuts it short: a protocol violation. - #[moq_clock::test] + #[kio::test] async fn an_end_inside_the_initial_set_is_refused() { const VERSION: Version = Version::Lite06; let end = @@ -6033,7 +6033,7 @@ mod tests { } /// The stream ending inside the counted set cuts it short too. - #[moq_clock::test] + #[kio::test] async fn a_fin_inside_the_initial_set_is_refused() { const VERSION: Version = Version::Lite06; let script = announce_script(VERSION, &[&announce_ok(VERSION, 2), &announce_start(VERSION, "a")]); @@ -6045,7 +6045,7 @@ mod tests { } /// Lite03/04 mark no initial set: synced, best effort, once the request is sent. - #[moq_clock::test] + #[kio::test] async fn an_unmarked_version_catches_up_on_the_request() { const VERSION: Version = Version::Lite04; let (mut prefix, consumer) = @@ -6058,7 +6058,7 @@ mod tests { } /// Lite01/02 mark the initial set with ANNOUNCE_INIT. - #[moq_clock::test] + #[kio::test] async fn announce_init_is_the_initial_set() { const VERSION: Version = Version::Lite02; let init = |w: &mut crate::coding::Encoder<'_>| { @@ -6082,7 +6082,7 @@ mod tests { /// An announce past the session's cap fails the session with TOO_MANY_REQUESTS, and /// the stream gives its slots back once the session drops it. - #[moq_clock::test] + #[kio::test] async fn announces_past_the_cap_close_the_session() { const VERSION: Version = Version::Lite06; let start = |suffix| lite::AnnounceBroadcast::Active { @@ -6138,7 +6138,7 @@ mod tests { } /// Distinct live GROUP starts are copies of the same group, including while /// readers retain every earlier tail. Exercise the real header/ingest path. - #[moq_clock::test] + #[kio::test] async fn live_group_tails_share_content_held_by_earlier_readers() { use crate::transport::poll::Session as _; let version = Version::Lite07; diff --git a/rs/moq-net/src/model/bandwidth.rs b/rs/moq-net/src/model/bandwidth.rs index ecafcde5693..90ac6a76d4d 100644 --- a/rs/moq-net/src/model/bandwidth.rs +++ b/rs/moq-net/src/model/bandwidth.rs @@ -897,7 +897,7 @@ mod tests { /// The headline case: two encoders on one connection must not each target the /// whole estimate. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn concurrent_tracks_split_the_estimate() { let estimate = Producer::new(); @@ -950,7 +950,7 @@ mod tests { /// Demand transitions have to wake a parked share, not just change what a later /// `peek` would see; the encoder is sitting in a `select!` on `changed`. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_share_wakes_when_a_sibling_goes_idle() { let estimate = Producer::new(); @@ -1011,7 +1011,7 @@ mod tests { /// waker armed. Reservations cap the slice, so most estimate changes don't reach /// it, and a poll that returned the value without arming anything would park the /// encoder with nothing left to wake it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_unchanged_slice_keeps_watching_the_estimate() { let estimate = Producer::new(); @@ -1038,7 +1038,7 @@ mod tests { } /// The same, for the other input: a sibling's demand. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_parked_share_is_woken_by_sibling_demand() { let estimate = Producer::new(); @@ -1064,7 +1064,7 @@ mod tests { /// A share follows the estimate's own lifecycle: unavailable while disconnected /// (hold the current rate), terminal once the session is gone for good. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_share_follows_the_estimate_lifecycle() { let estimate = Producer::new(); @@ -1108,7 +1108,7 @@ mod tests { /// Dropping the reservation hands the room back. The registry only ever prunes /// tracks that have *closed*, so a claim left behind by a track that is still /// publishing would stand for the rest of the connection. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dropping_a_reservation_releases_it() { let estimate = Producer::new(); @@ -1210,7 +1210,7 @@ mod tests { /// A reader parked on `changed` has to be woken by its own reservation moving, not /// just by the estimate or a sibling: the encoder is sitting in a `select!` on it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn update_wakes_a_parked_reader() { let estimate = Producer::new(); @@ -1233,7 +1233,7 @@ mod tests { /// The registry is the allocator's, not a share's: a share that outlives every /// allocator reports the estimate as gone rather than keeping the channel open. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_share_outliving_the_allocator_reports_closed() { let estimate = Producer::new(); @@ -1253,7 +1253,7 @@ mod tests { /// holds its rate for the former and stops watching for the latter. /// Reporting closure as `Ok(None)` would spin any `select!` over `changed()`, /// because a closed channel is always immediately ready. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn closed_is_distinct_from_unavailable() { let producer = Producer::new(); diff --git a/rs/moq-net/src/model/broadcast.rs b/rs/moq-net/src/model/broadcast.rs index 123d8f294c3..c1a315fa7cf 100644 --- a/rs/moq-net/src/model/broadcast.rs +++ b/rs/moq-net/src/model/broadcast.rs @@ -1338,7 +1338,7 @@ mod test { }}; } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn insert() { let mut producer = Info::new().produce(); @@ -1364,7 +1364,7 @@ mod test { track2_consumer.assert_group(); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn closed() { let mut producer = Info::new().produce(); @@ -1393,7 +1393,7 @@ mod test { } /// `close()` ends the broadcast for every clone at once, and a second close is a no-op. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn close_ends_every_clone() { let producer = Info::new().produce(); @@ -1410,7 +1410,7 @@ mod test { } /// Dropping the last producer ends the broadcast exactly like `close()`. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn drop_ends_like_close() { let producer = Info::new().produce(); @@ -1420,7 +1420,7 @@ mod test { assert!(matches!(consumer.track("video"), Err(Error::Unroutable))); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn requests() { let mut producer = Info::new().produce().requests(); @@ -1461,7 +1461,7 @@ mod test { assert!(track5.is_err(), "should have errored"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn stale_producer() { let mut broadcast = Info::new().produce().requests(); @@ -1550,7 +1550,7 @@ mod test { assert!(state.tracks.len() < 16, "{} names retained", state.tracks.len()); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn requested_unused() { let mut broadcast = Info::new().produce().requests(); @@ -1604,7 +1604,7 @@ mod test { /// ever sees the (now-taken) name. Without this the requester is stranded: /// the name exists the moment the track does, so the queue entry could /// never be served under it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn create_track_fulfills_queued_request() { let producer = Info::new().produce(); @@ -1678,7 +1678,7 @@ mod test { /// end. Ending the broadcast is where it does: `Consumer::track` answers /// `Unroutable` for a name asked about after this point, so whoever asked earlier gets /// the same answer instead of waiting on info that can never arrive. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn close_resolves_a_reserved_name() { let producer = Info::new().produce(); @@ -1693,7 +1693,7 @@ mod test { /// A request still queued for a handler is the same parking case reached from the /// consumer side, so it ends the same way. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn close_resolves_a_queued_request() { let producer = Info::new().produce(); @@ -1709,7 +1709,7 @@ mod test { /// A queued request answers the same when the broadcast ends by its last handle /// dropping, even when that handle is the `Requests` that would have served it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dropping_the_last_handle_resolves_a_queued_request() { let dynamic = Info::new().produce().requests(); @@ -1724,7 +1724,7 @@ mod test { /// A source that no longer names the instance that minted it takes no new track, even /// from a handler that checks nothing: its request stream ends and every later request /// answers `Unroutable`, while the track it accepted earlier runs on. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_lapsed_source_refuses_new_tracks() { let route = kio::Producer::new(()); @@ -1750,7 +1750,7 @@ mod test { /// With a producer still alive, losing the last handler is not the broadcast ending: /// the queued request fails as `Dropped`. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dropping_the_last_handler_resolves_a_queued_request_dropped() { let producer = Info::new().produce(); @@ -1767,7 +1767,7 @@ mod test { /// A request a handler already took is the handler's to answer: it may be in flight /// to a peer, and a retraction does not disturb subscriptions already in flight. /// Whatever the handler decides still reaches the consumer. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn close_leaves_a_claimed_request_to_its_handler() { let producer = Info::new().produce(); @@ -1800,7 +1800,7 @@ mod test { /// accepted, but it does not create a live publisher. Closing the broadcast /// must still reject that name so an arrival-order subscriber does not park on /// backfill that is deliberately absent from its queue. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn close_resolves_an_unaccepted_track_with_fetched_info() { let producer = Info::new().produce(); @@ -1825,7 +1825,7 @@ mod test { /// A staged track resolves no subscriber until it commits, and then with what was /// written meanwhile. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_staged_track_resolves_subscribers_at_commit() { let producer = Info::new().produce(); @@ -1836,7 +1836,7 @@ mod test { let mut staged = request.stage(crate::track::Info::timed()); staged.write_frame(crate::Timestamp::ZERO, b"x".as_slice()).unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; assert!(futures::poll!(subscribing.as_mut()).is_pending(), "still staged"); let _track = staged.commit(); @@ -1846,7 +1846,7 @@ mod test { /// Dropping a staged track uncommitted rejects the request, so its subscribers fail /// rather than wait on a track nobody will publish. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dropping_a_staged_track_rejects_the_request() { let producer = Info::new().produce(); @@ -1862,7 +1862,7 @@ mod test { /// Dropping a staged track uncommitted aborts a group still being written through it, so /// its writer fails rather than fill a track nobody will read. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dropping_a_staged_track_aborts_its_open_groups() { let producer = Info::new().produce(); @@ -1876,7 +1876,7 @@ mod test { /// Ending the broadcast doesn't cascade into a track someone is publishing: it keeps /// its cache and its publisher decides when it ends. Only a new lookup is refused. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn close_spares_a_served_track() { let producer = Info::new().produce(); @@ -1896,7 +1896,7 @@ mod test { /// The publisher may still be holding the `track::Request` for a name the broadcast /// just gave up on. Accepting it afterwards must not resurrect the track, or a /// subscriber that was told `Unroutable` could be contradicted by a later one. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn close_leaves_a_stale_reservation_inert() { let producer = Info::new().produce(); @@ -1918,7 +1918,7 @@ mod test { /// Dropping a `track::Request` is not a verdict about the name, so it resolves as /// `Dropped` (a handler lost to a crashed publisher or a dead transport), never as /// `NotFound`. Only an explicit rejection may claim the track is absent. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dropping_a_reserved_request_resolves_dropped() { let producer = Info::new().produce(); @@ -1934,7 +1934,7 @@ mod test { /// `track::Request::reject` carries its reason the same way, which is what lets a /// subscriber tell "no such track" from "the publisher went away". - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn rejecting_a_reserved_request_carries_the_reason() { let producer = Info::new().produce(); @@ -1953,7 +1953,7 @@ mod test { /// teardown commits. The returning viewer keeps the track alive, and once it /// really does commit the cached handle is reclaimed rather than handed out /// cancelled. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_idle_teardown_yields_to_a_returning_viewer() { let producer = Info::new().produce(); diff --git a/rs/moq-net/src/model/cache.rs b/rs/moq-net/src/model/cache.rs index 6de5651f370..172926d9bf5 100644 --- a/rs/moq-net/src/model/cache.rs +++ b/rs/moq-net/src/model/cache.rs @@ -1409,17 +1409,17 @@ mod test { /// Wall time can lead a lagging driver's sample, while another driver can supply /// future time. Neither a new driver nor a backward sample may rewind expiration. - #[moq_clock::test] + #[kio::test] async fn wall_deadlines_use_the_later_of_ambient_and_driven_time() { let pool = Pool::unbounded(); - let now = moq_clock::now(); + let now = kio::clock::now(); let waiter = kio::Waiter::noop(); pool.poll(now, &waiter); let track = Track::new(pool.clone(), Default::default(), kio::Weak::new()); let (read, reading) = flag(); let at = now + Duration::from_secs(1); track.watch_wall(at, &reading); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!(pool.poll(now, &waiter), None); assert!(read.0.swap(false, Ordering::SeqCst), "ambient time was ignored"); diff --git a/rs/moq-net/src/model/clock.rs b/rs/moq-net/src/model/clock.rs index 4545f5ac68d..d11604e0f66 100644 --- a/rs/moq-net/src/model/clock.rs +++ b/rs/moq-net/src/model/clock.rs @@ -15,7 +15,7 @@ use rand::RngExt; /// The current instant on the model's clock. pub(super) fn now() -> crate::time::Instant { - moq_clock::now() + kio::clock::now() } /// The instant a cache judges wall-clock staleness by, before the time its drivers @@ -25,23 +25,23 @@ pub(super) fn now() -> crate::time::Instant { /// staleness along with the drivers it supplies time to. #[cfg(not(any(test, loom)))] pub(super) fn wall() -> crate::time::Instant { - moq_clock::now() + kio::clock::now() } /// Loom permutes handoffs without advancing time, so scheduling cannot age groups. #[cfg(all(loom, not(test)))] pub(super) fn wall() -> crate::time::Instant { - static FROZEN: LazyLock = LazyLock::new(moq_clock::now); + static FROZEN: LazyLock = LazyLock::new(kio::clock::now); *FROZEN } /// Unit tests freeze the wall clock, so only time a test supplies moves it: the -/// simulated clock inside `moq_clock::sim`, or a pool stepped by hand outside it. +/// simulated clock inside `kio::clock::sim`, or a pool stepped by hand outside it. #[cfg(test)] pub(super) fn wall() -> crate::time::Instant { - static FROZEN: LazyLock = LazyLock::new(moq_clock::now); - match moq_clock::sim::is_running() { - true => moq_clock::now(), + static FROZEN: LazyLock = LazyLock::new(kio::clock::now); + match kio::clock::sim::is_running() { + true => kio::clock::now(), false => *FROZEN, } } @@ -54,9 +54,9 @@ pub(super) fn wall() -> crate::time::Instant { /// deters using it as a wall clock and catches implementations that assume /// unrelated broadcasts are synchronized. pub(super) fn anchor() -> (crate::time::Instant, Duration) { - static ANCHORS: LazyLock>> = + static ANCHORS: LazyLock>> = LazyLock::new(Default::default); - let (instant, wall) = moq_clock::origin(); + let (instant, wall) = kio::clock::origin(); let mut anchors = ANCHORS.lock().unwrap(); let offset = *anchors.entry((instant, wall)).or_insert_with(|| { let jitter = Duration::from_millis(rand::rng().random_range(1..69_420)); @@ -70,9 +70,9 @@ pub(super) fn anchor() -> (crate::time::Instant, Duration) { /// Counting from 50 years after the Unix epoch keeps the value ~1.5e12 ms smaller, /// trimming a byte or two off the first frame's varint. Saturates to zero on a wall /// clock set before 2020 (an unsynced clock), since only a non-negative start matters. -fn offset(wall: moq_clock::Wall, jitter: Duration) -> Duration { +fn offset(wall: kio::clock::Wall, jitter: Duration) -> Duration { const EPOCH: Duration = Duration::from_secs(1_577_836_800); - wall.saturating_duration_since(moq_clock::Wall::UNIX_EPOCH) + wall.saturating_duration_since(kio::clock::Wall::UNIX_EPOCH) .saturating_sub(EPOCH) .saturating_sub(jitter) } @@ -86,7 +86,7 @@ mod tests { #[test] fn unit_tests_freeze_the_cache_clock() { let frozen = wall(); - while moq_clock::now() <= frozen { + while kio::clock::now() <= frozen { std::hint::spin_loop(); } assert_eq!(wall(), frozen); @@ -94,11 +94,11 @@ mod tests { #[test] fn each_ambient_clock_owns_its_wall_anchor() { - let first = moq_clock::sim::run(async { anchor() }); - let second = moq_clock::sim::run(async { - moq_clock::sim::step_wall(moq_clock::Manual::WALL_START + Duration::from_secs(86_400)); + let first = kio::clock::sim::run(async { anchor() }); + let second = kio::clock::sim::run(async { + kio::clock::sim::step_wall(kio::clock::Manual::WALL_START + Duration::from_secs(86_400)); let before = anchor(); - moq_clock::sim::step_wall(moq_clock::Manual::WALL_START - Duration::from_secs(86_400)); + kio::clock::sim::step_wall(kio::clock::Manual::WALL_START - Duration::from_secs(86_400)); assert_eq!( anchor(), before, diff --git a/rs/moq-net/src/model/follow.rs b/rs/moq-net/src/model/follow.rs index 43763970379..6287bb3fccc 100644 --- a/rs/moq-net/src/model/follow.rs +++ b/rs/moq-net/src/model/follow.rs @@ -305,7 +305,7 @@ mod tests { /// The follower's next event, which must arrive within the origin's update hold. async fn followed(follow: &mut Follow) -> (&'static str, String) { - let event = moq_clock::timeout(Duration::from_secs(1), follow.next()) + let event = kio::clock::timeout(Duration::from_secs(1), follow.next()) .await .expect("no event") .expect("the origin closed"); @@ -319,7 +319,7 @@ mod tests { /// The follower stays quiet past the origin's update hold. async fn quiet(follow: &mut Follow) { - if let Ok(event) = moq_clock::timeout(Duration::from_secs(1), follow.next()).await { + if let Ok(event) = kio::clock::timeout(Duration::from_secs(1), follow.next()).await { panic!("expected nothing, got {event:?}"); } } @@ -328,7 +328,7 @@ mod tests { Route::default().with_epoch(epoch.clone()) } - #[moq_clock::test] + #[kio::test] async fn follow_reports_the_route_serving_the_path() { let origin = Hop::new(1).unwrap().produce(); let mut follow = origin.consume().follow("pool/job").unwrap(); @@ -367,7 +367,7 @@ mod tests { /// A follower that joins late starts on the route serving the path, not on whichever /// covering route the replay happened to reach first. - #[moq_clock::test] + #[kio::test] async fn follow_starts_on_the_serving_route_when_joining_late() { let origin = Hop::new(1).unwrap().produce(); let _pool = origin.requests_route("pool", Route::default()).unwrap(); @@ -380,7 +380,7 @@ mod tests { /// A gap with nothing serving the path ends any request on it, so a covering route that /// arrives after it is a start of its own, even under the same epoch. - #[moq_clock::test] + #[kio::test] async fn follow_keeps_a_gap_between_routes_of_one_epoch() { let origin = Hop::new(1).unwrap().produce(); let epoch = Epoch::mint(); @@ -404,7 +404,7 @@ mod tests { /// A prefix that started before the serving route's last change stood before the route's /// end, so it takes over in place even when the cursor never ran dry in between. - #[moq_clock::test] + #[kio::test] async fn follow_hands_over_to_a_prefix_that_started_before_the_last_change() { let origin = Hop::new(1).unwrap().produce(); let exact = origin.publish("pool/job", route(&Epoch::mint())).unwrap(); @@ -421,7 +421,7 @@ mod tests { } /// Without an epoch nothing says two routes serve the same bytes. - #[moq_clock::test] + #[kio::test] async fn follow_restarts_onto_a_more_specific_route_without_an_epoch() { let origin = Hop::new(1).unwrap().produce(); let mut follow = origin.consume().follow("pool/job").unwrap(); @@ -435,7 +435,7 @@ mod tests { /// A route whose claim covers only paths beneath the followed one never serves it, so it /// cannot mask the route that does, even when it would win the prefix on cost. - #[moq_clock::test] + #[kio::test] async fn follow_ignores_a_route_scoped_beneath_the_path() { let origin = Hop::new(1).unwrap().produce(); let chat = Patterns::from("room/*/chat".parse::().unwrap()); @@ -447,7 +447,7 @@ mod tests { let mut follow = origin.consume().follow("room/alice").unwrap(); let first = origin.publish("room/alice", Route::default().with_cost(5)).unwrap(); - let event = moq_clock::timeout(Duration::from_secs(1), follow.next()) + let event = kio::clock::timeout(Duration::from_secs(1), follow.next()) .await .unwrap() .unwrap(); @@ -459,7 +459,7 @@ mod tests { // A republish is another instance of the route that serves the path. let _second = origin.publish("room/alice", Route::default().with_cost(5)).unwrap(); drop(first); - let event = moq_clock::timeout(Duration::from_secs(1), follow.next()) + let event = kio::clock::timeout(Duration::from_secs(1), follow.next()) .await .unwrap() .unwrap(); @@ -471,7 +471,7 @@ mod tests { /// The next instance handed out, which must arrive within the origin's update hold. async fn available(announced: &mut AnnouncedBroadcast) -> broadcast::Consumer { - moq_clock::timeout(Duration::from_secs(1), announced.available()) + kio::clock::timeout(Duration::from_secs(1), announced.available()) .await .expect("no instance") .expect("the wait failed") @@ -480,7 +480,7 @@ mod tests { /// Nothing more is handed out past the origin's update hold. async fn none(announced: &mut AnnouncedBroadcast) { let hold = super::super::origin_impl::DEFAULT_UPDATE_HOLD * 2; - if let Ok(result) = moq_clock::timeout(hold, announced.available()).await { + if let Ok(result) = kio::clock::timeout(hold, announced.available()).await { panic!( "expected nothing, got {:?}", result.map(|broadcast| broadcast.info().epoch.clone()) @@ -490,7 +490,7 @@ mod tests { /// The next request a dynamic route receives for its path. async fn requested(dynamic: &crate::origin::Requests) -> crate::origin::Request { - moq_clock::timeout(Duration::from_secs(1), dynamic.requested_broadcast()) + kio::clock::timeout(Duration::from_secs(1), dynamic.requested_broadcast()) .await .expect("never asked") .expect("the route closed") @@ -498,7 +498,7 @@ mod tests { /// Another instance taking over while a wait resolves is the one it hands out, so the /// restart the origin holds for it must not hand it out again while the caller holds it. - #[moq_clock::test] + #[kio::test] async fn announced_hands_out_a_held_takeover_once() { let origin = Hop::new(1).unwrap().produce(); let dynamic = origin.requests("live").unwrap(); @@ -514,7 +514,7 @@ mod tests { /// The follower holds what it handed out weakly: a takeover the caller let go of retires, /// and the restart the origin held for it hands out a fresh front. - #[moq_clock::test] + #[kio::test] async fn announced_hands_out_a_dropped_takeover_again() { let origin = Hop::new(1).unwrap().produce(); let dynamic = origin.requests("live").unwrap(); @@ -534,7 +534,7 @@ mod tests { /// The route a wait resolves through leaving, and another instance arriving before it /// resolves, reach the follower as an end and a start alongside the answer. That start must /// not hand the newcomer out again. - #[moq_clock::test] + #[kio::test] async fn announced_hands_out_a_gap_while_resolving_once() { let origin = Hop::new(1).unwrap().produce(); let dynamic = origin.requests("").unwrap(); @@ -543,7 +543,7 @@ mod tests { let (_arrival, _publish) = futures::join!(available(&mut announced), async { let _unanswered = requested(&dynamic).await; drop(dynamic); - moq_clock::sleep(super::super::origin_impl::DEFAULT_UPDATE_HOLD * 2).await; + kio::clock::sleep(super::super::origin_impl::DEFAULT_UPDATE_HOLD * 2).await; origin.publish("live", Route::default()).unwrap() }); none(&mut announced).await; @@ -552,7 +552,7 @@ mod tests { /// An end is a gap that ended every request on the old route, even when a route above the /// path with the same epoch carries the instance on. So the instance serving the path /// afterwards is handed out again, though it is the one the caller still holds. - #[moq_clock::test] + #[kio::test] async fn announced_hands_out_the_instance_again_after_an_end() { let origin = Hop::new(1).unwrap().produce(); let epoch = Epoch::mint(); @@ -571,7 +571,7 @@ mod tests { /// An announced request that pins an epoch refuses another instance taking over instead of /// following it. - #[moq_clock::test] + #[kio::test] async fn announced_pinned_refuses_another_instance() { let origin = Hop::new(1).unwrap().produce(); let epoch = Epoch::mint(); diff --git a/rs/moq-net/src/model/group.rs b/rs/moq-net/src/model/group.rs index aaaa927dec5..067b673630d 100644 --- a/rs/moq-net/src/model/group.rs +++ b/rs/moq-net/src/model/group.rs @@ -4913,7 +4913,7 @@ mod test { /// a write guard was mutably accessed, so `frame_notify` must mark the guard /// modified; a guard dropped untouched wakes nobody and the reader would /// stall until the frame completed. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn chunk_write_wakes_parked_reader() { let producer = Info { sequence: 0 }.produce(); @@ -4925,11 +4925,11 @@ mod test { }) .unwrap(); let mut f = consumer.next_frame().await.unwrap().unwrap(); - let handle = moq_clock::sim::spawn(async move { f.read_chunk().await }); + let handle = kio::clock::sim::spawn(async move { f.read_chunk().await }); // Let the reader park on the empty partial before the chunk lands. - moq_clock::sleep(std::time::Duration::from_millis(50)).await; + kio::clock::sleep(std::time::Duration::from_millis(50)).await; frame.write(Bytes::from_static(b"foo")).unwrap(); - let chunk = moq_clock::timeout(std::time::Duration::from_secs(2), handle) + let chunk = kio::clock::timeout(std::time::Duration::from_secs(2), handle) .await .expect("parked chunk reader was never woken by the chunk write") .unwrap() @@ -4939,16 +4939,16 @@ mod test { /// Each frame is stamped when its last byte lands, whichever way it is written, and /// readers see that stamp however late they read. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn frames_carry_when_they_landed() { use std::time::Duration; - let start = moq_clock::now(); + let start = kio::clock::now(); let mut producer = Info { sequence: 0 }.produce(); producer.write_frame(Timestamp::ZERO, Bytes::from_static(b"a")).unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let mut chunked = producer .create_frame(frame::Info { size: 2, @@ -4956,23 +4956,23 @@ mod test { }) .unwrap(); chunked.write(Bytes::from_static(b"b")).unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; chunked.write(Bytes::from_static(b"c")).unwrap(); producer = chunked.finish().unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; let mut batch = frame::Buffer::<2>::new(); batch .push(Frame::new(Timestamp::ZERO, Bytes::from_static(b"d"))) .unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; batch .push(Frame::new(Timestamp::ZERO, Bytes::from_static(b"e"))) .unwrap(); producer.write_frames(&mut batch).unwrap(); producer.finish().unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let mut consumer = producer.consume(); let mut arrived = Vec::new(); while let Some(frame) = consumer.read_frame().await.unwrap() { diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index c86e983a276..399feec33ba 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -7258,8 +7258,8 @@ impl ProduceTest for Config { let self_ = self; let (producer, driver) = Producer::new(self_); #[cfg(feature = "async")] - if moq_clock::sim::is_running() { - moq_clock::sim::spawn(crate::time::run(driver)); + if kio::clock::sim::is_running() { + kio::clock::sim::spawn(crate::time::run(driver)); return producer; } { @@ -7375,7 +7375,7 @@ mod tests { /// Ending a logical track must finish its metadata producer as well as its routes, /// without losing the source's final group or warning about an unfinished writer. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_finished_logical_track_does_not_warn() { let warns = count_drop_warnings("track::Producer dropped without finish", || { @@ -7418,7 +7418,7 @@ mod tests { assert_eq!(warns, 0, "a clean logical end must not drop an unfinished producer"); } - #[moq_clock::test] + #[kio::test] async fn default_config_mints_a_real_hop() { let config = Config::default(); assert_ne!(config.hop, Hop::UNKNOWN); @@ -7427,7 +7427,7 @@ mod tests { assert_eq!(producer.consume().hop(), config.hop); } - #[moq_clock::test] + #[kio::test] async fn random_hops_fit_legacy_lite_clients() { for _ in 0..32 { assert!(Hop::random().id() < 1u64 << 53); @@ -7442,7 +7442,7 @@ mod tests { if check() { return; } - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } panic!("condition never settled"); } @@ -7477,7 +7477,7 @@ mod tests { next.unwrap() } - #[moq_clock::test] + #[kio::test] async fn announce_and_retract() { let producer = origin(1).produce(); let consumer = producer.consume(); @@ -7707,7 +7707,7 @@ mod tests { /// A `.`-prefixed segment below the requested prefix hides a route from /// discovery unless the reader opts in; one inside the prefix does not. - #[moq_clock::test] + #[kio::test] async fn hidden_routes_need_an_opt_in() { let producer = origin(1).produce(); let consumer = producer.consume(); @@ -7742,7 +7742,7 @@ mod tests { } /// Hiding narrows discovery only: an exact request resolves without an opt-in. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn hidden_broadcast_resolves_by_path() { let producer = origin(1).produce(); @@ -7757,7 +7757,7 @@ mod tests { /// An excluded subtree is neither discovered nor resolved, even under a route /// covering it, while its hidden siblings and the covering route still show. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn exclude_hides_and_refuses_the_subtree() { let producer = origin(1).produce(); @@ -7797,7 +7797,7 @@ mod tests { /// An exclusion inside a mount carves the target, and one over the mount point /// drops the mount. - #[moq_clock::test] + #[kio::test] async fn exclude_reaches_into_a_mount() { let producer = origin(1).produce(); let _foo = producer.publish(".svc/p1/foo", Route::default()).unwrap(); @@ -7838,7 +7838,7 @@ mod tests { /// A request through a mount is a request for the target path: it joins the /// one front there, so the fleet-wide claim is asked once for both readers. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn mount_resolves_on_the_target_front() { let producer = origin(1).produce(); @@ -7863,7 +7863,7 @@ mod tests { /// Routes under the target, and the claim covering it, present under the /// mount; what the origin holds at the mounted path itself does not. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn mount_presents_target_routes_under_the_mount() { let producer = origin(1).produce(); @@ -7906,7 +7906,7 @@ mod tests { /// The handle's own patterns authorize a path through the mount, named as the /// handle names it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn mount_authorizes_the_named_path() { let producer = origin(1).produce(); @@ -7941,7 +7941,7 @@ mod tests { /// A wildcard spanning the mount point captures the path as the handle names /// it, so capture-keyed consumers key a mounted route like any other. - #[moq_clock::test] + #[kio::test] async fn mount_captures_the_named_path() { let producer = origin(1).produce(); let _foo = producer.publish(".svc/p1/foo", Route::default()).unwrap(); @@ -7963,7 +7963,7 @@ mod tests { /// A target at the maximum depth still presents its exact path: the `**` a /// wildcard scope carries past it can only match nothing there. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn mount_keeps_a_max_depth_target() { let producer = origin(1).produce(); @@ -7990,7 +7990,7 @@ mod tests { /// A mount point deeper than its target never presents a route whose name /// through the mount is past the depth limit, and a mount point past it is refused. - #[moq_clock::test] + #[kio::test] async fn mount_bounds_the_named_path() { let producer = origin(1).produce(); let _near = producer.publish("t/x", Route::default()).unwrap(); @@ -8015,7 +8015,7 @@ mod tests { } /// Nothing is published at or beneath a mount. - #[moq_clock::test] + #[kio::test] async fn mount_is_read_only() { let producer = origin(1).produce(); let project = producer @@ -8036,7 +8036,7 @@ mod tests { } /// A mount reaches only what the handle already reaches, and mounts never nest. - #[moq_clock::test] + #[kio::test] async fn mount_never_widens_a_scope() { let (producer, _driver) = Producer::new(Config::new(origin(1))); let project = producer.scope("", &scopes(&["p1"])).unwrap(); @@ -8064,7 +8064,7 @@ mod tests { } /// A mount point no pattern can spell could never be announced or authorized. - #[moq_clock::test] + #[kio::test] async fn mount_refuses_a_wildcard_mount_point() { let (producer, _driver) = Producer::new(Config::new(origin(1))); for at in ["*", "p1/*", "p1/**", "p1/a*"] { @@ -8077,7 +8077,7 @@ mod tests { /// Egress through a mount counts under the path the reader named, so it /// attributes to the reader's root rather than the fleet-wide target. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn mount_egress_counts_under_the_named_path() { let registry = stats::Registry::new(stats::Config::new()); @@ -8106,7 +8106,7 @@ mod tests { } /// A route that turns up later is filtered the same way as the replay. - #[moq_clock::test] + #[kio::test] async fn hidden_route_announced_later_stays_hidden() { let producer = origin(1).produce(); let consumer = producer.consume(); @@ -8122,7 +8122,7 @@ mod tests { opted.expect_next_ended(".stats/node").await; } - #[moq_clock::test] + #[kio::test] async fn a_replayed_route_retracted_before_delivery_cancels() { let producer = origin(1).produce(); let alice = producer.announce("alice", Route::default()).unwrap(); @@ -8131,7 +8131,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn broadcast_announces_its_own_path() { let producer = origin(1).produce(); @@ -8173,7 +8173,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] async fn broadcast_announcement_retracts_with_the_last_producer() { let producer = origin(1).produce(); let consumer = producer.consume(); @@ -8191,7 +8191,7 @@ mod tests { announced.expect_next_ended("room/alice").await; } - #[moq_clock::test] + #[kio::test] async fn publish_creates_and_announces_together() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8199,7 +8199,7 @@ mod tests { announced.expect_next_active("room/alice").await; } - #[moq_clock::test] + #[kio::test] async fn standalone_broadcast_cannot_announce() { let broadcast = broadcast::Info::new().produce(); assert!(matches!(broadcast.announce(Route::default()), Err(Error::Closed))); @@ -8207,7 +8207,7 @@ mod tests { broadcast.unannounce(); } - #[moq_clock::test] + #[kio::test] async fn announce_replays_to_late_cursor() { let producer = origin(1).produce(); let _a = producer.announce("room/alice", Route::default()).unwrap(); @@ -8220,7 +8220,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] async fn announce_keeps_its_prefix_under_a_producer_scope() { let producer = origin(1).produce(); let scoped = producer.scope("", &scopes(&["room"])).unwrap(); @@ -8237,7 +8237,7 @@ mod tests { )); } - #[moq_clock::test] + #[kio::test] async fn cursor_keeps_an_overlapping_prefix_above_its_scope() { let producer = origin(1).produce(); let _a = producer.announce("", Route::default()).unwrap(); @@ -8247,7 +8247,7 @@ mod tests { announced.expect_next_active("").await; } - #[moq_clock::test] + #[kio::test] async fn cursor_root_strips_prefix() { let producer = origin(1).produce(); let _a = producer.announce("room/alice", Route::default()).unwrap(); @@ -8260,7 +8260,7 @@ mod tests { announced.expect_next_active("alice").await; } - #[moq_clock::test] + #[kio::test] async fn best_route_wins_and_fails_over() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8289,7 +8289,7 @@ mod tests { } /// Pinned so `spreadHash` in `js/net` picks the same pool member for a path. - #[moq_clock::test] + #[kio::test] async fn spread_hash_matches_js() { assert_eq!(fnv_key("pool/job-0", [origin(10)]), 0xefb5e20a66101c32); assert_eq!(fnv_key("pool/job-0", [origin(11)]), 0x0eb0a91370ff6653); @@ -8299,7 +8299,7 @@ mod tests { /// paths spreads across the pool, and one path always resolves to the same /// advertiser, whatever order the routes arrived in. The split is a rendezvous /// hash, so losing an advertiser moves only the paths it won. - #[moq_clock::test] + #[kio::test] async fn equal_cost_pool_spreads_paths() { const WORKERS: [u64; 4] = [10, 11, 12, 13]; const PATHS: usize = 64; @@ -8352,7 +8352,7 @@ mod tests { /// an epoch nothing says it serves the same bytes, so consumers restart; with the /// same epoch it is the same instance, and nothing is delivered. Retracting the stale /// twin is quiet either way. - #[moq_clock::test] + #[kio::test] async fn identical_reannounce_restarts_without_an_epoch() { for epoch in [None, Some(epoch())] { let producer = origin(1).produce(); @@ -8376,7 +8376,7 @@ mod tests { } /// A re-price of the winning route is an update in place, never a restart. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_reprice_is_an_update() { let producer = origin(1).produce(); @@ -8393,7 +8393,7 @@ mod tests { /// Swapping a route's auth is an update in place carrying the new auth, so the session /// advertising it can renew its request. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_auth_swap_is_an_update() { let handle = crate::auth::Link::ietf(false); @@ -8417,7 +8417,7 @@ mod tests { /// chain whose hash loses, competes with the lingering old route: nothing restarts and /// requests stay on the old route until it is withdrawn, then consumers restart and a /// re-request lands on the replacement. Every node ranks peer routes alike. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_equal_cost_peer_replacement_waits_for_the_old_route() { // Pinned in `spread_hash_matches_js`: hop 11 hashes below hop 10 for this path. @@ -8461,7 +8461,7 @@ mod tests { /// A publisher that restarts while its old session lingers announces its own path under /// a new first hop. The restart takes over at once whichever chain hashes lower, so new /// requests never wait on the old session. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_equal_cost_local_replacement_takes_over_at_once() { for (old_hop, new_hop) in [(11, 10), (10, 11)] { @@ -8525,7 +8525,7 @@ mod tests { #[cfg(feature = "async")] async fn quiet(announced: &mut AnnounceConsumer) { for _ in 0..20 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } announced.assert_next_wait(); } @@ -8534,7 +8534,7 @@ mod tests { #[cfg(feature = "async")] async fn restarted(announced: &mut AnnounceConsumer, prefix: &str) -> Route { for _ in 0..20 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } announced.expect_next_restarted(prefix).await } @@ -8542,7 +8542,7 @@ mod tests { /// A held path moving restarts a scoped cursor whose own winner stayed, even /// though the route the cursor cannot see left and so changed the prefix's /// overall winner. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_moved_path_restarts_a_scoped_cursor() { let (producer, claim) = scoped_pool(); @@ -8566,7 +8566,7 @@ mod tests { /// A requester joining the front after its cursor restarted is not covered by /// that restart: the path moving afterwards restarts the prefix again. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_moved_path_restarts_a_requester_that_joined_after_a_restart() { let (producer, claim) = scoped_pool(); @@ -8591,7 +8591,7 @@ mod tests { /// A path that moved with the prefix's own restart is settled: the prefix's winner /// moving back to a route the front saw restarts it once, and the front adds none. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_moved_path_settled_by_a_restart_stays_settled() { let (producer, claim) = scoped_pool(); @@ -8616,7 +8616,7 @@ mod tests { /// A route from before the request repricing to win both the prefix and the held /// path restarts the prefix once: the cursor's own switch covers the move. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_repriced_route_taking_a_held_path_restarts_once() { let (producer, claim) = scoped_pool(); @@ -8633,7 +8633,7 @@ mod tests { quiet(&mut announced).await; } - #[moq_clock::test] + #[kio::test] async fn exclude_hides_routes_through_the_peer() { let producer = origin(1).produce(); let _a = producer @@ -8647,7 +8647,7 @@ mod tests { visible.expect_next_active("room").await; } - #[moq_clock::test] + #[kio::test] async fn exclude_matches_via_when_the_chain_is_anonymous() { let producer = origin(1).produce(); let assigned = origin(777); @@ -8663,7 +8663,7 @@ mod tests { hidden.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] async fn anonymous_route_loses_to_identified_at_any_cost() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8683,7 +8683,7 @@ mod tests { assert_eq!(route.cost, Cost::new(5)); } - #[moq_clock::test] + #[kio::test] async fn anonymous_routes_order_by_cost() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8705,7 +8705,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] async fn anonymous_chain_from_identified_peer_still_ranks_last() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8729,7 +8729,7 @@ mod tests { assert_eq!(route.cost, Cost::new(5)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn request_prefers_identified_over_cheaper_anonymous() { let producer = origin(1).produce(); @@ -8751,7 +8751,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn request_avoids_a_demoted_link_even_when_cheaper() { let producer = origin(1).produce(); @@ -8775,7 +8775,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn update_reprices_in_place() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8789,7 +8789,7 @@ mod tests { } /// Re-pricing from the current route keeps the epoch, so it stays one broadcast. - #[moq_clock::test] + #[kio::test] async fn reprice_from_the_current_route_keeps_the_epoch() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8816,7 +8816,7 @@ mod tests { assert!(broadcast.route().is_none(), "withdrawn"); } - #[moq_clock::test] + #[kio::test] async fn retract_after_undelivered_reprice_still_delivered() { let producer = origin(1).produce(); let mut announced = producer.consume().announced(); @@ -8833,7 +8833,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] async fn scoped_cursor_advertises_most_specific_covering_route() { let producer = origin(1).produce(); // Broad and cheap; narrow and expensive. Both present relative to a cursor @@ -8851,7 +8851,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn capture_change_retracts_before_reannouncing_a_presented_prefix() { let producer = origin(1).produce(); @@ -8884,7 +8884,7 @@ mod tests { assert_eq!(replacement.captures, None); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_broadcast_resolves_once_announced() { let producer = origin(1).produce(); @@ -8897,7 +8897,7 @@ mod tests { // Creating is not announcing: still parked. let broadcast = producer.create_broadcast("room/alice").unwrap(); for _ in 0..20 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!((&mut resolving).now_or_never().is_none()); @@ -8909,7 +8909,7 @@ mod tests { /// A local broadcast competes on its announced cost: a cheaper route at the /// same path wins, for cursors and requests alike. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn cheaper_remote_route_beats_a_local_broadcast() { let producer = origin(1).produce(); @@ -8941,7 +8941,7 @@ mod tests { /// A resolved broadcast names the epoch of the route it came through, and none /// when that route has none. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_resolved_broadcast_carries_its_route_epoch() { let producer = origin(1).produce(); @@ -8960,7 +8960,7 @@ mod tests { /// A cheaper route that appears after a front was minted takes the front over: it /// carries the same epoch, so a newcomer joins the front. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn cheaper_route_after_a_front_takes_it_over() { let producer = origin(1).produce(); @@ -9001,7 +9001,7 @@ mod tests { } /// A front lists what its serving source lists, as it changes. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_front_lists_its_source() { let producer = origin(1).produce(); @@ -9025,7 +9025,7 @@ mod tests { /// A source closing right after its tracks finished, held or not, ends the front's /// listing after those finishes, never ahead of them. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_front_forwards_the_finishes_before_its_source_closed() { let producer = origin(1).produce(); @@ -9052,7 +9052,7 @@ mod tests { /// A source's handler ending its listing while the source stays, as a session does on /// its peer's FIN before any retraction, ends the front's listing too. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_front_ends_its_listing_with_its_sources() { let producer = origin(1).produce(); @@ -9074,7 +9074,7 @@ mod tests { /// A same-instance route taking the front over lists the same tracks: readers see /// only what differs, once the new source's listing synced. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_front_reconciles_a_takeover() { let producer = origin(1).produce(); @@ -9108,7 +9108,7 @@ mod tests { /// A path served on request through a covering prefix is not a broadcast anyone /// announced, so it has nothing to list. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_front_through_a_covering_prefix_lists_nothing() { let producer = origin(1).produce(); @@ -9127,7 +9127,7 @@ mod tests { /// At equal cost the local broadcast wins even over a route with no hops of its /// own, such as a later claim on this origin: locality is the tie-break after /// cost, not the newest entry. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn local_broadcast_wins_a_tie_with_a_hopless_route() { let producer = origin(1).produce(); @@ -9137,7 +9137,7 @@ mod tests { let server = producer.requests_route("room/alice", Route::default()).unwrap(); // Were the claim to win, the request would park on its handler forever. - let resolved = moq_clock::timeout(Duration::from_secs(1), consumer.request_broadcast("room/alice", None)) + let resolved = kio::clock::timeout(Duration::from_secs(1), consumer.request_broadcast("room/alice", None)) .await .expect("the newer hopless route won the tie") .expect("resolves"); @@ -9147,7 +9147,7 @@ mod tests { /// Ingress announce stats count advertised intervals, not the broadcast's /// lifetime: nothing while hidden, one per announce, none for a re-price. - #[moq_clock::test] + #[kio::test] async fn announce_stats_follow_the_advertisement() { let registry = stats::Registry::new(stats::Config::new()); let producer = origin(1).produce().with_stats( @@ -9183,7 +9183,7 @@ mod tests { } /// At equal cost the local broadcast wins. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn local_broadcast_wins_a_cost_tie() { let producer = origin(1).produce(); @@ -9205,14 +9205,14 @@ mod tests { let resolved = consumer.request_broadcast("room/alice", None).await.expect("resolves"); assert_eq!(resolved.info().path.as_str(), "room/alice"); for _ in 0..20 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!(server.poll_requested_broadcast(&kio::Waiter::noop()).is_pending()); } /// Unannouncing ends the front the origin served from the broadcast and /// refuses new requests at once, even before the front acts on it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn unannounce_ends_the_front() { let producer = origin(1).produce(); @@ -9239,7 +9239,7 @@ mod tests { /// A subscriber still waiting on the source's track info is in flight too: /// unannouncing leaves it on the copy it asked for, which the source can /// still answer and finish. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn unannounce_keeps_a_track_awaiting_its_info() { let producer = origin(1).produce(); @@ -9249,8 +9249,8 @@ mod tests { let mut dynamic = broadcast.requests(); let resolved = consumer.request_broadcast("room/alice", None).await.expect("resolves"); let track = resolved.track("video").unwrap(); - let subscribing = moq_clock::sim::spawn(async move { track.subscribe(None).await }); - let request = moq_clock::timeout(Duration::from_secs(1), dynamic.requested_track()) + let subscribing = kio::clock::sim::spawn(async move { track.subscribe(None).await }); + let request = kio::clock::timeout(Duration::from_secs(1), dynamic.requested_track()) .await .expect("the front asked the source") .expect("request"); @@ -9290,14 +9290,14 @@ mod tests { /// A finished track stays readable from the front while it is read and for the /// linger after, then leaves the broadcast so it stops pinning its cache: the next /// reader asks the source afresh. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn finished_track_is_forgotten_after_the_linger() { let (_server, _upstream, mut dynamic, resolved) = served_front().await; let track = resolved.track("catalog").unwrap(); - let subscribing = moq_clock::sim::spawn(async move { track.subscribe(None).await }); - let request = moq_clock::timeout(Duration::from_secs(1), dynamic.requested_track()) + let subscribing = kio::clock::sim::spawn(async move { track.subscribe(None).await }); + let request = kio::clock::timeout(Duration::from_secs(1), dynamic.requested_track()) .await .expect("the front asked the source") .expect("request"); @@ -9332,18 +9332,18 @@ mod tests { assert!(next_group(&mut subscription).await.unwrap().is_none()); drop(subscription); assert!( - moq_clock::timeout(Duration::from_secs(1), dynamic.requested_track()) + kio::clock::timeout(Duration::from_secs(1), dynamic.requested_track()) .await .is_err(), "a finished track within the linger asked the source again" ); // Paused time runs the front's earlier deadline before this sleep returns. - moq_clock::sleep(track::IDLE_LINGER).await; + kio::clock::sleep(track::IDLE_LINGER).await; let track = resolved.track("catalog").unwrap(); - let _subscribing = moq_clock::sim::spawn(async move { track.subscribe(None).await }); - moq_clock::timeout(Duration::from_secs(1), dynamic.requested_track()) + let _subscribing = kio::clock::sim::spawn(async move { track.subscribe(None).await }); + kio::clock::timeout(Duration::from_secs(1), dynamic.requested_track()) .await .expect("the finished track outlived the linger") .expect("request"); @@ -9352,7 +9352,7 @@ mod tests { /// Every viewer session excludes a hop of its own that no route chain names, so /// they all share the plain front instead of each minting one that outlives them /// for as long as the route stands (#4799). Its tracks still go with the linger. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn viewer_sessions_share_the_plain_front() { let producer = origin(1).produce(); @@ -9398,14 +9398,14 @@ mod tests { // The front outlives its viewers while the route stands, but not their track. let front = front.unwrap(); assert_eq!(front.open_tracks(), 1, "the unread track lingers"); - moq_clock::sleep(track::IDLE_LINGER).await; + kio::clock::sleep(track::IDLE_LINGER).await; settle(|| front.open_tracks() == 0).await; } /// A requester excluding a peer that a covering route passes through gets a front /// of its own. Decided per request: a peer whose hop joins a chain after it joined /// the plain front gets the filtered one on its next request. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_hop_in_a_chain_gets_its_own_front() { let producer = origin(1).produce(); @@ -9434,7 +9434,7 @@ mod tests { /// A front ends once nothing reads it for the linger and nothing holds its /// broadcast, rather than for as long as its route stands, and lets go of its source. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_unread_front_ends_after_the_linger() { let producer = origin(1).produce(); @@ -9458,11 +9458,11 @@ mod tests { drop(resolved); // Within the linger the unread track keeps its front for a returning reader. - moq_clock::sleep(track::IDLE_LINGER / 2).await; + kio::clock::sleep(track::IDLE_LINGER / 2).await; assert_eq!(fronts(), 1); assert!(upstream.is_held(), "the front let go of its source early"); - moq_clock::sleep(track::IDLE_LINGER).await; + kio::clock::sleep(track::IDLE_LINGER).await; settle(|| fronts() == 0).await; assert!(front.is_closed()); assert!(!upstream.is_held(), "an ended front still holds its source"); @@ -9470,7 +9470,7 @@ mod tests { /// A request racing a front's retirement never joins it as it ends: one that holds /// the front before its driver looks keeps it, and one after mints a fresh front. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_request_racing_a_front_retiring_never_joins_it_ending() { let producer = origin(1).produce(); @@ -9501,7 +9501,7 @@ mod tests { /// A track that ends while read is unread from then on, even with its reader still /// holding it: the front sees it go unread once and lets it linger, rather than /// keeping it read forever or spinning on it while it lingers ended and unread. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_track_ending_while_read_lets_its_front_retire() { let producer = origin(1).produce(); @@ -9523,7 +9523,7 @@ mod tests { source.abort(Error::NotFound).unwrap(); drop(resolved); - moq_clock::sleep(track::IDLE_LINGER).await; + kio::clock::sleep(track::IDLE_LINGER).await; settle(|| fronts() == 0).await; drop(reader); } @@ -9531,7 +9531,7 @@ mod tests { /// A front whose broadcast closes under it ends, rather than polling a holder edge /// that a closed broadcast answers at once. Nothing but the front closes it today, so /// the test does; a regression spins inside one poll and hangs the test. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_front_whose_broadcast_closes_ends() { let producer = origin(1).produce(); @@ -9560,7 +9560,7 @@ mod tests { assert!(front.as_mut().now_or_never().is_none(), "the front ended early"); broadcast.close(); - let in_flight = moq_clock::timeout(Duration::from_secs(1), front) + let in_flight = kio::clock::timeout(Duration::from_secs(1), front) .await .expect("the front outlived its broadcast"); assert!(in_flight.is_empty()); @@ -9569,7 +9569,7 @@ mod tests { /// The filtered front a peer session gets for a chain through it goes once the peer /// stops reading it, leaving the plain front its viewers share. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_peers_filtered_front_ends_once_unread() { let producer = origin(1).produce(); @@ -9600,14 +9600,14 @@ mod tests { drop(subscription); drop(peered); drop(peer); - moq_clock::sleep(track::IDLE_LINGER).await; + kio::clock::sleep(track::IDLE_LINGER).await; settle(|| fronts() == 1).await; } /// The hairpin the per-request choice accepts ends on its own. A peer still on the /// plain front when the only route left runs through it gets that route, but its own /// view withdraws the path, so it stops serving the path back to us. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_hairpin_through_the_plain_front_is_withdrawn() { let producer = origin(1).produce(); @@ -9642,7 +9642,7 @@ mod tests { /// whether the old route dies before the new one takes over (a reconnect) or after /// (a cheaper route preempting it). A reader joining mid-outage gets it too, and the /// reader already mid-group is not handed it a second time. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_takeover_serves_the_open_group_head_to_later_readers() { for dies_first in [true, false] { @@ -9667,7 +9667,7 @@ mod tests { #[cfg(feature = "async")] async fn read(group: &mut crate::group::Consumer) -> Vec { - let frame = moq_clock::timeout(Duration::from_secs(1), group.read_frame()) + let frame = kio::clock::timeout(Duration::from_secs(1), group.read_frame()) .await .expect("frame") .unwrap() @@ -9677,7 +9677,7 @@ mod tests { // A reader is mid-way through the open group when the route changes. let track = resolved.track("log").unwrap(); - let subscribing = moq_clock::sim::spawn(async move { track.subscribe(None).await }); + let subscribing = kio::clock::sim::spawn(async move { track.subscribe(None).await }); let source = dynamic .requested_track() .await @@ -9701,7 +9701,7 @@ mod tests { // the front give up on a path with no route left before the replacement lands. assert!(futures::FutureExt::now_or_never(subscription.recv_group()).is_none()); let track = resolved.track("log").unwrap(); - joining = Some(moq_clock::sim::spawn(async move { + joining = Some(kio::clock::sim::spawn(async move { let mut joined = track.subscribe(None).await.unwrap(); let group = joined.recv_group().await.unwrap().expect("track ended"); (joined, group) @@ -9720,7 +9720,7 @@ mod tests { let replacement = broadcast::Info::new().produce(); let mut replacement_dynamic = replacement.requests(); queued(&replacement_server).await.accept(&replacement); - let request = moq_clock::timeout(Duration::from_secs(1), replacement_dynamic.requested_track()) + let request = kio::clock::timeout(Duration::from_secs(1), replacement_dynamic.requested_track()) .await .expect("the front asked the replacement") .unwrap(); @@ -9728,7 +9728,7 @@ mod tests { let fetches = request.requests(); let fetched = Arc::new(crate::sync::Mutex::new(Vec::::new())); let serving = fetched.clone(); - let _fetching = moq_clock::sim::spawn(async move { + let _fetching = kio::clock::sim::spawn(async move { while let Ok(request) = fetches.requested_fill_group().await { let mut group = request.accept(crate::track::Info::timed()).unwrap(); for frame in [b"a", b"b", b"c"] { @@ -9756,11 +9756,11 @@ mod tests { drop(first); let track = resolved.track("log").unwrap(); - let mut later = moq_clock::timeout(Duration::from_secs(1), track.subscribe(None)) + let mut later = kio::clock::timeout(Duration::from_secs(1), track.subscribe(None)) .await .expect("subscribe") .unwrap(); - let mut late = moq_clock::timeout(Duration::from_secs(1), later.recv_group()) + let mut late = kio::clock::timeout(Duration::from_secs(1), later.recv_group()) .await .unwrap_or_else(|_| panic!("dies_first={dies_first}: the later reader never got the group")) .unwrap() @@ -9771,7 +9771,7 @@ mod tests { } let mut joined = None; if let Some(joining) = joining { - let (subscription, mut group) = moq_clock::timeout(Duration::from_secs(1), joining) + let (subscription, mut group) = kio::clock::timeout(Duration::from_secs(1), joining) .await .expect("the reader joining mid-outage never got the group") .unwrap(); @@ -9784,7 +9784,7 @@ mod tests { // The reader that was mid-group already has it. assert!( - moq_clock::timeout(Duration::from_secs(1), subscription.recv_group()) + kio::clock::timeout(Duration::from_secs(1), subscription.recv_group()) .await .is_err(), "dies_first={dies_first}: the group was handed out twice" @@ -9816,7 +9816,7 @@ mod tests { /// The same holds for a reader returning to a parked track: its warm cache /// does not stand in for the copy it is waiting on. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn unannounce_keeps_a_returning_reader_awaiting_its_info() { let producer = origin(1).produce(); @@ -9826,8 +9826,8 @@ mod tests { let mut dynamic = broadcast.requests(); let resolved = consumer.request_broadcast("room/alice", None).await.expect("resolves"); let track = resolved.track("video").unwrap(); - let subscribing = moq_clock::sim::spawn(async move { track.subscribe(None).await }); - let request = moq_clock::timeout(Duration::from_secs(1), dynamic.requested_track()) + let subscribing = kio::clock::sim::spawn(async move { track.subscribe(None).await }); + let request = kio::clock::timeout(Duration::from_secs(1), dynamic.requested_track()) .await .expect("the front asked the source") .expect("request"); @@ -9841,14 +9841,14 @@ mod tests { // Parked: the source copy goes, the delivered group stays warm. The source // then tears its idle track down, so a returning reader asks it afresh. - moq_clock::timeout(Duration::from_secs(1), source.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(1), source.demand().until(|wanted| wanted.is_none())) .await .expect("parked") .expect("source open"); drop(source); let track = resolved.track("video").unwrap(); - let subscribing = moq_clock::sim::spawn(async move { track.subscribe(None).await }); - let request = moq_clock::timeout(Duration::from_secs(1), dynamic.requested_track()) + let subscribing = kio::clock::sim::spawn(async move { track.subscribe(None).await }); + let request = kio::clock::timeout(Duration::from_secs(1), dynamic.requested_track()) .await .expect("the front asked the source again") .expect("request"); @@ -9873,7 +9873,7 @@ mod tests { /// A re-announce that lands before the front acts on the retraction reuses /// the same route entry, so the front carries on. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn reannounce_before_the_front_acts_keeps_it() { let producer = origin(1).produce(); @@ -9885,14 +9885,14 @@ mod tests { broadcast.unannounce(); broadcast.announce(Route::default()).unwrap(); for _ in 0..20 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!(!resolved.is_closed(), "the front ended across a reannouncement"); let again = consumer.request_broadcast("room/alice", None).await.expect("resolves"); assert!(again.is_clone(&resolved)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn local_broadcast_resolves_once_announced() { let producer = origin(1).produce(); @@ -9923,7 +9923,7 @@ mod tests { assert!(matches!(err, Error::Unroutable)); } - #[moq_clock::test] + #[kio::test] async fn create_broadcast_accepts_a_path_at_the_wire_limits() { let producer = origin(1).produce(); let path = vec!["a"; Path::MAX_PARTS].join("/"); @@ -9947,7 +9947,7 @@ mod tests { )); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn duplicate_routes_aggregate_until_the_last_leaves() { let producer = origin(1).produce(); @@ -9971,7 +9971,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] async fn dynamic_may_cover_a_scope_but_disjoint_prefixes_are_refused() { let producer = origin(1).produce(); let scoped = producer.scope("", &scopes(&["room"])).unwrap(); @@ -9988,7 +9988,7 @@ mod tests { )); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn requests_route_keeps_its_producer_scope() { let producer = origin(1).produce(); @@ -10022,7 +10022,7 @@ mod tests { assert_eq!(request.path().as_str(), "room/chat"); } - #[moq_clock::test] + #[kio::test] async fn scoped_cursor_selects_among_the_routes_it_can_see() { let producer = origin(1).produce(); let scoped = |pattern: &str| { @@ -10045,7 +10045,7 @@ mod tests { assert_eq!(video.expect_next_active("").await.cost, Cost::new(5)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn route_changes_preserve_each_cursors_visible_winner() { let producer = origin(1).produce(); @@ -10096,7 +10096,7 @@ mod tests { video.expect_next_ended("room/live").await; } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn root_cursor_keeps_the_more_specific_covering_route() { let producer = origin(1).produce(); @@ -10119,7 +10119,7 @@ mod tests { assert_eq!(announced.expect_next_active("").await.cost, Cost::new(0)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dynamic_accepts_a_max_depth_prefix() { let producer = origin(1).produce(); @@ -10139,7 +10139,7 @@ mod tests { assert_eq!(request.path().as_str(), path); } - #[moq_clock::test] + #[kio::test] async fn dynamic_exclusion_skips_routes_through_the_subscriber() { let producer = origin(1).produce(); let _server = producer @@ -10154,7 +10154,7 @@ mod tests { } /// The consumer is a `Stream` of the same updates as `next`. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn announce_consumer_is_a_stream() { use futures::StreamExt; @@ -10171,7 +10171,7 @@ mod tests { assert!(matches!(next(), Some(Some(AnnounceEvent::End(_))))); } - #[moq_clock::test] + #[kio::test] async fn dynamic_retracts() { let producer = origin(1).produce(); let server = producer.requests_route("live", Route::default()).unwrap(); @@ -10182,7 +10182,7 @@ mod tests { announced.expect_next_ended("live").await; } - #[moq_clock::test] + #[kio::test] async fn local_broadcast_is_invisible_until_announced() { let producer = origin(1).produce(); let mut local = producer.consume().announced(); @@ -10200,7 +10200,7 @@ mod tests { peer.expect_next_ended("room/alice").await; } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn served_route_materializes_on_demand() { let producer = origin(1).produce(); @@ -10224,7 +10224,7 @@ mod tests { assert!(again.is_clone(&resolved)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn served_requests_coalesce() { let producer = origin(1).produce(); @@ -10246,7 +10246,7 @@ mod tests { assert!(first.is_clone(&second)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn retract_rejects_pending_requests() { let producer = origin(1).produce(); @@ -10269,7 +10269,7 @@ mod tests { assert!(matches!(err, Error::Unroutable)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_broadcast_survives_serving_route_retraction() { let producer = origin(1).produce(); @@ -10302,7 +10302,7 @@ mod tests { assert_eq!(resolved.info().path.as_str(), "room/alice"); } - #[moq_clock::test] + #[kio::test] async fn split_horizon_skips_routes_through_the_requester() { let producer = origin(1).produce(); let _server = producer @@ -10325,7 +10325,7 @@ mod tests { assert!(pending.now_or_never().is_none()); } - #[moq_clock::test] + #[kio::test] async fn routes_report_where_they_entered() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); @@ -10363,15 +10363,15 @@ mod tests { /// A caller that only polls with `try_next` still gets a held update once its /// hold passes. Nothing else wakes the idle driver, so the hold's own timer /// must, or the origin's clock never reaches the deadline. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn try_next_delivers_a_held_update() { // Let paused time pass and every task woken by it run. #[cfg(feature = "async")] async fn step(by: Duration) { - moq_clock::sim::advance(by).await; + kio::clock::sim::advance(by).await; for _ in 0..10 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } } @@ -10455,14 +10455,14 @@ mod tests { /// A new route and a removal are delivered at once. A change of the best route /// within one instance waits out the update hold, and a newer change during the /// wait replaces it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_changed_route_waits_out_the_hold() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); let mut announced = producer.consume().announced(); // Holds count on the driver's clock, which starts at its first poll. - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; // One epoch, so the winner moving between routes is an update, not a restart. let route = |chain: &[u64], via| { @@ -10477,14 +10477,14 @@ mod tests { // The best route changes twice; the consumer sees only the last, once. let far = peer.requests_route("room", route(&[9, 3, 4], 4)).unwrap(); let farther = peer.requests_route("room", route(&[9, 5, 6, 7], 7)).unwrap(); - let start = moq_clock::now(); + let start = kio::clock::now(); drop(near); drop(far); match announced.next().await.unwrap() { AnnounceEvent::Update(update) => assert_eq!(update.route.hops, hops(&[9, 5, 6, 7])), other => panic!("should be an update: got {other:?}"), } - assert_eq!(moq_clock::now() - start, DEFAULT_UPDATE_HOLD); + assert_eq!(kio::clock::now() - start, DEFAULT_UPDATE_HOLD); announced.assert_next_wait(); // The last route goes: retracted at once. @@ -10494,13 +10494,13 @@ mod tests { /// After a retraction, a worse path to the same publisher waits out the /// quarantine. An anonymous route names no publisher, so one after it is not held. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_retraction_quarantines_a_named_publisher() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); let mut announced = producer.consume().announced(); - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; let route = |chain: &[u64], via| Route::default().with_hops(hops(chain)).with_via(origin(via)); @@ -10508,13 +10508,13 @@ mod tests { announced.expect_next_active("named").await; drop(near); announced.expect_next_ended("named").await; - let start = moq_clock::now(); + let start = kio::clock::now(); let _stale = peer.requests_route("named", route(&[9, 3, 4], 4)).unwrap(); match announced.next().await.unwrap() { AnnounceEvent::Start(announce) => assert_eq!(announce.route.hops, hops(&[9, 3, 4])), other => panic!("should be a start: got {other:?}"), } - assert!(moq_clock::now() - start >= RETRACT_QUARANTINE); + assert!(kio::clock::now() - start >= RETRACT_QUARANTINE); let near = peer.requests_route("anonymous", route(&[0, 2], 2)).unwrap(); announced.expect_next_active("anonymous").await; @@ -10543,7 +10543,7 @@ mod tests { assert!(!announced.retracted.is_empty()); for _ in 0..2 { announced.assert_next_wait(); - moq_clock::sleep(RETRACT_QUARANTINE).await; + kio::clock::sleep(RETRACT_QUARANTINE).await; } announced.assert_next_wait(); assert!(announced.retracted.is_empty(), "the ended quarantine is still held"); @@ -10552,7 +10552,7 @@ mod tests { /// A peer withdrawing a prefix hides the routes there through it, so the next /// best is never a path derived from the one withdrawn. Announcing again /// revives them, and nothing is remembered once no route passes through it. - #[moq_clock::test] + #[kio::test] async fn withdrawn_peer_hides_routes_through_it() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); @@ -10586,7 +10586,7 @@ mod tests { /// Overlapping sessions are independent claims, regardless of announcement order. /// The fallback to the older session is another source, so it restarts. - #[moq_clock::test] + #[kio::test] async fn old_session_withdrawal_keeps_newer_route() { for restart in [false, true] { let producer = origin(1).produce(); @@ -10615,7 +10615,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn withdrawn_route_no_longer_covers_requests() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); @@ -10642,7 +10642,7 @@ mod tests { /// A change of source alone is delivered: the same chain and cost arriving /// from a peer instead of a client is a different fact for the consumer. Under one /// epoch it is an update. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn source_change_is_an_update() { let producer = origin(1).produce(); @@ -10673,7 +10673,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] async fn local_view_hides_peer_routes() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); @@ -10723,7 +10723,7 @@ mod tests { /// An upstream link is offered what entered here and what other peers /// forwarded, but never a route learned on another upstream link, and the /// best route it sees skips a better upstream one. - #[moq_clock::test] + #[kio::test] async fn upstream_view_hides_upstream_routes() { let producer = origin(1).produce(); let peer = producer.clone().with_link(Link::Peer); @@ -10788,7 +10788,7 @@ mod tests { /// A handler that rejects a path with `Unroutable` while its route stands /// gives the requester that answer; the front must not re-ask the same route /// forever, which would spin the origin driver. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn handler_rejection_is_final() { let producer = origin(1).produce(); @@ -10798,7 +10798,7 @@ mod tests { let pending = consumer.request_broadcast("room/alice", None); let request = queued(&server).await; request.reject(Error::Unroutable); - let err = moq_clock::timeout(Duration::from_secs(5), pending) + let err = kio::clock::timeout(Duration::from_secs(5), pending) .await .expect("the front must give up, not spin") .err() @@ -10814,7 +10814,7 @@ mod tests { pending.await.expect("resolves"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn claim_answer_is_hidden_until_published_with_its_epoch() { let producer = origin(1).produce(); @@ -10838,7 +10838,7 @@ mod tests { } /// Only `publish` announces a prepared answer, under its epoch and after admission. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_prepared_answer_cannot_announce_itself() { let producer = origin(1).produce(); @@ -10861,7 +10861,7 @@ mod tests { } /// Announcement control follows the origin role while fill clones retain publication lifetime. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn publication_clones_share_control_and_fill_retention() { let producer = origin(1).produce(); @@ -10886,7 +10886,7 @@ mod tests { } /// A withdrawn stale publication cannot remove a replacement instance's route. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn stale_publication_control_cannot_withdraw_a_replacement() { let producer = origin(1).produce(); @@ -10909,7 +10909,7 @@ mod tests { } /// A refused answer keeps its announcer withheld, so a clone cannot announce it later. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_refused_prepared_answer_cannot_announce_later() { let producer = origin(1).produce(); @@ -10923,7 +10923,7 @@ mod tests { assert!(matches!(answer.announce(Route::default()), Err(Error::Closed))); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn dropping_a_prepared_claim_answer_refuses_the_request() { let producer = origin(1).produce(); @@ -10936,7 +10936,7 @@ mod tests { } /// An answer prepared for a claim that went away is refused, never announced. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_prepared_answer_for_an_abandoned_claim_is_never_announced() { let producer = origin(1).produce(); @@ -10953,7 +10953,7 @@ mod tests { } /// An answer prepared before the claim changed instance is refused, never announced. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_prepared_answer_for_a_released_request_is_never_announced() { let producer = origin(1).produce(); @@ -10973,7 +10973,7 @@ mod tests { /// A request pinned to an epoch resolves only through the answer published under it, /// never by asking the claim, which has no epoch of its own. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_pinned_request_resolves_only_through_the_published_epoch() { let producer = origin(1).produce(); @@ -10995,7 +10995,7 @@ mod tests { /// A refusal from the longest prefix is the answer: neither a costlier advertiser of /// that prefix nor a catch-all is asked instead. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn refusal_never_falls_through() { let producer = origin(1).produce(); @@ -11023,7 +11023,7 @@ mod tests { /// A refusal from a route a local broadcast superseded while it was pending is moot: /// the request resolves to the local broadcast instead of ending. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn superseded_refusal_does_not_end_the_request() { let producer = origin(1).produce(); @@ -11050,7 +11050,7 @@ mod tests { /// The same holds for a more specific remote route: the beaten route's refusal is /// moot, and the new winner is asked instead. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn refusal_from_a_beaten_route_asks_the_new_winner() { let producer = origin(1).produce(); @@ -11077,7 +11077,7 @@ mod tests { /// `routed_broadcast` treats a handler's rejection as the table's verdict: /// it waits for the table to move instead of re-asking the same route. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_broadcast_waits_out_a_rejection() { let producer = origin(1).produce(); @@ -11091,7 +11091,7 @@ mod tests { // Parked: the route stands, so nothing changed that a retry could use. for _ in 0..20 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!((&mut resolving).now_or_never().is_none()); assert!(server.poll_requested_broadcast(&kio::Waiter::noop()).is_pending()); @@ -11106,7 +11106,7 @@ mod tests { } /// Teardown rejects the parked request with the origin's own terminal cause. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_broadcast_reports_teardown_as_closed() { let (producer, driver) = Producer::new(Config::new(origin(1))); @@ -11119,7 +11119,7 @@ mod tests { drop(driver); - let err = moq_clock::timeout(Duration::from_secs(5), resolving) + let err = kio::clock::timeout(Duration::from_secs(5), resolving) .await .expect("teardown resolves the wait") .err() @@ -11129,7 +11129,7 @@ mod tests { /// A local broadcast announcing at the exact path is a table change too: a /// requester parked on a handler's rejection resolves to it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_broadcast_wakes_for_a_local_broadcast() { let producer = origin(1).produce(); @@ -11140,7 +11140,7 @@ mod tests { assert!((&mut resolving).now_or_never().is_none()); queued(&server).await.reject(Error::Unroutable); for _ in 0..20 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!((&mut resolving).now_or_never().is_none()); @@ -11153,7 +11153,7 @@ mod tests { /// A track first subscribed after the front is already serving another still /// replays what its source holds, like the first track did. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn late_track_on_a_served_front_replays() { let producer = origin(1).produce(); @@ -11182,7 +11182,7 @@ mod tests { .subscribe(budget.clone()) .await .expect("subscribe"); - let mut group = moq_clock::timeout(Duration::from_secs(5), subscription.recv_group()) + let mut group = kio::clock::timeout(Duration::from_secs(5), subscription.recv_group()) .await .expect("the late track must replay, not park") .expect("recv group") @@ -11192,7 +11192,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn most_specific_prefix_shadows() { let producer = origin(1).produce(); @@ -11217,7 +11217,7 @@ mod tests { assert_eq!(request.path().as_str(), "room/alice"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn root_dynamic_serves_any_path() { let producer = origin(1).produce(); @@ -11253,7 +11253,7 @@ mod tests { /// `scope` is authoritative, so an out-of-scope path is unauthorized before /// routing can send a request to the handler. A `Request` carries only a path, /// so the handler cannot tell who asked. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn out_of_scope_request_never_reaches_the_dynamic_handler() { let producer = origin(1).produce(); @@ -11275,7 +11275,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_waits_for_coverage() { let producer = origin(1).produce(); @@ -11297,7 +11297,7 @@ mod tests { .expect("routed"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_ignores_deeper_routes() { let producer = origin(1).produce(); @@ -11312,7 +11312,7 @@ mod tests { fut.now_or_never().expect("covered").expect("routed"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn routed_accepts_a_max_depth_path() { let producer = origin(1).produce(); @@ -11333,7 +11333,7 @@ mod tests { fut.now_or_never().expect("covered").expect("routed"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn teardown_ends_everything() { let (producer, driver) = Producer::new(Config::new(origin(1))); @@ -11510,7 +11510,7 @@ mod tests { /// Without an epoch nothing says another route serves the same bytes: a better /// route does not move the subscription, and when its own route goes it ends /// rather than resuming elsewhere. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_route_without_an_epoch_never_resumes_elsewhere() { let producer = origin(1).produce(); @@ -11547,7 +11547,7 @@ mod tests { /// A newer publisher at the path wins new requests even when it costs more, while /// the subscriptions on the old one stay with it until its route goes. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_newer_epoch_leaves_the_broadcast_in_flight() { let producer = origin(1).produce(); @@ -11591,7 +11591,7 @@ mod tests { /// A request in the same tick as a newer epoch's announcement is never handed /// the old front: its watcher has not noticed the replacement yet, but the /// request mints a front on the new epoch instead of joining the replaced one. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_request_racing_a_newer_epoch_skips_the_old_front() { let producer = origin(1).produce(); @@ -11635,7 +11635,7 @@ mod tests { /// A newer epoch winning while the front's first request is in flight beats that /// route: its late answer is not what requesters resolve to. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_answer_racing_a_newer_epoch_resolves_the_winner() { let producer = origin(1).produce(); @@ -11707,13 +11707,13 @@ mod tests { deliver(&fresh_track, &mut subscription, b"new").await; } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_request_held_across_an_epoch_change_is_asked_again() { held_request_across_an_epoch_change(false).await; } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_answer_before_an_epoch_change_is_asked_again() { held_request_across_an_epoch_change(true).await; @@ -11721,7 +11721,7 @@ mod tests { /// A refusal that lands just before an epoch change, before the front takes it, /// was the old instance's answer: the request is asked again, not ended. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_refusal_before_an_epoch_change_is_asked_again() { let producer = origin(1).produce(); @@ -11745,7 +11745,7 @@ mod tests { /// A release is not undone by the epoch coming back before the front looks: a /// request held across A to B to A is asked again, not refused. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_request_held_across_an_epoch_round_trip_is_asked_again() { let producer = origin(1).produce(); @@ -11777,7 +11777,7 @@ mod tests { /// A route that gains an epoch and then drops it serves a third instance, not the /// first: a request after the round trip is asked again rather than joining the /// front still serving the first instance's subscribers. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn losing_an_epoch_is_another_instance() { let producer = origin(1).produce(); @@ -11806,7 +11806,7 @@ mod tests { /// Announce cursors follow the newest epoch over a cheaper one, and deliver a /// change of epoch as a restart: a different broadcast. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn the_newest_epoch_is_announced_as_a_new_broadcast() { let producer = origin(1).produce(); @@ -11842,7 +11842,7 @@ mod tests { } /// A peer naming one publisher instance is never handed another. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_request_for_another_epoch_is_refused() { let producer = origin(1).produce(); @@ -11862,7 +11862,7 @@ mod tests { } /// A route without an epoch resolves a handle without one. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_route_without_an_epoch_resolves_without_one() { let producer = origin(1).produce(); @@ -11877,14 +11877,14 @@ mod tests { /// The driver's completion contract: it resolves once every producer handle /// drops, however many read handles remain. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn driver_resolves_with_live_consumers() { let (producer, driver) = Producer::new(Config::new(origin(1))); let consumer = producer.consume(); let run = crate::time::run(driver); drop(producer); - moq_clock::timeout(Duration::from_secs(5), run) + kio::clock::timeout(Duration::from_secs(5), run) .await .expect("driver must finish once the producers are gone"); drop(consumer); @@ -11893,7 +11893,7 @@ mod tests { /// A source claiming the same content cannot change immutable track metadata: /// the successor is refused instead of the subscriber's samples being read on /// a different grid, and the verdict outlives the aborted logical track. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn incompatible_successor_is_refused() { for replacement in [ @@ -11933,7 +11933,7 @@ mod tests { /// Routes with one epoch serve one broadcast: when the serving route dies, the /// subscription resumes through another with that epoch, whatever its first hop, /// or with none at all. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn any_route_at_the_path_resumes_the_subscription() { let cases = [ @@ -11954,7 +11954,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_replacement_query_carries_the_readers_resume_floor() { let (mut rig, incumbent, source) = ResumeRig::new(&[10]).await; @@ -11984,7 +11984,7 @@ mod tests { /// A route updated in place to a new first hop still serves the same broadcast: /// the subscription carries on through it, and a new request joins the front. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_first_hop_update_keeps_serving() { for first in [&[][..], &[0][..], &[10][..]] { @@ -12019,7 +12019,7 @@ mod tests { /// A session never subscribes to itself: when the route serving a peer dies, its /// front never resumes onto a route through that peer, even one from the same /// publisher. A reader that can see the route resumes there. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn resume_never_routes_through_the_requester() { for peer in [Some(origin(7)), None] { @@ -12089,7 +12089,7 @@ mod tests { /// /// The front closes with its last source, so the newcomer attaches a fresh /// one and the subscriber resolves it without parking. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn anonymous_handoff_serves_the_newcomer_immediately() { let producer = origin(1).produce(); @@ -12186,7 +12186,7 @@ mod tests { ); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn reprice_is_invisible_to_the_subscription() { let (rig, incumbent, source) = ResumeRig::new(&[10]).await; @@ -12218,7 +12218,7 @@ mod tests { assert_eq!(&frame.payload[..], b"steady"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn drain_reprice_migrates_before_the_session_dies() { let (mut rig, incumbent, source) = ResumeRig::new(&[10]).await; @@ -12245,7 +12245,7 @@ mod tests { /// A second broadcast at the path without an epoch is another instance: new /// requests resolve it on a fresh front, rather than join the first one's. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_newer_local_source_gets_a_fresh_front() { let producer = origin(1).produce(); @@ -12272,7 +12272,7 @@ mod tests { /// A front still resolving an instance that another has since beaten takes no new /// requester: it may already hold the beaten instance's source, and would hand it to a /// request that saw it lose, which no later announcement corrects. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_request_skips_a_front_resolving_a_beaten_instance() { let producer = origin(1).produce(); @@ -12294,7 +12294,7 @@ mod tests { /// A front that moved to the new winner before resolving takes requesters for it, so /// they share it rather than each minting a front on the winner. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_request_joins_a_front_resolving_the_winner() { let producer = origin(1).produce(); @@ -12329,7 +12329,7 @@ mod tests { /// /// The runtime is single-threaded and the publisher's whole ending has no await in /// it, so the outcome does not depend on timing. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_finished_broadcast_concludes_in_flight_subscriptions() { let producer = origin(1).produce(); @@ -12372,7 +12372,7 @@ mod tests { /// must still conclude normally. moq-lite, ANNOUNCE_END: "Retraction does not /// disturb subscriptions already in flight, which conclude normally with /// SUBSCRIBE_END." - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_retracted_route_concludes_in_flight_subscriptions() { let producer = origin(1).produce(); @@ -12421,7 +12421,7 @@ mod tests { /// A standing route outlives the source it produced: the front ends instead of /// asking that route for the broadcast that just closed. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_closed_source_is_not_requested_again_from_its_standing_route() { let producer = origin(1).produce(); @@ -12445,7 +12445,7 @@ mod tests { /// so the publisher's demand goes unwanted far below `track::IDLE_LINGER`. /// Cached groups stay on the front for the linger; a returning reader /// replays them and asks the source again for groups past that edge. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn origin_front_drops_the_source_when_unused() { let producer = origin(1).produce(); @@ -12469,7 +12469,7 @@ mod tests { drop(group); drop(subscription); - moq_clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_none())) .await .expect("source unused should resolve far below track::IDLE_LINGER") .expect("source closed"); @@ -12482,14 +12482,14 @@ mod tests { .subscribe(track::Subscription::default().with_max_delay(Duration::from_secs(3600))) .await .expect("resubscribe"); - let mut group = moq_clock::timeout(Duration::from_secs(1), again.recv_group()) + let mut group = kio::clock::timeout(Duration::from_secs(1), again.recv_group()) .await .expect("cached group is still on the front") .expect("recv group") .expect("track ended early"); assert_eq!(&group.read_frame().await.unwrap().unwrap().payload[..], b"cached"); - moq_clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_some())) + kio::clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_some())) .await .expect("returning reader re-splices the source") .expect("source closed"); @@ -12497,7 +12497,7 @@ mod tests { let mut group = track.append_group().unwrap(); group.write_frame(crate::Timestamp::ZERO, b"live".as_ref()).unwrap(); group.finish().unwrap(); - let mut group = moq_clock::timeout(Duration::from_secs(1), again.recv_group()) + let mut group = kio::clock::timeout(Duration::from_secs(1), again.recv_group()) .await .expect("groups past the cached edge come from the re-splice") .expect("recv group") @@ -12508,7 +12508,7 @@ mod tests { /// A reader still holding an open group after its track goes unread gets the rest /// of the group: parking the track reads no new group, but the upstream stays /// subscribed until the held one ends. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_held_group_continues_after_its_track_goes_unread() { let producer = origin(1).produce(); @@ -12528,19 +12528,19 @@ mod tests { assert_eq!(&reading.read_frame().await.unwrap().unwrap().payload[..], b"head"); drop(subscription); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; writing.write_frame(crate::Timestamp::ZERO, b"tail".as_ref()).unwrap(); writing.finish().unwrap(); - let tail = moq_clock::timeout(Duration::from_secs(1), reading.read_frame()) + let tail = kio::clock::timeout(Duration::from_secs(1), reading.read_frame()) .await .expect("the held group lost its source") .unwrap() .expect("the group ended early"); assert_eq!(&tail.payload[..], b"tail"); - let end = moq_clock::timeout(Duration::from_secs(1), reading.read_frame()).await; + let end = kio::clock::timeout(Duration::from_secs(1), reading.read_frame()).await; assert!(matches!(end, Ok(Ok(None))), "the group should finish: {end:?}"); - moq_clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_none())) .await .expect("the front lets the source go once the held group ends") .expect("source closed"); @@ -12549,7 +12549,7 @@ mod tests { /// A source that aborts one group while its track carries on ends that group for /// the reader too, rather than leaving it waiting for a route change that never /// comes. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_group_the_source_aborts_ends_while_the_track_lives() { let producer = origin(1).produce(); @@ -12564,14 +12564,14 @@ mod tests { assert_eq!(&reading.read_frame().await.unwrap().unwrap().payload[..], b"head"); aborted.abort(Error::Cancel).unwrap(); - let end = moq_clock::timeout(Duration::from_secs(1), reading.read_frame()).await; + let end = kio::clock::timeout(Duration::from_secs(1), reading.read_frame()).await; assert!(matches!(end, Ok(Err(_))), "the group should fail: {end:?}"); // The track carries on. let mut next = track.append_group().unwrap(); next.write_frame(crate::Timestamp::ZERO, b"next".as_ref()).unwrap(); next.finish().unwrap(); - let mut group = moq_clock::timeout(Duration::from_secs(1), subscription.recv_group()) + let mut group = kio::clock::timeout(Duration::from_secs(1), subscription.recv_group()) .await .expect("the next group") .unwrap() @@ -12582,7 +12582,7 @@ mod tests { /// A front serving from another front still drops upstream on the unused edge, /// so the publisher's demand goes unwanted far below `track::IDLE_LINGER` through /// the whole chain, and a returning reader reaches the publisher's cache afresh. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn chained_front_drops_the_source_when_unused() { let leaf = origin(1).produce(); @@ -12627,7 +12627,7 @@ mod tests { drop(group); drop(subscription); - moq_clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_none())) .await .expect("chained unused should resolve far below track::IDLE_LINGER") .expect("source closed"); @@ -12639,7 +12639,7 @@ mod tests { .subscribe(track::Subscription::default().with_max_delay(Duration::from_secs(3600))) .await .expect("resubscribe"); - moq_clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_some())) + kio::clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_some())) .await .expect("resubscribe should reach the leaf") .expect("source open"); @@ -12654,7 +12654,7 @@ mod tests { drop(group); drop(subscription); - moq_clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_none())) .await .expect("second chained unused should resolve far below track::IDLE_LINGER") .expect("source closed"); @@ -12667,11 +12667,11 @@ mod tests { let fetch = edge_resolved.track("video").unwrap().fetch_group(2, None); let mut fetch = std::pin::pin!(fetch); assert!(futures::poll!(fetch.as_mut()).is_pending(), "fetch should re-splice"); - moq_clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_some())) + kio::clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_some())) .await .expect("fetch should reach the leaf") .expect("source open"); - let mut group = moq_clock::timeout(Duration::from_secs(5), fetch) + let mut group = kio::clock::timeout(Duration::from_secs(5), fetch) .await .expect("re-spliced source should answer the fetch") .expect("fetch succeeds"); @@ -12681,7 +12681,7 @@ mod tests { /// A newer local source wins dispatch the moment it attaches, but one whose copy /// of the track carries different metadata is refused: the incumbent keeps /// serving, and the refusal is never retried once the incumbent leaves. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn incompatible_local_source_keeps_the_incumbent() { let producer = origin(1).produce(); @@ -12712,7 +12712,7 @@ mod tests { .create_track("video", track::Info::default().with_timescale(crate::Timescale::MICRO)) .unwrap(); for _ in 0..10 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } // Still spliced to the incumbent, still delivering. @@ -12759,7 +12759,7 @@ mod tests { /// A local newcomer takes over while its answer for "video" is pending, so the track /// drains the incumbent. The reader leaves: the incumbent's copy is dropped at once, /// like any unread track's, not held until the linger. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_unread_draining_track_releases_the_old_source() { let (producer, _server, _upstream, old, subscription) = remote_front().await; @@ -12767,13 +12767,13 @@ mod tests { let newcomer = producer.create_broadcast("room/alice").unwrap(); let mut handler = newcomer.requests(); newcomer.announce(Route::default().with_epoch(epoch())).unwrap(); - let _unanswered = moq_clock::timeout(Duration::from_secs(1), handler.requested_track()) + let _unanswered = kio::clock::timeout(Duration::from_secs(1), handler.requested_track()) .await .expect("the front asked the newcomer") .expect("request"); drop(subscription); - moq_clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) .await .expect("the draining source stays subscribed with nobody reading") .expect("open"); @@ -12783,7 +12783,7 @@ mod tests { /// (the park drops the incumbent's copy), a third source that also lacks the track /// takes over, and the reader returns: it gets an outcome rather than waiting on the /// dropped copy. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_returning_reader_is_not_stranded_on_a_dropped_copy() { let (producer, _server, upstream, old, mut subscription) = remote_front().await; @@ -12794,7 +12794,7 @@ mod tests { .publish("room/alice", Route::default().with_epoch(epoch())) .unwrap(); for _ in 0..10 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } let mut group = old.append_group().unwrap(); group.write_frame(crate::Timestamp::ZERO, b"draining".as_ref()).unwrap(); @@ -12804,7 +12804,7 @@ mod tests { drop(group); drop(subscription); - moq_clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) .await .expect("parked") .expect("open"); @@ -12813,14 +12813,14 @@ mod tests { .publish("room/alice", Route::default().with_epoch(epoch())) .unwrap(); for _ in 0..10 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } let mut again = resolved.track("video").unwrap().subscribe(None).await.unwrap(); let mut group = old.append_group().unwrap(); group.write_frame(crate::Timestamp::ZERO, b"after".as_ref()).unwrap(); group.finish().unwrap(); - let outcome = moq_clock::timeout(Duration::from_secs(5), async { + let outcome = kio::clock::timeout(Duration::from_secs(5), async { loop { match again.recv_group().await { Ok(Some(mut group)) => { @@ -12841,7 +12841,7 @@ mod tests { /// The reader leaves, parking the track. A fetch of a whole group the parked copy /// caches answers at once, without the front serving the copy again; an open group /// still waits on the front, and is served once the copy is back. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_parked_track_serves_whole_groups_from_its_copy() { let (producer, _server, _upstream, old, subscription) = remote_front().await; @@ -12849,7 +12849,7 @@ mod tests { let mut open = old.append_group().unwrap(); open.write_frame(crate::Timestamp::ZERO, b"open".as_ref()).unwrap(); drop(subscription); - moq_clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) .await .expect("parked") .expect("open"); @@ -12874,13 +12874,13 @@ mod tests { /// A new source takes over a parked track: a whole group its old copy caches is no /// longer served from that copy, but asked of the new route, which lacks it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_new_source_unparks_the_old_copy() { let (producer, _server, _upstream, old, subscription) = remote_front().await; let resolved = producer.consume().request_broadcast("room/alice", None).await.unwrap(); drop(subscription); - moq_clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(1), old.demand().until(|wanted| wanted.is_none())) .await .expect("parked") .expect("open"); @@ -12890,7 +12890,7 @@ mod tests { .unwrap(); let _video = newcomer.create_track("video", crate::track::Info::timed()).unwrap(); for _ in 0..10 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } let mut fetching = resolved.track("video").unwrap().fetch_group(0, None); @@ -12903,7 +12903,7 @@ mod tests { /// A newer local source's copy of "video" is refused for its metadata while the /// incumbent keeps serving: the refused copy is let go, not kept subscribed. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_refused_copy_is_not_kept_subscribed() { let producer = origin(1).produce(); @@ -12927,7 +12927,7 @@ mod tests { .create_track("video", track::Info::default().with_timescale(crate::Timescale::MICRO)) .unwrap(); for _ in 0..10 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } assert!(!incompatible.demand().is_used(), "the refused copy is still subscribed"); @@ -12940,7 +12940,7 @@ mod tests { /// As above, the newer source's copy was refused and the incumbent keeps serving. /// Then both withdraw and the front ends: the track in flight carries on with the /// incumbent, never the refused copy. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn the_end_never_feeds_a_refused_copy() { let producer = origin(1).produce(); @@ -12965,7 +12965,7 @@ mod tests { .create_track("video", track::Info::default().with_timescale(crate::Timescale::MICRO)) .unwrap(); for _ in 0..10 { - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; } first.unannounce(); @@ -12996,7 +12996,7 @@ mod tests { /// The track drains the incumbent while a newer source's answer is pending, then both /// withdraw and the front ends: the track carries on with the incumbent's copy rather /// than the unanswered one. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn the_end_keeps_the_copy_still_serving() { let producer = origin(1).produce(); @@ -13017,7 +13017,7 @@ mod tests { let second = producer.create_broadcast("room/alice").unwrap(); let mut handler = second.requests(); second.announce(Route::default().with_epoch(epoch())).unwrap(); - let request = moq_clock::timeout(Duration::from_secs(1), handler.requested_track()) + let request = kio::clock::timeout(Duration::from_secs(1), handler.requested_track()) .await .expect("the front asked the newcomer") .expect("request"); @@ -13038,7 +13038,7 @@ mod tests { assert_eq!(&group.read_frame().await.unwrap().unwrap().payload[..], b"still"); } - #[moq_clock::test] + #[kio::test] async fn multiple_scopes_present_one_broad_prefix() { let producer = origin(1).produce(); let _a = producer.announce("", Route::default()).unwrap(); @@ -13049,7 +13049,7 @@ mod tests { announced.assert_next_wait(); } - #[moq_clock::test] + #[kio::test] async fn scope_accepts_every_pattern_union() { let producer = origin(1).produce(); @@ -13085,7 +13085,7 @@ mod tests { assert_eq!(producer.scope("", &mixed).unwrap().allowed(), mixed); } - #[moq_clock::test] + #[kio::test] async fn route_table_prunes_to_empty() { let producer = origin(1).produce(); let consumer = producer.consume(); @@ -13126,7 +13126,7 @@ mod tests { /// A session handed an `origin::Producer` drops it once it has its own /// handles, so the driver must keep running while a published broadcast /// lives, and finish once the last one is gone. - #[moq_clock::test] + #[kio::test] async fn a_published_broadcast_keeps_the_driver_running() { let (producer, mut driver) = Producer::new(Config::new(origin(1))); let waiter = kio::Waiter::noop(); @@ -13142,11 +13142,11 @@ mod tests { /// A handler holding only its `Requests` keeps serving once every producer /// handle drops, and the driver finishes once the handler is gone too. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_dynamic_keeps_the_driver_running() { let (producer, driver) = Producer::new(Config::new(origin(1))); - let run = moq_clock::sim::spawn(crate::time::run(driver)); + let run = kio::clock::sim::spawn(crate::time::run(driver)); let consumer = producer.consume(); let server = producer.requests_route("room", Route::default()).unwrap(); drop(producer); @@ -13160,7 +13160,7 @@ mod tests { drop(resolved); drop(source); drop(server); - moq_clock::timeout(Duration::from_secs(5), run) + kio::clock::timeout(Duration::from_secs(5), run) .await .expect("driver must finish once the dynamic is gone") .unwrap(); @@ -13169,11 +13169,11 @@ mod tests { /// A reader still on a retracted broadcast's track keeps its front draining, but /// never keeps the driver from finishing once nothing owns the origin. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_retracted_reader_never_holds_the_driver() { let (producer, driver) = Producer::new(Config::new(origin(1))); - let run = moq_clock::sim::spawn(crate::time::run(driver)); + let run = kio::clock::sim::spawn(crate::time::run(driver)); let consumer = producer.consume(); let broadcast = producer.publish("room/alice", Route::default()).unwrap(); let track = broadcast.create_track("video", crate::track::Info::timed()).unwrap(); @@ -13184,7 +13184,7 @@ mod tests { settle(|| resolved.is_closed()).await; drop(broadcast); drop(producer); - moq_clock::timeout(Duration::from_secs(5), run) + kio::clock::timeout(Duration::from_secs(5), run) .await .expect("driver must finish once the producers are gone") .unwrap(); @@ -13194,11 +13194,11 @@ mod tests { /// A subscriber that asked before the retraction but was not polled yet still finds /// the copy after the origin is orphaned and its driver finishes. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_orphaned_front_keeps_the_copy_for_a_pending_subscriber() { let (producer, driver) = Producer::new(Config::new(origin(1))); - let run = moq_clock::sim::spawn(crate::time::run(driver)); + let run = kio::clock::sim::spawn(crate::time::run(driver)); let consumer = producer.consume(); let broadcast = producer.publish("room/alice", Route::default()).unwrap(); let mut track = broadcast.create_track("video", crate::track::Info::timed()).unwrap(); @@ -13210,7 +13210,7 @@ mod tests { settle(|| resolved.is_closed()).await; drop(broadcast); drop(producer); - moq_clock::timeout(Duration::from_secs(5), run) + kio::clock::timeout(Duration::from_secs(5), run) .await .expect("driver must finish once the producers are gone") .unwrap(); @@ -13223,7 +13223,7 @@ mod tests { /// A track whose last reader leaves as its broadcast ends, before the front parks it, /// lets go of its copy: the source is not kept subscribed for nobody. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_track_unread_as_its_broadcast_ends_releases_its_source() { let producer = origin(1).produce(); @@ -13232,7 +13232,7 @@ mod tests { let track = broadcast.create_track("video", crate::track::Info::timed()).unwrap(); let resolved = consumer.request_broadcast("room/alice", None).await.expect("resolves"); let sub = resolved.track("video").unwrap().subscribe(None).await.unwrap(); - moq_clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_some())) + kio::clock::timeout(Duration::from_secs(1), track.demand().until(|wanted| wanted.is_some())) .await .expect("the front subscribed the source") .unwrap(); @@ -13243,13 +13243,13 @@ mod tests { drop(broadcast); settle(|| resolved.is_closed()).await; - moq_clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_none())) + kio::clock::timeout(Duration::from_secs(5), track.demand().until(|wanted| wanted.is_none())) .await .expect("the ended copy must not keep the source subscribed") .unwrap(); } - #[moq_clock::test] + #[kio::test] async fn source_selection_leases_survive_reprices_but_never_revive_pending_work() { let producer = origin(1).produce(); let broad = producer @@ -13283,7 +13283,7 @@ mod tests { /// The answering lease outlives a withdrawal, since the peer still answers for the /// instance it retracted, and ends once another instance takes the path. - #[moq_clock::test] + #[kio::test] async fn source_selection_answering_ends_only_on_a_replacement() { let producer = origin(1).produce(); let path = Path::from_static("room/a"); @@ -13318,7 +13318,7 @@ mod tests { assert!(answering.is_closed()); } - #[moq_clock::test] + #[kio::test] async fn source_selection_unregisters_without_retaining_the_source() { let producer = origin(1).produce(); let route = producer @@ -13333,7 +13333,7 @@ mod tests { assert_eq!(table.routes.root.watches_below, 0); } - #[moq_clock::test] + #[kio::test] async fn watch_wakes_only_for_covering_changes() { let producer = origin(1).produce(); let waiter = kio::Waiter::noop(); @@ -13374,7 +13374,7 @@ mod tests { assert_eq!(table.routes.root.watches_below, 0); } - #[moq_clock::test] + #[kio::test] async fn a_discarded_front_task_unregisters_its_watch() { let (producer, _driver) = Producer::new(Config { hop: origin(1), @@ -13390,7 +13390,7 @@ mod tests { let _pending = consumer.request_broadcast("room/a", None); } - #[moq_clock::test] + #[kio::test] async fn published_names_refuse_navigation_segments() { let producer = origin(1).produce(); for path in ["room/./cam", "room/../cam", ".", ".."] { @@ -13406,7 +13406,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn create_broadcast_refuses_a_path_no_pattern_can_spell() { let producer = origin(1).produce(); @@ -13423,7 +13423,7 @@ mod tests { )); } - #[moq_clock::test] + #[kio::test] async fn scope_empty_union_grants_nothing() { let producer = origin(1).produce(); @@ -13435,7 +13435,7 @@ mod tests { )); } - #[moq_clock::test] + #[kio::test] async fn scope_nests_and_rebases_roots() { let producer = origin(1).produce(); @@ -13460,7 +13460,7 @@ mod tests { broadcast.close(); } - #[moq_clock::test] + #[kio::test] async fn scope_intersects_and_rebases_arbitrary_grants() { let producer = origin(1).produce(); let rooms = producer @@ -13490,7 +13490,7 @@ mod tests { drop(broadcast); } - #[moq_clock::test] + #[kio::test] async fn wildcard_scope_filters_announcements_and_reports_captures() { let producer = origin(1).produce(); let consumer = producer @@ -13523,7 +13523,7 @@ mod tests { drop(alice); } - #[moq_clock::test] + #[kio::test] async fn local_broadcast_wins_announcement_ties() { let producer = origin(1).produce(); let remote = producer.announce("room/alice", Route::default().with_cost(9)).unwrap(); @@ -13546,7 +13546,7 @@ mod tests { /// so a bogus peer sorts last, not first. The ceiling is the largest cost a /// varint can carry, so whatever a peer advertises, the sum we forward still /// encodes. - #[moq_clock::test] + #[kio::test] async fn cost_charge_saturates() { assert_eq!(Cost::new(4).charged(5), Cost::new(9)); assert_eq!(Cost::new(u64::MAX).charged(10), Cost::new(MAX_COST)); @@ -13568,7 +13568,7 @@ mod tests { /// A publisher that stalls with a group still open runs no write path, so the /// track's own write-driven expiry never fires and a reader parked in that group /// is never told. The driver's wall-clock sweep is the bound. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn stalled_publisher_open_group_is_reclaimed() { let expiry = Duration::from_secs(1); @@ -13589,7 +13589,7 @@ mod tests { // Production goes quiet: nothing writes to this track again. Bounded so a // regression fails rather than parking forever, which is the bug itself. Time // is simulated, so the wait costs nothing. - let reclaimed = moq_clock::timeout(Duration::from_secs(60), reading.read_frame()).await; + let reclaimed = kio::clock::timeout(Duration::from_secs(60), reading.read_frame()).await; assert!( matches!(reclaimed, Ok(Err(Error::Old))), "the sweep must reclaim an idle open group and surface the gap, got {reclaimed:?}" @@ -13598,7 +13598,7 @@ mod tests { /// Reclamation is the pool's policy, not the origin's: a pool with no expiry /// window keeps idle content until byte pressure takes it, sweep or no sweep. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn sweep_respects_a_disabled_expiry() { let origin = Config { @@ -13616,7 +13616,7 @@ mod tests { let mut reading = stalled.consume(); assert!(reading.read_frame().await.unwrap().is_some()); - moq_clock::sim::advance(Duration::from_secs(3600)).await; + kio::clock::sim::advance(Duration::from_secs(3600)).await; assert!( reading.read_frame().now_or_never().is_none(), @@ -13626,7 +13626,7 @@ mod tests { /// A draining cost still has to fit the wire, since the route keeps being /// announced downstream while it drains. - #[moq_clock::test] + #[kio::test] async fn drain_cost_is_encodable() { use crate::coding::Encode; diff --git a/rs/moq-net/src/model/resume.rs b/rs/moq-net/src/model/resume.rs index 5c5c324445e..99f5ab167d0 100644 --- a/rs/moq-net/src/model/resume.rs +++ b/rs/moq-net/src/model/resume.rs @@ -2209,7 +2209,7 @@ mod test { } /// A later stream header is not a verdict on the group held from a failed route. - #[moq_clock::test] + #[kio::test] async fn a_failed_route_waits_for_a_reordered_group_header() { let waiter = kio::Waiter::noop(); for arrives in [true, false] { @@ -2251,7 +2251,7 @@ mod test { assert_eq!(read(&mut held), Some(b"continued".to_vec())); assert_eq!(read(&mut held), None); } else { - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!(matches!( held.poll_read_frame(&waiter), Poll::Ready(Err(Error::NotFound)) @@ -2276,7 +2276,7 @@ mod test { ); } - #[moq_clock::test] + #[kio::test] async fn a_declared_end_survives_a_swap_before_it_is_polled() { let routes = Producer::new(); let logical = logical(&routes); @@ -2300,7 +2300,7 @@ mod test { ); } - #[moq_clock::test] + #[kio::test] async fn copies_must_agree_on_the_declared_end() { for next in [Position::group(5), Position { group: 4, frame: 3 }, Position::group(6)] { let routes = Producer::new(); @@ -2330,7 +2330,7 @@ mod test { } /// A copy that delivers past an end another copy declared contradicts it. - #[moq_clock::test] + #[kio::test] async fn content_past_the_declared_end_refuses_the_track() { for datagram in [false, true] { let routes = Producer::new(); @@ -2366,7 +2366,7 @@ mod test { /// A mid-group end another copy declared caps the group it falls in, even for frames /// that arrive after the group was handed out. - #[moq_clock::test] + #[kio::test] async fn a_mid_group_end_caps_another_copys_group() { let routes = Producer::new(); let logical = logical(&routes); @@ -2395,7 +2395,7 @@ mod test { } /// An end below a group a copy handed out or holds claims other content. - #[moq_clock::test] + #[kio::test] async fn an_end_below_a_seen_group_refuses_the_track() { for handed_out in [false, true] { let routes = Producer::new(); @@ -2419,7 +2419,7 @@ mod test { /// A mid-group end learned late, below a frame or datagram object already seen, claims /// other content. - #[moq_clock::test] + #[kio::test] async fn a_late_mid_group_end_below_a_seen_object_refuses_the_track() { for datagram in [false, true] { let routes = Producer::new(); @@ -2471,7 +2471,7 @@ mod test { } /// The newest datagram handed out bounds a late end after the budget forgets its identity. - #[moq_clock::test] + #[kio::test] async fn an_end_below_an_expired_datagram_refuses_the_track() { let routes = Producer::new(); let logical = logical(&routes); @@ -2484,7 +2484,7 @@ mod test { routes.serve(b.consume()); b.insert_datagram(1, ts(1), b"d".as_ref()).unwrap(); assert!(sub.poll_recv_datagram(&kio::Waiter::noop()).is_ready()); - moq_clock::sleep(Duration::from_secs(2)).await; + kio::clock::sleep(Duration::from_secs(2)).await; assert!(sub.poll_recv_datagram(&kio::Waiter::noop()).is_pending()); assert_eq!(copies(&routes), 1); b.finish_at(Position::group(5)).unwrap(); @@ -2494,7 +2494,7 @@ mod test { )); } - #[moq_clock::test] + #[kio::test] async fn route_flaps_keep_one_copy_per_distinct_route() { let routes = Producer::new(); let logical = logical(&routes); @@ -2523,7 +2523,7 @@ mod test { /// A returning route resumes where a fresh copy would: what it buffered while replaced, /// below what another route already handed out, is not handed out again. - #[moq_clock::test] + #[kio::test] async fn a_returning_route_resumes_at_the_readers_newest() { let routes = Producer::new(); let logical = logical(&routes); @@ -2546,7 +2546,7 @@ mod test { drop(held); } - #[moq_clock::test] + #[kio::test] async fn a_replaced_copy_is_not_kept_for_a_gap_outside_the_window() { let routes = Producer::new(); let logical = logical(&routes); @@ -2652,7 +2652,7 @@ mod test { /// Routes that close without concluding read like a conclusion: a reader stalled /// mid-group parks on the copy it is reading rather than polling the closed routes /// forever, and finishes the group from that copy. - #[moq_clock::test] + #[kio::test] async fn a_stalled_group_parks_when_the_routes_close() { let routes = Producer::new(); let logical = logical(&routes); @@ -2937,7 +2937,7 @@ mod test { /// A run the serving copy gave up waits while a copy it replaced may still deliver it /// under its bound, and goes out once that copy is past the reader's budget. - #[moq_clock::test] + #[kio::test] async fn a_drop_waits_while_a_replaced_copy_may_still_deliver_it() { let routes = Producer::new(); let logical = logical(&routes); @@ -2960,7 +2960,7 @@ mod test { assert_eq!(drain(&mut sub, false), [3]); assert_eq!(dropped(&mut sub), []); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!(dropped(&mut sub), [(2..3, StreamError::NotFound)]); write(&a, 2); assert_eq!(drain(&mut sub, false), Vec::::new()); @@ -3610,7 +3610,7 @@ mod test { /// A group the old route was still sending when the new route took over arrives after the /// new copy's first group, once polled: the old copy stays while it may still land, and /// goes once its publisher drops it or the reader's budget passes. - #[moq_clock::test] + #[kio::test] async fn an_arrival_reader_gets_a_group_still_in_flight_on_the_replaced_route() { for outcome in ["lands", "dropped", "expired"] { let routes = Producer::new(); @@ -3631,7 +3631,7 @@ mod test { match outcome { "lands" => {} "dropped" => a.drop_groups(1..2, StreamError::NotFound), - _ => moq_clock::sleep(Duration::from_secs(1)).await, + _ => kio::clock::sleep(Duration::from_secs(1)).await, } if outcome != "lands" { assert_eq!(drain(&mut sub, false), Vec::::new()); @@ -4492,7 +4492,7 @@ mod test { /// arrives, so only the deadline wake can release the reader: against a cold route, and /// against one whose copy already caches groups past the held one, so a cursor that /// skips ahead cannot hide the stall. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_untimed_group_no_route_continues_is_given_up_by_wall_clock() { let untimed = || { @@ -4645,7 +4645,7 @@ mod test { assert_eq!(routes.subscription(demand, 1).start(), Some(10)); } - #[moq_clock::test] + #[kio::test] async fn a_replacement_delivers_unseen_datagrams_below_the_newest_sequence() { let routes = Producer::new(); let front = logical(&routes); diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 740a498034d..224a2a7672d 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -8399,7 +8399,7 @@ mod test { /// An empty group raises the largest at its head, so its first frame names nothing newer. #[cfg(feature = "async")] - #[moq_clock::test] + #[kio::test] async fn largest_streams_groups_and_frames_and_coalesces() { let producer = track_producer("test", Info::default()); let mut subscriber = producer.subscribe(replay()); @@ -8578,7 +8578,7 @@ mod test { } #[cfg(feature = "async")] - #[moq_clock::test] + #[kio::test] async fn largest_starts_with_the_sources_report() { let producer = track_producer("test", Info::default()); let mut subscriber = producer.subscribe(replay()); @@ -9211,7 +9211,7 @@ mod test { } /// A cached observer must not keep an unfinished writer alive or serve its dead copy. - #[moq_clock::test] + #[kio::test] async fn dropped_group_writer_aborts_and_releases_its_cached_copy() { let pool = cache::Pool::unbounded(); let producer = track_producer_pooled("test", pool.clone()); @@ -9234,7 +9234,7 @@ mod test { assert_eq!(pool.used(), 0); } - #[moq_clock::test] + #[kio::test] async fn dropped_group_writer_is_absent_and_its_sequence_can_be_recreated() { let producer = track_producer("test", Info::timed()); let mut group = producer.create_group(group::Info { sequence: 3 }).unwrap(); @@ -9266,7 +9266,7 @@ mod test { )); } - #[moq_clock::test] + #[kio::test] async fn dropped_group_writer_preserves_the_committed_resume_position() { let producer = track_producer("test", Info::timed()); let consumer = producer.consume(); @@ -9750,7 +9750,7 @@ mod test { /// A group whose frames outlive `max_age` is aged out when the next group starts, but /// a subscriber that already drained it must still see the clean end of group. Otherwise a /// track with long groups (a per-minute rollup, say) fails its readers at every boundary. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn aging_out_a_finished_group_keeps_the_clean_end() { let producer = track_producer("test", Info::timed()); @@ -9773,7 +9773,7 @@ mod test { /// An actively-read group is not expired out from under its reader: every frame /// read restarts the retention clock. A group nobody reads still ages out on /// schedule, so reclamation stays intact. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn active_reader_survives_expiry() { let producer = track_producer("test", Info::timed()); @@ -9811,7 +9811,7 @@ mod test { /// alive: the batch is filled (and stamped) once per `Prefetch::CAP` frames, /// which bounds frames, not elapsed time, so a slow `read_frame` reader has to /// re-stamp on a time bound between refills. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn slow_prefetch_reader_survives_expiry() { let producer = track_producer("test", Info::timed()); @@ -9840,7 +9840,7 @@ mod test { /// Receiving a group is itself a cache access: a subscriber that takes /// delivery just before the group would age out still gets to read it a full /// window later. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn delivery_restarts_the_expiry_clock() { let producer = track_producer("test", Info::timed()); @@ -9936,7 +9936,7 @@ mod test { /// Re-offering a parked group (once the cap rises) is a delivery: it restarts /// the expiry clock so the subscriber gets to read what it was just handed. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn parked_reoffer_restarts_the_expiry_clock() { let producer = track_producer("test", Info::timed()); @@ -10297,7 +10297,7 @@ mod test { /// A read parked on a superseded group is released by the wall clock alone: nothing is /// written after its successor arrives, so no write could wake it. That holds whether a /// driver collected the pool before the read parked or only after. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_parked_read_wakes_at_its_wall_deadline() { for (info, primed) in [Info::default(), Info::timed()] @@ -10346,7 +10346,7 @@ mod test { /// A successor whose header landed but whose first frame never does still starts the /// wall clock, so a relay ages the group before it as the origin does. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_frameless_successor_ages_its_predecessor() { for info in [Info::default(), Info::timed()] { @@ -11059,7 +11059,7 @@ mod test { assert_eq!(drain(&mut subscriber), vec![1]); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_handed_out_group_expires_while_its_first_frame_is_stalled() { let mut producer = track_producer("test", Info::timed()); @@ -11067,8 +11067,8 @@ mod test { let _writer_1 = producer.append_group().unwrap(); let mut stalled = subscriber.recv_group().await.unwrap().expect("stalled group"); - let pending = moq_clock::sim::spawn(async move { stalled.read_frame().await }); - moq_clock::sim::yield_now().await; + let pending = kio::clock::sim::spawn(async move { stalled.read_frame().await }); + kio::clock::sim::yield_now().await; assert!( !pending.is_finished(), "the empty live edge still waits for its first frame" @@ -11086,7 +11086,7 @@ mod test { /// to be woken by it. The conviction needs a group beyond the held one's successor: /// a group is bounded by where its successor begins, so the successor itself never /// proves it stale. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_handed_out_group_wakes_when_a_newer_group_gets_its_first_timestamp() { let mut producer = track_producer("test", Info::timed()); @@ -11102,8 +11102,8 @@ mod test { assert!(held.read_frame().await.unwrap().is_some()); let mut live = producer.append_group().unwrap(); - let pending = moq_clock::sim::spawn(async move { held.read_frame().await }); - moq_clock::sim::yield_now().await; + let pending = kio::clock::sim::spawn(async move { held.read_frame().await }); + kio::clock::sim::yield_now().await; assert!(!pending.is_finished(), "the newer group has no timestamp yet"); // 2s edge against group 0's 1s reach: a full second past the budget. @@ -11112,7 +11112,7 @@ mod test { bytes::Bytes::from_static(b"live"), ) .unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; assert!(pending.is_finished(), "the new presentation edge wakes the held reader"); // Drained but never finished, so the budget fails the group. @@ -11603,7 +11603,7 @@ mod test { /// A frameless group whose stream ends with no frame, cleanly or reset, ends its readers /// with it, and the track's end follows. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_frameless_group_that_ends_empty_ends_its_readers() { for abort in [false, true] { @@ -11621,7 +11621,7 @@ mod test { true => group.abort(Error::Cancel).unwrap(), false => group.finish().unwrap(), } - moq_clock::timeout(Duration::from_secs(1), next) + kio::clock::timeout(Duration::from_secs(1), next) .await .expect("the end wakes the reader") }; @@ -11642,7 +11642,7 @@ mod test { /// and the next group's first frame are separate events and the wire does not order /// them. A zero budget gives up there, and the group fails with [`Error::Old`] since /// its producer never finished it, but only after the reader took every frame. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn real_time_reads_a_live_stream_without_truncating_it() { let producer = track_producer("test", Info::timed()); @@ -11709,7 +11709,7 @@ mod test { } /// Decode-order B-frames cannot rewind the presentation edge and re-admit an old group. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_reordered_tail_keeps_the_group_pts_drift_verdict() { for reordered in [false, true] { @@ -11751,7 +11751,7 @@ mod test { /// /// Measuring from the group's first frame instead makes the drift 2000ms, so a /// budget shorter than one GOP would drop the tail of every GOP. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_budget_is_measured_from_the_readers_position() { let producer = track_producer("test", Info::timed()); @@ -11797,7 +11797,7 @@ mod test { /// A drained group the budget gives up on fails with [`Error::Old`] on every probe, /// including [`group::Consumer::finished`]: the producer never finished it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_expired_group_stays_old_when_probed_again() { let mut producer = track_producer("test", Info::timed()); @@ -11809,13 +11809,13 @@ mod test { let mut group = subscriber.recv_group().await.unwrap().expect("group"); assert!(group.read_frame().await.unwrap().is_some()); - let probes = moq_clock::sim::spawn(async move { + let probes = kio::clock::sim::spawn(async move { let first = group.read_frame().await; let second = group.read_frame().await; let finished = group.finished().await; (first, second, finished) }); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; append_at(&mut producer, 1000); @@ -11825,7 +11825,7 @@ mod test { assert!(matches!(finished, Err(Error::Old)), "never finished: {finished:?}"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_drained_group_finishes_cleanly_after_the_live_edge_advances() { let mut producer = track_producer("test", Info::timed()); @@ -11840,7 +11840,7 @@ mod test { assert!(group.read_frame().await.unwrap().is_none()); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_handed_out_partial_frame_expires_while_its_payload_is_stalled() { let mut producer = track_producer("test", Info::timed()); @@ -11860,8 +11860,8 @@ mod test { frame.read_chunk().await.unwrap(), Some(bytes::Bytes::from_static(b"old")) ); - let pending = moq_clock::sim::spawn(async move { frame.read_chunk().await }); - moq_clock::sim::yield_now().await; + let pending = kio::clock::sim::spawn(async move { frame.read_chunk().await }); + kio::clock::sim::yield_now().await; assert!(!pending.is_finished(), "the partial payload is still stalled"); elapse(&producer, Duration::from_secs(1)); @@ -12311,7 +12311,7 @@ mod test { )); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetched_group_keeps_its_budget_while_reading() { let mut producer = track_producer("test", Info::timed()); @@ -12324,8 +12324,8 @@ mod test { let mut fetched = consumer.fetch_group(0, options).await.unwrap(); assert!(fetched.read_frame().await.unwrap().is_some()); - let pending = moq_clock::sim::spawn(async move { fetched.read_frame().await }); - moq_clock::sim::yield_now().await; + let pending = kio::clock::sim::spawn(async move { fetched.read_frame().await }); + kio::clock::sim::yield_now().await; elapse(&producer, Duration::from_secs(1)); append_at(&mut producer, 1000); append_at(&mut producer, 2000); @@ -12416,7 +12416,7 @@ mod test { /// A one-shot fetch populates the shared cache but never the live arrival cursor, /// so it cannot make content available to a subscription look stale. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetched_group_is_not_a_live_drift_edge() { let mut producer = track_producer("test", Info::timed()); @@ -12551,7 +12551,7 @@ mod test { /// A group handed out before the ranges moved above it is judged against the new run, /// not a cached group below its start: here group 1 would put group 0 18s behind the /// edge, past the budget, where the run's own group 10 puts it 9s behind. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_held_group_is_judged_against_the_moved_run() { let at = |millis| Timestamp::from_millis(millis).unwrap(); @@ -12570,8 +12570,8 @@ mod test { group.finish().unwrap(); } - let pending = moq_clock::sim::spawn(async move { held.read_frame().await }); - moq_clock::sim::yield_now().await; + let pending = kio::clock::sim::spawn(async move { held.read_frame().await }); + kio::clock::sim::yield_now().await; assert!(!pending.is_finished(), "group 0 is within the budget of its run"); } @@ -12699,7 +12699,7 @@ mod test { /// Ranges replaced through a [`Control`] republish what a held group is judged against /// at once, before the cursor next reads: group 0 is judged against the run's own /// group 10, not group 1, which the new ranges never read. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_control_update_moves_the_run_a_held_group_is_judged_against() { let at = |millis| Timestamp::from_millis(millis).unwrap(); @@ -12718,8 +12718,8 @@ mod test { group.finish().unwrap(); } - let pending = moq_clock::sim::spawn(async move { held.read_frame().await }); - moq_clock::sim::yield_now().await; + let pending = kio::clock::sim::spawn(async move { held.read_frame().await }); + kio::clock::sim::yield_now().await; assert!(!pending.is_finished(), "group 0 is within the budget of its run"); drop(subscriber); } @@ -13066,7 +13066,7 @@ mod test { /// Aborting a track also aborts a fetched head still being written, so its reader ends /// with the track's error rather than waiting on a fetch that can no longer land. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn abort_ends_an_open_fetched_head() { let producer = track_producer("test", Info::timed()); @@ -13395,7 +13395,7 @@ mod test { assert!(done.is_none(), "track completes once the boundary is reached"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn readers_end_at_the_boundary_with_missing_lower_groups() { let mut producer = track_producer("test", Info::timed()); @@ -13426,7 +13426,7 @@ mod test { /// A received copy's end holds readers at a hole below it, since a lower group's stream /// may arrive after a higher one, until the hole fills or its grace passes. The last /// producer going ends them regardless. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_pending_tail_holds_readers_at_a_hole() { let mut producer = track_producer("test", None); @@ -13474,7 +13474,7 @@ mod test { /// The grace alone ends a reader parked at a hole, with no write to wake it: below an /// arrival it runs from that arrival, and above the last one from the declared end. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_parked_reader_wakes_when_the_tail_grace_passes() { // The subscription's max delay is the grace. @@ -13654,7 +13654,7 @@ mod test { /// A fetched copy of a group the live feed still owes never reaches an arrival-order /// reader, so it does not fill the hole: the reader waits for the live group. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_fetched_group_does_not_fill_a_pending_tail() { let mut producer = track_producer("test", None); @@ -13678,7 +13678,7 @@ mod test { /// An abort ends the wait for a pending tail. A group the tail still owed was cut off, /// so readers get the abort rather than a clean end without it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_abort_errors_a_pending_tail_short_of_a_group() { let mut producer = track_producer("test", None); @@ -13700,7 +13700,7 @@ mod test { /// A reader that got every group ends cleanly, even when the track aborts before the /// reader polls past the last one. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_abort_after_a_full_tail_ends_cleanly() { let mut producer = track_producer("test", None); @@ -13723,7 +13723,7 @@ mod test { /// A gap the grace already gave up on was lost before the abort, not cut off by it, so /// readers end cleanly. Within the grace, the same abort errors them. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_abort_past_the_grace_ends_a_pending_tail_cleanly() { for (waited, ended) in [(ledger::GRACE / 2, false), (ledger::GRACE, true)] { @@ -13800,7 +13800,7 @@ mod test { /// The wire's end can land after the highest group, with lower groups still owed. A /// reader already past that group stays held at the hole: the end never shows without /// its pending tail. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn an_end_after_the_highest_group_holds_the_reader() { let mut producer = track_producer("test", None); @@ -14840,7 +14840,7 @@ mod test { ); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn group_ranges_preserve_the_floor_when_the_cap_changes() { let producer = track_producer("test", Info::timed()); @@ -15120,7 +15120,7 @@ mod test { assert!(matches!(producer.append_group(), Err(Error::BoundsExceeded(_)))); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_cache_hit() { let producer = track_producer("test", Info::timed()); @@ -15145,7 +15145,7 @@ mod test { assert!(dynamic.poll_requested_fill_group(&kio::Waiter::noop()).is_pending()); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_miss_signals_dynamic() { let producer = track_producer("test", Info::timed()); @@ -15179,7 +15179,7 @@ mod test { assert_eq!(&g.read_frame().await.unwrap().unwrap().payload[..], b"hi"); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_miss_rejects() { let producer = track_producer("test", Info::timed()); @@ -15199,7 +15199,7 @@ mod test { assert!(fetch.read().is_empty()); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_miss_drop_rejects() { let producer = track_producer("test", Info::timed()); @@ -15219,7 +15219,7 @@ mod test { /// A request stays wanted while any joined fetch waits, and once the last leaves it /// is withdrawn: a later fetch starts a fresh request instead of joining it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_request_unused_once_every_fetch_leaves() { let producer = track_producer("test", Info::timed()); @@ -15253,7 +15253,7 @@ mod test { /// A fetch abandoned before any handler took it is withdrawn from the queue too, so /// no handler serves it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_abandoned_while_queued_never_reaches_the_handler() { let producer = track_producer("test", Info::timed()); @@ -15268,7 +15268,7 @@ mod test { /// The withdrawal happens as the last caller leaves, not when the handler notices: a /// fetch arriving before the handler drops the abandoned request is not failed with it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_after_the_last_caller_left_is_not_dropped() { let producer = track_producer("test", Info::timed()); @@ -15298,7 +15298,7 @@ mod test { /// A handler that accepts after every caller left still caches the group, so a fetch /// that queued a fresh request meanwhile resolves from it and that request is moot. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_accept_after_withdrawal_caches_the_group() { let producer = track_producer("test", Info::timed()); @@ -15343,7 +15343,7 @@ mod test { /// A fetch that hits the cache holds the group until polled, so a handler that aborts /// the group once nobody wants it (an abandoned upstream fetch) leaves it alone. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_hit_keeps_the_group_wanted() { let producer = track_producer("test", Info::timed()); @@ -15372,7 +15372,7 @@ mod test { } /// A bounded FIN is local to its request, never proof that the original group ended. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn bounded_transport_copies_never_answer_whole_fetches() { let producer = track_producer("test", Info::timed()); @@ -15431,7 +15431,7 @@ mod test { } /// Tail starts replace one backfill slot rather than retaining a copy per peer range. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn bounded_tail_refills_coalesce_behind_a_live_copy() { let producer = track_producer("test", Info::timed()); @@ -15473,7 +15473,7 @@ mod test { /// A bounded fill that a later, disjoint one displaces from the cache still answers the /// fetch that asked for it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_displaced_bounded_fill_still_answers_its_fetch() { let producer = track_producer("test", Info::timed()); @@ -15508,7 +15508,7 @@ mod test { /// A copy cut short at the back never displaces a fetched one that reaches the group's /// end, so whole-group readers keep it, and it still answers its own fetch. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_bounded_fill_never_displaces_a_whole_tail() { let producer = track_producer("test", Info::timed()); @@ -15548,7 +15548,7 @@ mod test { /// A track abort ends every copy still being written, including one the cache never held /// or has since displaced: its reader gets the abort and its writer fails. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_track_abort_ends_uncached_copies() { let producer = track_producer("test", Info::timed()); @@ -15605,7 +15605,7 @@ mod test { /// A track abort keeps a finished bounded copy for the reader still draining it, as it /// does a finished whole group. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_track_abort_keeps_a_finished_bounded_copy() { let producer = track_producer("test", Info::timed()); @@ -15638,7 +15638,7 @@ mod test { /// A finished bounded copy below the declared end is nothing in flight, so an abort after /// the end is reached still ends the track cleanly. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_finished_bounded_copy_lets_the_end_settle() { let mut producer = track_producer("test", Info::timed()); @@ -15676,7 +15676,7 @@ mod test { /// A copy cut short at the back never answers a whole-group reader. A live group the /// publisher cut is still handed out as that cut, and one it cancelled stays a hole, /// whatever bounded copy of it remains. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_back_cut_copy_never_answers_a_whole_group_reader() { let producer = track_producer("test", Info::timed()); @@ -15726,7 +15726,7 @@ mod test { } /// Queued ranges widen before dispatch; a taken cap does not promise an unseen suffix. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn bounded_fetches_widen_before_dispatch_and_split_after() { let producer = track_producer("test", Info::timed()); @@ -15748,7 +15748,7 @@ mod test { /// An accepted group starts where its request did before anyone can see it, so a /// wider fetch arriving before the handler writes misses instead of being handed a /// reader that would skip the head it asked for. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn accepted_group_starts_at_the_request() { let producer = track_producer("test", Info::timed()); @@ -15781,7 +15781,7 @@ mod test { /// Once a group nobody wanted is aborted, a later fetch misses rather than reading /// the abort, and queues a fresh request. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_misses_an_abandoned_group() { let producer = track_producer("test", Info::timed()); @@ -15808,7 +15808,7 @@ mod test { assert!(retry.await.unwrap().read_frame().await.unwrap().is_none()); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_reject_does_not_poison_retry() { let producer = track_producer("test", Info::timed()); @@ -15843,7 +15843,7 @@ mod test { /// A group cached from a frame-bounded subscription starts partway in. Serving it to /// someone who asked for the whole group would silently hand back a tail, so it is a /// miss and the fetch goes upstream instead. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_ignores_a_group_that_starts_too_late() { let producer = track_producer("test", Info::timed()); @@ -15898,7 +15898,7 @@ mod test { /// A fetch for the head of a live group the feed started partway into keeps that group /// in arrival order: subscribers get the fetched copy while it lasts, and the live /// group again once the fetch is gone. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_fills_the_head_of_a_live_group() { let producer = track_producer("test", Info::timed()); @@ -15943,7 +15943,7 @@ mod test { } /// A refused mid-group end caps none of its group's copies, even one that fit under it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_refused_end_leaves_every_copy_uncapped() { let mut producer = track_producer("test", Info::timed()); @@ -16004,7 +16004,7 @@ mod test { /// A fetched head still writing holds the largest stream open after the live copy /// aborted and the track ended, so a later head frame is reported rather than lost. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_fetched_head_holds_the_largest_open() { let producer = track_producer("test", Info::timed()); @@ -16045,7 +16045,7 @@ mod test { assert_eq!(reader.poll_largest(&noop), Poll::Ready(None)); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_live_abort_does_not_remove_a_parked_fetched_head() { let producer = track_producer("test", Info::timed()); @@ -16065,7 +16065,7 @@ mod test { /// The live copy ending early (its subscription went away) leaves a fetched head /// that still holds the whole group servable, instead of reclaiming the slot. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn aborted_live_group_keeps_its_fetched_head() { let producer = track_producer("test", Info::timed()); @@ -16084,7 +16084,7 @@ mod test { /// Reads land on the fetched head, so they keep the slot from expiring even though /// the live copy beside it sits idle. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn reading_the_head_keeps_the_slot_from_expiring() { let producer = track_producer("test", Info::timed()); @@ -16139,7 +16139,7 @@ mod test { /// A head left alone in its slot still joins the pool's access average when the /// slot is demoted, so memory pressure can evict it. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_head_only_slot_yields_to_memory_pressure() { assert!(pressure_evicts_a_headed_slot(true).await); @@ -16147,7 +16147,7 @@ mod test { /// A slot weighs its copies the way the pool's average samples them, so two copies /// with different access stamps can't keep it above the average on their own. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_two_copy_slot_yields_to_memory_pressure() { assert!(pressure_evicts_a_headed_slot(false).await); @@ -16155,7 +16155,7 @@ mod test { /// Joining a queued fetch widens its range. A caller that arrives once the range is /// already on the wire asks for its own frames rather than being handed the narrower group. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_widens_or_asks_afresh() { let producer = track_producer("test", Info::timed()); @@ -16214,7 +16214,7 @@ mod test { group.finish().unwrap(); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_coalesces_concurrent() { let producer = track_producer("test", Info::timed()); @@ -16267,7 +16267,7 @@ mod test { /// A looser caller that joined after a tighter budget went on the wire is not failed by /// that budget's `Old`: it asks again with its own. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_late_looser_fetch_asks_again_after_old() { let producer = track_producer("test", Info::timed()); @@ -16294,7 +16294,7 @@ mod test { assert_eq!(loose.await.unwrap().sequence, 5); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_coalesced_reject_fails_all() { let producer = track_producer("test", Info::timed()); @@ -16324,7 +16324,7 @@ mod test { assert_eq!(req.sequence(), 5); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_queued_fails_when_handlers_leave() { let producer = track_producer("test", Info::timed()); @@ -16342,7 +16342,7 @@ mod test { assert!(fetch.read().is_empty()); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_miss_no_dynamic_not_found() { // A track with no `Requests` can't serve old content, so a cache miss @@ -16353,7 +16353,7 @@ mod test { assert!(matches!(consumer.fetch_group(5, None).await, Err(Error::NotFound))); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_past_final_not_found() { let producer = track_producer("test", Info::timed()); @@ -16462,7 +16462,7 @@ mod test { } /// The latest group is never in the eviction order, so it survives any budget. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn latest_group_never_evicted() { // Far too small for even one group: the latest survives anyway. @@ -16483,7 +16483,7 @@ mod test { /// A FETCH cache hit refreshes the group's access time: anything accessed more /// recently than the pool-wide average is protected, so the eviction walk skips /// it and evicts a never-read group instead, even one that arrived later. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_refresh_survives_eviction() { let (mut producer, _pool) = pooled_producer(10_000); @@ -16513,7 +16513,7 @@ mod test { /// A consumer holding an evicted group surfaces the eviction, not a hang or a /// truncated clean end. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn eviction_aborts_readers() { let (mut producer, _pool) = pooled_producer(10_000); @@ -16621,7 +16621,7 @@ mod test { /// Accepting a track after pre-accept backfill must keep the same write /// counter: the counter is owned by the track state, so replacing the info /// can't strand the bytes already-created groups keep charging. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn accept_preserves_write_accounting() { let config = cache::Config::default() @@ -16815,7 +16815,7 @@ mod test { /// A backfill served before the track was accepted settles its own debt: the /// account exists from the moment the state does, so acceptance replacing the /// `Info` can't leave already-created groups writing for free. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn pre_accept_backfill_settles_late_writes() { let config = cache::Config::default() @@ -16884,7 +16884,7 @@ mod test { /// Continuously refreshed entries at the front of the eviction order must not /// starve expiry of entries behind them: the scan cursor rotates. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn refreshed_front_does_not_starve_expiry() { let (producer, _pool) = pooled_producer(1 << 40); @@ -17164,7 +17164,7 @@ mod test { /// A stale arrival entry whose sequence was later re-served by fetched backfill /// must not leak the replacement into arrival-order subscriptions. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn refilled_sequence_stays_out_of_subscriptions() { let (producer, _pool) = pooled_producer(1 << 40); @@ -17201,7 +17201,7 @@ mod test { /// An expired backfill can't hide behind a refreshed one: the eviction-order /// expiry scans a bounded prefix instead of stopping at the first fresh entry. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn expired_backfill_behind_refreshed_reclaimed() { let (producer, _pool) = pooled_producer(1 << 40); @@ -17237,7 +17237,7 @@ mod test { /// A FETCH hit within the same coarse clock tick still protects the group: the /// refresh stamps one tick ahead, so it reads strictly newer than the mean. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn same_tick_fetch_protects() { // No time advances at all: every timestamp lands in the same tick. @@ -17260,7 +17260,7 @@ mod test { /// A refetched group that reclaims max_sequence is the live edge again: it must /// not re-enter the eviction order, or memory pressure could evict the newest /// content. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn refetched_latest_stays_protected() { let (producer, _pool) = pooled_producer(10_000); @@ -17302,7 +17302,7 @@ mod test { /// An evicted group is a cache miss, so a fetch re-fetches it and the accepted /// replacement serves the sequence again (not `Error::Duplicate`). - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn eviction_allows_refetch() { let (mut producer, _pool) = pooled_producer(10_000); @@ -17371,7 +17371,7 @@ mod test { /// Lowering the floor re-offers only what the arrival walk could have read: a fetched /// group stays out of arrival order, while a live one is offered before its first frame. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_lowered_floor_reoffers_live_groups_but_not_fetched_ones() { let (producer, _pool) = pooled_producer(1 << 40); @@ -17415,7 +17415,7 @@ mod test { /// A fetched (backfill) group is served by sequence but never replayed to /// arrival-order subscribers. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetched_backfill_not_subscribed() { let (producer, _pool) = pooled_producer(1 << 40); @@ -17451,7 +17451,7 @@ mod test { /// Fetched backfill isn't in arrival order, so it ages out through the eviction /// order instead of lingering until the track closes. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn expired_backfill_reclaimed() { let (producer, pool) = pooled_producer(1 << 40); @@ -18561,7 +18561,7 @@ mod test { /// A group the source no longer has fails its fetch, and is named dropped for good only /// once the live feed gave up on it too: a fetch answered before a late group header /// arrives says nothing about the feed. - #[moq_clock::test] + #[kio::test] async fn dropped_fill_group_fails_its_fetch() { let producer = track_producer("test", Info::timed()); let dynamic = producer.requests(); @@ -18569,23 +18569,23 @@ mod test { assert!(matches!(drop_through_fill(&producer, &dynamic, true), Error::NotFound)); assert!(drops(&producer).is_empty(), "the feed may still deliver 3"); - moq_clock::sim::advance(Duration::from_secs(60)).await; + kio::clock::sim::advance(Duration::from_secs(60)).await; assert!(matches!(drop_through_fill(&producer, &dynamic, true), Error::NotFound)); assert_eq!(drops(&producer), vec![3..4], "clipped to the fill"); } /// Dropping a fill a reader still waits on names what it left as dropped. - #[moq_clock::test] + #[kio::test] async fn fill_dropped_unanswered_names_the_rest_dropped() { let producer = track_producer("test", Info::timed()); let dynamic = producer.requests(); write_group(&producer, 5); - moq_clock::sim::advance(Duration::from_secs(60)).await; + kio::clock::sim::advance(Duration::from_secs(60)).await; assert!(matches!(drop_through_fill(&producer, &dynamic, false), Error::Dropped)); assert_eq!(drops(&producer), vec![3..4]); } - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn fetch_aborts_with_track() { let producer = track_producer("test", Info::timed()); @@ -18930,7 +18930,7 @@ mod test { /// Fetched backfill past the newest produced group moves no relative start, whether the /// track had a produced group at subscribe or not. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_live_range_ignores_a_fetched_group_past_the_newest_group() { let producer = track_producer("test", Info::timed()); @@ -19435,7 +19435,7 @@ mod test { /// Filling a span asks once per run of misses, and a run is served up to a group the /// cache gained since, which it skips: the handler fetches each run at once. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_filled_span_is_served_a_run_at_a_time() { let producer = track_producer("test", Info::timed()); @@ -19486,7 +19486,7 @@ mod test { /// A span fill that joined after a tighter budget went on the wire is not answered by /// that budget's `Old`: it asks again with its own, as a fetch does. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_span_fill_asks_again_after_another_budget_is_too_old() { let producer = track_producer("test", Info::timed()); @@ -19511,7 +19511,7 @@ mod test { /// A drop judges the subscription, not a fetch: a fetched head still arriving keeps /// serving the group to its end after the drop ends the live copy. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_drop_spares_a_fetched_head_still_arriving() { let producer = track_producer("test", Info::timed()); @@ -19828,7 +19828,7 @@ mod test { /// A read parked on a time end's cap wakes when the speculative group starts, and when /// a later group starts inside the end while the speculative one stalls. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn a_read_parked_on_a_time_end_wakes_as_groups_start() { let at = |millis| Timestamp::from_millis(millis).unwrap(); @@ -19842,17 +19842,17 @@ mod test { }])); assert_eq!(drain(&mut subscriber), vec![0]); - let parked = moq_clock::sim::spawn(async move { + let parked = kio::clock::sim::spawn(async move { let one = subscriber.recv_group().await.unwrap().unwrap().sequence; let two = subscriber.recv_group().await.unwrap().unwrap().sequence; (one, two, subscriber) }); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; assert!(!parked.is_finished(), "1 waits on 0 starting"); groups[0] .write_frame(at(3000), bytes::Bytes::from_static(b"x")) .unwrap(); - moq_clock::sim::yield_now().await; + kio::clock::sim::yield_now().await; assert!(!parked.is_finished(), "1 is read, and 2 waits on 1 starting"); // 1 stalls, so only 2 starting inside the end lifts the cap past it. @@ -20154,7 +20154,7 @@ mod test { } /// Distinct transport starts retain delivery outcomes, but share the same indexed /// bytes even while every earlier delivery is held by an unread consumer. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn distinct_tail_readers_share_canonical_content() { for size in [0, 1, 1024] { @@ -20241,7 +20241,7 @@ mod test { /// Evicting a Slot does not hide a canonical owner from still-held older tails; /// explicitly recreating the live group, however, starts a new incarnation. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn tail_owner_survives_slot_removal_but_not_live_recreation() { let producer = track_producer("test", Info::timed()); @@ -20315,7 +20315,7 @@ mod test { /// Activation preserves an already-streaming reader and producer, and every /// delivery's progress, arrival and abort while sharing the origin's admission. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn canonical_activation_preserves_inflight_delivery_ownership() { for abort_first in [false, true] { @@ -20361,7 +20361,7 @@ mod test { second.write(vec![4; 256]).unwrap(); assert_eq!(first.remaining(), 512, "another delivery credits no progress"); assert!(streaming.read_chunk().now_or_never().is_none()); - moq_clock::sim::advance(Duration::from_millis(20)).await; + kio::clock::sim::advance(Duration::from_millis(20)).await; if abort_first { first.abort(Error::Cancel).unwrap(); assert!(budget.reserve(1).is_none(), "the survivor still holds admission"); @@ -20387,7 +20387,7 @@ mod test { ); assert_eq!(first.remaining(), 512); assert!(streaming.read_chunk().now_or_never().is_none()); - moq_clock::sim::advance(Duration::from_millis(10)).await; + kio::clock::sim::advance(Duration::from_millis(10)).await; first.write(vec![4; 512]).unwrap(); let mut first = first.finish().unwrap(); first.finish().unwrap(); @@ -20408,7 +20408,7 @@ mod test { } /// IETF Object IDs can occupy different delivery ordinals. Sharing bytes must /// preserve their typed fields and each delivery's independent terminal record. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn canonical_content_keys_typed_objects_by_id_not_ordinal() { fn wire(first: u64) -> group::Wire { @@ -20523,7 +20523,7 @@ mod test { /// Compressed transport refills keep the received slices, share one inflation, /// and continue widening hostile tail requests rather than minting local encoders. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn canonical_compressed_ingress_preserves_raw_plain_and_widening() { fn ingest(group: group::Producer, object: &frame::Object) -> group::Producer { @@ -20599,7 +20599,7 @@ mod test { let meter = registry.publisher_meter(crate::Path::new("demo").unwrap(), &stats::Tier::default()); let mut first = head.consume().with_meter(meter.clone()); assert_eq!(first.read_frame().await.unwrap().unwrap().payload, expected[0]); - moq_clock::sim::advance(Duration::from_millis(20)).await; + kio::clock::sim::advance(Duration::from_millis(20)).await; head = ingest(head, &stored[8]); head.finish().unwrap(); pending.await.unwrap(); @@ -20660,7 +20660,7 @@ mod test { /// An evicted streaming reader still owns in-flight storage until it is dropped. /// A refill must discover those same bytes without changing that reader's abort. - #[moq_clock::test] + #[kio::test] #[cfg(feature = "async")] async fn canonical_owner_follows_an_evicted_streaming_frame_reader() { let producer = track_producer("test", Info::timed()); diff --git a/rs/moq-net/src/model/track/miss.rs b/rs/moq-net/src/model/track/miss.rs index f50ce641a41..365d56c8bc6 100644 --- a/rs/moq-net/src/model/track/miss.rs +++ b/rs/moq-net/src/model/track/miss.rs @@ -769,7 +769,7 @@ mod tests { use super::super::{Servable, Subscription}; use super::*; - #[moq_clock::test] + #[kio::test] async fn a_recreated_accounted_group_clears_its_earlier_fill_refusal() { let broadcast = crate::broadcast::Info::default().produce(); let mut track = broadcast @@ -870,7 +870,7 @@ mod tests { assert!(given_up.is_empty(), "a live recreation is never given up"); } - #[moq_clock::test] + #[kio::test] async fn an_aborted_live_group_keeps_its_earlier_fill_refusal() { let broadcast = crate::broadcast::Info::default().produce(); let mut track = broadcast @@ -938,7 +938,7 @@ mod tests { assert!(!asks.contains(&2), "a refused hole is not asked again"); assert_eq!(given_up, vec![2..3]); } - #[moq_clock::test] + #[kio::test] async fn unchanged_probes_and_late_arrivals_keep_other_gap_deadlines() { let broadcast = crate::broadcast::Info::default().produce(); let track = broadcast.create_track("sparse", crate::track::Info::default()).unwrap(); diff --git a/rs/moq-net/src/priority.rs b/rs/moq-net/src/priority.rs index 361ac502d7b..cd09c2864c1 100644 --- a/rs/moq-net/src/priority.rs +++ b/rs/moq-net/src/priority.rs @@ -929,7 +929,7 @@ mod tests { assert_eq!(low_track_high_group.current(), 4); // track=-78, group=100 } - #[moq_clock::test] + #[kio::test] async fn test_watch_notification_on_overflow_promotion() { let queue = PriorityQueue::default(); @@ -941,10 +941,10 @@ mod tests { assert_eq!(overflow_item.current(), u8::MAX); // Spawn task to wait for promotion from overflow - let task = moq_clock::sim::spawn(async move { overflow_item.next().await }); + let task = kio::clock::sim::spawn(async move { overflow_item.next().await }); // Give the task time to start waiting - moq_clock::sleep(std::time::Duration::from_millis(10)).await; + kio::clock::sleep(std::time::Duration::from_millis(10)).await; // Drop highest priority item, which should promote from overflow fillers.remove(0); @@ -1046,7 +1046,7 @@ mod tests { assert_eq!(handles[1].current(), 0); } - #[moq_clock::test] + #[kio::test] async fn test_notification_on_demotion_to_overflow() { let queue = PriorityQueue::default(); @@ -1058,9 +1058,9 @@ mod tests { assert_eq!(at_edge.current(), 254); // Spawn task to wait for demotion notification - let task = moq_clock::sim::spawn(async move { at_edge.next().await }); + let task = kio::clock::sim::spawn(async move { at_edge.next().await }); - moq_clock::sleep(std::time::Duration::from_millis(10)).await; + kio::clock::sleep(std::time::Duration::from_millis(10)).await; // Insert very high priority item, kicking at_edge to overflow let _high = queue.insert(live(127, 1000)); @@ -1113,7 +1113,7 @@ mod tests { assert_eq!(s1_g1.current(), 3); } - #[moq_clock::test] + #[kio::test] async fn test_steer_track_notifies_other_handles() { let queue = PriorityQueue::default(); @@ -1124,8 +1124,8 @@ mod tests { assert_eq!(h_low.current(), 1); // Wait for a change notification on h_low while another handle's steer runs. - let task = moq_clock::sim::spawn(async move { h_low.next().await }); - moq_clock::sleep(std::time::Duration::from_millis(10)).await; + let task = kio::clock::sim::spawn(async move { h_low.next().await }); + kio::clock::sleep(std::time::Duration::from_millis(10)).await; // Demote h_high below h_low. h_high.steer(-118, Order::Descending); @@ -1223,7 +1223,7 @@ mod tests { assert_eq!(low.current(), 2); } - #[moq_clock::test] + #[kio::test] async fn test_steer_track_notifies_swapped_overflow_item() { let queue = PriorityQueue::default(); @@ -1236,8 +1236,8 @@ mod tests { let mut f1 = fillers.remove(0); assert_eq!(f1.current(), u8::MAX); - let task = moq_clock::sim::spawn(async move { f1.next().await }); - moq_clock::sim::yield_now().await; + let task = kio::clock::sim::spawn(async move { f1.next().await }); + kio::clock::sim::yield_now().await; // Demoting top below every filler swaps it with f1 in overflow. top.steer(-128, Order::Descending); diff --git a/rs/moq-net/src/server.rs b/rs/moq-net/src/server.rs index 0eb8d2b6d3c..5e8c2c94707 100644 --- a/rs/moq-net/src/server.rs +++ b/rs/moq-net/src/server.rs @@ -797,7 +797,7 @@ impl Handshake { }; let res = match deadline { // The guard refuses the session on the way out. - Some(at) => moq_clock::timeout_at(at, reply).await.map_err(|_| Error::Timeout)?, + Some(at) => kio::clock::timeout_at(at, reply).await.map_err(|_| Error::Timeout)?, None => reply.await, }; unanswered.answered(); @@ -1173,7 +1173,7 @@ mod tests { /// The session's own `auth()` (the handle the driver polls) routes a request token to that /// pre-ok consumer instead of falling to the `Unsupported` default, and granting admits. /// A QUIC server has no other point to install the verifier. - #[moq_clock::test] + #[kio::test] async fn a_pre_ok_verifier_governs_the_session() { let cases = [( FakeSession::new(ALPN_18, [ietf_setup(ietf::Version::Draft18, Some("room/alice"))]), @@ -1182,7 +1182,7 @@ mod tests { for (session, version) in cases { let mut request = Server::new() - .accept_request(moq_clock::now(), session) + .accept_request(kio::clock::now(), session) .await .unwrap_or_else(|e| panic!("accept at {version:?}: {e}")); @@ -1209,14 +1209,14 @@ mod tests { /// A peer that never takes the SETUP reply is refused at the handshake's deadline /// with the timeout code, and the session's stats count it. - #[moq_clock::test] + #[kio::test] async fn a_reply_the_peer_never_takes_fails_at_the_deadline() { let registry = stats::Registry::new(Default::default()); let version = Version::Lite(lite::Version::Lite02); let session = FakeSession::new(ALPN_LITE, []) .with_bi(moql_setup()) .withholding_credit(); - let start = moq_clock::now(); + let start = kio::clock::now(); let deadline = start + std::time::Duration::from_secs(10); let request = Server::new() .accept_request(start, session.clone()) @@ -1232,7 +1232,7 @@ mod tests { panic!("a reply the peer never took completed"); }; assert!(matches!(err, Error::Timeout), "{err:?}"); - assert_eq!(moq_clock::now(), deadline); + assert_eq!(kio::clock::now(), deadline); assert_eq!(session.close_code(), Some(version.session_code(&SessionError::Timeout))); let failed = registry.snapshot().sessions()[0].1.sessions_failed; assert_eq!(failed.count(stats::Failure::Application), 1, "{failed:?}"); @@ -1240,7 +1240,7 @@ mod tests { /// A reply the caller stops waiting for, as a relay does at its drain deadline, is /// refused like one past the handshake's own deadline. - #[moq_clock::test] + #[kio::test] async fn an_abandoned_reply_fails_like_the_deadline() { let registry = stats::Registry::new(Default::default()); let version = Version::Lite(lite::Version::Lite02); @@ -1248,7 +1248,7 @@ mod tests { .with_bi(moql_setup()) .withholding_credit(); let request = Server::new() - .accept_request(moq_clock::now(), session.clone()) + .accept_request(kio::clock::now(), session.clone()) .await .unwrap() .with_stats( @@ -1256,7 +1256,7 @@ mod tests { .tier(Default::default()) .session(crate::Path::from_static("room")), ); - let abandoned = moq_clock::timeout(std::time::Duration::from_secs(1), request.ok()).await; + let abandoned = kio::clock::timeout(std::time::Duration::from_secs(1), request.ok()).await; assert!(abandoned.is_err(), "a reply the peer never took completed"); assert_eq!(session.close_code(), Some(version.session_code(&SessionError::Timeout))); let failed = registry.snapshot().sessions()[0].1.sessions_failed; @@ -1265,7 +1265,7 @@ mod tests { /// A rejection counts by the code the peer is told, so a "no error" close is clean /// however this side spelled it. - #[moq_clock::test] + #[kio::test] async fn a_rejection_counts_by_its_code() { for (err, failed) in [ (Error::GoingAway, None), @@ -1275,7 +1275,7 @@ mod tests { let registry = stats::Registry::new(Default::default()); let session = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, None)]); Server::new() - .accept_request(moq_clock::now(), session) + .accept_request(kio::clock::now(), session) .await .unwrap() .with_stats( @@ -1292,7 +1292,7 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn accept_request_exposes_the_setup_token() { let ietf = FakeSession::new( ALPN_22, @@ -1301,22 +1301,22 @@ mod tests { token_params(ietf::Version::Draft22), )], ); - let request = Server::new().accept_request(moq_clock::now(), ietf).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), ietf).await.unwrap(); assert_eq!(request.token(), Some(&setup_token())); } - #[moq_clock::test] + #[kio::test] async fn accept_request_without_a_token_reports_none() { let ietf = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, None)]); let lite = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); for (name, session) in [("draft-22", ietf), ("lite-05", lite)] { - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.token(), None, "{name}"); } } /// A SETUP the server refuses closes the session with the code naming why. - #[moq_clock::test] + #[kio::test] async fn a_refused_setup_token_closes_with_its_code() { let delete = [0x0, 0x7]; // DELETE alias 7 let truncated = [0x3]; // USE_VALUE with no Token Type @@ -1328,34 +1328,34 @@ mod tests { params.set_bytes(ietf::ParameterBytes::AuthorizationToken, raw.to_vec()); let session = FakeSession::new(ALPN_22, [ietf_setup_with(ietf::Version::Draft22, params)]); - let result = Server::new().accept_request(moq_clock::now(), session.clone()).await; + let result = Server::new().accept_request(kio::clock::now(), session.clone()).await; assert!(result.is_err()); assert_eq!(session.close_code(), Some(code.to_code()), "{code}"); } } - #[moq_clock::test] + #[kio::test] async fn accept_request_reads_ietf_path() { // Every draft gates on the SETUP stream before starting, so the // path is known at authorization time just like lite-05. for (alpn, version) in [(ALPN_18, ietf::Version::Draft18), (ALPN_22, ietf::Version::Draft22)] { let session = FakeSession::new(alpn, [ietf_setup(version, Some("/team/room"))]); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/team/room", "{alpn}"); } } - #[moq_clock::test] + #[kio::test] async fn accept_request_ietf_without_path_is_empty() { let session = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, None)]); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } - #[moq_clock::test] + #[kio::test] async fn accept_request_ietf_empty_path_is_accepted() { let session = FakeSession::new(ALPN_22, [ietf_setup(ietf::Version::Draft22, Some(""))]); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } @@ -1371,31 +1371,31 @@ mod tests { buf } - #[moq_clock::test] + #[kio::test] async fn accept_request_reads_lite05_path() { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(Some("/team/room"), None, None)]); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/team/room"); assert_eq!(request.role(), None, "a client that omits the role is bidirectional"); } - #[moq_clock::test] + #[kio::test] async fn accept_request_lite05_without_path_is_empty() { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } - #[moq_clock::test] + #[kio::test] async fn accept_request_lite05_empty_path_is_accepted() { // An empty path is valid on the wire and means the same as omitting it, so a // client that wants the root doesn't have to special-case the parameter. let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(Some(""), None, None)]); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } - #[moq_clock::test] + #[kio::test] async fn uri_address_rejects_setup_path_presence() { for alpn in [ALPN_LITE_05, ALPN_LITE_06, ALPN_LITE_07_WIP] { for path in ["", "/team/room"] { @@ -1404,7 +1404,7 @@ mod tests { let observed = session.clone(); let result = Server::new() .with_versions(alpn.parse::().unwrap().into()) - .accept_request(moq_clock::now(), session) + .accept_request(kio::clock::now(), session) .await; assert!( matches!(result, Err(Error::ProtocolViolation)), @@ -1415,64 +1415,64 @@ mod tests { } } - #[moq_clock::test] + #[kio::test] async fn uri_address_accepts_setup_without_path() { let mut session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); session.address = crate::transport::Address::Uri; - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), ""); } - #[moq_clock::test] + #[kio::test] async fn accept_request_reads_lite05_role() { let session = FakeSession::new( ALPN_LITE_05, [lite05_setup(Some("/team/room"), Some(Role::Publisher), None)], ); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.role(), Some(Role::Publisher)); } - #[moq_clock::test] + #[kio::test] async fn accept_request_holds_uni_stream_before_setup() { let session = FakeSession::new( ALPN_LITE_05, [lite05_group(), lite05_setup(Some("/team/room"), None, None)], ); let stops = session.stops.clone(); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/team/room"); assert!(stops.lock().unwrap().is_empty(), "the early stream must stay open"); } - #[moq_clock::test] + #[kio::test] async fn accept_request_reads_buffered_setup_after_transport_close() { let mut session = FakeSession::new(ALPN_LITE_05, [lite05_setup(Some("/closed"), None, None)]); crate::transport::poll::Session::close(&mut session, SessionError::Cancel.to_code(), "closed"); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.path(), "/closed"); } - #[moq_clock::test] + #[kio::test] async fn accepted_lite_setup_refuses_a_second_setup_stream() { let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, None)]); let transport = session.clone(); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); let (_session, mut driver) = request.ok().await.unwrap(); transport.uni.lock().unwrap().push_back(vec![1]); - let _ = driver.poll(moq_clock::now(), &kio::Waiter::noop()); + let _ = driver.poll(kio::clock::now(), &kio::Waiter::noop()); assert_eq!(transport.close_code(), Some(SessionError::ProtocolViolation.to_code())); } - #[moq_clock::test] + #[kio::test] async fn accept_request_reads_lite05_peer_hop() { let hop = Hop::new(42).unwrap(); let session = FakeSession::new(ALPN_LITE_05, [lite05_setup(None, None, Some(hop))]); - let request = Server::new().accept_request(moq_clock::now(), session).await.unwrap(); + let request = Server::new().accept_request(kio::clock::now(), session).await.unwrap(); assert_eq!(request.peer_hop(), Some(hop)); } - #[moq_clock::test] + #[kio::test] async fn anonymous_peer_hop_filters_routes_from_server_session() { let other = Hop::new(778).unwrap(); let origin = crate::origin::Config::new(Hop::new(1).unwrap()).produce(); @@ -1491,7 +1491,7 @@ mod tests { auth: crate::auth::Link::ietf(false), inner: Some(RequestInner { server: Server::new().with_publisher(&origin), - runtime: Deadlines::new(moq_clock::now()), + runtime: Deadlines::new(kio::clock::now()), deadline: None, handshake: PausedHandshake::Ietf(PausedIetf { session: Transport::new(transport), @@ -1531,13 +1531,13 @@ mod tests { .unwrap(); let (session, driver) = request.ok().await.unwrap(); - moq_clock::sim::spawn(crate::time::run(driver)); + kio::clock::sim::spawn(crate::time::run(driver)); for _ in 0..100 { if occurrences(&log, b"local-route") > 0 { break; } - moq_clock::sleep(std::time::Duration::from_millis(1)).await; + kio::clock::sleep(std::time::Duration::from_millis(1)).await; } assert_eq!(occurrences(&log, b"echoed-route"), 0); diff --git a/rs/moq-net/src/tail.rs b/rs/moq-net/src/tail.rs index 0888b4a0508..476b89875a2 100644 --- a/rs/moq-net/src/tail.rs +++ b/rs/moq-net/src/tail.rs @@ -195,7 +195,7 @@ mod tests { /// The grace gives up on streams that never arrived, never on one still being read: /// its group, or the END_OF_TRACK it carries, still belongs to the track. - #[moq_clock::test] + #[kio::test] async fn the_grace_waits_for_a_stream_being_read() { let runtime = crate::time::sim(); let tail = kio::Producer::new(Tail::default()); @@ -203,7 +203,7 @@ mod tests { let mut settle = Settle::new(&runtime, tail.consume()); let mut settled = std::pin::pin!(kio::wait(|waiter| settle.poll(waiter, |_| false))); - moq_clock::sleep(GRACE * 2).await; + kio::clock::sleep(GRACE * 2).await; assert!( futures::poll!(settled.as_mut()).is_pending(), "a stream is still being read" @@ -214,13 +214,13 @@ mod tests { } /// A stream that outlives the grace still reaches `complete` once it finishes. - #[moq_clock::test] + #[kio::test] async fn completion_is_judged_after_the_grace() { let runtime = crate::time::sim(); let tail = kio::Producer::new(Tail::default()); let reading = Reading::open(&tail, Some(0), runtime.now()); let mut settle = Settle::new(&runtime, tail.consume()); - moq_clock::sleep(GRACE * 2).await; + kio::clock::sleep(GRACE * 2).await; drop(reading); let mut complete = false; @@ -235,7 +235,7 @@ mod tests { } /// A stream parked on another one does not hold the end open. - #[moq_clock::test] + #[kio::test] async fn a_parked_stream_does_not_hold_the_end() { let runtime = crate::time::sim(); let tail = kio::Producer::new(Tail::default()); diff --git a/rs/moq-net/src/time.rs b/rs/moq-net/src/time.rs index a2d9b7b4f67..680764439d5 100644 --- a/rs/moq-net/src/time.rs +++ b/rs/moq-net/src/time.rs @@ -2,8 +2,8 @@ //! //! Drivers take the current [`Instant`] on every poll and never read a clock. -pub use moq_clock::Instant; -pub(crate) use moq_clock::{Deadline, Deadlines}; +pub use kio::clock::Instant; +pub(crate) use kio::clock::{Deadline, Deadlines}; use crate::Error; @@ -23,13 +23,13 @@ pub trait Driver { #[cfg(feature = "async")] pub async fn run(driver: D) -> Error { let mut driver = Box::new(driver); - moq_clock::drive(move |now, waiter| driver.poll(now, waiter)).await + kio::clock::drive(move |now, waiter| driver.poll(now, waiter)).await } /// A deadline queue attached to the deterministic test clock. #[cfg(all(test, feature = "async"))] pub(crate) fn sim() -> Deadlines { - let deadlines = Deadlines::new(moq_clock::now()); - moq_clock::sim::attach(&deadlines); + let deadlines = Deadlines::new(kio::clock::now()); + kio::clock::sim::attach(&deadlines); deadlines } diff --git a/rs/moq-net/tests/integration/announce_covering_route.rs b/rs/moq-net/tests/integration/announce_covering_route.rs index c8ce94e79c4..6290f9c9f8b 100644 --- a/rs/moq-net/tests/integration/announce_covering_route.rs +++ b/rs/moq-net/tests/integration/announce_covering_route.rs @@ -66,16 +66,16 @@ async fn covering(version: Option<&str>) -> Vec { let served = publisher.create_broadcast(SERVED).unwrap(); served.announce(Default::default()).unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; log.push(format!("served: {:?}", drain(&mut announced))); let below = publisher.create_broadcast(format!("{REQUESTED}/cam")).unwrap(); below.announce(Default::default()).unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; log.push(format!("below: {:?}", drain(&mut announced))); if let Some(pair) = pair { - let closed = moq_clock::timeout(SETTLE, pair.client.closed()).await; + let closed = kio::clock::timeout(SETTLE, pair.client.closed()).await; log.push(format!("session open: {}", closed.is_err())); } @@ -84,12 +84,12 @@ async fn covering(version: Option<&str>) -> Vec { const EXPECTED: &[&str] = &["served: [\"Start \"]", "below: [\"Start cam\"]"]; -#[moq_clock::test] +#[kio::test] async fn local_cursor_sees_the_covering_route_at_its_root() { assert_eq!(covering(None).await, EXPECTED); } -#[moq_clock::test] +#[kio::test] async fn remote_lite_peer_hears_the_covering_route() { let mut expected = EXPECTED.to_vec(); expected.push("session open: true"); @@ -104,7 +104,7 @@ async fn remote_lite_peer_hears_the_covering_route() { } } -#[moq_clock::test] +#[kio::test] async fn remote_ietf_peer_hears_the_covering_route() { let mut expected = EXPECTED.to_vec(); expected.push("session open: true"); diff --git a/rs/moq-net/tests/integration/announce_to_serve.rs b/rs/moq-net/tests/integration/announce_to_serve.rs index ef48d02197f..26e179710dc 100644 --- a/rs/moq-net/tests/integration/announce_to_serve.rs +++ b/rs/moq-net/tests/integration/announce_to_serve.rs @@ -86,7 +86,7 @@ async fn read(broadcast: &moq_net::broadcast::Consumer, name: &str) -> mpsc::Unb .await .expect("subscribe"); let (tx, rx) = mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { loop { let mut group = match sub.recv_group().await { Ok(Some(group)) => group, @@ -113,7 +113,7 @@ async fn read(broadcast: &moq_net::broadcast::Consumer, name: &str) -> mpsc::Unb /// The reader's next report, or `stalled` if nothing arrives in time. async fn next(rx: &mut mpsc::UnboundedReceiver) -> String { - match moq_clock::timeout(SETTLE, rx.next()).await { + match kio::clock::timeout(SETTLE, rx.next()).await { Ok(Some(report)) => report, _ => "stalled".to_string(), } @@ -146,7 +146,7 @@ async fn lifecycle(observer: Observer) -> Vec { // Created, not yet announced: nobody can see or reach it. let broadcast = publisher.create_broadcast(PATH).unwrap(); let track = broadcast.create_track("video", timed()).unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; log.push(format!( "created: {:?} {}", drain(&mut announced), @@ -155,14 +155,14 @@ async fn lifecycle(observer: Observer) -> Vec { // Announced: listed, and a request resolves. broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; let first = request(&consumer).await; log.push(format!("announced: {:?} {}", drain(&mut announced), outcome(&first))); let first = first.expect("an announced broadcast resolves"); // A track in flight across the unannounce. let mut reader = read(&first, "video").await; - moq_clock::timeout(SETTLE, crate::support::wanted(track.demand())) + kio::clock::timeout(SETTLE, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); @@ -173,7 +173,7 @@ async fn lifecycle(observer: Observer) -> Vec { // than joining the broadcast still draining, which ends, while the track // already in flight carries on to its own end. broadcast.unannounce(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; log.push(format!( "unannounced: {:?} {} closed={}", drain(&mut announced), @@ -190,7 +190,7 @@ async fn lifecycle(observer: Observer) -> Vec { // Announced again: listed and servable, through a fresh broadcast. broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; let again = request(&consumer).await; log.push(format!( "reannounced: {:?} {} fresh={}", @@ -202,7 +202,7 @@ async fn lifecycle(observer: Observer) -> Vec { let audio = broadcast.create_track("audio", timed()).unwrap(); let mut reader = read(&again, "audio").await; - moq_clock::timeout(SETTLE, crate::support::wanted(audio.demand())) + kio::clock::timeout(SETTLE, crate::support::wanted(audio.demand())) .await .expect("no subscriber appeared after reannouncing") .unwrap(); @@ -222,17 +222,17 @@ const EXPECTED: &[&str] = &[ "serving again: again", ]; -#[moq_clock::test] +#[kio::test] async fn local_consumer_sees_only_announced_broadcasts() { assert_eq!(lifecycle(Observer::Local).await, EXPECTED); } -#[moq_clock::test] +#[kio::test] async fn remote_lite_consumer_sees_what_a_local_one_does() { assert_eq!(lifecycle(Observer::Remote("moq-lite-05")).await, EXPECTED); } -#[moq_clock::test] +#[kio::test] async fn remote_ietf_consumer_sees_what_a_local_one_does() { // Each request has its own stream, which has to end a finished track the way // moq-lite does. diff --git a/rs/moq-net/tests/integration/auth.rs b/rs/moq-net/tests/integration/auth.rs index e18d797106d..3b26aa6935c 100644 --- a/rs/moq-net/tests/integration/auth.rs +++ b/rs/moq-net/tests/integration/auth.rs @@ -39,13 +39,13 @@ const MOQT_22: &str = "moq-transport-22"; macro_rules! cases { ($($case:ident),* $(,)?) => { mod lite_07 { - $(#[moq_clock::test] async fn $case() { super::$case(super::LITE_07).await })* + $(#[kio::test] async fn $case() { super::$case(super::LITE_07).await })* } mod moqt_18 { - $(#[moq_clock::test] async fn $case() { super::$case(super::MOQT_18).await })* + $(#[kio::test] async fn $case() { super::$case(super::MOQT_18).await })* } mod moqt_22 { - $(#[moq_clock::test] async fn $case() { super::$case(super::MOQT_22).await })* + $(#[kio::test] async fn $case() { super::$case(super::MOQT_22).await })* } }; } @@ -81,23 +81,23 @@ cases!( ); /// moq-transport's AUTH_ERROR carries no code that may pass, so only lite retries. -#[moq_clock::test] +#[kio::test] async fn lite_07_presents_a_transiently_refused_token_again() { a_transient_refusal_is_presented_again(LITE_07).await } /// moq-transport's u16 message size is the one a test can overflow quickly. -#[moq_clock::test] +#[kio::test] async fn moqt_18_a_grant_too_large_for_one_message_is_unsupported() { a_grant_too_large_for_one_message_is_unsupported(MOQT_18).await } -#[moq_clock::test] +#[kio::test] async fn moqt_22_a_grant_too_large_for_one_message_is_unsupported() { a_grant_too_large_for_one_message_is_unsupported(MOQT_22).await } -#[moq_clock::test] +#[kio::test] async fn lite_06_has_no_grant() { older_versions_have_no_grant(LITE_06).await } @@ -105,7 +105,7 @@ async fn lite_06_has_no_grant() { /// The control for the lite versions without AUTH: on the same barrier, lite-07 has /// opened an Auth Stream on each side, which is what makes its absence on them mean /// something. -#[moq_clock::test] +#[kio::test] async fn lite_07_opens_an_auth_stream_per_side() { within(async { let (pair, _broadcast) = connect_announced(LITE_07).await; @@ -121,22 +121,22 @@ async fn lite_07_opens_an_auth_stream_per_side() { .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn lite_05_has_no_grant() { older_versions_have_no_grant("moq-lite-05").await } -#[moq_clock::test] +#[kio::test] async fn moqt_22_route_auth_renews_its_announce() { a_route_auth_renews_its_announce(MOQT_22).await } -#[moq_clock::test] +#[kio::test] async fn moqt_22_route_auth_survives_a_reconnect() { a_route_auth_survives_a_reconnect(MOQT_22).await } -#[moq_clock::test] +#[kio::test] async fn moqt_22_renewing_a_cancelled_announce_keeps_the_session() { within(async { let (mut pair, client_origin, _server_origin) = connect_route_auth(MOQT_22).await; @@ -153,7 +153,7 @@ async fn moqt_22_renewing_a_cancelled_announce_keeps_the_session() { drop(first); let (token, _again) = tokens.next().await.expect("offered again after the cancel"); assert_eq!(token, b"first"); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let (second, _) = pair.client.auth().add("second").await.expect("kept for requests"); broadcast.announce(origin::Route::default().with_auth(second)).unwrap(); let (token, _second) = tokens.next().await.expect("announced again"); @@ -164,7 +164,7 @@ async fn moqt_22_renewing_a_cancelled_announce_keeps_the_session() { .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn moqt_22_a_cancelled_renewal_keeps_the_session() { within(async { let (mut pair, client_origin, _server_origin) = connect_route_auth(MOQT_22).await; @@ -180,9 +180,9 @@ async fn moqt_22_a_cancelled_renewal_keeps_the_session() { let (second, _) = pair.client.auth().add("second").await.expect("kept for requests"); broadcast.announce(origin::Route::default().with_auth(second)).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; drop(first); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!(pair.client_transport.close_reason(), None); }) .await @@ -192,7 +192,7 @@ async fn moqt_22_a_cancelled_renewal_keeps_the_session() { /// An acceptor that accepts a renewal and drops the grant it replaces in one step keeps the /// announcement: the old grant ending is not the request ending once its replacement is in. /// The replacement then holds it, so an update that stops covering it ends it. -#[moq_clock::test] +#[kio::test] async fn moqt_22_dropping_the_old_grant_with_its_renewal_keeps_the_announce() { within(async { let (mut pair, client_origin, server_origin) = connect_route_auth(MOQT_22).await; @@ -214,7 +214,7 @@ async fn moqt_22_dropping_the_old_grant_with_its_renewal_keeps_the_announce() { let second = renewal.accept(Grant::all()); drop(first); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!( futures::FutureExt::now_or_never(second.closed()).is_none(), "the request ended with the grant its renewal replaced" @@ -230,7 +230,7 @@ async fn moqt_22_dropping_the_old_grant_with_its_renewal_keeps_the_announce() { /// A route auth the peer revokes on its AUTH stream is no longer carried, so its request is /// made again without it, even while another token keeps the session's grant unchanged. -#[moq_clock::test] +#[kio::test] async fn moqt_22_a_revoked_route_auth_remakes_its_announce() { within(async { let client_origin = produce_origin(2); @@ -448,7 +448,7 @@ struct Pair { /// The SETUP token the server's handshake read. setup_token: Option, /// Aborting it drops the server's driver without letting it finish. - server_driver: moq_clock::sim::JoinHandle, + server_driver: kio::clock::sim::JoinHandle, } async fn connect(opts: Options) -> Pair { @@ -504,7 +504,7 @@ async fn connect(opts: Options) -> Pair { // Taken before the session starts, the way a relay verifying tokens would. let requests = opts.server_requests.then(|| handshake.requests()); let (session, mut driver) = handshake.ok().await.expect("server accept"); - let driver = moq_clock::sim::spawn(moq_clock::drive(move |now, waiter| { + let driver = kio::clock::sim::spawn(kio::clock::drive(move |now, waiter| { moq_net::time::Driver::poll(&mut driver, now, waiter) })); (session, requests, setup_token, driver) @@ -529,7 +529,7 @@ fn serve( answer: impl Fn(&[u8]) -> Option + 'static, ) -> futures::channel::mpsc::UnboundedReceiver<(Vec, auth::Issued)> { let (tx, rx) = futures::channel::mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { let mut unanswered = Vec::new(); while let Some(request) = requests.next().await { let token = request.token().to_vec(); @@ -544,8 +544,8 @@ fn serve( rx } -fn within(f: F) -> impl std::future::Future> { - moq_clock::timeout(TEST_TIMEOUT, f) +fn within(f: F) -> impl std::future::Future> { + kio::clock::timeout(TEST_TIMEOUT, f) } /// Each side's default grant is what the other side's origin handles allow: @@ -671,11 +671,11 @@ async fn an_unanswered_token_holds_the_check(version: &'static str) { let _setup = requests.next().await.unwrap().accept(grant(&["baz"], &[])); assert_eq!(granted(&pair.client).await, grant(&["baz"], &[])); let auth = pair.client.auth(); - let pending = moq_clock::sim::spawn(async move { auth.add("new").await }); + let pending = kio::clock::sim::spawn(async move { auth.add("new").await }); let unanswered = requests.next().await.unwrap(); let broadcast = publisher.create_broadcast("foo/bar").unwrap(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; use futures::FutureExt; assert!( pair.server.closed().now_or_never().is_none(), @@ -713,13 +713,13 @@ async fn a_broadcast_withdrawn_while_its_token_waits_is_not_refused(version: &'s let _setup = requests.next().await.unwrap().accept(grant(&["baz"], &[])); assert_eq!(granted(&pair.client).await, grant(&["baz"], &[])); let auth = pair.client.auth(); - let pending = moq_clock::sim::spawn(async move { auth.add("new").await }); + let pending = kio::clock::sim::spawn(async move { auth.add("new").await }); let unanswered = requests.next().await.unwrap(); let withdrawn = publisher.create_broadcast("foo/bar").unwrap(); withdrawn.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; withdrawn.unannounce(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let _issued = unanswered.accept(grant(&["other"], &[])); let _token = pending.await.unwrap().unwrap(); assert_eq!(granted(&pair.client).await, grant(&["baz", "other"], &[])); @@ -861,7 +861,7 @@ async fn a_refused_token_reports_the_code(version: &'static str) { }) .await; let mut requests = pair.requests.take().unwrap(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { while let Some(request) = requests.next().await { match request.token().is_empty() { true => { @@ -896,7 +896,7 @@ async fn a_refused_setup_token_grants_nothing(version: &'static str) { }) .await; let mut requests = pair.requests.take().unwrap(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { while let Some(request) = requests.next().await { request.reject(SessionError::Unauthorized, "bad credential"); } @@ -936,7 +936,7 @@ async fn the_setup_token_is_the_connection_credential(version: &'static str) { /// A lite version without the Token parameter carries none, so the caller's URL query /// has to. -#[moq_clock::test] +#[kio::test] async fn lite_06_sends_no_setup_token() { within(async { let pair = connect(Options { @@ -966,9 +966,9 @@ async fn dropping_the_requests_refuses_queued_tokens(version: &'static str) { let first = requests.next().await.expect("setup token"); drop(first.accept(Grant::default())); let auth = pair.client.auth(); - let pending = moq_clock::sim::spawn(async move { auth.add("queued").await.map(drop) }); + let pending = kio::clock::sim::spawn(async move { auth.add("queued").await.map(drop) }); // Give the second token time to reach the queue before dropping it. - moq_clock::sleep(Duration::from_millis(50)).await; + kio::clock::sleep(Duration::from_millis(50)).await; drop(requests); let err = pending.await.unwrap().expect_err("refused"); @@ -1454,7 +1454,7 @@ async fn nothing_outside_the_grant_reaches_the_peer(version: &'static str) { // Hold the answer, so the peer's discovery request is in long before the grant. let mut requests = pair.requests.take().unwrap(); let setup = requests.next().await.expect("setup token"); - let leaked = moq_clock::timeout( + let leaked = kio::clock::timeout( Duration::from_millis(100), wait_announced(&relay.consume(), "foo/bar", true), ) @@ -1512,16 +1512,16 @@ async fn a_broadcast_received_from_the_peer_is_not_ours_to_check(version: &'stat macro_rules! limit_cases { ($($case:ident),* $(,)?) => { mod limit_lite_05 { - $(#[moq_clock::test] async fn $case() { super::$case("moq-lite-05").await })* + $(#[kio::test] async fn $case() { super::$case("moq-lite-05").await })* } mod limit_lite_06 { - $(#[moq_clock::test] async fn $case() { super::$case(super::LITE_06).await })* + $(#[kio::test] async fn $case() { super::$case(super::LITE_06).await })* } mod limit_lite_07 { - $(#[moq_clock::test] async fn $case() { super::$case(super::LITE_07).await })* + $(#[kio::test] async fn $case() { super::$case(super::LITE_07).await })* } mod limit_moqt_18 { - $(#[moq_clock::test] async fn $case() { super::$case(super::MOQT_18).await })* + $(#[kio::test] async fn $case() { super::$case(super::MOQT_18).await })* } }; } @@ -1533,17 +1533,17 @@ limit_cases!( a_widening_brings_back_what_the_peer_published, ); -#[moq_clock::test] +#[kio::test] async fn lite_05_narrowing_resets_a_fetch_in_flight() { a_narrowing_resets_a_fetch_in_flight("moq-lite-05").await } -#[moq_clock::test] +#[kio::test] async fn lite_06_narrowing_resets_a_fetch_in_flight() { a_narrowing_resets_a_fetch_in_flight(LITE_06).await } -#[moq_clock::test] +#[kio::test] async fn lite_07_narrowing_resets_a_fetch_in_flight() { a_narrowing_resets_a_fetch_in_flight(LITE_07).await } @@ -1863,7 +1863,7 @@ async fn a_widening_brings_back_what_the_peer_published(version: &'static str) { async fn a_shared_handle_presents_its_token_on_every_session(version: &'static str) { within(async { let handle = auth::Handle::new(); - let added = moq_clock::sim::spawn({ + let added = kio::clock::sim::spawn({ let handle = handle.clone(); async move { handle.add("token").await } }); @@ -1938,7 +1938,7 @@ async fn a_handle_backs_one_active_session(version: &'static str) { }; let mut first = connect(options()).await; let mut first_requests = first.requests.take().unwrap(); - let added = moq_clock::sim::spawn({ + let added = kio::clock::sim::spawn({ let handle = handle.clone(); async move { handle.add("token").await } }); @@ -1973,13 +1973,13 @@ async fn a_handle_backs_one_active_session(version: &'static str) { let _second_issued = presented(&mut second_tokens).await; let _token = added.await.expect("joined").expect("granted on the second session"); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!( unanswered.closed().now_or_never().is_none(), "the draining session withdrew its unanswered token" ); let first_grant = unanswered.accept(Grant::all()); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!( first_grant.closed().now_or_never().is_none(), "the draining session dropped its late grant" @@ -2021,7 +2021,7 @@ async fn a_token_queued_before_our_goaway_rides_only_the_successor(version: &'st let mut adding = Box::pin(handle.add("late")); assert!(adding.as_mut().now_or_never().is_none()); first.client.drain().send(moq_net::goaway::Goaway::new()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!( first_tokens.next().now_or_never().is_none(), "the draining session presented a new token" @@ -2055,7 +2055,7 @@ async fn a_transient_refusal_is_presented_again(version: &'static str) { .await; let mut requests = pair.requests.take().unwrap(); let (tx, mut issued) = futures::channel::mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { let mut refused = false; while let Some(request) = requests.next().await { if request.token().is_empty() || refused { diff --git a/rs/moq-net/tests/integration/broadcast_close.rs b/rs/moq-net/tests/integration/broadcast_close.rs index eae57feab10..c7d93ced652 100644 --- a/rs/moq-net/tests/integration/broadcast_close.rs +++ b/rs/moq-net/tests/integration/broadcast_close.rs @@ -27,11 +27,11 @@ async fn close_then_lookup(publisher: moq_net::origin::Producer, reader: moq_net broadcast.announce(Default::default()).unwrap(); let consumer = reader.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let handle = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let handle = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -39,7 +39,7 @@ async fn close_then_lookup(publisher: moq_net::origin::Producer, reader: moq_net broadcast.close(); - moq_clock::timeout(TIMEOUT, handle.closed()) + kio::clock::timeout(TIMEOUT, handle.closed()) .await .expect("the handle never closed"); assert!(matches!(handle.track("video"), Err(Error::Unroutable))); @@ -51,13 +51,13 @@ async fn close_then_lookup(publisher: moq_net::origin::Producer, reader: moq_net assert!(matches!(broadcast.announce(Default::default()), Err(Error::Closed))); } -#[moq_clock::test] +#[kio::test] async fn close_ends_a_local_consumer() { let origin = produce_origin(1); close_then_lookup(origin.clone(), origin).await; } -#[moq_clock::test] +#[kio::test] async fn close_ends_a_remote_consumer() { for version in ["moq-lite-05", "moq-transport-18"] { let publisher = produce_origin(1); diff --git a/rs/moq-net/tests/integration/catalog_acquisition.rs b/rs/moq-net/tests/integration/catalog_acquisition.rs index 8111b27b9f9..ff752b7e22a 100644 --- a/rs/moq-net/tests/integration/catalog_acquisition.rs +++ b/rs/moq-net/tests/integration/catalog_acquisition.rs @@ -72,12 +72,12 @@ async fn acquisition(version: &str, carries_epoch: bool) { } } -#[moq_clock::test] +#[kio::test] async fn epochless_replacement_refuses_pending_catalog() { acquisition("moq-lite-06", false).await; } -#[moq_clock::test] +#[kio::test] async fn same_epoch_replacement_acquires_pending_catalog() { acquisition("moq-lite-07-wip", true).await; acquisition("moq-transport-18", true).await; diff --git a/rs/moq-net/tests/integration/catalog_churn.rs b/rs/moq-net/tests/integration/catalog_churn.rs index 31c944f87c2..327ebfeb269 100644 --- a/rs/moq-net/tests/integration/catalog_churn.rs +++ b/rs/moq-net/tests/integration/catalog_churn.rs @@ -134,7 +134,7 @@ struct Reader { expected: Vec, seen: Vec, /// Owns the subscription, so dropping the reader leaves the track. - task: moq_clock::sim::JoinHandle<()>, + task: kio::clock::sim::JoinHandle<()>, } impl Drop for Reader { @@ -146,7 +146,7 @@ impl Drop for Reader { impl Reader { fn new(id: usize, mut sub: track::Subscriber, expected: Vec) -> Self { let (tx, rx) = mpsc::unbounded(); - let task = moq_clock::sim::spawn(async move { + let task = kio::clock::sim::spawn(async move { loop { let mut group = match sub.recv_group().await { Ok(Some(group)) => group, @@ -266,7 +266,7 @@ impl Topology { /// A fresh request for the broadcast; `None` when refused, as with no route right now. async fn request(&self, step: usize) -> Result, Failure> { let request = self.subscriber.consume().request_broadcast("live", None); - match moq_clock::timeout(READ_TIMEOUT, request).await { + match kio::clock::timeout(READ_TIMEOUT, request).await { Ok(result) => Ok(result.ok()), Err(_) => Err(stuck(format!("{step}: request hung"))), } @@ -331,14 +331,14 @@ async fn execute(version: Version, ops: &[Op]) -> Result<(), Failure> { written.clear(); write(&mut group, &mut written, &mut readers, "snapshot"); // Let it reach `R`, so the newest group at the next join is unambiguous. - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; } Op::Join => { let Some(remote) = topology.request(step).await? else { continue; }; let subscribe = remote.track("catalog.json").unwrap().subscribe(None); - match moq_clock::timeout(READ_TIMEOUT, subscribe).await { + match kio::clock::timeout(READ_TIMEOUT, subscribe).await { Ok(Ok(sub)) => readers.push(Reader::new(joined, sub, written.clone())), Ok(Err(_)) => {} Err(_) => return Err(stuck(format!("{step}: subscribe hung"))), @@ -350,14 +350,14 @@ async fn execute(version: Version, ops: &[Op]) -> Result<(), Failure> { continue; }; let fetch = remote.track("catalog.json").unwrap().fetch_group(group.sequence, None); - let mut fetched = match moq_clock::timeout(READ_TIMEOUT, fetch).await { + let mut fetched = match kio::clock::timeout(READ_TIMEOUT, fetch).await { Ok(Ok(fetched)) => fetched, Ok(Err(_)) => continue, Err(_) => return Err(stuck(format!("{step}: fetch hung"))), }; let mut got = Vec::new(); while got.len() < written.len() { - match moq_clock::timeout(READ_TIMEOUT, fetched.read_frame()).await { + match kio::clock::timeout(READ_TIMEOUT, fetched.read_frame()).await { Ok(Ok(Some(frame))) => got.push(format!( "{}:{}", fetched.sequence, @@ -380,9 +380,9 @@ async fn execute(version: Version, ops: &[Op]) -> Result<(), Failure> { Op::ToggleA => topology.toggle(0).await, Op::ToggleB => topology.toggle(1).await, Op::ToggleDirect => topology.toggle(2).await, - Op::Sleep(pause) => moq_clock::sleep(pause).await, + Op::Sleep(pause) => kio::clock::sleep(pause).await, Op::Check => { - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; let mut failed = Vec::new(); for (index, reader) in readers.iter_mut().enumerate() { let open = reader.drain(); @@ -392,7 +392,7 @@ async fn execute(version: Version, ops: &[Op]) -> Result<(), Failure> { _ if !open => failed.push(index), Verdict::Done => {} Verdict::Short => { - let _ = moq_clock::timeout(STUCK_AFTER, async { + let _ = kio::clock::timeout(STUCK_AFTER, async { while reader.judge() == Verdict::Short { match reader.rx.next().await { Some(Ok(frame)) => reader.seen.push(frame), @@ -448,13 +448,13 @@ async fn churn(version: &str) { } /// Routes carry the publisher's epoch, so subscriptions resume across them. -#[moq_clock::test] +#[kio::test] async fn catalog_churn_lite_07() { churn("moq-lite-07-wip").await; } /// No epoch on the wire: a route change ends subscriptions, which must fail loudly. -#[moq_clock::test] +#[kio::test] async fn catalog_churn_lite_06() { churn("moq-lite-06").await; } diff --git a/rs/moq-net/tests/integration/catalog_handover.rs b/rs/moq-net/tests/integration/catalog_handover.rs index 39cfbc80ae4..8ae3bde8b00 100644 --- a/rs/moq-net/tests/integration/catalog_handover.rs +++ b/rs/moq-net/tests/integration/catalog_handover.rs @@ -55,7 +55,7 @@ fn abort(pair: MockPair) { /// Let every task settle. Time is paused, so this returns once the runtime is idle. async fn settle() { - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; } /// How the serving route changes. @@ -167,11 +167,11 @@ impl Topology { /// A new reader on `R`: a fresh broadcast request and a floorless subscription. async fn reader(&self) -> Reader { - let remote = moq_clock::timeout(READ_TIMEOUT, self.subscriber.consume().request_broadcast("live", None)) + let remote = kio::clock::timeout(READ_TIMEOUT, self.subscriber.consume().request_broadcast("live", None)) .await .expect("request hung") .expect("request refused"); - let sub = moq_clock::timeout(READ_TIMEOUT, remote.track("catalog.json").unwrap().subscribe(None)) + let sub = kio::clock::timeout(READ_TIMEOUT, remote.track("catalog.json").unwrap().subscribe(None)) .await .expect("subscribe hung") .expect("subscribe refused"); @@ -184,7 +184,7 @@ impl Topology { struct Reader { rx: mpsc::UnboundedReceiver>, /// Owns the subscription, so dropping the reader leaves the track. - task: moq_clock::sim::JoinHandle<()>, + task: kio::clock::sim::JoinHandle<()>, } impl Drop for Reader { @@ -196,7 +196,7 @@ impl Drop for Reader { impl Reader { fn new(mut sub: track::Subscriber) -> Self { let (tx, rx) = mpsc::unbounded(); - let task = moq_clock::sim::spawn(async move { + let task = kio::clock::sim::spawn(async move { loop { let mut group = match sub.recv_group().await { Ok(Some(group)) => group, @@ -232,7 +232,7 @@ impl Reader { async fn take(&mut self, n: usize, who: &str) -> Vec { let mut frames = Vec::new(); while frames.len() < n { - match moq_clock::timeout(READ_TIMEOUT, self.rx.next()).await { + match kio::clock::timeout(READ_TIMEOUT, self.rx.next()).await { Ok(Some(Ok(frame))) => frames.push(frame), Ok(Some(Err(err))) => panic!("{who}: failed after {frames:?}: {err}"), Ok(None) => panic!("{who}: ended after {frames:?}"), @@ -250,7 +250,7 @@ impl Reader { /// The subscription fails or ends, rather than hanging or delivering more. async fn expect_end(&mut self, who: &str) { - match moq_clock::timeout(READ_TIMEOUT, self.rx.next()).await { + match kio::clock::timeout(READ_TIMEOUT, self.rx.next()).await { Ok(None | Some(Err(_))) => {} Ok(Some(Ok(frame))) => panic!("{who}: delivered {frame:?} past its route"), Err(_) => panic!("{who}: hung instead of ending"), @@ -322,7 +322,7 @@ async fn handover(version: &str, trigger: Trigger, holder: Holder) { assert_eq!(viewer.take(1, &tag).await, ["0:delta3"], "{tag}: viewer continues"); } // Returning well past the relays' idle linger, so no copy of the head is warm. - moq_clock::sleep(RETURN_AFTER).await; + kio::clock::sleep(RETURN_AFTER).await; let mut returning = topology.reader().await; returning.expect_all(&topology, &format!("{tag}: returning")).await; @@ -365,14 +365,14 @@ async fn late_reader(version: &str, before: Before) { Before::Resume => { settle().await; drop(first); - moq_clock::sleep(Duration::from_secs(5)).await; + kio::clock::sleep(Duration::from_secs(5)).await; let mut resumed = topology.reader().await; resumed.expect_all(&topology, &format!("{tag}: resumed")).await; resumed } }; - moq_clock::sleep(RETURN_AFTER).await; + kio::clock::sleep(RETURN_AFTER).await; let mut late = topology.reader().await; late.expect_all(&topology, &format!("{tag}: late")).await; } @@ -389,7 +389,7 @@ async fn fetch_after_leave(version: &str, pause: Duration) { reader.expect_all(&topology, &format!("{tag}: reader")).await; topology.write("delta1"); drop(reader); - moq_clock::sleep(pause).await; + kio::clock::sleep(pause).await; let remote = topology .subscriber @@ -398,13 +398,13 @@ async fn fetch_after_leave(version: &str, pause: Duration) { .await .unwrap(); let fetch = remote.track("catalog.json").unwrap().fetch_group(0, None); - let mut group = moq_clock::timeout(READ_TIMEOUT, fetch) + let mut group = kio::clock::timeout(READ_TIMEOUT, fetch) .await .unwrap_or_else(|_| panic!("{tag}: fetch hung")) .unwrap_or_else(|err| panic!("{tag}: fetch refused: {err}")); let mut got = Vec::new(); while got.len() < topology.written.len() { - match moq_clock::timeout(READ_TIMEOUT, group.read_frame()).await { + match kio::clock::timeout(READ_TIMEOUT, group.read_frame()).await { Ok(Ok(Some(frame))) => got.push(String::from_utf8_lossy(&frame.payload).to_string()), Ok(Ok(None)) => panic!("{tag}: fetch ended after {got:?}"), Ok(Err(err)) => panic!("{tag}: fetch failed after {got:?}: {err}"), @@ -421,61 +421,61 @@ macro_rules! handover_tests { use super::*; async fn run(trigger: Trigger, holder: Holder) { - moq_clock::timeout(TEST_TIMEOUT, handover($version, trigger, holder)) + kio::clock::timeout(TEST_TIMEOUT, handover($version, trigger, holder)) .await .expect("timed out"); } - #[moq_clock::test] + #[kio::test] async fn disconnect_with_viewer() { run(Trigger::Disconnect, Holder::Viewer).await; } - #[moq_clock::test] + #[kio::test] async fn disconnect_parked() { run(Trigger::Disconnect, Holder::Parked).await; } - #[moq_clock::test] + #[kio::test] async fn unannounce_with_viewer() { run(Trigger::Unannounce, Holder::Viewer).await; } - #[moq_clock::test] + #[kio::test] async fn unannounce_parked() { run(Trigger::Unannounce, Holder::Parked).await; } - #[moq_clock::test] + #[kio::test] async fn better_route_with_viewer() { run(Trigger::BetterRoute, Holder::Viewer).await; } - #[moq_clock::test] + #[kio::test] async fn better_route_parked() { run(Trigger::BetterRoute, Holder::Parked).await; } - #[moq_clock::test] + #[kio::test] async fn reconnect_with_viewer() { run(Trigger::Reconnect, Holder::Viewer).await; } - #[moq_clock::test] + #[kio::test] async fn reconnect_parked() { run(Trigger::Reconnect, Holder::Parked).await; } - #[moq_clock::test] + #[kio::test] async fn late_reader_after_route_change() { - moq_clock::timeout(TEST_TIMEOUT, late_reader($version, Before::RouteChange)) + kio::clock::timeout(TEST_TIMEOUT, late_reader($version, Before::RouteChange)) .await .expect("timed out"); } - #[moq_clock::test] + #[kio::test] async fn late_reader_after_resume() { - moq_clock::timeout(TEST_TIMEOUT, late_reader($version, Before::Resume)) + kio::clock::timeout(TEST_TIMEOUT, late_reader($version, Before::Resume)) .await .expect("timed out"); } @@ -496,16 +496,16 @@ macro_rules! fetch_tests { mod $name { use super::*; - #[moq_clock::test] + #[kio::test] async fn fetch_right_after_leave() { - moq_clock::timeout(TEST_TIMEOUT, fetch_after_leave($version, Duration::ZERO)) + kio::clock::timeout(TEST_TIMEOUT, fetch_after_leave($version, Duration::ZERO)) .await .expect("timed out"); } - #[moq_clock::test] + #[kio::test] async fn fetch_after_leave_settles() { - moq_clock::timeout(TEST_TIMEOUT, fetch_after_leave($version, Duration::from_millis(500))) + kio::clock::timeout(TEST_TIMEOUT, fetch_after_leave($version, Duration::from_millis(500))) .await .expect("timed out"); } diff --git a/rs/moq-net/tests/integration/compress.rs b/rs/moq-net/tests/integration/compress.rs index a7d8acd47ee..dc0244b1b45 100644 --- a/rs/moq-net/tests/integration/compress.rs +++ b/rs/moq-net/tests/integration/compress.rs @@ -120,7 +120,7 @@ const RANGED: &[&str] = &["moq-lite-07-wip", "moq-transport-18", "moq-transport- /// A subscription starting at a group delivers it whole from its first frame across every /// pair of hops, compressed or not, whether the group began before it subscribed or after. -#[moq_clock::test] +#[kio::test] async fn a_start_group_arrives_whole() { use moq_net::track::{Anchor, Subscription}; let write = |group: &mut moq_net::group::Producer, frames: std::ops::Range| { @@ -139,7 +139,7 @@ async fn a_start_group_arrives_whole() { // or fill delivers. for head in [0, 3] { let case = format!("{upstream} -> {downstream}, compress {compress}, head {head}"); - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { let info = match compress { true => compressed(), false => moq_net::track::Info::default().with_timescale(moq_net::Timescale::MILLI), @@ -181,10 +181,10 @@ async fn a_start_group_arrives_whole() { /// Whole and chunked frames on a compressed track read back as written on every version, /// and only a peer that can signal it learns the track is compressed. -#[moq_clock::test] +#[kio::test] async fn relay_serves_every_version() { for &version in VERSIONS { - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { let mut fixture = connect("moq-lite-07-wip", version).await; assert_eq!( fixture.subscriber.info().compress, @@ -231,10 +231,10 @@ async fn relay_serves_every_version() { /// A compressed track's datagrams read back as written, whether the subscriber takes them /// compressed or inflated. -#[moq_clock::test] +#[kio::test] async fn datagrams_serve_every_version() { for &version in &["moq-lite-07-wip", "moq-lite-06", "moq-transport-18", "moq-transport-22"] { - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { let mut fixture = connect("moq-lite-07-wip", version).await; fixture .track @@ -262,10 +262,10 @@ fn traffic(registry: &moq_net::stats::Registry, role: moq_net::stats::Role) -> m /// A relay meters a compressed track's datagram in the form each wire carries: compressed /// on ingress and on moq-lite 07 egress, inflated to an older subscriber. Only `inflated` /// counts the bytes the relay inflated. -#[moq_clock::test] +#[kio::test] async fn datagrams_meter_the_bytes_on_the_wire() { for &version in &["moq-lite-07-wip", "moq-lite-06"] { - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); let mut track = broadcast.create_track("data", compressed()).unwrap(); @@ -326,11 +326,11 @@ async fn datagrams_meter_the_bytes_on_the_wire() { } /// Negotiated IETF ingress stays compressed across a relay to IETF or lite-07 egress. -#[moq_clock::test] +#[kio::test] async fn ietf_ingress_stays_compressed_across_protocols() { for upstream in ["moq-transport-18", "moq-transport-22"] { for downstream in ["moq-lite-07-wip", "moq-transport-22"] { - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { let mut fixture = connect(upstream, downstream).await; assert!(fixture.subscriber.info().compress, "{upstream} -> {downstream}"); let mut group = fixture.track.append_group().unwrap(); @@ -371,10 +371,10 @@ async fn ietf_ingress_stays_compressed_across_protocols() { } /// A finished compressed track remains fetchable without subscribing to its live feed. -#[moq_clock::test] +#[kio::test] async fn ietf_fetch_keeps_the_stored_form() { for version in ["moq-transport-18", "moq-transport-22"] { - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); let track = broadcast.create_track("data", compressed()).unwrap(); diff --git a/rs/moq-net/tests/integration/control_stats.rs b/rs/moq-net/tests/integration/control_stats.rs index 4e83721804f..b106be2f79b 100644 --- a/rs/moq-net/tests/integration/control_stats.rs +++ b/rs/moq-net/tests/integration/control_stats.rs @@ -17,7 +17,7 @@ fn origin() -> origin::Producer { origin } -#[moq_clock::test] +#[kio::test] async fn control_classes_cross_lite_and_ietf_sessions_without_counting_payload() { for version in ["moq-lite-03", "moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { let publisher = origin(); @@ -66,7 +66,7 @@ async fn control_classes_cross_lite_and_ietf_sessions_without_counting_payload() /// The SETUP a server reads before admission counts under the stats the handshake is /// admitted with, even for a session with neither origin. -#[moq_clock::test] +#[kio::test] async fn setup_counts_under_the_admitted_stats() { for version in ["moq-lite-07-wip", "moq-transport-22"] { let version: moq_net::Version = version.parse().unwrap(); @@ -90,7 +90,7 @@ async fn setup_counts_under_the_admitted_stats() { session }; let _sessions = futures::join!(client, server); - moq_clock::sleep(std::time::Duration::from_millis(100)).await; + kio::clock::sleep(std::time::Duration::from_millis(100)).await; let rows = registry.snapshot().control(); assert!( rows.iter() diff --git a/rs/moq-net/tests/integration/datagram.rs b/rs/moq-net/tests/integration/datagram.rs index 08b7219addb..54e6f04ded6 100644 --- a/rs/moq-net/tests/integration/datagram.rs +++ b/rs/moq-net/tests/integration/datagram.rs @@ -77,9 +77,9 @@ async fn connect_datagram_track() -> Fixture { /// asserts what delivery actually guarantees rather than a fixed count: whatever /// arrives is intact and in order, and the last one written arrives, since nothing /// is pushed during the drain to evict it. -#[moq_clock::test] +#[kio::test] async fn datagrams_reach_the_subscriber_in_order() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let mut fixture = connect_datagram_track().await; const COUNT: u64 = 32; @@ -122,10 +122,10 @@ async fn datagrams_reach_the_subscriber_in_order() { /// MoQ Transport carries a datagram as an OBJECT_DATAGRAM at object 0, so it arrives as a /// datagram with its sequence, alongside the groups on streams. -#[moq_clock::test] +#[kio::test] async fn ietf_delivers_datagrams() { for version in ["moq-transport-18", "moq-transport-22"] { - moq_clock::timeout(TEST_TIMEOUT, ietf_delivers_datagrams_on(version)) + kio::clock::timeout(TEST_TIMEOUT, ietf_delivers_datagrams_on(version)) .await .unwrap_or_else(|_| panic!("{version}: timed out")); } @@ -186,9 +186,9 @@ async fn ietf_delivers_datagrams_on(version: &str) { } /// Explicit insert keeps the origin sequence on the lite wire, including a gap. -#[moq_clock::test] +#[kio::test] async fn inserted_sequences_survive_the_lite_wire() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let mut fixture = connect_datagram_track().await; fixture @@ -230,7 +230,7 @@ async fn inserted_sequences_survive_the_lite_wire() { /// moq-lite-07, and with the NOT_FOUND an earlier version has for it. A relay carries the /// answer across in the downstream version's terms. The moq-transport side (DOES_NOT_EXIST) /// is covered by the IETF publisher's own tests. -#[moq_clock::test] +#[kio::test] async fn a_fetched_datagram_is_refused_per_version() { const NOT_FETCHABLE: &str = "not fetchable"; const NOT_FOUND: &str = "not found"; @@ -269,7 +269,7 @@ async fn a_fetched_datagram_is_refused_per_version() { (&["moq-lite-07-wip"], NOT_FETCHABLE), (&["moq-lite-07-wip", "moq-lite-06"], NOT_FOUND), ] { - let refused = moq_clock::timeout(TEST_TIMEOUT, fetch_a_datagram(versions)) + let refused = kio::clock::timeout(TEST_TIMEOUT, fetch_a_datagram(versions)) .await .unwrap_or_else(|_| panic!("{versions:?}: timed out")); assert_eq!(refused, expected, "{versions:?}"); diff --git a/rs/moq-net/tests/integration/dial_split_horizon.rs b/rs/moq-net/tests/integration/dial_split_horizon.rs index 46498de80d0..cbb8c974381 100644 --- a/rs/moq-net/tests/integration/dial_split_horizon.rs +++ b/rs/moq-net/tests/integration/dial_split_horizon.rs @@ -95,7 +95,7 @@ fn traffic(registry: &stats::Registry, role: stats::Role) -> stats::Traffic { /// The hop the dialer attributed `path` to, once that announce has arrived. async fn learned_hop(dialer: &origin::Producer, path: &str) -> Hop { let mut announced = dialer.consume().announced(); - let event = moq_clock::timeout(SETTLE, async { + let event = kio::clock::timeout(SETTLE, async { loop { let event = announced.next().await.expect("announce cursor closed"); let announce = match event { @@ -123,13 +123,13 @@ fn hop(id: u64) -> Hop { } /// Edges that declare their own hop over the MoQ Cluster extension. -#[moq_clock::test] +#[kio::test] async fn dialed_named_session_does_not_echo_or_route_subscribe_back() { split_horizon("moq-transport-18", [hop(2), hop(3)]).await; } /// moq-lite-01 carries no hop, so neither side declares one. -#[moq_clock::test] +#[kio::test] async fn dialed_anonymous_session_does_not_echo_or_route_subscribe_back() { split_horizon("moq-lite-01", [hop(2), hop(3)]).await; } @@ -160,7 +160,7 @@ async fn split_horizon(version: &str, [publisher_hop, subscriber_hop]: [Hop; 2]) // The other edge learns the namespace, attributed to a different hop, so the // two dials are not one endpoint. let mut subscriber_announced = subscriber.consume().announced(); - let subscriber_saw = moq_clock::timeout(SETTLE, subscriber_announced.next()) + let subscriber_saw = kio::clock::timeout(SETTLE, subscriber_announced.next()) .await .expect("the other edge never learned the namespace") .expect("announce cursor closed"); @@ -175,7 +175,7 @@ async fn split_horizon(version: &str, [publisher_hop, subscriber_hop]: [Hop; 2]) assert_ne!(subscriber_hop, publisher_hop, "each dial gets its own hop"); assert_ne!(subscriber_hop, Hop::UNKNOWN); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; let echoed = traffic(&to_publisher.registry, stats::Role::Subscriber); assert_eq!( @@ -203,12 +203,12 @@ async fn split_horizon(version: &str, [publisher_hop, subscriber_hop]: [Hop; 2]) .subscribe(subscription) .await .expect("subscriber subscribes"); - moq_clock::timeout(SETTLE, crate::support::wanted(track.demand())) + kio::clock::timeout(SETTLE, crate::support::wanted(track.demand())) .await .expect("the subscribe never reached the announcer") .unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; let from_announcer = traffic(&to_publisher.registry, stats::Role::Publisher); assert_eq!( diff --git a/rs/moq-net/tests/integration/drained_claim.rs b/rs/moq-net/tests/integration/drained_claim.rs index 3e4f7de7f6e..15f6a2f9206 100644 --- a/rs/moq-net/tests/integration/drained_claim.rs +++ b/rs/moq-net/tests/integration/drained_claim.rs @@ -40,7 +40,7 @@ async fn link(version: Version, from: &origin::Producer, to: &origin::Producer, /// Let every task settle. Time is paused, so this returns once the runtime is idle. async fn settle() { - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; } /// A worker claiming `pool`, answering each request with an output whose `video` @@ -58,7 +58,7 @@ impl Worker { let claim = Rc::new(origin.requests("pool").unwrap()); let outputs = Rc::new(RefCell::new(Vec::new())); let (handler, served) = (claim.clone(), outputs.clone()); - drop(moq_clock::sim::spawn(async move { + drop(kio::clock::sim::spawn(async move { while let Ok(request) = handler.requested_broadcast().await { let prepared = request.prepare(Epoch::mint()).unwrap(); let track = prepared.broadcast().create_track("video", timed()).unwrap(); @@ -111,7 +111,7 @@ async fn drained_claim(version: &str) { a_link.server.drain().send(Goaway::new()).unwrap(); // Past the linger, which is as long as the cache window, nothing reads the relay's // front for the path. - moq_clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2).await; + kio::clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2).await; assert_eq!( watch(&relay).await, @@ -122,16 +122,16 @@ async fn drained_claim(version: &str) { assert_eq!(b.served(), 1, "{version}"); } -#[moq_clock::test] +#[kio::test] async fn a_drained_claims_front_ends_once_unread_lite06() { - moq_clock::timeout(TEST_TIMEOUT, drained_claim("moq-lite-06")) + kio::clock::timeout(TEST_TIMEOUT, drained_claim("moq-lite-06")) .await .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn a_drained_claims_front_ends_once_unread_lite07() { - moq_clock::timeout(TEST_TIMEOUT, drained_claim("moq-lite-07-wip")) + kio::clock::timeout(TEST_TIMEOUT, drained_claim("moq-lite-07-wip")) .await .expect("timed out"); } diff --git a/rs/moq-net/tests/integration/empty_group.rs b/rs/moq-net/tests/integration/empty_group.rs index 3b853a60a96..588c61912bf 100644 --- a/rs/moq-net/tests/integration/empty_group.rs +++ b/rs/moq-net/tests/integration/empty_group.rs @@ -24,7 +24,7 @@ fn produce_origin(hop: u64) -> origin::Producer { producer } -#[moq_clock::test] +#[kio::test] async fn an_empty_group_arrives_empty() { for version in VERSIONS { let publisher = produce_origin(1); @@ -37,24 +37,24 @@ async fn an_empty_group_arrives_empty() { let consumer = subscriber.consume(); consumer.routed("room").await.unwrap(); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); - let mut sub = moq_clock::timeout(TIMEOUT, remote.track("data").unwrap().subscribe(None)) + let mut sub = kio::clock::timeout(TIMEOUT, remote.track("data").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); subscribed(&track).await; track.append_group().unwrap().finish().unwrap(); - let mut empty = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut empty = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .unwrap_or_else(|_| panic!("{version}: the empty group was dropped")) .unwrap() .expect("a group"); assert_eq!(empty.sequence, 0, "{version}"); - let frame = moq_clock::timeout(TIMEOUT, empty.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, empty.read_frame()) .await .expect("frame timeout") .unwrap(); @@ -63,7 +63,7 @@ async fn an_empty_group_arrives_empty() { let mut group = track.append_group().unwrap(); group.write_frame(Timestamp::ZERO, &b"ok"[..]).unwrap(); group.finish().unwrap(); - let mut next = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut next = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() diff --git a/rs/moq-net/tests/integration/extensions.rs b/rs/moq-net/tests/integration/extensions.rs index 16e2aee3537..d37ba141a6e 100644 --- a/rs/moq-net/tests/integration/extensions.rs +++ b/rs/moq-net/tests/integration/extensions.rs @@ -60,7 +60,7 @@ fn announced(origin: &origin::Producer, path: &str) -> bool { /// A side that declines MoQ Solicit invites unsolicited advertisements, so its peer /// announces unasked and that is not held against the peer, even though the peer /// implements the extension itself. -#[moq_clock::test] +#[kio::test] async fn a_side_that_declines_solicit_takes_unsolicited_announces() { for name in MOQT { let version: Version = name.parse().unwrap(); @@ -87,7 +87,7 @@ async fn a_side_that_declines_solicit_takes_unsolicited_announces() { let broadcast = publisher.create_broadcast("room/cam").unwrap(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; assert!(announced(&subscriber, "room/cam"), "{context}: never announced"); assert_open(&pair, &context); @@ -98,7 +98,7 @@ async fn a_side_that_declines_solicit_takes_unsolicited_announces() { /// A side that declines MoQ Auth leaves it un-negotiated whichever side declines: /// neither side holds a grant, and a token is kept for the requests that name it /// rather than presented on an AUTH stream. -#[moq_clock::test] +#[kio::test] async fn a_declined_auth_extension_is_not_negotiated() { for name in AUTH { let version: Version = name.parse().unwrap(); @@ -106,7 +106,7 @@ async fn a_declined_auth_extension_is_not_negotiated() { // Control: offered by both, the client's connection credential earns a grant. let pair = connect_mock(MockConnectOptions::new(version)).await; let mut grant = pair.client.auth().grant(); - moq_clock::timeout(SETTLE, async { + kio::clock::timeout(SETTLE, async { while grant.peek().is_none() { grant.changed().await.expect("grant watch ended"); } @@ -123,13 +123,13 @@ async fn a_declined_auth_extension_is_not_negotiated() { false => options.client_extensions = no_auth, } let pair = connect_mock(options).await; - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; for session in [&pair.client, &pair.server] { assert_eq!(session.auth().grant().peek(), None, "{context}"); // Only a request that names it can carry the token, so it resolves at once with // a grant that stays unknown. - let (added, answer) = moq_clock::timeout(SETTLE, session.auth().add("token")) + let (added, answer) = kio::clock::timeout(SETTLE, session.auth().add("token")) .await .unwrap_or_else(|_| panic!("{context}: add never resolved")) .unwrap_or_else(|err| panic!("{context}: {err:?}")); @@ -168,7 +168,7 @@ fn route(origin: &origin::Producer, path: &str) -> Option { /// MoQ Epoch carries the publisher's epoch, in either direction, only when both sides /// offer it. A side declining it leaves the route epochless exactly as before the /// extension, and nothing on the wire breaks the session. -#[moq_clock::test] +#[kio::test] async fn an_epoch_crosses_only_when_both_offer_it() { for name in MOQT { let version: Version = name.parse().unwrap(); @@ -202,7 +202,7 @@ async fn an_epoch_crosses_only_when_both_offer_it() { broadcast .announce(origin::Route::default().with_epoch(epoch.clone())) .unwrap(); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; let route = route(&subscriber, "room/cam").unwrap_or_else(|| panic!("{context}: never announced")); let expected = declines.is_none().then_some(epoch); diff --git a/rs/moq-net/tests/integration/fetch_cancel.rs b/rs/moq-net/tests/integration/fetch_cancel.rs index 3aaff468c8d..33b33da9016 100644 --- a/rs/moq-net/tests/integration/fetch_cancel.rs +++ b/rs/moq-net/tests/integration/fetch_cancel.rs @@ -50,7 +50,7 @@ async fn abandoned_fetch_reaches_the_publisher(version: &str, relays: u64, stage let broadcast = nodes[0].create_broadcast("room").unwrap(); let mut dynamic = broadcast.requests(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let consumer = nodes[relays as usize] .consume() @@ -75,7 +75,7 @@ async fn abandoned_fetch_reaches_the_publisher(version: &str, relays: u64, stage match stage { Stage::Unanswered => { drop(waiting); - moq_clock::timeout(Duration::from_secs(5), kio::wait(|waiter| request.poll_unused(waiter))) + kio::clock::timeout(Duration::from_secs(5), kio::wait(|waiter| request.poll_unused(waiter))) .await .unwrap_or_else(|_| panic!("{ctx}: the publisher's fetch is still wanted")); } @@ -94,7 +94,7 @@ async fn abandoned_fetch_reaches_the_publisher(version: &str, relays: u64, stage while demand.wanted_changed().await? {} Ok::<_, moq_net::Error>(()) }; - moq_clock::timeout(Duration::from_secs(5), unwanted) + kio::clock::timeout(Duration::from_secs(5), unwanted) .await .unwrap_or_else(|_| panic!("{ctx}: the publisher still serves the fetch")) .unwrap(); @@ -102,7 +102,7 @@ async fn abandoned_fetch_reaches_the_publisher(version: &str, relays: u64, stage // No hop cached the head as the whole group: a fresh fetch reads it all. group.write_frame(Timestamp::ZERO, Bytes::from_static(b"tail")).unwrap(); group.finish().unwrap(); - let mut fetched = moq_clock::timeout(Duration::from_secs(5), track.fetch_group(0, None)) + let mut fetched = kio::clock::timeout(Duration::from_secs(5), track.fetch_group(0, None)) .await .unwrap_or_else(|_| panic!("{ctx}: the refetch stalled")) .unwrap(); @@ -128,13 +128,13 @@ async fn abandoned_fetch_reaches_the_publisher(version: &str, relays: u64, stage const LATENCY: Duration = Duration::from_millis(100); _pairs.last().unwrap().client_transport.set_latency(LATENCY); group.finish().unwrap(); - moq_clock::sleep(LATENCY).await; + kio::clock::sleep(LATENCY).await; drop(fetched); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; // The publisher can no longer serve it, so only a cached copy answers. group.abort(moq_net::Error::Cancel).unwrap(); - let mut fetched = moq_clock::timeout(Duration::from_secs(5), track.fetch_group(0, None)) + let mut fetched = kio::clock::timeout(Duration::from_secs(5), track.fetch_group(0, None)) .await .unwrap_or_else(|_| panic!("{ctx}: the refetch stalled")) .unwrap_or_else(|err| panic!("{ctx}: the whole group was not cached: {err}")); @@ -155,12 +155,12 @@ async fn abandoned_fetches_reach_the_publisher(version: &str) { } } -#[moq_clock::test] +#[kio::test] async fn abandoned_fetch_reaches_the_publisher_lite05() { abandoned_fetches_reach_the_publisher("moq-lite-05").await; } -#[moq_clock::test] +#[kio::test] async fn abandoned_fetch_reaches_the_publisher_lite06() { abandoned_fetches_reach_the_publisher("moq-lite-06").await; } @@ -177,7 +177,7 @@ async fn a_refetch_within_the_linger_stays_on_the_relay(version: &str) { let broadcast = publisher.create_broadcast("room").unwrap(); let mut dynamic = broadcast.requests(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let consumer = relay.consume().request_broadcast("room", None).await.unwrap(); let mut waiting = Box::pin(consumer.track("video").unwrap().fetch_group(0, None)); @@ -203,7 +203,7 @@ async fn a_refetch_within_the_linger_stays_on_the_relay(version: &str) { group.abort(moq_net::Error::Cancel).unwrap(); // The track goes unread between segments, well inside the linger. - moq_clock::sleep(Duration::from_secs(5)).await; + kio::clock::sleep(Duration::from_secs(5)).await; let mut refetch = Box::pin(consumer.track("video").unwrap().fetch_group(0, None)); let track_request = std::pin::pin!(dynamic.requested_track()); @@ -221,17 +221,17 @@ async fn a_refetch_within_the_linger_stays_on_the_relay(version: &str) { assert_eq!(&fetched.read_frame().await.unwrap().unwrap().payload[..], b"segment"); } -#[moq_clock::test] +#[kio::test] async fn a_refetch_within_the_linger_stays_on_the_relay_lite06() { a_refetch_within_the_linger_stays_on_the_relay("moq-lite-06").await; } -#[moq_clock::test] +#[kio::test] async fn a_refetch_within_the_linger_stays_on_the_relay_lite07() { a_refetch_within_the_linger_stays_on_the_relay("moq-lite-07-wip").await; } -#[moq_clock::test] +#[kio::test] async fn a_refetch_within_the_linger_stays_on_the_relay_ietf18() { a_refetch_within_the_linger_stays_on_the_relay("moq-transport-18").await; } diff --git a/rs/moq-net/tests/integration/fetch_fanout.rs b/rs/moq-net/tests/integration/fetch_fanout.rs index 3b09be36bf8..e32eab560a4 100644 --- a/rs/moq-net/tests/integration/fetch_fanout.rs +++ b/rs/moq-net/tests/integration/fetch_fanout.rs @@ -14,7 +14,7 @@ fn origin(hop: u64) -> origin::Producer { origin } -#[moq_clock::test] +#[kio::test] async fn sequential_viewers_share_the_relays_fetched_groups() { for version in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip"] { let version: Version = version.parse().unwrap(); @@ -69,7 +69,7 @@ async fn sequential_viewers_share_the_relays_fetched_groups() { .count(); assert_eq!(fetches, round as usize + 1, "{version}: viewer {i}, group {sequence}"); } - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; } let types = upstream.client_transport.bidi_types(); assert_eq!( diff --git a/rs/moq-net/tests/integration/fetch_from_feed.rs b/rs/moq-net/tests/integration/fetch_from_feed.rs index 2431a93f096..c8043af6018 100644 --- a/rs/moq-net/tests/integration/fetch_from_feed.rs +++ b/rs/moq-net/tests/integration/fetch_from_feed.rs @@ -46,11 +46,11 @@ async fn relay(version: &str) -> Relay { let pair = connect_mock(options).await; let consumer = client.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -66,22 +66,22 @@ async fn relay(version: &str) -> Relay { /// The error a fetch of `sequence` fails with. async fn fetch_err(relay: &Relay, sequence: u64) -> moq_net::Error { let fetching = relay.remote.track("video").unwrap().fetch_group(sequence, None); - match moq_clock::timeout(TIMEOUT, fetching).await.expect("fetch timed out") { + match kio::clock::timeout(TIMEOUT, fetching).await.expect("fetch timed out") { Ok(_) => panic!("group {sequence} was served"), Err(err) => err, } } /// The groups a recorder fetches as the live subscription delivers them are served. -#[moq_clock::test] +#[kio::test] async fn a_fetch_is_served_from_the_live_feed() { for version in VERSIONS { let mut relay = relay(version).await; - let mut subscriber = moq_clock::timeout(TIMEOUT, relay.remote.track("video").unwrap().subscribe(None)) + let mut subscriber = kio::clock::timeout(TIMEOUT, relay.remote.track("video").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - let first = moq_clock::timeout(TIMEOUT, subscriber.recv_group()) + let first = kio::clock::timeout(TIMEOUT, subscriber.recv_group()) .await .expect("group timeout") .unwrap() @@ -92,17 +92,17 @@ async fn a_fetch_is_served_from_the_live_feed() { let next = first + 1; let mut fetching = relay.remote.track("video").unwrap().fetch_group(next, None); assert!( - moq_clock::timeout(Duration::from_millis(100), &mut fetching) + kio::clock::timeout(Duration::from_millis(100), &mut fetching) .await .is_err(), "{version}: answered before the group exists" ); relay.track.write_frame(None, &b"1"[..]).unwrap(); - let mut group = moq_clock::timeout(TIMEOUT, fetching) + let mut group = kio::clock::timeout(TIMEOUT, fetching) .await .expect("fetch timed out") .unwrap_or_else(|err| panic!("{version}: {err}")); - let frame = moq_clock::timeout(TIMEOUT, group.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("read timed out"); assert_eq!(&frame.unwrap().expect("a frame").payload[..], b"1", "{version}"); @@ -112,7 +112,7 @@ async fn a_fetch_is_served_from_the_live_feed() { /// A fetch that reaches the relay alongside the subscription that will carry it, as a /// recorder starting on an uncached group sends them, waits for that feed. The relay /// already serves the track, with no feed, for an earlier fetch. -#[moq_clock::test] +#[kio::test] async fn a_fetch_waits_for_a_feed_opened_with_it() { for version in VERSIONS { let mut relay = relay(version).await; @@ -122,17 +122,17 @@ async fn a_fetch_waits_for_a_feed_opened_with_it() { let track = relay.remote.track("video").unwrap(); let subscribing = track.subscribe(None); let fetching = track.fetch_group(1, None); - let _subscriber = moq_clock::timeout(TIMEOUT, subscribing) + let _subscriber = kio::clock::timeout(TIMEOUT, subscribing) .await .expect("subscribe timeout") .expect("subscribe"); relay.track.write_frame(None, &b"1"[..]).unwrap(); - let mut group = moq_clock::timeout(TIMEOUT, fetching) + let mut group = kio::clock::timeout(TIMEOUT, fetching) .await .expect("fetch timed out") .unwrap_or_else(|err| panic!("{version}: {err}")); - let frame = moq_clock::timeout(TIMEOUT, group.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("read timed out"); assert_eq!(&frame.unwrap().expect("a frame").payload[..], b"1", "{version}"); @@ -141,7 +141,7 @@ async fn a_fetch_waits_for_a_feed_opened_with_it() { /// A group with no feed at all, or one the feed went past, is a miss rather than a version /// error. -#[moq_clock::test] +#[kio::test] async fn an_unfed_fetch_is_a_miss() { for version in VERSIONS { let mut relay = relay(version).await; @@ -153,11 +153,11 @@ async fn an_unfed_fetch_is_a_miss() { let mut skipped = relay.track.create_group(moq_net::group::Info { sequence: 3 }).unwrap(); skipped.write_frame(None, &b"3"[..]).unwrap(); skipped.finish().unwrap(); - let mut subscriber = moq_clock::timeout(TIMEOUT, relay.remote.track("video").unwrap().subscribe(None)) + let mut subscriber = kio::clock::timeout(TIMEOUT, relay.remote.track("video").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - let first = moq_clock::timeout(TIMEOUT, subscriber.recv_group()) + let first = kio::clock::timeout(TIMEOUT, subscriber.recv_group()) .await .expect("group timeout") .unwrap() diff --git a/rs/moq-net/tests/integration/fetch_only.rs b/rs/moq-net/tests/integration/fetch_only.rs index 71e318198b3..b4490de50ce 100644 --- a/rs/moq-net/tests/integration/fetch_only.rs +++ b/rs/moq-net/tests/integration/fetch_only.rs @@ -30,11 +30,11 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Consumer { let consumer = origin.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves") @@ -58,7 +58,7 @@ fn publish_finished(origin: &moq_net::origin::Producer) -> (moq_net::origin::Pub let subscribed = Arc::new(AtomicBool::new(false)); let flag = subscribed.clone(); - drop(moq_clock::sim::spawn(async move { + drop(kio::clock::sim::spawn(async move { while let Ok(subscription) = track.subscription_changed().await { if subscription.is_some() { flag.store(true, Ordering::SeqCst); @@ -69,13 +69,13 @@ fn publish_finished(origin: &moq_net::origin::Producer) -> (moq_net::origin::Pub } async fn fetch(broadcast: &moq_net::broadcast::Consumer, sequence: u64) -> Result>, moq_net::Error> { - let mut group = moq_clock::timeout(TIMEOUT, async { + let mut group = kio::clock::timeout(TIMEOUT, async { broadcast.track("video").unwrap().fetch_group(sequence, None).await }) .await .expect("fetch timed out")?; let mut frames = Vec::new(); - while let Some(frame) = moq_clock::timeout(TIMEOUT, group.read_frame()) + while let Some(frame) = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("read timed out")? { @@ -109,11 +109,11 @@ async fn direct(version: &str) { } /// A finished track is fetched without a SUBSCRIBE, which it would refuse. -#[moq_clock::test] +#[kio::test] async fn a_fetch_learns_the_track_without_subscribing() { let mut failures = Vec::new(); for version in VERSIONS { - if moq_clock::sim::spawn(direct(version)).await.is_err() { + if kio::clock::sim::spawn(direct(version)).await.is_err() { failures.push(*version); } } @@ -155,10 +155,10 @@ async fn relayed(version: &str) { /// A subscriber arriving at a copy learned from TRACK_STATUS still gets timestamped /// frames: the copy is timed from TRACK_STATUS_OK, and the resumed SUBSCRIBE keeps it so. -#[moq_clock::test] +#[kio::test] async fn a_subscribe_after_track_status_keeps_timestamps() { for version in ["moq-transport-18", "moq-transport-22"] { - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); let track = broadcast.create_track("video", timed()).unwrap(); @@ -198,11 +198,11 @@ async fn a_subscribe_after_track_status_keeps_timestamps() { } /// A relay serves a downstream fetch with a fetch upstream, never a subscription. -#[moq_clock::test] +#[kio::test] async fn a_relay_fetches_without_subscribing_upstream() { let mut failures = Vec::new(); for version in VERSIONS { - if moq_clock::sim::spawn(relayed(version)).await.is_err() { + if kio::clock::sim::spawn(relayed(version)).await.is_err() { failures.push(*version); } } diff --git a/rs/moq-net/tests/integration/finished_broadcast_mock.rs b/rs/moq-net/tests/integration/finished_broadcast_mock.rs index 7c8701f3e6d..f4ae1247c0d 100644 --- a/rs/moq-net/tests/integration/finished_broadcast_mock.rs +++ b/rs/moq-net/tests/integration/finished_broadcast_mock.rs @@ -50,16 +50,16 @@ async fn round(finish_broadcast: bool) -> (Vec>, Option) let pair: MockPair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let subscription = moq_net::track::Subscription::default().with_range(0..); let mut sub = remote .track("video") @@ -84,7 +84,7 @@ async fn round(finish_broadcast: bool) -> (Vec>, Option) } }); - moq_clock::timeout(TIMEOUT, support::harness::subscribed(&track)) + kio::clock::timeout(TIMEOUT, support::harness::subscribed(&track)) .await .expect("no subscriber appeared"); @@ -100,7 +100,7 @@ async fn round(finish_broadcast: bool) -> (Vec>, Option) } // The session and both origins stay up until the reader is done. - let result = moq_clock::timeout(TIMEOUT, reader) + let result = kio::clock::timeout(TIMEOUT, reader) .await .expect("the subscription never ended") .expect("reader panicked"); @@ -117,13 +117,13 @@ fn assert_complete((got, err): (Vec>, Option)) { } /// The bug: finishing the broadcast after its track loses the track. -#[moq_clock::test] +#[kio::test] async fn a_finished_broadcast_delivers_its_finished_track() { assert_complete(round(true).await); } /// Control: the same track with the broadcast left alive arrives whole. -#[moq_clock::test] +#[kio::test] async fn a_finished_track_is_delivered_while_its_broadcast_lives() { assert_complete(round(false).await); } diff --git a/rs/moq-net/tests/integration/finite_relay.rs b/rs/moq-net/tests/integration/finite_relay.rs index 8d16ffad4f9..5dc6a03863c 100644 --- a/rs/moq-net/tests/integration/finite_relay.rs +++ b/rs/moq-net/tests/integration/finite_relay.rs @@ -76,17 +76,17 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E let downstream = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); let (mut heads, mut opened) = futures::channel::mpsc::unbounded(); - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let subscription = Subscription::default().with_max_delay(MAX_DELAY).with_range(0..); let mut sub = remote .track("tail") @@ -108,7 +108,7 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E }; assert_eq!(&head.payload[..], b"head"); heads.send(group.sequence).await.unwrap(); - tails.push(moq_clock::sim::spawn(async move { + tails.push(kio::clock::sim::spawn(async move { let tail = group.read_frame().await?.expect("tail frame"); assert_eq!(&tail.payload[..], b"tail"); assert!(group.read_frame().await?.is_none(), "extra frame"); @@ -126,14 +126,14 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E (seen, end) }); - moq_clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); // Let the publisher answer while the track is still empty, so no Largest Object // tells the relay where its feed starts; otherwise the outcome rests on whether the // first group is written before SUBSCRIBE_OK. - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; track.finish_at(moq_net::track::Position::group(GROUPS)).unwrap(); match arrival { Arrival::HeldTails => { @@ -143,7 +143,7 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E group.write_frame(Timestamp::ZERO, &b"head"[..]).unwrap(); groups.push(group); // IETF requests the live edge, so observe each header before advancing it. - match moq_clock::timeout(TIMEOUT, opened.next()).await.expect("head timeout") { + match kio::clock::timeout(TIMEOUT, opened.next()).await.expect("head timeout") { Some(head) => assert_eq!(head, sequence, "{name}"), None => panic!("{name}: the reader stopped: {:?}", reader.await), } @@ -151,7 +151,7 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E // Simulated time advances only once every task is idle: each group has reached // the subscriber, so the relay's downstream subscription has seen the end. - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; for mut group in groups { group.write_frame(Timestamp::ZERO, &b"tail"[..]).unwrap(); group.finish().unwrap(); @@ -166,17 +166,17 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E group.finish().unwrap(); // IETF serves from the live edge, so let each group open its stream before // the next one supersedes it. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; } // Once idle, the publisher has opened every stream and ended the subscription, // so the relay knows the end before any group arrives. - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; // Deliver streams newest first (IETF also carries the end on a stream of its // own) until the last group reaches the subscriber, at the declared boundary. let newest = loop { let held = upstream.server_transport.release_newest_uni(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; match opened.try_recv() { Ok(head) => break head, Err(TryRecvError::Closed) => panic!("{name}: the reader stopped: {:?}", reader.await), @@ -185,13 +185,13 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E assert!(held > 0, "{name}: no group reached the subscriber"); }; assert_eq!(newest, GROUPS - 1, "{name}"); - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; upstream.server_transport.release_unis(); } } // Lite03 carries no declared end: each of the two hops waits one max-delay grace. - let outcome = moq_clock::timeout(MAX_DELAY * 2 + TIMEOUT, reader) + let outcome = kio::clock::timeout(MAX_DELAY * 2 + TIMEOUT, reader) .await .unwrap_or_else(|_| panic!("{name}: the track never ended")) .expect("reader panicked"); @@ -199,7 +199,7 @@ async fn round(name: &str, arrival: Arrival) -> (Vec, Result<(), moq_net::E outcome } -#[moq_clock::test] +#[kio::test] async fn relay_keeps_groups_in_flight_past_the_end() { for version in VERSIONS { let (seen, end) = round(version, Arrival::HeldTails).await; @@ -210,7 +210,7 @@ async fn relay_keeps_groups_in_flight_past_the_end() { /// The relay learns the end, then receives the last group's stream before the others: it /// keeps serving until the upstream tail settles instead of ending at the boundary. -#[moq_clock::test] +#[kio::test] async fn relay_waits_for_reordered_upstream_headers() { for version in VERSIONS { let (seen, end) = round(version, Arrival::NewestFirst).await; diff --git a/rs/moq-net/tests/integration/goaway.rs b/rs/moq-net/tests/integration/goaway.rs index 0c14c298d73..0123b8efb56 100644 --- a/rs/moq-net/tests/integration/goaway.rs +++ b/rs/moq-net/tests/integration/goaway.rs @@ -37,24 +37,24 @@ const GOAWAY_VERSIONS: &[&str] = &["moq-lite-04", "moq-lite-05", "moq-transport- /// A full receive window or missing FIN ACK cannot hold a drain beyond its local deadline. async fn closes_stalled_goaway(version: Version, writes: bool) { let pair = connect_mock(MockConnectOptions::new(version)).await; - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let before = pair.server_transport.blocked_writes(); if writes { pair.server_transport.hold_writes(); } else { pair.server_transport.hold_fin_acknowledgements(); } - let started = moq_clock::now(); + let started = kio::clock::now(); let timeout = Duration::from_secs(1); pair.server.drain().send(Goaway::new().with_timeout(timeout)).unwrap(); - let reason = moq_clock::timeout(timeout * 2, pair.server.closed()) + let reason = kio::clock::timeout(timeout * 2, pair.server.closed()) .await .unwrap_or_else(|_| panic!("{version}: a stalled GOAWAY held the session past its deadline")); assert!( matches!(reason, moq_net::Error::Session(moq_net::SessionError::GoawayTimeout)), "{version}: {reason}" ); - assert_eq!(moq_clock::now() - started, timeout, "{version}: drain window moved"); + assert_eq!(kio::clock::now() - started, timeout, "{version}: drain window moved"); if writes { assert!( pair.server_transport.blocked_writes() > before, @@ -63,7 +63,7 @@ async fn closes_stalled_goaway(version: Version, writes: bool) { } } -#[moq_clock::test] +#[kio::test] async fn a_stalled_lite_goaway_is_still_closed_at_the_deadline() { for name in ["moq-lite-04", "moq-lite-05", "moq-lite-06", "moq-lite-07-wip"] { let version = name.parse().unwrap(); @@ -73,7 +73,7 @@ async fn a_stalled_lite_goaway_is_still_closed_at_the_deadline() { } } -#[moq_clock::test] +#[kio::test] async fn a_stalled_ietf_goaway_is_still_closed_at_the_deadline() { for version in support::every_version() .into_iter() @@ -86,10 +86,10 @@ async fn a_stalled_ietf_goaway_is_still_closed_at_the_deadline() { /// Server drains with a redirect URI; the client observes it through /// `Session::draining()`. Exercises every GOAWAY channel in the version /// matrix, in both directions. -#[moq_clock::test] +#[kio::test] async fn goaway_send_receive_all_versions() { for version in GOAWAY_VERSIONS { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let version: Version = version.parse().unwrap(); let pair = connect_mock(MockConnectOptions::new(version)).await; @@ -130,9 +130,9 @@ async fn goaway_send_receive_all_versions() { /// The IETF GOAWAY carries a timeout on the wire; the receiver observes the /// sender's advertised deadline. -#[moq_clock::test] +#[kio::test] async fn goaway_wire_timeout_moq_transport() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let version: Version = "moq-transport-18".parse().unwrap(); let pair = connect_mock(MockConnectOptions::new(version)).await; @@ -158,9 +158,9 @@ async fn goaway_wire_timeout_moq_transport() { } /// The client also drains the server: GOAWAY is symmetric. -#[moq_clock::test] +#[kio::test] async fn goaway_client_to_server_moq_lite_04() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let version: Version = "moq-lite-04".parse().unwrap(); let pair = connect_mock(MockConnectOptions::new(version)).await; @@ -185,9 +185,9 @@ async fn goaway_client_to_server_moq_lite_04() { /// A version with no GOAWAY message (moq-lite-03 and earlier) still drains: the /// deadline is the sender's own timer, so the session closes on schedule even /// though the peer is never told why. Callers do not branch on the version. -#[moq_clock::test] +#[kio::test] async fn goaway_drains_without_a_wire_message_moq_lite_03() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let version: Version = "moq-lite-03".parse().unwrap(); let pair = connect_mock(MockConnectOptions::new(version)).await; @@ -212,9 +212,9 @@ async fn goaway_drains_without_a_wire_message_moq_lite_03() { /// A moq-transport client cannot tell a server where to reconnect, so naming a /// URI is refused locally instead of getting the session closed by the peer. -#[moq_clock::test] +#[kio::test] async fn goaway_client_redirect_refused_moq_transport_18() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let version: Version = "moq-transport-18".parse().unwrap(); let pair = connect_mock(MockConnectOptions::new(version)).await; @@ -245,9 +245,9 @@ async fn goaway_client_redirect_refused_moq_transport_18() { /// The draining side force-closes the session when the peer overstays the /// deadline, and the peer observes the GOAWAY_TIMEOUT close code. -#[moq_clock::test] +#[kio::test] async fn goaway_timeout_force_close_moq_transport_17() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let version: Version = "moq-transport-18".parse().unwrap(); let pair = connect_mock(MockConnectOptions::new(version)).await; @@ -284,7 +284,7 @@ async fn goaway_timeout_force_close_moq_transport_17() { /// The public API's drain claim only ever sends one GOAWAY per session, so the /// handshake is hand-rolled to keep a raw transport clone for injecting /// wire-level GOAWAY control streams. -#[moq_clock::test] +#[kio::test] async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { /// Open a raw lite Goaway control stream: /// `[ControlType::Goaway][message size][uri length][uri bytes]`. @@ -315,7 +315,7 @@ async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { while let Ok(Some(_)) = recv.read_chunk(usize::MAX).await {} } - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let version: Version = "moq-lite-04".parse().unwrap(); let mut mock = moq_net::transport::memory::Config::default(); @@ -366,7 +366,7 @@ async fn duplicate_goaway_keeps_first_payload_moq_lite_04() { /// After a received GOAWAY, a new subscription still opens on the draining /// session, which is the only route, while an existing one keeps delivering. async fn goaway_keeps_new_subscribes(version: Version) { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { // Server publishes a broadcast with one live track. let pub_origin = produce_origin(Hop::random()); let broadcast = pub_origin.create_broadcast("test").expect("create broadcast"); @@ -455,17 +455,17 @@ async fn goaway_keeps_new_subscribes(version: Version) { .expect("test timed out (likely a mock deadlock)"); } -#[moq_clock::test] +#[kio::test] async fn goaway_keeps_new_subscribes_moq_lite_04() { goaway_keeps_new_subscribes("moq-lite-04".parse().unwrap()).await; } -#[moq_clock::test] +#[kio::test] async fn goaway_keeps_new_subscribes_moq_lite_05() { goaway_keeps_new_subscribes("moq-lite-05".parse().unwrap()).await; } -#[moq_clock::test] +#[kio::test] async fn goaway_keeps_new_subscribes_moq_transport_22() { goaway_keeps_new_subscribes("moq-transport-22".parse().unwrap()).await; } @@ -477,7 +477,7 @@ async fn goaway_keeps_new_subscribes_moq_transport_22() { /// subscriber has to react to the signal itself, not to a later announce that a /// draining peer has no reason to send. async fn goaway_drains_routes(version: Version) { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let pub_origin = produce_origin(Hop::random()); let broadcast = pub_origin.create_broadcast("test").expect("create broadcast"); broadcast.announce(moq_net::origin::Route::default()).expect("announce"); @@ -519,12 +519,12 @@ async fn goaway_drains_routes(version: Version) { .expect("test timed out (likely a route that never drained)"); } -#[moq_clock::test] +#[kio::test] async fn goaway_drains_routes_moq_lite_04() { goaway_drains_routes("moq-lite-04".parse().unwrap()).await; } -#[moq_clock::test] +#[kio::test] async fn goaway_drains_routes_moq_transport_18() { goaway_drains_routes("moq-transport-18".parse().unwrap()).await; } diff --git a/rs/moq-net/tests/integration/group_order.rs b/rs/moq-net/tests/integration/group_order.rs index 9b11f292572..66fd8462d42 100644 --- a/rs/moq-net/tests/integration/group_order.rs +++ b/rs/moq-net/tests/integration/group_order.rs @@ -44,10 +44,10 @@ async fn connect( /// Subscribe to the test track through `origin` in `order`, then read every backlog group /// in the order it arrives. -fn read_arrivals(origin: moq_net::origin::Producer, order: Order) -> moq_clock::sim::JoinHandle> { - moq_clock::sim::spawn(async move { +fn read_arrivals(origin: moq_net::origin::Producer, order: Order) -> kio::clock::sim::JoinHandle> { + kio::clock::sim::spawn(async move { let consumer = origin.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); @@ -68,7 +68,7 @@ fn read_arrivals(origin: moq_net::origin::Producer, order: Order) -> moq_clock:: let mut arrivals = Vec::new(); while arrivals.len() < BACKLOG.len() { - let group = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let group = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .expect("recv_group") @@ -137,15 +137,15 @@ async fn round(version: &str, relay: bool, order: Order) -> Vec { support::harness::subscribed(&track).await; // Simulated time advances only once every task is idle, so this settles the // subscription on every hop before the groups exist. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; pair.server_transport.hold_unis(); let backlog = write_backlog(&track); // Every group stream is open and ranked before any reaches the subscriber. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; pair.server_transport.release_unis_by_priority(); - let got = moq_clock::timeout(TIMEOUT * 3, reader) + let got = kio::clock::timeout(TIMEOUT * 3, reader) .await .expect("reader hung") .expect("reader panicked"); @@ -153,7 +153,7 @@ async fn round(version: &str, relay: bool, order: Order) -> Vec { got } -#[moq_clock::test] +#[kio::test] async fn a_backlog_is_served_in_the_subscription_order() { let mut failures = Vec::new(); for version in [ @@ -183,7 +183,7 @@ async fn a_backlog_is_served_in_the_subscription_order() { /// One relay request serves an ascending and a descending subscriber: upstream asks for /// descending so the live subscriber stays fresh, and each downstream session still sends /// its own subscriber's backlog in that subscriber's order. -#[moq_clock::test] +#[kio::test] async fn merged_subscribers_keep_their_own_order() { for version in ["moq-lite-07-wip", "moq-transport-18"] { let version: Version = version.parse().unwrap(); @@ -205,7 +205,7 @@ async fn merged_subscribers_keep_their_own_order() { let ascending = read_arrivals(ascending_origin.clone(), Order::Ascending); support::harness::subscribed(&track).await; - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; assert_eq!( upstream_order(), Some(Order::Ascending), @@ -213,7 +213,7 @@ async fn merged_subscribers_keep_their_own_order() { ); let descending = read_arrivals(descending_origin.clone(), Order::Descending); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; // lite-07 moves the upstream request with a SUBSCRIBE_UPDATE. This moq-transport // subscriber never updates a request, priority included, so its first order stands. let merged = match version.is_lite() { @@ -225,12 +225,12 @@ async fn merged_subscribers_keep_their_own_order() { descending_pair.server_transport.hold_unis(); ascending_pair.server_transport.hold_unis(); let backlog = write_backlog(&track); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; descending_pair.server_transport.release_unis_by_priority(); ascending_pair.server_transport.release_unis_by_priority(); for (reader, order) in [(descending, Order::Descending), (ascending, Order::Ascending)] { - let got = moq_clock::timeout(TIMEOUT * 3, reader) + let got = kio::clock::timeout(TIMEOUT * 3, reader) .await .expect("reader hung") .expect("reader panicked"); diff --git a/rs/moq-net/tests/integration/history_groups.rs b/rs/moq-net/tests/integration/history_groups.rs index fd813fb17c2..08fa53fbb09 100644 --- a/rs/moq-net/tests/integration/history_groups.rs +++ b/rs/moq-net/tests/integration/history_groups.rs @@ -71,16 +71,16 @@ async fn round(version: &str, relay: bool, newest_first: bool) -> Vec<(u64, usiz let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let subscription = Subscription::default().with_max_delay(FOREVER).with_range(0..); let mut sub = remote .track("history") @@ -92,14 +92,14 @@ async fn round(version: &str, relay: bool, newest_first: bool) -> Vec<(u64, usiz // Group 6 never ends, so read until every frame arrived or nothing more does. let mut got = Vec::new(); while got.iter().map(|(_, frames)| frames).sum::() < 5 { - let Ok(next) = moq_clock::timeout(TIMEOUT, sub.recv_group()).await else { + let Ok(next) = kio::clock::timeout(TIMEOUT, sub.recv_group()).await else { break; }; let Some(mut group) = next.expect("recv_group") else { break; }; let mut frames = 0; - while let Ok(frame) = moq_clock::timeout(TIMEOUT, group.read_frame()).await { + while let Ok(frame) = kio::clock::timeout(TIMEOUT, group.read_frame()).await { match frame.expect("read_frame") { Some(_) => frames += 1, None => break, @@ -111,13 +111,13 @@ async fn round(version: &str, relay: bool, newest_first: bool) -> Vec<(u64, usiz got }); - moq_clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); // Simulated time advances only once every task is idle, so this settles the // subscription before the groups exist. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; // The hop the publisher's group streams cross first: into the relay, when there is one. let first_hop = upstream @@ -139,11 +139,11 @@ async fn round(version: &str, relay: bool, newest_first: bool) -> Vec<(u64, usiz if newest_first { // Paused time advances only once every task is idle: both streams are open. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; first_hop.release_unis_reversed(); } - let got = moq_clock::timeout(TIMEOUT * 3, reader) + let got = kio::clock::timeout(TIMEOUT * 3, reader) .await .expect("reader hung") .expect("reader panicked"); @@ -160,7 +160,7 @@ async fn round(version: &str, relay: bool, newest_first: bool) -> Vec<(u64, usiz got } -#[moq_clock::test] +#[kio::test] async fn a_fresh_subscriber_receives_the_finished_older_group() { let mut failures = Vec::new(); for version in VERSIONS { @@ -196,7 +196,7 @@ async fn read_history(sub: &mut moq_net::track::Subscriber) { assert_eq!(sequences, [5, 6]); } -#[moq_clock::test] +#[kio::test] async fn a_late_subscriber_receives_the_relays_cached_history() { // Older drafts canonicalize group 0 to the live edge instead of replay. let version: Version = "moq-lite-07-wip".parse().unwrap(); @@ -224,7 +224,7 @@ async fn a_late_subscriber_receives_the_relays_cached_history() { let remote = consumer.request_broadcast("bcast", None).await.unwrap(); let subscription = Subscription::default().with_max_delay(FOREVER).with_range(0..); let first_subscription = subscription.clone(); - let first_reader = moq_clock::sim::spawn(async move { + let first_reader = kio::clock::sim::spawn(async move { let mut sub = remote .track("history") .unwrap() @@ -246,9 +246,9 @@ async fn a_late_subscriber_receives_the_relays_cached_history() { live.write_frame(Timestamp::now(), &b"live"[..]).unwrap(); } // Both streams open before paused time advances; 10ms stays below linger. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; upstream.server_transport.release_unis_reversed(); - let first_sub = moq_clock::timeout(TIMEOUT, first_reader) + let first_sub = kio::clock::timeout(TIMEOUT, first_reader) .await .expect("first subscriber history") .unwrap(); @@ -261,7 +261,7 @@ async fn a_late_subscriber_receives_the_relays_cached_history() { consumer.routed("bcast").await.unwrap(); let remote = consumer.request_broadcast("bcast", None).await.unwrap(); let mut late_sub = remote.track("history").unwrap().subscribe(subscription).await.unwrap(); - moq_clock::timeout(TIMEOUT, read_history(&mut late_sub)) + kio::clock::timeout(TIMEOUT, read_history(&mut late_sub)) .await .unwrap_or_else(|_| panic!("{version}: late subscriber history")); drop((first_sub, late_sub, first_pair, late_pair, upstream, live)); diff --git a/rs/moq-net/tests/integration/idle_cancel_refetch.rs b/rs/moq-net/tests/integration/idle_cancel_refetch.rs index 0705c09f658..9c9a3eb01c1 100644 --- a/rs/moq-net/tests/integration/idle_cancel_refetch.rs +++ b/rs/moq-net/tests/integration/idle_cancel_refetch.rs @@ -18,7 +18,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { producer } -#[moq_clock::test] +#[kio::test] async fn a_group_cut_by_an_idle_cancel_is_refetched_whole() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -40,27 +40,27 @@ async fn a_group_cut_by_an_idle_cancel_is_refetched_whole() { let _pair = connect_mock(options).await; let consumer = client.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .unwrap() .unwrap(); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .unwrap() .unwrap(); { - let mut subscriber = moq_clock::timeout(TIMEOUT, remote.track("audio").unwrap().subscribe(None)) + let mut subscriber = kio::clock::timeout(TIMEOUT, remote.track("audio").unwrap().subscribe(None)) .await .unwrap() .unwrap(); - let mut group = moq_clock::timeout(TIMEOUT, subscriber.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, subscriber.recv_group()) .await .unwrap() .unwrap() .unwrap(); assert_eq!(group.sequence, 1); - let frame = moq_clock::timeout(TIMEOUT, group.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .unwrap() .unwrap() @@ -69,7 +69,7 @@ async fn a_group_cut_by_an_idle_cancel_is_refetched_whole() { } // The relay cancels the idle upstream subscription. - moq_clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) .await .unwrap() .unwrap(); @@ -81,13 +81,13 @@ async fn a_group_cut_by_an_idle_cancel_is_refetched_whole() { let track = remote.track("audio").unwrap(); let _feed = track.subscribe(None); - let mut group = moq_clock::timeout(TIMEOUT, track.fetch_group(1, None)) + let mut group = kio::clock::timeout(TIMEOUT, track.fetch_group(1, None)) .await .unwrap() .unwrap(); let mut frames = Vec::new(); loop { - match moq_clock::timeout(TIMEOUT, group.read_frame()) + match kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("group 1 hangs") { diff --git a/rs/moq-net/tests/integration/idle_session.rs b/rs/moq-net/tests/integration/idle_session.rs index bbcc800bc8c..8f1cf854992 100644 --- a/rs/moq-net/tests/integration/idle_session.rs +++ b/rs/moq-net/tests/integration/idle_session.rs @@ -50,7 +50,7 @@ async fn viewer( let mut probe = pair.client.recv_bandwidth().expect("lite carries PROBE"); assert_eq!(probe.changed().await.unwrap(), Some(Rate::from_bps(1_000_000))); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; (pair, probe) } @@ -60,7 +60,7 @@ fn origin() -> origin::Producer { origin } -#[moq_clock::test] +#[kio::test] async fn idle_viewer_does_not_wake_the_server() { for version in VERSIONS { let origin = origin(); @@ -70,7 +70,7 @@ async fn idle_viewer_does_not_wake_the_server() { let reads = &pair.server_transport; let (start_polls, start_reads) = (polls.load(Ordering::Relaxed), reads.stats_reads()); assert!(start_polls > 0, "the requested poll counter must observe the handshake"); - moq_clock::sleep(IDLE).await; + kio::clock::sleep(IDLE).await; let polls = polls.load(Ordering::Relaxed) - start_polls; let reads = reads.stats_reads() - start_reads; @@ -84,7 +84,7 @@ async fn idle_viewer_does_not_wake_the_server() { /// The flip side: a session the server is doing work for samples as it goes, so a /// moved estimate reaches the viewer with that work, not at the next max age. -#[moq_clock::test] +#[kio::test] async fn busy_viewer_sees_the_estimate_move() { for version in VERSIONS { let origin = origin(); @@ -98,7 +98,7 @@ async fn busy_viewer_sees_the_estimate_move() { let broadcast = origin.create_broadcast("live").unwrap(); broadcast.announce(Default::default()).unwrap(); - let moved = moq_clock::timeout(Duration::from_millis(1), probe.changed()).await; + let moved = kio::clock::timeout(Duration::from_millis(1), probe.changed()).await; assert_eq!( moved.expect("reported with the work").unwrap(), Some(Rate::from_bps(2_000_000)), @@ -108,7 +108,7 @@ async fn busy_viewer_sees_the_estimate_move() { } /// A transport estimate demanded locally still costs one poll per sampling deadline. -#[moq_clock::test] +#[kio::test] async fn ietf_stats_refresh_costs_one_driver_poll() { for version in ["moq-transport-22"] { let polls = Arc::new(AtomicUsize::new(0)); @@ -117,10 +117,10 @@ async fn ietf_stats_refresh_costs_one_driver_poll() { options.server_polls = Some(polls.clone()); let pair = connect_mock(options).await; let _bandwidth = pair.server.send_bandwidth().expect("transport estimate"); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let start = polls.load(Ordering::Relaxed); let reads = pair.server_transport.stats_reads(); - moq_clock::sleep(Duration::from_secs(10)).await; + kio::clock::sleep(Duration::from_secs(10)).await; let polls = polls.load(Ordering::Relaxed) - start; let reads = pair.server_transport.stats_reads() - reads; assert_eq!(reads, 100, "{version}: one sample per 100 ms"); @@ -129,7 +129,7 @@ async fn ietf_stats_refresh_costs_one_driver_poll() { } /// The session and stats snapshots are not demand; only held consumers open PROBE. -#[moq_clock::test] +#[kio::test] async fn probe_follows_consumer_lifetime() { for version in VERSIONS { let mut options = MockConnectOptions::new(version.parse::().unwrap()); @@ -143,7 +143,7 @@ async fn probe_follows_consumer_lifetime() { .count() }; let _ = pair.client.stats(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!(probe_count(), 0, "{version}: an idle session must not open PROBE"); let mut first = pair.client.recv_bandwidth().unwrap(); @@ -152,14 +152,14 @@ async fn probe_follows_consumer_lifetime() { let second = first.clone(); let resets = pair.client_transport.resets().len(); drop(first); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!( pair.client_transport.resets().len(), resets, "{version}: a clone still needs PROBE" ); drop(second); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!( pair.client_transport.resets().len() > resets, "{version}: last drop resets PROBE" @@ -167,13 +167,13 @@ async fn probe_follows_consumer_lifetime() { let mut resumed = pair.client.recv_bandwidth().unwrap(); assert_eq!(resumed.peek(), None, "{version}: an unused estimate is cleared"); assert_eq!(resumed.changed().await.unwrap(), Some(Rate::from_bps(1_000_000))); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!(probe_count(), 2, "{version}: demand can resume"); } } /// A stats tick reads the transport's wire counters and adds no sampler timer or session wake. -#[moq_clock::test] +#[kio::test] async fn wire_collection_never_arms_the_idle_sampler() { for version in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { let registry = moq_net::stats::Registry::new(Default::default()); @@ -184,7 +184,7 @@ async fn wire_collection_never_arms_the_idle_sampler() { .session(moq_net::Path::from_static("room")); options.server_polls = Some(polls.clone()); let pair = connect_mock(options).await; - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let start_polls = polls.load(Ordering::Relaxed); let start_reads = pair.server_transport.stats_reads(); for tick in 1..=60 { @@ -196,7 +196,7 @@ async fn wire_collection_never_arms_the_idle_sampler() { (report.sessions[0].presence.wire_tx, report.sessions[0].presence.wire_rx), (tick, tick * 2) ); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; } assert_eq!( polls.load(Ordering::Relaxed), diff --git a/rs/moq-net/tests/integration/implementation.rs b/rs/moq-net/tests/integration/implementation.rs index 2832bb43dc5..c01bb84398f 100644 --- a/rs/moq-net/tests/integration/implementation.rs +++ b/rs/moq-net/tests/integration/implementation.rs @@ -34,7 +34,7 @@ async fn exchange(version: Version, client: Option<&str>, server: Option<&str>) ) } -#[moq_clock::test] +#[kio::test] async fn each_side_reads_the_others_implementation() { for (name, carried) in VERSIONS { let version: Version = name.parse().unwrap(); @@ -53,7 +53,7 @@ async fn each_side_reads_the_others_implementation() { } /// Unconfigured, each side names this crate; configured empty, it advertises nothing. -#[moq_clock::test] +#[kio::test] async fn the_default_names_the_crate_and_empty_omits_it() { for name in ["moq-lite-06", "moq-transport-22"] { let version: Version = name.parse().unwrap(); @@ -64,7 +64,7 @@ async fn the_default_names_the_crate_and_empty_omits_it() { } /// A SETUP too large to encode fails the dial instead of leaving the peer waiting for it. -#[moq_clock::test] +#[kio::test] async fn an_oversized_implementation_fails_the_dial() { let version: Version = "moq-lite-06".parse().unwrap(); let mut transport = moq_net::transport::memory::Config::default(); @@ -80,7 +80,7 @@ async fn an_oversized_implementation_fails_the_dial() { /// A session that ends before the peer's SETUP resolves `None`, even while the caller still /// holds the finished driver. -#[moq_clock::test] +#[kio::test] async fn the_wait_ends_with_the_session() { let version: Version = "moq-lite-06".parse().unwrap(); let mut transport = moq_net::transport::memory::Config::default(); @@ -95,11 +95,11 @@ async fn the_wait_ends_with_the_session() { session.abort(moq_net::Error::Cancel); // The driver outlives its result, as one kept in a struct or a join handle would. - drop(moq_clock::sim::spawn(moq_clock::drive(move |now, waiter| { + drop(kio::clock::sim::spawn(kio::clock::drive(move |now, waiter| { Ok::<_, std::convert::Infallible>(driver.poll(now, waiter).unwrap_or(None)) }))); - let seen = moq_clock::timeout(std::time::Duration::from_secs(5), session.peer_implementation()) + let seen = kio::clock::timeout(std::time::Duration::from_secs(5), session.peer_implementation()) .await .expect("the wait ends with the session"); assert_eq!(seen, None); diff --git a/rs/moq-net/tests/integration/late_lower_group.rs b/rs/moq-net/tests/integration/late_lower_group.rs index db34d444489..bc994e49b75 100644 --- a/rs/moq-net/tests/integration/late_lower_group.rs +++ b/rs/moq-net/tests/integration/late_lower_group.rs @@ -56,7 +56,7 @@ fn write_group(track: &moq_net::track::Producer, sequence: u64) { async fn read_all(sub: &mut moq_net::track::Subscriber) -> Vec<(u64, usize)> { let mut got = Vec::new(); loop { - let next = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let next = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("recv_group timed out"); let Some(mut group) = next.expect("recv_group") else { @@ -64,7 +64,7 @@ async fn read_all(sub: &mut moq_net::track::Subscriber) -> Vec<(u64, usize)> { }; let mut frames = 0; loop { - let frame = moq_clock::timeout(TIMEOUT, group.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("read_frame timed out") .expect("read_frame"); @@ -114,11 +114,11 @@ async fn session(version: &str, relay: bool, start: Option) -> Vec<(u64, us let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -126,7 +126,7 @@ async fn session(version: &str, relay: bool, start: Option) -> Vec<(u64, us let subscription = Subscription::default() .with_max_delay(BUDGET) .with_ranges([floored(start)]); - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let mut sub = remote .track("late") .unwrap() @@ -136,19 +136,19 @@ async fn session(version: &str, relay: bool, start: Option) -> Vec<(u64, us read_all(&mut sub).await }); - moq_clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); // Idle time lets the subscription settle, and again lets SUBSCRIBE_START land, // before the lower group is created. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 1); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 0); track.finish().unwrap(); - let got = moq_clock::timeout(TIMEOUT * 3, reader) + let got = kio::clock::timeout(TIMEOUT * 3, reader) .await .expect("reader hung") .expect("reader panicked"); @@ -171,13 +171,13 @@ async fn in_process(start: Option) -> Vec<(u64, usize)> { .with_max_delay(BUDGET) .with_ranges([floored(start)]); let mut sub = track.subscribe(subscription); - let reader = moq_clock::sim::spawn(async move { read_all(&mut sub).await }); - moq_clock::sleep(Duration::from_millis(10)).await; + let reader = kio::clock::sim::spawn(async move { read_all(&mut sub).await }); + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 1); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 0); track.finish().unwrap(); - let got = moq_clock::timeout(TIMEOUT * 3, reader) + let got = kio::clock::timeout(TIMEOUT * 3, reader) .await .expect("reader hung") .expect("reader panicked"); @@ -185,7 +185,7 @@ async fn in_process(start: Option) -> Vec<(u64, usize)> { got } -#[moq_clock::test] +#[kio::test] async fn an_explicit_floor_receives_a_group_created_below_the_first_served_group() { let want = vec![(1, 4), (0, 4)]; let mut failures = Vec::new(); @@ -235,11 +235,11 @@ async fn merged(version: &str) -> (Vec<(u64, usize)>, Vec<(u64, usize)>) { let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -248,22 +248,22 @@ async fn merged(version: &str) -> (Vec<(u64, usize)>, Vec<(u64, usize)>) { let track = remote.track("late").unwrap(); async move { let subscription = Subscription::default().with_max_delay(BUDGET).with_ranges([range]); - moq_clock::timeout(TIMEOUT, track.subscribe(subscription)) + kio::clock::timeout(TIMEOUT, track.subscribe(subscription)) .await .expect("subscribe timeout") .expect("subscribe") } }; let mut live = subscribe(Range::live()).await; - moq_clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 1); // The live reader is on group 1 before the other joins. - let first = moq_clock::timeout(TIMEOUT, live.recv_group()) + let first = kio::clock::timeout(TIMEOUT, live.recv_group()) .await .expect("recv_group timed out") .expect("recv_group") @@ -272,7 +272,7 @@ async fn merged(version: &str) -> (Vec<(u64, usize)>, Vec<(u64, usize)>) { let mut oldest = subscribe(floored(Some(0))).await; // Idle time lets the merged demand reach the publisher before the lower group exists. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 0); track.finish().unwrap(); @@ -288,7 +288,7 @@ async fn merged(version: &str) -> (Vec<(u64, usize)>, Vec<(u64, usize)>) { /// A wire with one span cannot carry both starts, and lite-05 reads an absent start as /// the latest group, so the relay must spell group 0 for a fresh group 0 to reach the /// reader that asked for it. The live reader joined above it and never sees it. -#[moq_clock::test] +#[kio::test] async fn a_merged_subscription_keeps_an_absolute_floor() { let mut failures = Vec::new(); for version in LITE { @@ -303,7 +303,7 @@ async fn a_merged_subscription_keeps_an_absolute_floor() { /// Pre-06, an omitted floor joins at the first served group. Group 0, created after /// group 1 was served, is below that join. Lite-06 cannot spell this separately from /// a floor of group 0; that case is the explicit-floor test. -#[moq_clock::test] +#[kio::test] async fn an_unfloored_lite05_join_drops_a_group_created_below_the_first_served_group() { let want = vec![(1, 4)]; let mut failures = Vec::new(); diff --git a/rs/moq-net/tests/integration/lazy_discovery.rs b/rs/moq-net/tests/integration/lazy_discovery.rs index e93c48af9c8..681599a0d02 100644 --- a/rs/moq-net/tests/integration/lazy_discovery.rs +++ b/rs/moq-net/tests/integration/lazy_discovery.rs @@ -58,7 +58,7 @@ impl Lazy { options.client_subscribe = Some(subscriber.clone()); options.client_discovers_all = false; let pair = connect_mock(options).await; - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; Self { subscriber, pair, @@ -99,7 +99,7 @@ impl Lazy { async fn synced(announced: &mut announce::Consumer) -> Vec { let mut seen = Vec::new(); while !announced.poll_synced(&moq_net::kio::Waiter::noop()).is_ready() { - let event = moq_clock::timeout(SETTLE, announced.next()) + let event = kio::clock::timeout(SETTLE, announced.next()) .await .expect("synced in time") .expect("the stream stays open"); @@ -116,7 +116,7 @@ async fn synced(announced: &mut announce::Consumer) -> Vec { } /// Nothing watched, nothing asked: the peer's broadcasts stay undiscovered. -#[moq_clock::test] +#[kio::test] async fn asks_nothing_until_watched() { for version in VERSIONS { let lazy = Lazy::new(version).await; @@ -126,7 +126,7 @@ async fn asks_nothing_until_watched() { } /// A watch asks about its own prefix and nothing else. -#[moq_clock::test] +#[kio::test] async fn asks_only_about_the_watched_prefix() { for version in VERSIONS { let lazy = Lazy::new(version).await; @@ -139,7 +139,7 @@ async fn asks_only_about_the_watched_prefix() { } /// A watch made before the session exists is asked about once it connects. -#[moq_clock::test] +#[kio::test] async fn a_new_session_asks_about_existing_watches() { let subscriber = produce_origin(2); let mut watch = subscriber @@ -154,7 +154,7 @@ async fn a_new_session_asks_about_existing_watches() { } /// The request outlives its last watcher by the linger, then closes and retracts. -#[moq_clock::test] +#[kio::test] async fn lingers_after_the_last_watcher() { for version in VERSIONS { let lazy = Lazy::new(version).await; @@ -162,23 +162,23 @@ async fn lingers_after_the_last_watcher() { synced(&mut watch).await; drop(watch); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!(lazy.routes("a/x").await, "{version}: still lingering"); // Watched again within the linger: the same request carries on. let again = lazy.watch("a"); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(lazy.routes("a/x").await, "{version}: rewatched"); assert_eq!(lazy.requests(), 1, "{version}"); drop(again); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(!lazy.routes("a/x").await, "{version}: closed"); } } /// A narrower watch rides an open broader request, which stays open while it does. -#[moq_clock::test] +#[kio::test] async fn a_narrower_watch_rides_the_broader_request() { for version in VERSIONS { let lazy = Lazy::new(version).await; @@ -189,7 +189,7 @@ async fn a_narrower_watch_rides_the_broader_request() { assert_eq!(lazy.requests(), 1, "{version}"); drop(root); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert_eq!(lazy.requests(), 1, "{version}: nothing reopened"); assert!(lazy.routes("a/x").await, "{version}"); assert!(narrower.try_next().is_none(), "{version}: nothing retracted"); @@ -197,7 +197,7 @@ async fn a_narrower_watch_rides_the_broader_request() { } /// A narrower request open before a broader one stays until the broader one goes. -#[moq_clock::test] +#[kio::test] async fn a_broader_request_holds_the_narrower_open() { for version in VERSIONS { let lazy = Lazy::new(version).await; @@ -208,22 +208,22 @@ async fn a_broader_request_holds_the_narrower_open() { assert_eq!(lazy.requests(), 2, "{version}"); drop(narrower); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(root.try_next().is_none(), "{version}: nothing retracted"); // The broader request lingers out, then the narrower one it held does. drop(root); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(!lazy.routes("b/y").await, "{version}"); assert!(lazy.routes("a/x").await, "{version}"); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(!lazy.routes("a/x").await, "{version}"); } } /// A narrower request still lingering when a broader one opens is held like one still /// watched, rather than lingering out on its own timer. -#[moq_clock::test] +#[kio::test] async fn a_broader_request_holds_a_lingering_narrower_open() { for version in VERSIONS { let lazy = Lazy::new(version).await; @@ -231,28 +231,28 @@ async fn a_broader_request_holds_a_lingering_narrower_open() { synced(&mut narrower).await; drop(narrower); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let mut root = lazy.watch(""); assert_eq!(synced(&mut root).await, ["a/x", "b/y"], "{version}"); assert_eq!(lazy.requests(), 2, "{version}"); // Past the narrower request's own linger: it is held, not closed. - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(root.try_next().is_none(), "{version}: nothing retracted"); // The broader request lingers out, then the narrower one it held does. drop(root); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(!lazy.routes("b/y").await, "{version}"); assert!(lazy.routes("a/x").await, "{version}"); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(!lazy.routes("a/x").await, "{version}"); } } /// A broadcast resolved through a discovered route keeps it discovered after the /// listing that found it closes. -#[moq_clock::test] +#[kio::test] async fn a_resolved_broadcast_keeps_its_route() { for version in VERSIONS { let lazy = Lazy::new(version).await; @@ -261,7 +261,7 @@ async fn a_resolved_broadcast_keeps_its_route() { let broadcast = lazy.subscriber.consume().request_broadcast("a/x", None).await.unwrap(); drop(watch); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(lazy.routes("a/x").await, "{version}"); assert!(!lazy.routes("b/y").await, "{version}"); @@ -270,17 +270,17 @@ async fn a_resolved_broadcast_keeps_its_route() { } /// Waiting on a path asks about it. -#[moq_clock::test] +#[kio::test] async fn waiting_on_a_path_asks_about_it() { for version in VERSIONS { let lazy = Lazy::new(version).await; let consumer = lazy.subscriber.consume(); - moq_clock::timeout(SETTLE, consumer.routed_broadcast("a/x")) + kio::clock::timeout(SETTLE, consumer.routed_broadcast("a/x")) .await .expect("routed in time") .unwrap(); let mut followed = consumer.announced_broadcast("b/y", None).unwrap(); - moq_clock::timeout(SETTLE, followed.available()) + kio::clock::timeout(SETTLE, followed.available()) .await .expect("announced in time") .unwrap(); @@ -290,7 +290,7 @@ async fn waiting_on_a_path_asks_about_it() { /// A relay's link asks for everything, watched or not, so discovery never narrows /// what a relay learns. -#[moq_clock::test] +#[kio::test] async fn a_relay_link_asks_for_everything() { for version in VERSIONS { for upstream in [false, true] { @@ -310,7 +310,7 @@ async fn a_relay_link_asks_for_everything() { } /// A server asks a client for everything it may, so a relay ingests what clients publish. -#[moq_clock::test] +#[kio::test] async fn a_server_asks_for_everything() { for version in VERSIONS { let publisher = produce_origin(1); @@ -321,14 +321,14 @@ async fn a_server_asks_for_everything() { options.client_publish = Some(publisher.consume()); options.server_subscribe = Some(relay.clone()); let _pair = connect_mock(options).await; - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; relay.consume().request_broadcast("a/x", None).await.unwrap(); } } /// Serving the peer's own request is no local reader: a client publishing and /// consuming through one origin still asks about only what its readers watch. -#[moq_clock::test] +#[kio::test] async fn serving_the_peer_asks_nothing() { for version in VERSIONS { let local = produce_origin(2); @@ -343,7 +343,7 @@ async fn serving_the_peer_asks_nothing() { options.server_publish = Some(remote.consume()); options.server_subscribe = Some(remote.clone()); let pair = connect_mock(options).await; - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; let requests = pair .client_transport @@ -365,7 +365,7 @@ const IETF: &[&str] = &["moq-transport-18", "moq-transport-22"]; /// Apply what `announced` reports once everything in flight has arrived to `held`, and /// say whether any of it ended a prefix. async fn settled(announced: &mut announce::Consumer, held: &mut Vec) -> bool { - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; let mut ended = false; while let Some(event) = announced.try_next() { match event { @@ -385,7 +385,7 @@ async fn settled(announced: &mut announce::Consumer, held: &mut Vec) -> } /// Nothing watched, nothing asked: the peer's broadcasts stay undiscovered. -#[moq_clock::test] +#[kio::test] async fn ietf_asks_nothing_until_watched() { for version in IETF { let lazy = Lazy::new(version).await; @@ -394,7 +394,7 @@ async fn ietf_asks_nothing_until_watched() { } /// A watch asks about its own prefix and nothing else. -#[moq_clock::test] +#[kio::test] async fn ietf_asks_only_about_the_watched_prefix() { for version in IETF { let lazy = Lazy::new(version).await; @@ -409,7 +409,7 @@ async fn ietf_asks_only_about_the_watched_prefix() { /// The request outlives its last watcher by the linger, then ends, and what it reported /// goes with it. -#[moq_clock::test] +#[kio::test] async fn ietf_lingers_after_the_last_watcher() { for version in IETF { let lazy = Lazy::new(version).await; @@ -417,22 +417,22 @@ async fn ietf_lingers_after_the_last_watcher() { settled(&mut watch, &mut Vec::new()).await; drop(watch); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!(lazy.routes("a/x").await, "{version}: still lingering"); let again = lazy.watch("a"); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(lazy.routes("a/x").await, "{version}: rewatched"); drop(again); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(!lazy.routes("a/x").await, "{version}: ended"); } } /// A broader watch after a narrower one discovers everything, and retracts nothing the /// narrower one holds. -#[moq_clock::test] +#[kio::test] async fn ietf_a_broader_watch_retracts_nothing() { for version in IETF { let lazy = Lazy::new(version).await; @@ -451,7 +451,7 @@ async fn ietf_a_broader_watch_retracts_nothing() { ); drop(root); - moq_clock::sleep(LINGERED).await; + kio::clock::sleep(LINGERED).await; assert!(lazy.routes("a/x").await, "{version}: the narrower watch still holds it"); assert!( !settled(&mut narrower, &mut held).await, @@ -459,19 +459,19 @@ async fn ietf_a_broader_watch_retracts_nothing() { ); drop(narrower); - moq_clock::sleep(LINGERED * 2).await; + kio::clock::sleep(LINGERED * 2).await; assert!(!lazy.routes("a/x").await, "{version}"); assert!(!lazy.routes("b/y").await, "{version}"); } } /// Waiting on a path asks about it. -#[moq_clock::test] +#[kio::test] async fn ietf_waiting_on_a_path_asks_about_it() { for version in IETF { let lazy = Lazy::new(version).await; let consumer = lazy.subscriber.consume(); - moq_clock::timeout(SETTLE, consumer.routed_broadcast("a/x")) + kio::clock::timeout(SETTLE, consumer.routed_broadcast("a/x")) .await .expect("routed in time") .unwrap(); @@ -480,7 +480,7 @@ async fn ietf_waiting_on_a_path_asks_about_it() { } /// A relay's link still asks for everything it may. -#[moq_clock::test] +#[kio::test] async fn ietf_a_relay_link_asks_for_everything() { for version in IETF { let relay = produce_origin(2); diff --git a/rs/moq-net/tests/integration/mesh_withdraw.rs b/rs/moq-net/tests/integration/mesh_withdraw.rs index b547e95aa61..739f3e56deb 100644 --- a/rs/moq-net/tests/integration/mesh_withdraw.rs +++ b/rs/moq-net/tests/integration/mesh_withdraw.rs @@ -22,7 +22,7 @@ fn produce_origin(hop: u64) -> origin::Producer { /// An origin holding route updates for `hold`. Its cache never expires idle /// groups: nothing here carries media, and the expiry sweep would keep a timer -/// armed forever, so [`moq_clock::sim::idle`] could never see the mesh settle. +/// armed forever, so [`kio::clock::sim::idle`] could never see the mesh settle. fn produce(hop: u64, hold: Duration) -> origin::Producer { let mut config = origin::Config::new(Hop::new(hop).unwrap()); config.pool = cache::Pool::unbounded(); @@ -41,7 +41,7 @@ enum Kind { End, } -/// Every update per prefix the watcher has seen. Await [`moq_clock::sim::idle`] +/// Every update per prefix the watcher has seen. Await [`kio::clock::sim::idle`] /// first, so every link, hold and quarantine in the mesh has settled. fn drain(watched: &mut mpsc::UnboundedReceiver<(String, Kind)>) -> HashMap> { let mut updates = HashMap::>::new(); @@ -56,7 +56,7 @@ fn drain(watched: &mut mpsc::UnboundedReceiver<(String, Kind)>) -> HashMap mpsc::UnboundedReceiver<(String, Kind)> { let (tx, rx) = mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { while let Some(event) = announced.next().await { let (kind, announce) = match event { announce::Event::Start(announce) => (Kind::Start, announce), @@ -108,7 +108,7 @@ impl Mesh { broadcast }) .collect(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let updates = drain(&mut self.watched); assert_eq!(updates.len(), count); for (prefix, kinds) in updates { @@ -131,12 +131,12 @@ fn ring_with_chords(n: usize) -> Vec<(usize, usize)> { /// Every relay neighbors the publisher's, so each hears the withdrawal first-hand /// and drops every path derived from it at once. Lite04 names the peer only in /// the chain, later versions in the announce handshake too. -#[moq_clock::test] +#[kio::test] async fn full_mesh_withdraw_retracts_once_lite04() { full_mesh_withdraw_retracts_once("moq-lite-04").await; } -#[moq_clock::test] +#[kio::test] async fn full_mesh_withdraw_retracts_once_lite06() { full_mesh_withdraw_retracts_once("moq-lite-06").await; } @@ -145,7 +145,7 @@ async fn full_mesh_withdraw_retracts_once(version: &str) { let mut mesh = Mesh::new(version, 8, &full_mesh(8)).await; let broadcasts = mesh.publish(100, 0).await; drop(broadcasts); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let updates = drain(&mut mesh.watched); assert_eq!(updates.len(), 100); for (prefix, kinds) in updates { @@ -159,12 +159,12 @@ async fn full_mesh_withdraw_retracts_once(version: &str) { /// why, so it can still pass through a stale path or two. Every broadcast must still /// end retracted, and republishing from other relays must reach the watcher again: /// no withdrawal outlives the peer announcing the path again. -#[moq_clock::test] +#[kio::test] async fn partial_mesh_withdraw_then_republish() { let mut mesh = Mesh::new("moq-lite-06", 12, &ring_with_chords(12)).await; let broadcasts = mesh.publish(100, 0).await; drop(broadcasts); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let updates = drain(&mut mesh.watched); assert_eq!(updates.len(), 100); for (prefix, kinds) in updates { @@ -213,7 +213,7 @@ const PRODUCTION_LATENCY_MS: &[u64] = &[ /// announcement. Holding route updates (`origin::Config::update_hold`) lets the /// withdrawal remove those paths first; with link latency and no hold, each /// withdrawal here costs tens of thousands of announcements. -#[moq_clock::test] +#[kio::test] async fn partial_mesh_withdraw_retracts_once() { let version: Version = "moq-lite-06".parse().unwrap(); let nodes: Vec<_> = (1..=34).map(produce_origin).collect(); @@ -226,7 +226,7 @@ async fn partial_mesh_withdraw_retracts_once() { for publisher in [5, 13, 22, 26, 32] { let broadcast = nodes[publisher].create_broadcast(format!("room/{publisher}")).unwrap(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; for (relay, watched) in watched.iter_mut().enumerate() { let updates = drain(watched); assert!( @@ -236,7 +236,7 @@ async fn partial_mesh_withdraw_retracts_once() { } drop(broadcast); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let mut hunted = Vec::new(); for (relay, watched) in watched.iter_mut().enumerate() { let updates = drain(watched); @@ -268,7 +268,7 @@ const STALE_PATHS: &[Link] = &[ /// again. Its neighbors, two or more hops from the publisher's relay, still hunt /// through stale paths; one that falls back to a path not through this relay /// offers it as a new route after the relay forgot the withdrawal. -#[moq_clock::test] +#[kio::test] async fn retracted_relay_ignores_a_stale_path() { let version: Version = "moq-lite-06".parse().unwrap(); let nodes: Vec<_> = (1..=8).map(produce_origin).collect(); @@ -280,13 +280,13 @@ async fn retracted_relay_ignores_a_stale_path() { let broadcast = nodes[7].create_broadcast("room/7").unwrap(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; for watched in watched.iter_mut() { drain(watched); } drop(broadcast); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let mut revived = Vec::new(); for (relay, watched) in watched.iter_mut().enumerate() { let kinds = drain(watched).remove("room/7").unwrap(); @@ -352,7 +352,7 @@ impl Cluster { relays: relays.iter().map(|relay| watch(relay.consume().announced())).collect(), }; // Let every session's announce interest land before anything is published. - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; assert!(drain(&mut cluster.client).is_empty()); cluster } @@ -362,7 +362,7 @@ impl Cluster { async fn publish(&mut self, path: &str) -> (moq_net::origin::Publication, Vec) { let broadcast = self.publisher.create_broadcast(path).unwrap(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let client = drain(&mut self.client).remove(path).unwrap(); assert_ne!(client.last(), Some(&Kind::End), "client: {client:?}"); for (relay, watched) in self.relays.iter_mut().enumerate() { @@ -375,7 +375,7 @@ impl Cluster { /// Close `broadcast` cleanly: what the watching client, then each relay, saw. async fn close(&mut self, path: &str, broadcast: moq_net::origin::Publication) -> (Vec, Vec>) { drop(broadcast); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let client = drain(&mut self.client).remove(path).unwrap(); let mut relays = Vec::new(); for watched in self.relays.iter_mut() { @@ -390,12 +390,12 @@ impl Cluster { /// release before the retraction quarantine (#5376), this client saw it /// retracted, announced, and retracted again. Relay 0 still restarts onto a /// stale path after the hold; see [`residual_slow_ring_reannounces`]. -#[moq_clock::test] +#[kio::test] async fn cross_node_close_retracts_once_lite06() { cross_node_close_retracts_once("moq-lite-06").await; } -#[moq_clock::test] +#[kio::test] async fn cross_node_close_retracts_once_lite07() { cross_node_close_retracts_once("moq-lite-07-wip").await; } @@ -424,7 +424,7 @@ async fn cross_node_close_retracts_once(version: &str) { /// The positive control for [`cross_node_close_retracts_once`]: without the /// update hold and the quarantine, the client sees the broadcast come back /// before it ends. -#[moq_clock::test] +#[kio::test] async fn cross_node_close_without_hold_reannounces() { let mut cluster = Cluster::new( "moq-lite-06", @@ -452,7 +452,7 @@ async fn cross_node_close_without_hold_reannounces() { /// from relay 2 at 84 ms, but relay 5's equal-cost copy, the long way round, /// stays live until 446 ms. That outlasts the hold, so relay 3 restarts onto /// the stale copy and its client sees the broadcast come back. -#[moq_clock::test] +#[kio::test] async fn residual_slow_ring_reannounces() { #[rustfmt::skip] const EDGES: &[Link] = &[ @@ -471,7 +471,7 @@ async fn residual_slow_ring_reannounces() { /// Nine relays, reduced from a seeded random mesh with [`random_mesh`]'s /// links. Relays 2 and 8 retract the broadcast and then announce it again: a /// revival the quarantine misses. -#[moq_clock::test] +#[kio::test] async fn residual_mesh_revives() { #[rustfmt::skip] const EDGES: &[Link] = &[ @@ -559,14 +559,14 @@ fn random_mesh(seed: u64) -> (Vec, usize) { /// onto a stale path, or by reviving it after retracting), how many of those /// revive, and how many updates they send beyond the one retraction. Pinned at /// today's counts; Routes and announces brings all three to zero. -#[moq_clock::test] +#[kio::test] async fn residual_random_meshes() { assert_eq!(withdrawal_counts(false).await, (179, 3, 192)); } /// The same topologies and terminal states with room for the diameter and two /// extra hops, including the publishing client outside the relay graph. -#[moq_clock::test] +#[kio::test] async fn capped_random_meshes_hunt_less() { let capped = withdrawal_counts(true).await; assert_eq!(capped, (151, 1, 154)); @@ -623,7 +623,7 @@ async fn withdrawal_counts(capped: bool) -> (usize, usize, usize) { /// A permissive source sends an over-limit path to prove ingress refusal; an /// accepted boundary path then proves egress counts the relay's own stamp. -#[moq_clock::test] +#[kio::test] async fn hop_limit_bounds_receive_and_send() { for name in [ "moq-lite-03", @@ -646,7 +646,7 @@ async fn hop_limit_bounds_receive_and_send() { let _downstream = peer(version, &relay, &sink).await; let mut received = watch(relay.consume().announced()); let mut sent = watch(sink.consume().announced()); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let route = |count: u64| { origin::Route::default().with_hops( moq_net::Hops::try_from((100..100 + count).map(|id| Hop::new(id).unwrap()).collect::>()) @@ -656,7 +656,7 @@ async fn hop_limit_bounds_receive_and_send() { let _long = source.publish("long", route(2)).unwrap(); let _boundary = source.publish("boundary", route(1)).unwrap(); let short = source.publish("short", route(0)).unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let received = drain(&mut received); assert!(!received.contains_key("long"), "{name}: accepted over-limit path"); assert!(received.contains_key("boundary"), "{name}: refused boundary path"); @@ -668,19 +668,19 @@ async fn hop_limit_bounds_receive_and_send() { if matches!(name, "moq-lite-03" | "moq-lite-04") { // These wires have no route metadata update: withdraw, then replace it. drop(short); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; assert_eq!( drain(&mut sent).get("short").and_then(|kinds| kinds.last()), Some(&Kind::End), "{name}" ); let _replacement = source.publish("short", route(1)).unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; assert!(drain(&mut sent).is_empty(), "{name}: forwarded over-limit replacement"); continue; } short.announce(route(1)).unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let ended = drain(&mut sent); assert_eq!( ended.get("short").and_then(|kinds| kinds.last()), @@ -693,7 +693,7 @@ async fn hop_limit_bounds_receive_and_send() { /// A cheaper route at the cap wins locally but cannot be forwarded, so the relay /// advertises the pricier in-cap route instead of withdrawing the prefix, and /// withdraws only once no in-cap route is left. -#[moq_clock::test] +#[kio::test] async fn hop_limit_falls_back_to_a_forwardable_route() { // Only wires carrying a route cost can rank a longer route first. for name in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-18", "moq-transport-22"] { @@ -710,7 +710,7 @@ async fn hop_limit_falls_back_to_a_forwardable_route() { let _far = peer(version, &far, &relay).await; let _downstream = peer(version, &relay, &sink).await; let mut sent = watch(sink.consume().announced()); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let route = |first: u64, count: u64, cost: u64| { origin::Route::default() @@ -728,7 +728,7 @@ async fn hop_limit_falls_back_to_a_forwardable_route() { let _cheap = far.publish("room", route(100, 2, 1)).unwrap(); // Two hops at the relay, so it has room for the relay's own. let pricey = near.publish("room", route(200, 1, 50)).unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let started = drain(&mut sent); assert_eq!( started.get("room").and_then(|kinds| kinds.last()), @@ -737,7 +737,7 @@ async fn hop_limit_falls_back_to_a_forwardable_route() { ); drop(pricey); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let ended = drain(&mut sent); assert_eq!( ended.get("room").and_then(|kinds| kinds.last()), diff --git a/rs/moq-net/tests/integration/multi_cdn.rs b/rs/moq-net/tests/integration/multi_cdn.rs index 4da239fbcbb..2ac4df6fe52 100644 --- a/rs/moq-net/tests/integration/multi_cdn.rs +++ b/rs/moq-net/tests/integration/multi_cdn.rs @@ -39,7 +39,7 @@ fn produce_origin(hop: u64) -> origin::Producer { /// Let every task settle. Time is paused, so this returns once the runtime is idle. async fn settle() { - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; } /// `P` pushes everything it publishes to `cdn`. @@ -84,7 +84,7 @@ type Delivery = (u64, moq_net::Result<(Option, Vec)>); /// Read every group in full, reporting each frame as it arrives. fn read(mut sub: track::Subscriber) -> mpsc::UnboundedReceiver { let (tx, rx) = mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { loop { let mut group = match sub.recv_group().await { Ok(Some(group)) => group, @@ -118,7 +118,7 @@ fn read(mut sub: track::Subscriber) -> mpsc::UnboundedReceiver { /// The next frame the reader reports, failing on an error or a hang. async fn next(rx: &mut mpsc::UnboundedReceiver) -> (u64, Option, Vec) { - let (group, frame) = moq_clock::timeout(Duration::from_secs(10), rx.next()) + let (group, frame) = kio::clock::timeout(Duration::from_secs(10), rx.next()) .await .expect("reader hung") .expect("reader ended"); @@ -269,7 +269,7 @@ fn assert_continuous(seen: &[(u64, Vec, Option)], groups: u64) { /// Two CDNs under one epoch, `B` over `secondary`: `S` reads through `A` although `B` is /// cheaper, resumes on `B` when `A` goes, and moves back once `A` returns, every frame once. async fn fails_over_and_back(secondary: &str) { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let mut topology = Topology::new(secondary.parse().unwrap()).await; let mut announced = topology.subscriber.consume().announced(); let start = announced.next().await.expect("announced"); @@ -306,7 +306,7 @@ async fn fails_over_and_back(secondary: &str) { .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn preferred_cdn_fails_over_and_back() { fails_over_and_back("moq-lite-07-wip").await; } @@ -316,7 +316,7 @@ async fn preferred_cdn_fails_over_and_back() { /// it crossed, and one epoch means identical content: `S` refuses the copy, so the track /// ends with no frame of `B`'s. async fn refused_across_protocols(secondary: &str) { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let mut topology = Topology::new(secondary.parse().unwrap()).await; let mut announced = topology.subscriber.consume().announced(); let start = announced.next().await.expect("announced"); @@ -345,13 +345,13 @@ async fn refused_across_protocols(secondary: &str) { .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn transport_secondary_is_refused() { refused_across_protocols("moq-transport-22").await; } /// The same over the first draft that can carry the epoch. -#[moq_clock::test] +#[kio::test] async fn transport_17_secondary_is_refused() { refused_across_protocols("moq-transport-18").await; } diff --git a/rs/moq-net/tests/integration/partial_group.rs b/rs/moq-net/tests/integration/partial_group.rs index 90136b30881..19871c8927c 100644 --- a/rs/moq-net/tests/integration/partial_group.rs +++ b/rs/moq-net/tests/integration/partial_group.rs @@ -40,15 +40,15 @@ async fn round(version: &str) -> Option, moq_net::Error>> { broadcast.announce(Default::default()).unwrap(); let consumer = downstream.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("room")) + kio::clock::timeout(TIMEOUT, consumer.routed("room")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); - let mut live = moq_clock::timeout( + let mut live = kio::clock::timeout( TIMEOUT, remote .track("data") @@ -62,7 +62,7 @@ async fn round(version: &str) -> Option, moq_net::Error>> { let mut stalled = track.append_group().unwrap(); stalled.write_frame(Timestamp::ZERO, &b"head"[..]).unwrap(); - let mut group = moq_clock::timeout(TIMEOUT, live.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, live.recv_group()) .await .expect("group timeout") .unwrap() @@ -71,21 +71,21 @@ async fn round(version: &str) -> Option, moq_net::Error>> { assert!(group.read_frame().await.unwrap().is_some()); // The live edge moves a full second past the stalled group's reach. - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; for millis in [1000, 2000] { let mut next = track.append_group().unwrap(); next.write_frame(Timestamp::from_millis(millis).unwrap(), &b"edge"[..]) .unwrap(); next.finish().unwrap(); } - let tail = moq_clock::timeout(TIMEOUT, group.read_frame()) + let tail = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("the stalled group never gave up"); assert!(tail.is_err(), "{version}: the live reader saw a clean end: {tail:?}"); - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; // A reader with no budget to apply sees only what the downstream hop cached. - let mut cached = moq_clock::timeout( + let mut cached = kio::clock::timeout( TIMEOUT, remote.track("data").unwrap().subscribe( Subscription::default() @@ -96,7 +96,7 @@ async fn round(version: &str) -> Option, moq_net::Error>> { .await .expect("subscribe timeout") .expect("subscribe"); - let first = moq_clock::timeout(TIMEOUT, cached.recv_group()) + let first = kio::clock::timeout(TIMEOUT, cached.recv_group()) .await .expect("group timeout") .unwrap() @@ -108,7 +108,7 @@ async fn round(version: &str) -> Option, moq_net::Error>> { let mut first = first; let mut frames = 0; let end = loop { - match moq_clock::timeout(TIMEOUT, first.read_frame()) + match kio::clock::timeout(TIMEOUT, first.read_frame()) .await .expect("read timeout") { @@ -121,7 +121,7 @@ async fn round(version: &str) -> Option, moq_net::Error>> { Some(end) } -#[moq_clock::test] +#[kio::test] async fn a_stalled_group_is_never_cached_downstream_as_finished() { let mut failures = Vec::new(); for version in VERSIONS { diff --git a/rs/moq-net/tests/integration/quiet_catalog.rs b/rs/moq-net/tests/integration/quiet_catalog.rs index bdb367f0805..c410d238c71 100644 --- a/rs/moq-net/tests/integration/quiet_catalog.rs +++ b/rs/moq-net/tests/integration/quiet_catalog.rs @@ -43,7 +43,7 @@ fn abort(pair: MockPair) { } async fn settle() { - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; } /// Announce `live/catalog.json` holding one finished snapshot group. @@ -69,16 +69,16 @@ async fn read_snapshot(remote: &broadcast::Consumer) -> Result>>(versions: &[&str], let mut failures = Vec::new(); for version in versions { let version: Version = version.parse().unwrap(); - match moq_clock::timeout(Duration::from_secs(30), scenario(version)).await { + match kio::clock::timeout(Duration::from_secs(30), scenario(version)).await { Ok(Ok(())) => {} Ok(Err(err)) => failures.push(format!("{version}: {err}")), Err(_) => failures.push(format!("{version}: scenario timed out")), @@ -105,7 +105,7 @@ async fn each_version>>(versions: &[&str], /// `P -> A -> R` is serving a finished catalog and `P -> B -> R` is standing by. /// `A` dies. A new reader on `R` has to receive the snapshot `P` still holds. -#[moq_clock::test] +#[kio::test] async fn a_quiet_catalog_reaches_a_late_reader_after_its_route_dies() { each_version(VERSIONS, |version| async move { let publisher = produce_origin(1); @@ -144,14 +144,14 @@ async fn a_quiet_catalog_reaches_a_late_reader_after_its_route_dies() { /// A peer resumes one group past a finished catalog before anyone else has /// fetched it, so the relay's upstream subscription is created past the only /// group. A fresh reader must still receive that group. -#[moq_clock::test] +#[kio::test] async fn a_quiet_catalog_reaches_a_fresh_reader_when_a_peer_resumes_past_it() { each_version(LITE, |version| resume_then_fresh(version, false)).await; } /// The same, with the fresh reader in-process at the relay. It names no floor at all, /// so the aggregate must not keep the resume's floor above the only group. -#[moq_clock::test] +#[kio::test] async fn a_quiet_catalog_reaches_an_unfloored_relay_reader_when_a_peer_resumes_past_it() { each_version(LITE, |version| resume_then_fresh(version, true)).await; } @@ -170,20 +170,20 @@ async fn resume_then_fresh(version: Version, in_process: bool) -> Result<(), Str let resume_remote = request(&resuming).await; // Held until the scenario returns. Dropping it would cancel the upstream // subscription and let the fresh reader open a new one at the live edge. - let _resume = moq_clock::sim::spawn(async move { + let _resume = kio::clock::sim::spawn(async move { let _sub = resume_remote .track("catalog.json") .unwrap() .subscribe(track::Subscription::default().with_range(1..)) .await .expect("resume subscribe"); - moq_clock::sleep(Duration::from_secs(60)).await; + kio::clock::sleep(Duration::from_secs(60)).await; }); // Wait for the resume to reach the publisher, so the fresh reader widens it // rather than opening its own floorless subscription. let resumed = vec![track::Range::groups(1..)]; - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { while track.subscription().map(|sub| sub.ranges).as_ref() != Some(&resumed) { track.subscription_changed().await.unwrap(); } diff --git a/rs/moq-net/tests/integration/range_anchors.rs b/rs/moq-net/tests/integration/range_anchors.rs index 71850dd535b..a34c46d144a 100644 --- a/rs/moq-net/tests/integration/range_anchors.rs +++ b/rs/moq-net/tests/integration/range_anchors.rs @@ -61,18 +61,18 @@ async fn read(version: Option<&str>, range: Range) -> Result, Error> { let _pair; let remote = match version { // Through the origin, as a reader of a local route. - None => moq_clock::timeout(TIMEOUT, publisher.consume().request_broadcast("room", None)) + None => kio::clock::timeout(TIMEOUT, publisher.consume().request_broadcast("room", None)) .await .expect("resolve timeout") .expect("broadcast resolves"), Some(version) => { _pair = peer(version.parse::().unwrap(), &publisher, &subscriber).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("room")) + kio::clock::timeout(TIMEOUT, consumer.routed("room")) .await .expect("announce timeout") .expect("routed"); - moq_clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) + kio::clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) .await .expect("resolve timeout") .expect("broadcast resolves") @@ -83,12 +83,12 @@ async fn read(version: Option<&str>, range: Range) -> Result, Error> { .with_max_delay(FOREVER) .with_order(Order::Ascending) .with_ranges([range]); - let mut reader = moq_clock::timeout(TIMEOUT, remote.track("data").unwrap().subscribe(subscription)) + let mut reader = kio::clock::timeout(TIMEOUT, remote.track("data").unwrap().subscribe(subscription)) .await .expect("subscribe timeout")?; let mut read = Vec::new(); - while let Ok(group) = moq_clock::timeout(TIMEOUT, reader.recv_group()).await { + while let Ok(group) = kio::clock::timeout(TIMEOUT, reader.recv_group()).await { match group? { Some(group) => read.push(group.sequence), None => break, @@ -120,7 +120,7 @@ fn anchored() -> [(Range, Vec); 6] { /// Each wire resolves the anchors it carries as the held track does and refuses the rest, /// rather than resolve them against the part of the track its copy happens to hold. -#[moq_clock::test] +#[kio::test] async fn each_wire_refuses_only_the_anchors_it_drops() { for version in std::iter::once(None).chain(VERSIONS.iter().copied().map(Some)) { // Lite-07 reports the largest and media time and asks for everything the budget @@ -146,7 +146,7 @@ async fn each_wire_refuses_only_the_anchors_it_drops() { /// Every wire carries the live and oldest starts, which it spells with no floor. A wire whose /// copy starts at the live edge fills the older groups after it. -#[moq_clock::test] +#[kio::test] async fn every_wire_carries_the_live_and_oldest_starts() { for version in VERSIONS { let live = read(Some(version), Range::live()).await; diff --git a/rs/moq-net/tests/integration/received_rewind.rs b/rs/moq-net/tests/integration/received_rewind.rs index 6b8bd7cda19..e1a2472e909 100644 --- a/rs/moq-net/tests/integration/received_rewind.rs +++ b/rs/moq-net/tests/integration/received_rewind.rs @@ -65,17 +65,17 @@ async fn relay( let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); let subscription = Subscription::default().with_max_delay(BUDGET).with_range(0..); - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let mut sub = remote .track("data") .unwrap() @@ -85,13 +85,13 @@ async fn relay( let timescale = sub.info().timescale; let mut got = Vec::new(); loop { - let next = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let next = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("recv_group timed out"); let Some(mut group) = next.expect("recv_group") else { break; }; - while moq_clock::timeout(TIMEOUT, group.read_frame()) + while kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("read_frame timed out") .expect("read_frame") @@ -102,18 +102,18 @@ async fn relay( (timescale, got) }); - moq_clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 1); // Sent later, so group 0's send time lands after group 1's. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; write_group(&track, 0); track.finish().unwrap(); - let got = moq_clock::timeout(TIMEOUT * 3, reader) + let got = kio::clock::timeout(TIMEOUT * 3, reader) .await .expect("reader hung") .expect("reader panicked"); @@ -121,7 +121,7 @@ async fn relay( got } -#[moq_clock::test] +#[kio::test] async fn a_relay_forwards_descending_send_times_without_closing_the_track() { let mut failures = Vec::new(); for downstream in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { @@ -136,7 +136,7 @@ async fn a_relay_forwards_descending_send_times_without_closing_the_track() { /// A moq-transport peer may stamp arrival times, so a relay keeps a timed track's timestamps /// unchecked and passes them on only over moq-transport: a moq-lite hop, which checks every /// timestamp it receives, is served the track untimed. -#[moq_clock::test] +#[kio::test] async fn moq_transport_timestamps_stay_on_moq_transport() { let mut failures = Vec::new(); for (downstream, expected) in [ @@ -171,11 +171,11 @@ async fn fetch_only(version: &str) -> Vec> { let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -187,15 +187,15 @@ async fn fetch_only(version: &str) -> Vec> { while group.read_frame().await?.is_some() {} Ok(group.sequence) }; - got.push(moq_clock::timeout(TIMEOUT, read).await.expect("fetch timed out")); + got.push(kio::clock::timeout(TIMEOUT, read).await.expect("fetch timed out")); // Answered later, so group 0's send time lands after group 1's. - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; } drop((pair, remote, broadcast, publisher, subscriber)); got } -#[moq_clock::test] +#[kio::test] async fn fetches_alone_accept_descending_send_times() { let mut failures = Vec::new(); for version in ["moq-lite-05", "moq-lite-06"] { diff --git a/rs/moq-net/tests/integration/rejoin.rs b/rs/moq-net/tests/integration/rejoin.rs index 3efe02589fa..bd65578f705 100644 --- a/rs/moq-net/tests/integration/rejoin.rs +++ b/rs/moq-net/tests/integration/rejoin.rs @@ -37,11 +37,11 @@ async fn read_all(group: &mut group::Consumer) -> moq_net::Result>> /// The relay cancels its idle upstream subscription, resetting that group mid-transfer. /// Resuming the rejoin at the frame where the reset landed would ask upstream for a tail /// whose head is gone, so the group would never reach the returning reader. -#[moq_clock::test] +#[kio::test] async fn rejoin_recovers_the_group_reset_on_leave() { for advance in [false, true] { for version in ["moq-lite-05", "moq-lite-06"] { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let publisher = produce_origin(1); let relay = produce_origin(2); @@ -125,7 +125,7 @@ async fn rejoin_recovers_the_group_reset_on_leave() { /// on meanwhile. The cache is stale until the route answers again, so the rejoining reader /// starts at the live edge, whether the answer carries the largest position (lite-07) or /// the first frame says where the feed is. -#[moq_clock::test] +#[kio::test] async fn rejoin_skips_a_cache_kept_by_another_handle() { for version in [ "moq-lite-05", @@ -134,7 +134,7 @@ async fn rejoin_skips_a_cache_kept_by_another_handle() { "moq-transport-18", "moq-transport-22", ] { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let publisher = produce_origin(1); let relay = produce_origin(2); @@ -188,7 +188,7 @@ async fn rejoin_skips_a_cache_kept_by_another_handle() { /// The client still holds the group's head when it rejoins, so it may ask the relay for /// only the rest. A later reader at the relay joins at the live edge and needs the group /// from its first frame, so the relay's copy must keep it. -#[moq_clock::test] +#[kio::test] async fn rejoin_mid_group_keeps_the_head_for_later_readers() { for version in [ "moq-lite-05", @@ -197,7 +197,7 @@ async fn rejoin_mid_group_keeps_the_head_for_later_readers() { "moq-transport-18", "moq-transport-22", ] { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let publisher = produce_origin(1); let relay = produce_origin(2); let client = produce_origin(3); @@ -267,10 +267,10 @@ async fn rejoin_mid_group_keeps_the_head_for_later_readers() { /// The publisher accepts the join, but its stream is lost before its header. The open group /// is gone for this copy, but the groups after it must still reach readers, local and /// downstream, rather than wait on a head that is never coming. -#[moq_clock::test] +#[kio::test] async fn rejoin_goes_live_without_the_join_head() { for version in ["moq-transport-18", "moq-transport-22"] { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let publisher = produce_origin(1); let relay = produce_origin(2); let client = produce_origin(3); @@ -302,7 +302,7 @@ async fn rejoin_goes_live_without_the_join_head() { // The rejoin's join stream is lost before its header. upstream.server_transport.hold_unis(); - let rejoin = moq_clock::sim::spawn(async move { + let rejoin = kio::clock::sim::spawn(async move { let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); loop { let mut group = sub.recv_group().await.unwrap().unwrap(); @@ -312,7 +312,7 @@ async fn rejoin_goes_live_without_the_join_head() { } }); crate::support::wanted(track.demand()).await.unwrap(); - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; upstream.server_transport.drop_unis(); let mut next = track.append_group().unwrap(); @@ -338,10 +338,10 @@ async fn rejoin_goes_live_without_the_join_head() { /// Cancelling waits on the publisher, a round trip on a slow link, but the publisher stops /// serving as soon as the cancel lands. A reader returning in between must already find the /// copy idle, or it takes the cached group as the live edge. -#[moq_clock::test] +#[kio::test] async fn rejoin_during_the_cancel_skips_the_cache() { for version in support::every_version() { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let publisher = produce_origin(1); let relay = produce_origin(2); @@ -396,7 +396,7 @@ async fn rejoin_during_the_cancel_skips_the_cache() { /// rejoin with that group, right after the one the relay cached. Its header lands before its /// first frame. Shown in between, it would leave the cached group without a stamped /// successor, and a reader at the live edge would be handed that older group first. -#[moq_clock::test] +#[kio::test] async fn rejoin_waits_for_the_answers_first_frame() { // Lite01/02 carry no max age, so the publisher serves the relay's cached head again and // that answer is what makes the cache current. @@ -405,7 +405,7 @@ async fn rejoin_waits_for_the_answers_first_frame() { .into_iter() .filter(|version| !unbudgeted.contains(&version.as_str())) { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let publisher = produce_origin(1); let relay = produce_origin(2); @@ -441,7 +441,7 @@ async fn rejoin_waits_for_the_answers_first_frame() { pair.server_transport.split_unis(); let mut sub = remote.track("video").unwrap().subscribe(None).await.unwrap(); - let early = moq_clock::timeout(Duration::from_secs(1), sub.recv_group()).await; + let early = kio::clock::timeout(Duration::from_secs(1), sub.recv_group()).await; assert!( early.is_err(), "{version}: the rejoining reader got the cached group {:?} first", @@ -468,7 +468,7 @@ async fn rejoin_waits_for_the_answers_first_frame() { /// A catalog's latest group can sit unread past the cache's idle expiry. A downstream /// session that read it and then leaves must not take the relay's copy of that group with /// it: a reader that joins afterwards needs it, and no newer group may ever come. -#[moq_clock::test] +#[kio::test] async fn leaving_after_the_cache_window_keeps_the_latest_group() { for version in [ "moq-lite-05", @@ -477,7 +477,7 @@ async fn leaving_after_the_cache_window_keeps_the_latest_group() { "moq-transport-18", "moq-transport-22", ] { - moq_clock::timeout(TEST_TIMEOUT + moq_net::cache::DEFAULT_EXPIRY * 3, async { + kio::clock::timeout(TEST_TIMEOUT + moq_net::cache::DEFAULT_EXPIRY * 3, async { let version: Version = version.parse().unwrap(); let publisher = produce_origin(1); let relay = produce_origin(2); @@ -519,7 +519,7 @@ async fn leaving_after_the_cache_window_keeps_the_latest_group() { let mut sub = leaver.track("catalog").unwrap().subscribe(None).await.unwrap(); let mut group = sub.recv_group().await.unwrap().unwrap(); assert_eq!(read_all(&mut group).await.unwrap(), [b"c0"], "{version}"); - moq_clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2).await; + kio::clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2).await; drop((group, sub, leaver, leaver_session)); // Right after the leave, and again once the leaver's front has lingered and let go @@ -528,10 +528,10 @@ async fn leaving_after_the_cache_window_keeps_the_latest_group() { (5, Duration::from_millis(100)), (6, moq_net::cache::DEFAULT_EXPIRY + Duration::from_secs(1)), ] { - moq_clock::sleep(after).await; + kio::clock::sleep(after).await; let (later, _later) = session(hop).await; let mut sub = later.track("catalog").unwrap().subscribe(None).await.unwrap(); - let group = moq_clock::timeout(Duration::from_secs(1), sub.recv_group()).await; + let group = kio::clock::timeout(Duration::from_secs(1), sub.recv_group()).await; let mut group = group .unwrap_or_else(|_| panic!("{version}: reader {hop} never got the latest group")) .unwrap() @@ -550,10 +550,10 @@ async fn leaving_after_the_cache_window_keeps_the_latest_group() { /// The returning subscription opts out of the track's properties from draft-22, since the /// copy already learned them, so its units must come from that first answer rather than /// the empty block the second one carries. -#[moq_clock::test] +#[kio::test] async fn rejoin_keeps_source_timestamps() { for version in ["moq-transport-18", "moq-transport-22"] { - moq_clock::timeout(TEST_TIMEOUT, async { + kio::clock::timeout(TEST_TIMEOUT, async { let publisher = produce_origin(1); let client = produce_origin(2); @@ -607,7 +607,7 @@ async fn rejoin_keeps_source_timestamps() { /// group must stay protected while that reader holds the track open: a reader joining /// after the cache window needs it, and no newer group may ever come. Once a newer group /// supersedes it, it expires like any other. -#[moq_clock::test] +#[kio::test] async fn rejoined_quiet_catalog_survives_cache_expiry() { for version in [ "moq-lite-05", @@ -625,7 +625,7 @@ async fn rejoined_quiet_catalog_survives_cache_expiry() { /// The publisher reconnects while a reader holds the catalog. A late reader through the /// new connection still needs the quiet catalog, even on a wire without epochs where /// the old reader ends with its route. -#[moq_clock::test] +#[kio::test] async fn taken_over_quiet_catalog_survives_cache_expiry() { for version in [ "moq-lite-05", @@ -639,7 +639,7 @@ async fn taken_over_quiet_catalog_survives_cache_expiry() { } async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { - moq_clock::timeout(TEST_TIMEOUT + moq_net::cache::DEFAULT_EXPIRY * 5, async { + kio::clock::timeout(TEST_TIMEOUT + moq_net::cache::DEFAULT_EXPIRY * 5, async { let publisher = produce_origin(1); let relay = produce_origin(2); let broadcast = publisher.create_broadcast("bench").unwrap(); @@ -707,9 +707,9 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { (holder, remote, pair) }; - moq_clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2 + Duration::from_secs(2)).await; + kio::clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2 + Duration::from_secs(2)).await; let (mut later, later_remote, _later_pair) = session(5).await; - let mut group = moq_clock::timeout(Duration::from_secs(1), later.recv_group()) + let mut group = kio::clock::timeout(Duration::from_secs(1), later.recv_group()) .await .unwrap_or_else(|_| panic!("{version} takeover={takeover}: late reader lost the latest catalog")) .unwrap() @@ -726,13 +726,13 @@ async fn quiet_catalog_survives_cache_expiry(version: Version, takeover: bool) { // Epochless wires end the old holder on takeover. The late reader uses the // current route on every version, and keeps that copy live for the expiry check. assert_eq!(later.recv_group().await.unwrap().unwrap().sequence, 1, "{version}"); - moq_clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2 + Duration::from_secs(2)).await; + kio::clock::sleep(moq_net::cache::DEFAULT_EXPIRY * 2 + Duration::from_secs(2)).await; let old = async { let mut group = later_remote.track("catalog").unwrap().fetch_group(0, None).await?; group.read_frame().await }; assert!( - moq_clock::timeout(Duration::from_secs(1), old).await.unwrap().is_err(), + kio::clock::timeout(Duration::from_secs(1), old).await.unwrap().is_err(), "{version} takeover={takeover}: the superseded catalog never expired" ); drop(upstream_session); diff --git a/rs/moq-net/tests/integration/relay_upstream_close.rs b/rs/moq-net/tests/integration/relay_upstream_close.rs index 4c9eb212682..b8f63979e5f 100644 --- a/rs/moq-net/tests/integration/relay_upstream_close.rs +++ b/rs/moq-net/tests/integration/relay_upstream_close.rs @@ -111,11 +111,11 @@ async fn round(name: &str, end: End) -> Vec { let downstream = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -124,12 +124,12 @@ async fn round(name: &str, end: End) -> Vec { for (index, track) in tracks.iter().enumerate() { let subscription = Subscription::default().with_max_delay(MAX_DELAY).with_range(0..); let sub = remote.track(&format!("track{index}")).unwrap().subscribe(subscription); - let sub = moq_clock::timeout(TIMEOUT, sub) + let sub = kio::clock::timeout(TIMEOUT, sub) .await .expect("the subscription never became active") .expect("subscribe"); - readers.push(moq_clock::sim::spawn(read(sub))); - moq_clock::timeout(TIMEOUT, support::harness::subscribed(track)) + readers.push(kio::clock::sim::spawn(read(sub))); + kio::clock::timeout(TIMEOUT, support::harness::subscribed(track)) .await .expect("no subscriber appeared"); } @@ -149,25 +149,25 @@ async fn round(name: &str, end: End) -> Vec { } match end { - End::Close => moq_clock::timeout(TIMEOUT, upstream.server.clone().close()) + End::Close => kio::clock::timeout(TIMEOUT, upstream.server.clone().close()) .await .expect("close timed out") .expect("the close drains"), End::Abort => { // Simulated time advances only once every task is idle: the relay has read // everything the unheld upstream hop carried. - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; upstream.server.abort(Error::Cancel); } } drop((tracks, broadcast, publisher, upstream)); // The relay sees the session and its broadcast go before the subscriber reads on. - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; downstream.server_transport.release_unis(); let mut outcomes = Vec::new(); for reader in readers { - let outcome = moq_clock::timeout(TIMEOUT, reader) + let outcome = kio::clock::timeout(TIMEOUT, reader) .await .unwrap_or_else(|_| panic!("{name} {end:?}: a track never ended")) .expect("reader panicked"); @@ -181,7 +181,7 @@ async fn round(name: &str, end: End) -> Vec { /// relay is still waiting out its tail grace when the session goes, and on a close each /// track's SUBSCRIBE FIN is its only end: the transport acknowledges it, which lets the /// close drain, before the relay has read it. -#[moq_clock::test] +#[kio::test] async fn relay_delivers_finished_tracks_after_upstream_closes() { let want: Vec<(u64, u64)> = (0..GROUPS) .flat_map(|group| (0..FRAMES).map(move |frame| (group, frame))) diff --git a/rs/moq-net/tests/integration/replacement.rs b/rs/moq-net/tests/integration/replacement.rs index 313542a6219..ff1e4fe6423 100644 --- a/rs/moq-net/tests/integration/replacement.rs +++ b/rs/moq-net/tests/integration/replacement.rs @@ -40,7 +40,7 @@ async fn link(version: Version, from: &origin::Producer, to: &origin::Producer) /// The next announce event, failing on a hang. async fn next_event(announced: &mut announce::Consumer) -> announce::Event { - moq_clock::timeout(Duration::from_secs(10), announced.next()) + kio::clock::timeout(Duration::from_secs(10), announced.next()) .await .expect("announce hung") .expect("announce ended") @@ -55,7 +55,7 @@ fn write(track: &track::Producer, tag: &str) { /// The next frame a subscription delivers, as text. async fn read(subscription: &mut track::Subscriber) -> String { - let mut group = moq_clock::timeout(Duration::from_secs(10), subscription.recv_group()) + let mut group = kio::clock::timeout(Duration::from_secs(10), subscription.recv_group()) .await .expect("subscription hung") .unwrap() @@ -65,7 +65,7 @@ async fn read(subscription: &mut track::Subscriber) -> String { } async fn subscribe(broadcast: &broadcast::Consumer, name: &str) -> Result { - moq_clock::timeout(Duration::from_secs(10), broadcast.track(name)?.subscribe(None)) + kio::clock::timeout(Duration::from_secs(10), broadcast.track(name)?.subscribe(None)) .await .expect("subscribe hung") } @@ -103,7 +103,7 @@ async fn replace(version: &str, epoch: Option) { // The replacement: the same peer re-announces everything over a second session, // while the first one is still open. let _second = link(version, &publisher, &viewer).await; - moq_clock::sleep(WITHIN_HOLD).await; + kio::clock::sleep(WITHIN_HOLD).await; // A request through the old handle right after the replacement is still served. let mut late = subscribe(&old, "audio") @@ -115,7 +115,7 @@ async fn replace(version: &str, epoch: Option) { if epoch.is_some() { // The epoch continues across the replacement: nothing to restart, and the old // handle keeps serving. - if let Ok(event) = moq_clock::timeout(PAST_HOLD, announced.next()).await { + if let Ok(event) = kio::clock::timeout(PAST_HOLD, announced.next()).await { panic!("{version}: an epoch route restarted on replacement: {event:?}"); } let mut later = subscribe(&old, "meta").await.unwrap(); @@ -126,7 +126,7 @@ async fn replace(version: &str, epoch: Option) { // Without an epoch the replacement is a restart: once the hold releases it, the old // handle refuses new requests, and the restart is already there to follow. - moq_clock::sleep(PAST_HOLD).await; + kio::clock::sleep(PAST_HOLD).await; let Err(err) = subscribe(&old, "meta").await else { panic!("{version}: a retired handle served a request"); }; @@ -149,43 +149,43 @@ fn epoch() -> Epoch { "01900000-0000-7000-8000-000000000001".parse().unwrap() } -#[moq_clock::test] +#[kio::test] async fn epochless_lite06() { - moq_clock::timeout(TEST_TIMEOUT, replace("moq-lite-06", None)) + kio::clock::timeout(TEST_TIMEOUT, replace("moq-lite-06", None)) .await .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn epochless_lite07() { - moq_clock::timeout(TEST_TIMEOUT, replace("moq-lite-07-wip", None)) + kio::clock::timeout(TEST_TIMEOUT, replace("moq-lite-07-wip", None)) .await .expect("timed out"); } /// Only lite-07 carries the epoch. -#[moq_clock::test] +#[kio::test] async fn epoch_lite07() { - moq_clock::timeout(TEST_TIMEOUT, replace("moq-lite-07-wip", Some(epoch()))) + kio::clock::timeout(TEST_TIMEOUT, replace("moq-lite-07-wip", Some(epoch()))) .await .expect("timed out"); } /// moq-transport carries the epoch with the MoQ Epoch extension. -#[moq_clock::test] +#[kio::test] async fn epoch_ietf() { for version in ["moq-transport-18", "moq-transport-22"] { - moq_clock::timeout(TEST_TIMEOUT, replace(version, Some(epoch()))) + kio::clock::timeout(TEST_TIMEOUT, replace(version, Some(epoch()))) .await .expect("timed out"); } } /// Without one, a moq-transport replacement restarts as it does over lite. -#[moq_clock::test] +#[kio::test] async fn epochless_ietf() { for version in ["moq-transport-22"] { - moq_clock::timeout(TEST_TIMEOUT, replace(version, None)) + kio::clock::timeout(TEST_TIMEOUT, replace(version, None)) .await .expect("timed out"); } @@ -221,7 +221,7 @@ async fn route_death(version: &str, relayed: bool, wait: Duration) { assert_eq!(read(&mut sticky).await, "video:0", "{version}"); let _replacement = link(version, &publisher, upstream).await; - moq_clock::sleep(wait).await; + kio::clock::sleep(wait).await; write(&video, "video:1"); assert_eq!( read(&mut sticky).await, @@ -230,7 +230,7 @@ async fn route_death(version: &str, relayed: bool, wait: Duration) { ); let _ = old_session.server.close().await; - let end = moq_clock::timeout(Duration::from_secs(10), async { + let end = kio::clock::timeout(Duration::from_secs(10), async { loop { match sticky.recv_group().await { Ok(Some(_)) => continue, @@ -247,22 +247,22 @@ async fn route_death(version: &str, relayed: bool, wait: Duration) { ); } -#[moq_clock::test] +#[kio::test] async fn route_death_within_hold_errors() { for version in ["moq-lite-06", "moq-lite-07-wip"] { for relayed in [false, true] { - moq_clock::timeout(TEST_TIMEOUT, route_death(version, relayed, WITHIN_HOLD)) + kio::clock::timeout(TEST_TIMEOUT, route_death(version, relayed, WITHIN_HOLD)) .await .expect("timed out"); } } } -#[moq_clock::test] +#[kio::test] async fn route_death_past_hold_errors() { for version in ["moq-lite-06", "moq-lite-07-wip"] { for relayed in [false, true] { - moq_clock::timeout(TEST_TIMEOUT, route_death(version, relayed, PAST_HOLD)) + kio::clock::timeout(TEST_TIMEOUT, route_death(version, relayed, PAST_HOLD)) .await .expect("timed out"); } @@ -291,7 +291,7 @@ async fn restart_while_the_old_session_lingers(version: &str, old_hop: u64, new_ let new_cam = new.publish("cam", origin::Route::default()).unwrap(); let new_video = new_cam.create_track("video", timed()).unwrap(); let _new_session = link(version, &new, &viewer).await; - moq_clock::sleep(PAST_HOLD).await; + kio::clock::sleep(PAST_HOLD).await; let cam = viewer.consume().request_broadcast("cam", None).await.unwrap(); let mut video = subscribe(&cam, "video") @@ -301,11 +301,11 @@ async fn restart_while_the_old_session_lingers(version: &str, old_hop: u64, new_ assert_eq!(read(&mut video).await, "new:0", "{version} ({old_hop} -> {new_hop})"); } -#[moq_clock::test] +#[kio::test] async fn restart_while_the_old_session_lingers_wins() { for version in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { for (old_hop, new_hop) in [(1, 4), (4, 1)] { - moq_clock::timeout( + kio::clock::timeout( TEST_TIMEOUT, restart_while_the_old_session_lingers(version, old_hop, new_hop), ) diff --git a/rs/moq-net/tests/integration/request_caps.rs b/rs/moq-net/tests/integration/request_caps.rs index 79f9586dcf5..b2e7e5e1343 100644 --- a/rs/moq-net/tests/integration/request_caps.rs +++ b/rs/moq-net/tests/integration/request_caps.rs @@ -66,20 +66,20 @@ fn limits(announces: usize) -> Limits { /// Many more requests than the stream credit admits at once, opened and closed in turn, all /// succeed: each one that closes is granted back. -#[moq_clock::test] +#[kio::test] async fn closed_requests_are_granted_back() { const ROUNDS: usize = 64; for version in VERSIONS { let setup = setup(version, limits(0), ROUNDS).await; - let broadcast = moq_clock::timeout(TIMEOUT, setup.client.consume().routed_broadcast("bcast")) + let broadcast = kio::clock::timeout(TIMEOUT, setup.client.consume().routed_broadcast("bcast")) .await .expect("announce timeout") .unwrap(); for round in 0..ROUNDS { let track = broadcast.track(&format!("t{round}")).unwrap(); - let subscriber = moq_clock::timeout(TIMEOUT, track.subscribe(None)) + let subscriber = kio::clock::timeout(TIMEOUT, track.subscribe(None)) .await .unwrap_or_else(|_| panic!("{version}: round {round} stalled")) .unwrap_or_else(|err| panic!("{version}: round {round} refused: {err}")); @@ -88,7 +88,7 @@ async fn closed_requests_are_granted_back() { // Wait for the server to see it end, so the next round is a fresh request. let published = &setup.tracks[round]; - moq_clock::timeout(TIMEOUT, crate::support::unwanted(published.demand())) + kio::clock::timeout(TIMEOUT, crate::support::unwanted(published.demand())) .await .unwrap_or_else(|_| panic!("{version}: round {round} never ended")) .unwrap(); @@ -99,7 +99,7 @@ async fn closed_requests_are_granted_back() { /// With no subscription cap, a client asking for more subscriptions than the server admits /// still holds no more than the stream credit at once. The rest wait rather than close the /// session. -#[moq_clock::test] +#[kio::test] async fn flow_control_bounds_the_subscriptions_a_peer_holds() { // 8 bidi streams toward the server. const BOUND: usize = 8; @@ -122,26 +122,26 @@ async fn flow_control_bounds_the_subscriptions_a_peer_holds() { options.server_limits = Some(limits(0)); let pair = connect_mock(options).await; - let remote = moq_clock::timeout(TIMEOUT, client.consume().routed_broadcast("bcast")) + let remote = kio::clock::timeout(TIMEOUT, client.consume().routed_broadcast("bcast")) .await .expect("announce timeout") .unwrap(); let subscribing: Vec<_> = (0..TRACKS) .map(|i| { let track = remote.track(&format!("t{i}")).unwrap(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { let _subscriber = track.subscribe(None).await; std::future::pending::<()>().await }) }) .collect(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let held = tracks.iter().filter(|track| track.demand().wanted().is_some()).count(); assert!(held > 0, "{version}: nothing was subscribed"); assert!(held <= BOUND, "{version}: the server holds {held} subscriptions"); assert!( - moq_clock::timeout(Duration::from_millis(100), pair.client.closed()) + kio::clock::timeout(Duration::from_millis(100), pair.client.closed()) .await .is_err(), "{version}: the session closed" @@ -153,7 +153,7 @@ async fn flow_control_bounds_the_subscriptions_a_peer_holds() { } /// A broadcast announced past the cap closes the session with TOO_MANY_REQUESTS. -#[moq_clock::test] +#[kio::test] async fn an_announce_past_the_cap_closes_the_session() { for version in VERSIONS { let version: Version = version.parse().unwrap(); @@ -170,7 +170,7 @@ async fn an_announce_past_the_cap_closes_the_session() { options.server_limits = Some(limits(1)); let pair = connect_mock(options).await; - let err = moq_clock::timeout(TIMEOUT, pair.client.closed()) + let err = kio::clock::timeout(TIMEOUT, pair.client.closed()) .await .unwrap_or_else(|_| panic!("{version}: the session stayed open")); assert!( diff --git a/rs/moq-net/tests/integration/route_change.rs b/rs/moq-net/tests/integration/route_change.rs index f7a7ca97ef9..642191b05b6 100644 --- a/rs/moq-net/tests/integration/route_change.rs +++ b/rs/moq-net/tests/integration/route_change.rs @@ -66,7 +66,7 @@ fn tagged(name: &str, group: u64, frame: u64) -> Vec { /// Let every task settle. Time is paused, so this returns once the runtime is idle. async fn settle() { - moq_clock::sleep(Duration::from_millis(500)).await; + kio::clock::sleep(Duration::from_millis(500)).await; } /// How the serving route goes away (or is beaten). @@ -183,7 +183,7 @@ type Delivery = (u64, moq_net::Result<(Option, Vec)>); /// Read every group in full, reporting each frame as it arrives. fn read(mut sub: track::Subscriber) -> mpsc::UnboundedReceiver { let (tx, rx) = mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { loop { let mut group = match sub.recv_group().await { Ok(Some(group)) => group, @@ -221,7 +221,7 @@ async fn next(rx: &mut mpsc::UnboundedReceiver) -> (u64, Vec) { /// [`next`], keeping the frame's timestamp. async fn next_timed(rx: &mut mpsc::UnboundedReceiver) -> (u64, Option, Vec) { - let (group, frame) = moq_clock::timeout(Duration::from_secs(10), rx.next()) + let (group, frame) = kio::clock::timeout(Duration::from_secs(10), rx.next()) .await .expect("reader hung") .expect("reader ended"); @@ -345,7 +345,7 @@ async fn route_dies_without_an_epoch(version: &str, trigger: Trigger) { let mut group = topology.track.append_group().unwrap(); group.write_frame(Timestamp::ZERO, payload(1, 0)).unwrap(); settle().await; - match moq_clock::timeout(Duration::from_secs(10), rx.next()) + match kio::clock::timeout(Duration::from_secs(10), rx.next()) .await .expect("reader hung") { @@ -426,37 +426,37 @@ macro_rules! route_change_tests { use super::*; async fn run(trigger: Trigger, position: Position) { - moq_clock::timeout(TEST_TIMEOUT, route_change($version, trigger, position)) + kio::clock::timeout(TEST_TIMEOUT, route_change($version, trigger, position)) .await .expect("timed out"); } - #[moq_clock::test] + #[kio::test] async fn disconnect_between_groups() { run(Trigger::Disconnect, Position::BetweenGroups).await; } - #[moq_clock::test] + #[kio::test] async fn disconnect_mid_group() { run(Trigger::Disconnect, Position::MidGroup).await; } - #[moq_clock::test] + #[kio::test] async fn unannounce_between_groups() { run(Trigger::Unannounce, Position::BetweenGroups).await; } - #[moq_clock::test] + #[kio::test] async fn unannounce_mid_group() { run(Trigger::Unannounce, Position::MidGroup).await; } - #[moq_clock::test] + #[kio::test] async fn better_route_between_groups() { run(Trigger::BetterRoute, Position::BetweenGroups).await; } - #[moq_clock::test] + #[kio::test] async fn better_route_mid_group() { run(Trigger::BetterRoute, Position::MidGroup).await; } @@ -479,26 +479,26 @@ macro_rules! pinned_tests { use super::*; async fn run(trigger: Trigger) { - moq_clock::timeout(TEST_TIMEOUT, route_dies_without_an_epoch($version, trigger)) + kio::clock::timeout(TEST_TIMEOUT, route_dies_without_an_epoch($version, trigger)) .await .expect("timed out"); } - #[moq_clock::test] + #[kio::test] async fn disconnect_ends_the_subscription() { run(Trigger::Disconnect).await; } - #[moq_clock::test] + #[kio::test] async fn unannounce_ends_the_subscription() { run(Trigger::Unannounce).await; } /// A better route without an epoch wins new requests and announces as a /// restart, while the incumbent's subscriptions continue. - #[moq_clock::test] + #[kio::test] async fn better_route_keeps_the_incumbent() { - moq_clock::timeout(TEST_TIMEOUT, better_route_restarts($version)) + kio::clock::timeout(TEST_TIMEOUT, better_route_restarts($version)) .await .expect("timed out"); } @@ -604,17 +604,17 @@ async fn lagging_route_dies(version: Version) { let _keep = (broadcast, track, group, p_a, p_b, b_w, b_r, warm, a_r, p, a, b, r, w); } -#[moq_clock::test] +#[kio::test] async fn lite_resumes_after_a_lagging_route_dies() { lagging_route_dies("moq-lite-07-wip".parse().unwrap()).await; } -#[moq_clock::test] +#[kio::test] async fn ietf_17_resumes_after_a_lagging_route_dies() { lagging_route_dies("moq-transport-18".parse().unwrap()).await; } -#[moq_clock::test] +#[kio::test] async fn ietf_22_resumes_after_a_lagging_route_dies() { lagging_route_dies("moq-transport-22".parse().unwrap()).await; } @@ -675,7 +675,7 @@ async fn undetected_outage(budget: Duration) -> BTreeMap> { pair.client_transport.set_latency(Duration::from_secs(3600)); } } - moq_clock::sleep(STEP).await; + kio::clock::sleep(STEP).await; } group.finish().unwrap(); if sequence == O_NOTICES { @@ -684,13 +684,13 @@ async fn undetected_outage(budget: Duration) -> BTreeMap> { } if sequence == E_NOTICES { // Off the group boundary, so no group's age sits on the budget. - moq_clock::sleep(STEP * 5 / 2).await; + kio::clock::sleep(STEP * 5 / 2).await; // The groups `O` asks for again reach it newest first, as a congested `P` sends // a descending track. p_o.server_transport.hold_unis(); m1_e.server.abort(Error::Cancel); m1_e.client.abort(Error::Cancel); - moq_clock::sleep(STEP).await; + kio::clock::sleep(STEP).await; p_o.server_transport.release_unis_by_priority(); } while let Ok((group, frame)) = rx.try_recv() { @@ -715,9 +715,9 @@ fn resumed(groups: std::ops::RangeInclusive) -> BTreeMap> } /// A budget that outlasts the outage gets every group it held back. -#[moq_clock::test] +#[kio::test] async fn resume_delivers_an_outage_within_the_budget() { - let after = moq_clock::timeout(TEST_TIMEOUT, undetected_outage(Duration::from_secs(10))) + let after = kio::clock::timeout(TEST_TIMEOUT, undetected_outage(Duration::from_secs(10))) .await .expect("timed out"); assert_eq!(after, resumed(5..=12)); @@ -726,9 +726,9 @@ async fn resume_delivers_an_outage_within_the_budget() { /// A budget shorter than the outage gets only the groups it still covers: a group is /// stale once its successor arrived a full budget ago. Group 4 is the one being read, so /// it continues regardless. -#[moq_clock::test] +#[kio::test] async fn resume_delivers_the_outage_tail_within_the_budget() { - let after = moq_clock::timeout(TEST_TIMEOUT, undetected_outage(Duration::from_secs(4))) + let after = kio::clock::timeout(TEST_TIMEOUT, undetected_outage(Duration::from_secs(4))) .await .expect("timed out"); assert_eq!(after, resumed(6..=12)); @@ -737,9 +737,9 @@ async fn resume_delivers_the_outage_tail_within_the_budget() { macro_rules! route_flap_tests { ($($name:ident: $version:literal,)*) => { $( - #[moq_clock::test] + #[kio::test] async fn $name() { - moq_clock::timeout(TEST_TIMEOUT, route_flaps($version)) + kio::clock::timeout(TEST_TIMEOUT, route_flaps($version)) .await .expect("timed out"); } @@ -861,9 +861,9 @@ async fn redundant_pair_fails_over(version: &str, loss: Loss) { drop(kept); } -#[moq_clock::test] +#[kio::test] async fn redundant_pair_fails_over_when_unreachable() { - moq_clock::timeout( + kio::clock::timeout( TEST_TIMEOUT, redundant_pair_fails_over("moq-lite-07-wip", Loss::Unreachable), ) @@ -871,9 +871,9 @@ async fn redundant_pair_fails_over_when_unreachable() { .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn redundant_pair_fails_over_when_the_incumbent_ends() { - moq_clock::timeout(TEST_TIMEOUT, redundant_pair_fails_over("moq-lite-07-wip", Loss::Ends)) + kio::clock::timeout(TEST_TIMEOUT, redundant_pair_fails_over("moq-lite-07-wip", Loss::Ends)) .await .expect("timed out"); } @@ -965,34 +965,34 @@ async fn replaced_behind_a_relay(version: &str, epoch: Option, r drop((dead, replicas)); } -#[moq_clock::test] +#[kio::test] async fn replaced_without_an_epoch_ends_lite_06() { - moq_clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-06", None, false)) + kio::clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-06", None, false)) .await .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn replaced_without_an_epoch_ends_lite_07() { - moq_clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-07-wip", None, false)) + kio::clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-07-wip", None, false)) .await .expect("timed out"); } /// The relay resumes a pair sharing an epoch, so nothing reaches `D`. -#[moq_clock::test] +#[kio::test] async fn pair_behind_a_relay_fails_over_lite_07() { let epoch = Some(moq_net::Epoch::mint()); - moq_clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-07-wip", epoch, true)) + kio::clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-07-wip", epoch, true)) .await .expect("timed out"); } /// lite-06 carries no epoch, so the relay cannot tell the pair is one broadcast. -#[moq_clock::test] +#[kio::test] async fn pair_behind_a_relay_ends_lite_06() { let epoch = Some(moq_net::Epoch::mint()); - moq_clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-06", epoch, false)) + kio::clock::timeout(TEST_TIMEOUT, replaced_behind_a_relay("moq-lite-06", epoch, false)) .await .expect("timed out"); } @@ -1082,16 +1082,16 @@ async fn compression_changes_behind_a_relay(compress: bool) { drop((dead, replicas)); } -#[moq_clock::test] +#[kio::test] async fn same_compression_resumes_behind_a_relay() { - moq_clock::timeout(TEST_TIMEOUT, compression_changes_behind_a_relay(true)) + kio::clock::timeout(TEST_TIMEOUT, compression_changes_behind_a_relay(true)) .await .expect("timed out"); } -#[moq_clock::test] +#[kio::test] async fn different_compression_is_refused_behind_a_relay() { - moq_clock::timeout(TEST_TIMEOUT, compression_changes_behind_a_relay(false)) + kio::clock::timeout(TEST_TIMEOUT, compression_changes_behind_a_relay(false)) .await .expect("timed out"); } @@ -1113,7 +1113,7 @@ async fn producer_replaced(version: &str) { .announce(origin::Route::default().with_epoch(moq_net::Epoch::mint())) .unwrap(); let (tx, mut producers) = mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { while let Ok(request) = dynamic.requested_track().await { if tx.unbounded_send(request.accept(timed())).is_err() { return; @@ -1145,7 +1145,7 @@ async fn producer_replaced(version: &str) { // The encoder restarts: the old producer goes away mid-broadcast, and the resumed // subscription asks for the track again. first.abort(Error::Cancel).unwrap(); - let second = moq_clock::timeout(Duration::from_secs(10), producers.next()) + let second = kio::clock::timeout(Duration::from_secs(10), producers.next()) .await .expect("the track was not requested again") .unwrap(); @@ -1169,9 +1169,9 @@ async fn producer_replaced(version: &str) { macro_rules! producer_replaced_tests { ($($name:ident: $version:literal,)*) => { $( - #[moq_clock::test] + #[kio::test] async fn $name() { - moq_clock::timeout(TEST_TIMEOUT, producer_replaced($version)) + kio::clock::timeout(TEST_TIMEOUT, producer_replaced($version)) .await .expect("timed out"); } diff --git a/rs/moq-net/tests/integration/segmented_frame.rs b/rs/moq-net/tests/integration/segmented_frame.rs index 0bfe4898972..c2d2d6dbfdf 100644 --- a/rs/moq-net/tests/integration/segmented_frame.rs +++ b/rs/moq-net/tests/integration/segmented_frame.rs @@ -23,7 +23,7 @@ fn origin(hop: u64) -> origin::Producer { origin } -#[moq_clock::test] +#[kio::test] async fn a_segmented_frame_crosses_whole() { let payload = Bytes::from((0..SIZE).map(|i| (i % 251) as u8).collect::>()); for version in VERSIONS { @@ -40,7 +40,7 @@ async fn a_segmented_frame_crosses_whole() { options.client_subscribe = Some(viewer.clone()); let _pair = connect_mock(options).await; - let remote = moq_clock::timeout(TIMEOUT, viewer.consume().routed_broadcast("room")) + let remote = kio::clock::timeout(TIMEOUT, viewer.consume().routed_broadcast("room")) .await .expect("broadcast timeout") .unwrap(); @@ -63,7 +63,7 @@ async fn a_segmented_frame_crosses_whole() { } group.finish().unwrap(); - let mut group = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() diff --git a/rs/moq-net/tests/integration/session_close.rs b/rs/moq-net/tests/integration/session_close.rs index 178a26945b1..f7ff74955e3 100644 --- a/rs/moq-net/tests/integration/session_close.rs +++ b/rs/moq-net/tests/integration/session_close.rs @@ -32,7 +32,7 @@ type Read = (Vec>, Result<(), Error>); struct Setup { pair: MockPair, track: moq_net::track::Producer, - reader: moq_clock::sim::JoinHandle, + reader: kio::clock::sim::JoinHandle, _broadcast: moq_net::origin::Publication, } @@ -54,18 +54,18 @@ async fn setup_with_gate(version: &str, gate: Option>) -> Se let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); // The publisher only learns of a subscription once the subscriber polls it. let (ready, active) = futures::channel::oneshot::channel(); - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let mut sub = remote.track("video").unwrap().subscribe(None).await.expect("subscribe"); let _ = ready.send(()); let mut got = Vec::new(); @@ -85,12 +85,12 @@ async fn setup_with_gate(version: &str, gate: Option>) -> Se } }); - moq_clock::timeout(TIMEOUT, support::harness::subscribed(&track)) + kio::clock::timeout(TIMEOUT, support::harness::subscribed(&track)) .await .expect("no subscriber appeared"); // Both ends hold the subscription, so a close tests only the group tail and not a // control response still in flight. - moq_clock::timeout(TIMEOUT, active) + kio::clock::timeout(TIMEOUT, active) .await .expect("the subscription never became active") .expect("reader alive"); @@ -104,7 +104,7 @@ async fn setup_with_gate(version: &str, gate: Option>) -> Se } /// TRACK_INFO creates demand before any SUBSCRIBE, so demand alone cannot gate a drain test. -#[moq_clock::test] +#[kio::test] async fn track_info_interest_precedes_a_subscription() { for version in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip"] { let publisher = produce_origin(1); @@ -130,12 +130,12 @@ async fn track_info_interest_precedes_a_subscription() { /// A finished track's last group and FIN reach the subscriber, even though the /// close is requested before the session wrote them. -#[moq_clock::test] +#[kio::test] async fn close_delivers_a_finished_track() { close_delivers_a_finished_track_for("moq-lite-05").await; } -#[moq_clock::test] +#[kio::test] async fn ietf_close_delivers_a_finished_track() { close_delivers_a_finished_track_for("moq-transport-22").await; } @@ -150,17 +150,17 @@ async fn close_delivers_a_finished_track_for(version: &str) { group.finish().unwrap(); track.finish().unwrap(); - let started = moq_clock::now(); - moq_clock::timeout(TIMEOUT, pair.client.close()) + let started = kio::clock::now(); + kio::clock::timeout(TIMEOUT, pair.client.close()) .await .expect("close timed out") .expect("the close drains"); assert!( - (moq_clock::now() - started) < Duration::from_secs(1), + (kio::clock::now() - started) < Duration::from_secs(1), "drained before the deadline" ); - let (got, end) = moq_clock::timeout(TIMEOUT, reader) + let (got, end) = kio::clock::timeout(TIMEOUT, reader) .await .expect("reader timed out") .unwrap(); @@ -170,12 +170,12 @@ async fn close_delivers_a_finished_track_for(version: &str) { /// A track that never finishes holds the drain until the deadline, then the /// session closes anyway. -#[moq_clock::test] +#[kio::test] async fn close_gives_up_on_a_live_track() { close_gives_up_on_a_live_track_for("moq-lite-05").await; } -#[moq_clock::test] +#[kio::test] async fn ietf_close_gives_up_on_a_live_track() { close_gives_up_on_a_live_track_for("moq-transport-22").await; } @@ -185,21 +185,21 @@ async fn close_gives_up_on_a_live_track_for(version: &str) { pair, track: _track, .. } = setup(version).await; - let started = moq_clock::now(); - let res = moq_clock::timeout(TIMEOUT, pair.client.close()) + let started = kio::clock::now(); + let res = kio::clock::timeout(TIMEOUT, pair.client.close()) .await .expect("close timed out"); assert!(matches!(res, Err(Error::Timeout)), "{res:?}"); - assert_eq!((moq_clock::now() - started), Duration::from_secs(1)); + assert_eq!((kio::clock::now() - started), Duration::from_secs(1)); } /// An abort from another handle cuts a drain short. -#[moq_clock::test] +#[kio::test] async fn abort_cuts_a_drain_short() { abort_cuts_a_drain_short_for("moq-lite-05").await; } -#[moq_clock::test] +#[kio::test] async fn ietf_abort_cuts_a_drain_short() { abort_cuts_a_drain_short_for("moq-transport-22").await; } @@ -210,24 +210,24 @@ async fn abort_cuts_a_drain_short_for(version: &str) { } = setup(version).await; let other = pair.client.clone(); - let started = moq_clock::now(); - let close = moq_clock::sim::spawn(pair.client.close()); - moq_clock::sleep(Duration::from_millis(100)).await; + let started = kio::clock::now(); + let close = kio::clock::sim::spawn(pair.client.close()); + kio::clock::sleep(Duration::from_millis(100)).await; other.abort(Error::Cancel); - let res = moq_clock::timeout(TIMEOUT, close) + let res = kio::clock::timeout(TIMEOUT, close) .await .expect("close timed out") .unwrap(); assert!(res.is_err() && !matches!(res, Err(Error::Timeout)), "{res:?}"); assert!( - (moq_clock::now() - started) < Duration::from_secs(1), + (kio::clock::now() - started) < Duration::from_secs(1), "{res:?} after {:?}", - (moq_clock::now() - started) + (kio::clock::now() - started) ); } -#[moq_clock::test] +#[kio::test] async fn close_withdraws_announcements_before_closing_the_transport() { for version in ["moq-lite-01", "moq-lite-07-wip", "moq-transport-18", "moq-transport-22"] { let publisher = produce_origin(1); @@ -248,7 +248,7 @@ async fn close_withdraws_announcements_before_closing_the_transport() { } } -#[moq_clock::test] +#[kio::test] async fn close_times_out_waiting_for_announcement_acknowledgements() { for version in ["moq-lite-01", "moq-lite-07-wip", "moq-transport-18", "moq-transport-22"] { let publisher = produce_origin(1); @@ -261,14 +261,14 @@ async fn close_times_out_waiting_for_announcement_acknowledgements() { let pair = connect_mock(options).await; subscriber.consume().routed("bcast").await.unwrap(); pair.client_transport.hold_fin_acknowledgements(); - let started = moq_clock::now(); + let started = kio::clock::now(); assert!(matches!(pair.client.close().await, Err(Error::Timeout)), "{version}"); - assert_eq!(moq_clock::now() - started, Duration::from_secs(1)); + assert_eq!(kio::clock::now() - started, Duration::from_secs(1)); } } /// A transport ACK is not proof the subscriber read the final group. -#[moq_clock::test] +#[kio::test] async fn close_tail() { let Setup { pair, track, reader, .. @@ -279,8 +279,8 @@ async fn close_tail() { group.write_frame(Timestamp::ZERO, b"last".as_slice()).unwrap(); group.finish().unwrap(); track.finish().unwrap(); - let close = moq_clock::sim::spawn(pair.client.close()); - moq_clock::sleep(Duration::from_millis(100)).await; + let close = kio::clock::sim::spawn(pair.client.close()); + kio::clock::sleep(Duration::from_millis(100)).await; assert!( !close.is_finished(), "close must wait for the subscriber, not the transport ACK" @@ -296,7 +296,7 @@ async fn close_tail() { } /// A lite07 peer that never acknowledges the track end cannot report a successful close. -#[moq_clock::test] +#[kio::test] async fn close_requires_subscriber_fin() { let Setup { pair, @@ -310,27 +310,27 @@ async fn close_requires_subscriber_fin() { group.write_frame(Timestamp::ZERO, b"last".as_slice()).unwrap(); group.finish().unwrap(); track.finish().unwrap(); - let started = moq_clock::now(); + let started = kio::clock::now(); assert!(matches!(pair.client.close().await, Err(Error::Timeout))); - assert_eq!(moq_clock::now() - started, Duration::from_secs(1)); + assert_eq!(kio::clock::now() - started, Duration::from_secs(1)); } /// Released drafts retain ACK-based close even when application delivery is delayed. -#[moq_clock::test] +#[kio::test] async fn older_lite_close_keeps_ack_drain() { for version in ["moq-lite-05", "moq-lite-06"] { peer_close_reads_buffered_tail(version).await; } } -#[moq_clock::test] +#[kio::test] async fn earlier_lite_peer_close_reads_buffered_tail() { for version in ["moq-lite-01", "moq-lite-02", "moq-lite-03", "moq-lite-04"] { peer_close_reads_buffered_tail(version).await; } } -#[moq_clock::test] +#[kio::test] async fn ietf_peer_close_reads_buffered_tail() { for version in ["moq-transport-18", "moq-transport-22"] { peer_close_reads_buffered_tail(version).await; @@ -355,7 +355,7 @@ async fn peer_close_reads_buffered_tail(version: &str) { /// Legacy session/control streams and the accept error race the buffered group. /// Holding the whole receiver ensures the close is visible on its first poll. -#[moq_clock::test] +#[kio::test] async fn peer_close_before_receiver_poll_keeps_buffered_tail() { for version in [ "moq-lite-01", @@ -382,7 +382,7 @@ async fn peer_close_before_receiver_poll_keeps_buffered_tail() { } /// A locally unsupported feature uses only the negotiated session registry. -#[moq_clock::test] +#[kio::test] async fn unsupported_abort_uses_the_negotiated_session_registry() { for protocol in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-18", "moq-transport-22"] { let version: Version = protocol.parse().unwrap(); @@ -395,7 +395,7 @@ async fn unsupported_abort_uses_the_negotiated_session_registry() { } /// A Lite-only close code arriving on IETF stays unknown instead of gaining Lite semantics. -#[moq_clock::test] +#[kio::test] async fn unsupported_close_is_decoded_by_the_negotiated_session_registry() { for protocol in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-18", "moq-transport-22"] { let version: Version = protocol.parse().unwrap(); @@ -413,7 +413,7 @@ async fn unsupported_close_is_decoded_by_the_negotiated_session_registry() { /// moq-lite's own session range (0x30-0x3f) is never sent as an unknown code on either /// wire, while a code outside it passes through. -#[moq_clock::test] +#[kio::test] async fn an_unknown_lite_range_abort_is_unspecified_on_every_wire() { for protocol in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-18", "moq-transport-22"] { for (unknown, expected) in [(0x31, 0x1), (0x20, 0x20)] { @@ -437,12 +437,12 @@ async fn ended(version: &str, close: impl FnOnce(&MockPair)) -> (Error, moq_net: .session(moq_net::Path::from_static("room")); let pair = connect_mock(options).await; close(&pair); - let err = moq_clock::timeout(TIMEOUT, pair.server.closed()) + let err = kio::clock::timeout(TIMEOUT, pair.server.closed()) .await .expect("the session closes"); drop(pair); // The drivers release the stats once the transport has closed under them. - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let presence = registry.snapshot().sessions()[0].1; assert_eq!(presence.sessions_ended, 1, "{version}: the session ended"); (err, presence.sessions_failed) @@ -450,7 +450,7 @@ async fn ended(version: &str, close: impl FnOnce(&MockPair)) -> (Error, moq_net: /// A clean close is `Error::Cancel` and no failure, whichever side closed. Anything else /// counts by its kind, without the caller recording it. -#[moq_clock::test] +#[kio::test] async fn a_session_records_how_it_ended() { use moq_net::stats::Failures; for version in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { diff --git a/rs/moq-net/tests/integration/session_panic.rs b/rs/moq-net/tests/integration/session_panic.rs index 3d44c69693a..dd493c7d401 100644 --- a/rs/moq-net/tests/integration/session_panic.rs +++ b/rs/moq-net/tests/integration/session_panic.rs @@ -31,7 +31,7 @@ struct Publisher { client: Session, server: Session, server_transport: MockSession, - server_driver: moq_clock::sim::JoinHandle, + server_driver: kio::clock::sim::JoinHandle, /// The client's origin, which it publishes from. origin: origin::Producer, _broadcast: moq_net::origin::Publication, @@ -59,7 +59,7 @@ async fn publish(version: Version, relay: &origin::Producer, hop: u64, name: &st }; let server = async { let (session, mut driver) = server.accept(now(), server_transport.clone()).await.unwrap(); - let driver = moq_clock::sim::spawn(moq_clock::drive(move |now, waiter| { + let driver = kio::clock::sim::spawn(kio::clock::drive(move |now, waiter| { moq_net::time::Driver::poll(&mut driver, now, waiter) })); (session, driver) @@ -91,12 +91,12 @@ async fn until(announced: &mut announce::Consumer, path: &str, active: bool) { } } }; - moq_clock::timeout(TIMEOUT, wait) + kio::clock::timeout(TIMEOUT, wait) .await .unwrap_or_else(|_| panic!("{path} never became active={active}")); } -#[moq_clock::test] +#[kio::test] async fn a_panicking_session_leaves_the_others_serving() { for version in ["moq-lite-07-wip", "moq-transport-22"] { let version: Version = version.parse().unwrap(); @@ -110,7 +110,7 @@ async fn a_panicking_session_leaves_the_others_serving() { broken.server_transport.panic_on_stats(); let _ = broken.server.stats(); - let ended = moq_clock::timeout(TIMEOUT, broken.server_driver) + let ended = kio::clock::timeout(TIMEOUT, broken.server_driver) .await .expect("the driver never sampled the stats"); assert!( @@ -119,7 +119,7 @@ async fn a_panicking_session_leaves_the_others_serving() { ); until(&mut announced, "broken", false).await; - moq_clock::timeout(TIMEOUT, broken.server.closed()) + kio::clock::timeout(TIMEOUT, broken.server.closed()) .await .unwrap_or_else(|_| panic!("{version}: the panicked session never closed")); diff --git a/rs/moq-net/tests/integration/settled_end_survives_abort.rs b/rs/moq-net/tests/integration/settled_end_survives_abort.rs index 090336763ea..d36b171c33e 100644 --- a/rs/moq-net/tests/integration/settled_end_survives_abort.rs +++ b/rs/moq-net/tests/integration/settled_end_survives_abort.rs @@ -77,19 +77,19 @@ fn assert_whole((got, err): (Vec, Option), what: &str) { } /// The groups a settled track holds outlive an abort: a late reader gets all of them. -#[moq_clock::test] +#[kio::test] async fn an_abort_after_the_end_settled_keeps_the_groups_for_a_late_reader() { assert_whole(round(true, false).await, "arrival order, aborted after the end settled"); } /// The same in sequence order: the ordered cursor ends clean too, not with the abort. -#[moq_clock::test] +#[kio::test] async fn an_abort_after_the_end_settled_keeps_the_groups_for_a_late_ordered_reader() { assert_whole(round(true, true).await, "sequence order, aborted after the end settled"); } /// Control: with no abort the same late reader gets every group, then the clean end. -#[moq_clock::test] +#[kio::test] async fn a_settled_track_delivers_every_group_to_a_late_reader() { assert_whole(round(false, false).await, "arrival order, no abort"); assert_whole(round(false, true).await, "sequence order, no abort"); diff --git a/rs/moq-net/tests/integration/setup_negotiation.rs b/rs/moq-net/tests/integration/setup_negotiation.rs index 454d93ad169..acb1a5e1a64 100644 --- a/rs/moq-net/tests/integration/setup_negotiation.rs +++ b/rs/moq-net/tests/integration/setup_negotiation.rs @@ -45,7 +45,7 @@ async fn dial( ) } -#[moq_clock::test] +#[kio::test] async fn every_lite_version_negotiates_in_setup() { for name in [ "moq-lite-07-wip", @@ -70,7 +70,7 @@ async fn every_lite_version_negotiates_in_setup() { } } -#[moq_clock::test] +#[kio::test] async fn disjoint_versions_are_refused() { let (upstream, downstream) = (origin(), origin()); let (client, server) = dial( diff --git a/rs/moq-net/tests/integration/source_errors.rs b/rs/moq-net/tests/integration/source_errors.rs index 6e2f5a6c93c..8631b72e1ad 100644 --- a/rs/moq-net/tests/integration/source_errors.rs +++ b/rs/moq-net/tests/integration/source_errors.rs @@ -40,11 +40,11 @@ struct Relayed { async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Consumer { let consumer = origin.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves") @@ -105,20 +105,20 @@ fn assert_ended(result: Result<(), Error>, expected: StreamError, version: &str) /// #5347: a TRACK request is in flight to an upstream publisher session that dies before /// answering. The relay's request, and the far end's through it, find the path has no /// route; neither is an internal error. -#[moq_clock::test] +#[kio::test] async fn request_in_flight_to_a_dead_upstream_is_unroutable() { for version in VERSIONS { let setup = relayed(version).await; let _track = setup.broadcast.create_track("catalog", timed()).unwrap(); // The relay's requests never reach the publisher. setup.upstream.client_transport.hold_bidis(); - let relayed = moq_clock::sim::spawn(read_to_end(setup.relayed.clone(), "catalog")); - let remote = moq_clock::sim::spawn(read_to_end(setup.remote.clone(), "catalog")); - moq_clock::sleep(Duration::from_secs(1)).await; + let relayed = kio::clock::sim::spawn(read_to_end(setup.relayed.clone(), "catalog")); + let remote = kio::clock::sim::spawn(read_to_end(setup.remote.clone(), "catalog")); + kio::clock::sleep(Duration::from_secs(1)).await; assert!(!relayed.is_finished(), "{version}: answered through a held stream"); setup.upstream.server.abort(Error::Timeout); for reader in [relayed, remote] { - let result = moq_clock::timeout(TIMEOUT, reader) + let result = kio::clock::timeout(TIMEOUT, reader) .await .expect("request hung") .unwrap(); @@ -129,7 +129,7 @@ async fn request_in_flight_to_a_dead_upstream_is_unroutable() { /// A subscription already delivering when the upstream session dies, with nothing to /// replace it: the far end learns the path is gone, not that its own session closed. -#[moq_clock::test] +#[kio::test] async fn track_in_flight_through_a_dead_upstream_is_unroutable() { for version in VERSIONS { let setup = relayed(version).await; @@ -138,13 +138,13 @@ async fn track_in_flight_through_a_dead_upstream_is_unroutable() { let mut group = track.append_group().unwrap(); group.write_frame(Timestamp::ZERO, b"head".as_ref()).unwrap(); group.finish().unwrap(); - moq_clock::timeout(TIMEOUT, sub.recv_group()) + kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() .unwrap(); setup.upstream.server.abort(Error::Timeout); - let result = moq_clock::timeout(TIMEOUT, async { + let result = kio::clock::timeout(TIMEOUT, async { while sub.recv_group().await?.is_some() {} Ok(()) }) @@ -157,7 +157,7 @@ async fn track_in_flight_through_a_dead_upstream_is_unroutable() { /// #4349: the broadcast is withdrawn under an active subscription, then its track fails /// with a specific error. The withdrawal does not disturb the subscription, which ends /// with that error. -#[moq_clock::test] +#[kio::test] async fn withdrawn_broadcast_keeps_the_source_error() { for version in VERSIONS { let setup = relayed(version).await; @@ -166,15 +166,15 @@ async fn withdrawn_broadcast_keeps_the_source_error() { let mut group = track.append_group().unwrap(); group.write_frame(Timestamp::ZERO, b"head".as_ref()).unwrap(); group.finish().unwrap(); - moq_clock::timeout(TIMEOUT, sub.recv_group()) + kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() .unwrap(); setup.broadcast.unannounce(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; track.abort(Error::App(7)).unwrap(); - let result = moq_clock::timeout(TIMEOUT, async { + let result = kio::clock::timeout(TIMEOUT, async { while sub.recv_group().await?.is_some() {} Ok(()) }) @@ -185,15 +185,15 @@ async fn withdrawn_broadcast_keeps_the_source_error() { } /// A subscribe on a broadcast whose route was withdrawn is refused as unroutable. -#[moq_clock::test] +#[kio::test] async fn subscribe_after_withdrawal_is_unroutable() { for version in VERSIONS { let setup = relayed(version).await; let _track = setup.broadcast.create_track("video", timed()).unwrap(); setup.broadcast.unannounce(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; for broadcast in [setup.relayed.clone(), setup.remote.clone()] { - let result = moq_clock::timeout(TIMEOUT, read_to_end(broadcast, "video")) + let result = kio::clock::timeout(TIMEOUT, read_to_end(broadcast, "video")) .await .expect("subscribe hung"); assert_ended(result, StreamError::Unroutable, version); diff --git a/rs/moq-net/tests/integration/stream_credit.rs b/rs/moq-net/tests/integration/stream_credit.rs index af927a68852..ccadfb0b043 100644 --- a/rs/moq-net/tests/integration/stream_credit.rs +++ b/rs/moq-net/tests/integration/stream_credit.rs @@ -14,7 +14,7 @@ fn origin(hop: u64) -> origin::Producer { origin } -#[moq_clock::test] +#[kio::test] async fn one_stream_credit_serves_every_backlogged_group() { for version in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { let version: Version = version.parse().unwrap(); @@ -53,7 +53,7 @@ async fn one_stream_credit_serves_every_backlogged_group() { // The transport, not the publisher, picks which parked open gets the next grant. let mut received = Vec::new(); while received.len() < 4 { - let group = moq_clock::timeout(Duration::from_secs(5), subscriber.recv_group()) + let group = kio::clock::timeout(Duration::from_secs(5), subscriber.recv_group()) .await .unwrap_or_else(|_| panic!("{version}: only {received:?} arrived")) .unwrap() diff --git a/rs/moq-net/tests/integration/subscribe_priority.rs b/rs/moq-net/tests/integration/subscribe_priority.rs index a8b4bc9b3b0..2623f1b9aed 100644 --- a/rs/moq-net/tests/integration/subscribe_priority.rs +++ b/rs/moq-net/tests/integration/subscribe_priority.rs @@ -27,7 +27,7 @@ fn produce_origin(hop: u64) -> origin::Producer { /// Wait until the subscription `track` serves asks for `want`. async fn priority(track: &moq_net::track::Producer, want: i8) -> Result<(), String> { let mut track = track.clone(); - let reached = moq_clock::timeout(TIMEOUT, async { + let reached = kio::clock::timeout(TIMEOUT, async { while track .subscription() .is_none_or(|subscription| subscription.priority != want) @@ -65,18 +65,18 @@ async fn follows(version: Version, relay: bool) -> Result<(), String> { } let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); let subscribe = |priority: i8| { let track = remote.track("video").unwrap(); async move { - moq_clock::timeout( + kio::clock::timeout( TIMEOUT, track.subscribe(Subscription::default().with_priority(priority)), ) @@ -99,7 +99,7 @@ async fn follows(version: Version, relay: bool) -> Result<(), String> { Ok(()) } -#[moq_clock::test] +#[kio::test] async fn upstream_priority_follows_the_subscribers() { let mut failures = Vec::new(); for version in VERSIONS { diff --git a/rs/moq-net/tests/integration/subscribe_ranges.rs b/rs/moq-net/tests/integration/subscribe_ranges.rs index b5c50cfe806..887f570a9f5 100644 --- a/rs/moq-net/tests/integration/subscribe_ranges.rs +++ b/rs/moq-net/tests/integration/subscribe_ranges.rs @@ -32,7 +32,7 @@ fn write_group(track: &moq_net::track::Producer, sequence: u64) { /// The next group's sequence, or `None` once the track ends or nothing arrives in time. async fn next(sub: &mut moq_net::track::Subscriber) -> Option { - let group = moq_clock::timeout(TIMEOUT, sub.recv_group()).await.ok()?; + let group = kio::clock::timeout(TIMEOUT, sub.recv_group()).await.ok()?; group.expect("recv_group").map(|group| group.sequence) } @@ -91,11 +91,11 @@ async fn ahead_then_live(version: Option<&str>, relay: bool) -> (Vec, Vec, relay: bool) -> (Vec, Vec, relay: bool) -> (Vec, Vec Rang options.client_subscribe = Some(subscriber.clone()); sessions.push(connect_mock(options).await); let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("ranges")) + kio::clock::timeout(TIMEOUT, consumer.routed("ranges")) .await .unwrap() .unwrap(); @@ -263,7 +263,7 @@ async fn range_fixture_history(version: &str, relay: bool, history: u64) -> Rang } /// Mixed fixed and live ranges retain history for both live and finished cached sources. -#[moq_clock::test] +#[kio::test] async fn initial_mixed_ranges_keep_the_absolute_history() { for version in ["moq-transport-18", "moq-transport-22"] { for relay in [false, true] { @@ -298,7 +298,7 @@ async fn initial_mixed_ranges_keep_the_absolute_history() { /// A widening fill crosses cached groups without replacing them or losing the groups /// after them. A later narrowing reaches the publisher and can be widened again. -#[moq_clock::test] +#[kio::test] async fn draft22_updates_both_bounds_across_cached_groups() { for relay in [false, true] { let mut fixture = range_fixture(relay).await; @@ -319,7 +319,7 @@ async fn draft22_updates_both_bounds_across_cached_groups() { got.sort_unstable(); assert_eq!(got, [0, 1, 4, 5], "relay={relay}"); reader.update(initial.clone().with_range(4..5)).unwrap(); - moq_clock::timeout( + kio::clock::timeout( TIMEOUT, kio::wait(|waiter| { assert!( @@ -356,7 +356,7 @@ async fn draft22_updates_both_bounds_across_cached_groups() { } /// A warm copy resolves a time end before updating upstream; an unknown end is refused. -#[moq_clock::test] +#[kio::test] async fn draft22_resolves_cached_time_ends() { for relay in [false, true] { let mut fixture = range_fixture(relay).await; @@ -383,7 +383,7 @@ async fn draft22_resolves_cached_time_ends() { let mut got = vec![next(&mut reader).await.unwrap(), next(&mut reader).await.unwrap()]; got.sort_unstable(); assert_eq!(got, [0, 1], "relay={relay}"); - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { loop { if fixture .track @@ -411,7 +411,7 @@ async fn draft22_resolves_cached_time_ends() { /// A quiet current group does not hold its filled head while a later range update /// asks for older history; the subgroup header transfers ownership before any tail byte. -#[moq_clock::test] +#[kio::test] async fn draft22_can_widen_while_the_current_group_is_quiet() { for relay in [false, true] { let fixture = range_fixture(relay).await; @@ -423,14 +423,14 @@ async fn draft22_can_widen_while_the_current_group_is_quiet() { .write_frame(Timestamp::from_millis(6000).unwrap(), b"head".as_slice()) .unwrap(); let mut live = subscribe(&fixture.remote, Subscription::default().with_ranges([Range::live()])).await; - let mut current = moq_clock::timeout(TIMEOUT, live.recv_group()) + let mut current = kio::clock::timeout(TIMEOUT, live.recv_group()) .await .unwrap() .unwrap() .unwrap(); assert_eq!(current.sequence, 6); assert_eq!( - moq_clock::timeout(TIMEOUT, current.read_frame()) + kio::clock::timeout(TIMEOUT, current.read_frame()) .await .unwrap() .unwrap() @@ -448,7 +448,7 @@ async fn draft22_can_widen_while_the_current_group_is_quiet() { assert_eq!(got, [0, 1], "relay={relay}"); quiet.finish().unwrap(); assert!( - moq_clock::timeout(TIMEOUT, current.read_frame()) + kio::clock::timeout(TIMEOUT, current.read_frame()) .await .unwrap() .unwrap() @@ -459,7 +459,7 @@ async fn draft22_can_widen_while_the_current_group_is_quiet() { /// Draft-18 peers already join live and fetch the head. Their filters can narrow that /// established subscription and widen it over groups published meanwhile. -#[moq_clock::test] +#[kio::test] async fn draft18_updates_narrow_then_widen() { let version = "moq-transport-18"; for relay in [false, true] { @@ -473,7 +473,7 @@ async fn draft18_updates_narrow_then_widen() { seen.sort_unstable(); assert_eq!(seen, [0, 1, 2, 3, 4, 5], "{version} relay={relay}"); reader.update(initial.clone().with_range(4..5)).unwrap(); - moq_clock::timeout( + kio::clock::timeout( TIMEOUT, kio::wait(|waiter| { assert!(reader.poll_recv_group(waiter).is_pending()); @@ -506,20 +506,20 @@ async fn draft18_updates_narrow_then_widen() { reader.update(initial).unwrap(); let mut seen = Vec::new(); for _ in 0..2 { - let mut group = moq_clock::timeout(TIMEOUT, reader.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, reader.recv_group()) .await .unwrap_or_else(|_| panic!("{version} relay={relay}: widening lost history; got {seen:?}")) .unwrap() .unwrap(); seen.push(group.sequence); - let frame = moq_clock::timeout(TIMEOUT, group.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .unwrap() .unwrap() .unwrap(); assert_eq!(frame.payload, group.sequence.to_be_bytes().as_slice()); assert!( - moq_clock::timeout(TIMEOUT, group.read_frame()) + kio::clock::timeout(TIMEOUT, group.read_frame()) .await .unwrap() .unwrap() @@ -533,7 +533,7 @@ async fn draft18_updates_narrow_then_widen() { /// Empty ranges retire only demand no other reader holds. A later widening reuses /// the copy and joins the new live group, without disturbing a sibling reader. -#[moq_clock::test] +#[kio::test] async fn empty_ranges_retire_the_wire_and_can_widen_again() { for version in ["moq-transport-18", "moq-transport-22"] { for relay in [false, true] { @@ -558,7 +558,7 @@ async fn empty_ranges_retire_the_wire_and_can_widen_again() { assert_eq!(next(&mut reader).await, Some(6)); drop(sibling); reader.update(live.clone().with_ranges([])).unwrap(); - moq_clock::timeout( + kio::clock::timeout( TIMEOUT, kio::wait(|waiter| { assert!(reader.poll_recv_group(waiter).is_pending()); @@ -590,7 +590,7 @@ async fn empty_ranges_retire_the_wire_and_can_widen_again() { /// A fill that widens an initially empty copy must finish every completed group, /// including the snapshot head, before the publisher produces another group. -#[moq_clock::test] +#[kio::test] async fn draft22_cold_widening_finishes_every_filled_group() { for relay in [false, true] { let mut fixture = range_fixture_history("moq-transport-22", relay, 0).await; @@ -599,7 +599,7 @@ async fn draft22_cold_widening_finishes_every_filled_group() { for start in [0, 2, 4] { let future = start + 2; reader.update(initial.clone().with_range(future..)).unwrap(); - moq_clock::timeout( + kio::clock::timeout( TIMEOUT, kio::wait(|waiter| { assert!(reader.poll_recv_group(waiter).is_pending()); @@ -629,7 +629,7 @@ async fn draft22_cold_widening_finishes_every_filled_group() { reader.update(initial.clone().with_range(start..)).unwrap(); let mut sequences = Vec::new(); for _ in start..future { - let mut group = moq_clock::timeout(TIMEOUT, reader.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, reader.recv_group()) .await .unwrap_or_else(|_| { panic!("relay={relay}: a filled group from {start} did not arrive; got {sequences:?}") @@ -637,14 +637,14 @@ async fn draft22_cold_widening_finishes_every_filled_group() { .unwrap() .unwrap(); sequences.push(group.sequence); - let frame = moq_clock::timeout(TIMEOUT, group.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .unwrap() .unwrap() .unwrap(); assert_eq!(frame.payload, group.sequence.to_be_bytes().as_slice()); assert!( - moq_clock::timeout(TIMEOUT, group.read_frame()) + kio::clock::timeout(TIMEOUT, group.read_frame()) .await .unwrap_or_else(|_| panic!("relay={relay}: group {} never finished", group.sequence)) .unwrap() @@ -658,7 +658,7 @@ async fn draft22_cold_widening_finishes_every_filled_group() { } /// A pending refusal is local to the new reader even before it is awaited. -#[moq_clock::test] +#[kio::test] async fn unresolved_time_reader_never_changes_sibling_demand() { for version in ["moq-transport-18", "moq-transport-22"] { for relay in [false, true] { @@ -666,7 +666,7 @@ async fn unresolved_time_reader_never_changes_sibling_demand() { let mut healthy = subscribe(&fixture.remote, Subscription::default()).await; assert_eq!(next(&mut healthy).await, Some(5)); healthy.update(Subscription::default().with_range(4..8)).unwrap(); - moq_clock::timeout( + kio::clock::timeout( TIMEOUT, kio::wait(|waiter| { assert!(healthy.poll_recv_group(waiter).is_pending()); @@ -711,7 +711,7 @@ async fn unresolved_time_reader_never_changes_sibling_demand() { ) .unwrap(); group.finish().unwrap(); - let mut got = moq_clock::timeout(TIMEOUT, healthy.recv_group()) + let mut got = kio::clock::timeout(TIMEOUT, healthy.recv_group()) .await .unwrap() .unwrap_or_else(|err| panic!("{version} relay={relay}: pending refusal aborted sibling: {err:?}")) @@ -732,7 +732,7 @@ async fn unresolved_time_reader_never_changes_sibling_demand() { /// track does not end, the same range reads again from the cache, and a wider one /// subscribes again for the rest, past a group that never existed. Older versions park /// instead, since their subscriber reads a FIN as the track's end. -#[moq_clock::test] +#[kio::test] async fn a_covered_bounded_subscription_ends_on_lite07() { for version in LITE { let publisher = produce_origin(1); @@ -751,11 +751,11 @@ async fn a_covered_bounded_subscription_ends_on_lite07() { options.client_subscribe = Some(subscriber.clone()); let session = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -770,7 +770,7 @@ async fn a_covered_bounded_subscription_ends_on_lite07() { assert_eq!(next(&mut reader).await, Some(1), "{version}"); assert_eq!(next(&mut reader).await, Some(2), "{version}"); - let released = moq_clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())).await; + let released = kio::clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())).await; if *version != "moq-lite-07-wip" { assert!(released.is_err(), "{version}: the publisher parks"); drop((reader, track, session, subscriber, broadcast, publisher)); @@ -778,7 +778,7 @@ async fn a_covered_bounded_subscription_ends_on_lite07() { } released.expect("the covered subscription ends").unwrap(); assert!( - moq_clock::timeout(TIMEOUT, reader.finished()).await.is_err(), + kio::clock::timeout(TIMEOUT, reader.finished()).await.is_err(), "the track goes on" ); @@ -795,7 +795,7 @@ async fn a_covered_bounded_subscription_ends_on_lite07() { assert_eq!(got, [1, 2, 4, 5]); // Group 3 may still arrive on a live track, so it is dropped once the feed gives up // on it, past the arrivals grace. - moq_clock::timeout(Duration::from_secs(60), crate::support::unwanted(track.demand())) + kio::clock::timeout(Duration::from_secs(60), crate::support::unwanted(track.demand())) .await .expect("the wider subscription ends past the missing group") .unwrap(); diff --git a/rs/moq-net/tests/integration/subscribe_tracks.rs b/rs/moq-net/tests/integration/subscribe_tracks.rs index 34bf4203ff2..3b7df2eafea 100644 --- a/rs/moq-net/tests/integration/subscribe_tracks.rs +++ b/rs/moq-net/tests/integration/subscribe_tracks.rs @@ -61,17 +61,17 @@ async fn setup(version: Version) -> Setup { let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("room")) + kio::clock::timeout(TIMEOUT, consumer.routed("room")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); let (tx, frames) = futures::channel::mpsc::unbounded(); - moq_clock::sim::spawn(async move { + kio::clock::sim::spawn(async move { let mut sub = remote.track("video").unwrap().subscribe(None).await.expect("subscribe"); while let Ok(Some(mut group)) = sub.recv_group().await { while let Ok(Some(frame)) = group.read_frame().await { @@ -80,7 +80,7 @@ async fn setup(version: Version) -> Setup { } }); - moq_clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); @@ -97,7 +97,7 @@ async fn deliver(setup: &mut Setup, payload: &'static [u8]) { let mut group = setup.track.append_group().unwrap(); group.write_frame(Timestamp::ZERO, payload).unwrap(); group.finish().unwrap(); - let got = moq_clock::timeout(TIMEOUT, setup.frames.next()) + let got = kio::clock::timeout(TIMEOUT, setup.frames.next()) .await .expect("frame timed out") .expect("the subscription ended"); @@ -117,7 +117,7 @@ async fn subscribe_tracks(pair: &MockPair, len: usize) -> Vec { let mut reply = Vec::new(); while reply.len() < len - && let Some(chunk) = moq_clock::timeout(TIMEOUT, recv.read_chunk(len - reply.len())) + && let Some(chunk) = kio::clock::timeout(TIMEOUT, recv.read_chunk(len - reply.len())) .await .expect("reply timed out") .expect("read") @@ -130,7 +130,7 @@ async fn subscribe_tracks(pair: &MockPair, len: usize) -> Vec { /// An omitted FORWARD asks for every track's objects, which we never push unasked: on /// draft-22 each track is answered with PUBLISH_SKIPPED, and the subscription already on /// the session keeps going. -#[moq_clock::test] +#[kio::test] async fn subscribe_tracks_skips_every_track() { let version = "moq-transport-22"; let mut setup = setup(version.parse().unwrap()).await; @@ -151,7 +151,7 @@ async fn subscribe_tracks_skips_every_track() { /// Draft-18 has no PUBLISH_SKIPPED, so a listing that must forward is refused on its own /// stream with NOT_SUPPORTED, and the session keeps delivering. -#[moq_clock::test] +#[kio::test] async fn subscribe_tracks_needs_forward_0_on_draft_18() { let mut setup = setup("moq-transport-18".parse().unwrap()).await; deliver(&mut setup, b"before").await; diff --git a/rs/moq-net/tests/integration/subscriber_max_age.rs b/rs/moq-net/tests/integration/subscriber_max_age.rs index c809cf9d44c..c9a36cd9daa 100644 --- a/rs/moq-net/tests/integration/subscriber_max_age.rs +++ b/rs/moq-net/tests/integration/subscriber_max_age.rs @@ -15,7 +15,7 @@ fn origin(hop: u64) -> origin::Producer { } async fn budget(track: &mut track::Producer, millis: u64, version: Version) { - moq_clock::timeout(Duration::from_secs(5), async { + kio::clock::timeout(Duration::from_secs(5), async { loop { if track .subscription() @@ -30,7 +30,7 @@ async fn budget(track: &mut track::Producer, millis: u64, version: Version) { .unwrap_or_else(|_| panic!("{version}: wanted {millis}ms, publisher has {:?}", track.subscription())); } -#[moq_clock::test] +#[kio::test] async fn relay_forwards_the_most_tolerant_subscriber_max_age() { for draft in [18, 22] { let version: Version = format!("moq-transport-{draft}").parse().unwrap(); @@ -66,7 +66,7 @@ async fn relay_forwards_the_most_tolerant_subscriber_max_age() { drop(tolerant); budget(&mut source, 10, version).await; // A quiet catalog survives far longer than the budget because it has no successor. - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!(snapshot.sequence, 0, "{version}"); assert_eq!( snapshot.read_frame().await.unwrap().unwrap().payload, diff --git a/rs/moq-net/tests/integration/subscription_end_integrity.rs b/rs/moq-net/tests/integration/subscription_end_integrity.rs index 7cf37edc556..e0624a9e61a 100644 --- a/rs/moq-net/tests/integration/subscription_end_integrity.rs +++ b/rs/moq-net/tests/integration/subscription_end_integrity.rs @@ -44,7 +44,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { /// Let the drivers run until nothing is runnable: under paused time an idle runtime /// auto-advances the clock, so this returns once every queued write has been sent. async fn settle() { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } fn expected() -> Vec> { @@ -67,11 +67,11 @@ async fn round(drop_session: bool) -> (Vec>, Option) { let MockPair { client, server, .. } = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -82,7 +82,7 @@ async fn round(drop_session: bool) -> (Vec>, Option) { let (drained_tx, drained_rx) = futures::channel::oneshot::channel(); let (go_tx, go_rx) = futures::channel::oneshot::channel::<()>(); - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let subscription = moq_net::track::Subscription::default().with_range(0..); let mut sub = remote .track("video") @@ -113,7 +113,7 @@ async fn round(drop_session: bool) -> (Vec>, Option) { } }); - moq_clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::wanted(track.demand())) .await .expect("no subscriber appeared") .unwrap(); @@ -123,7 +123,7 @@ async fn round(drop_session: bool) -> (Vec>, Option) { head.write_frame(Timestamp::ZERO, payload).unwrap(); } head.finish().unwrap(); - moq_clock::timeout(TIMEOUT, drained_rx) + kio::clock::timeout(TIMEOUT, drained_rx) .await .expect("the head group never arrived") .expect("reader gone"); @@ -152,7 +152,7 @@ async fn round(drop_session: bool) -> (Vec>, Option) { // merely slower than the network. settle().await; let _ = go_tx.send(()); - let result = moq_clock::timeout(TIMEOUT, reader) + let result = kio::clock::timeout(TIMEOUT, reader) .await .expect("the subscription never ended") .expect("reader panicked"); @@ -162,7 +162,7 @@ async fn round(drop_session: bool) -> (Vec>, Option) { /// The session closes with the final group in flight: the subscription ends with an /// error, or delivers every frame. -#[moq_clock::test] +#[kio::test] async fn a_subscription_cut_by_the_session_close_does_not_end_clean() { let (got, err) = round(true).await; assert!( @@ -178,7 +178,7 @@ async fn a_subscription_cut_by_the_session_close_does_not_end_clean() { } /// With the session kept alive the same track arrives whole and ends `Ok(None)`. -#[moq_clock::test] +#[kio::test] async fn a_finished_track_ends_clean_while_its_session_lives() { let (got, err) = round(false).await; assert!( @@ -223,7 +223,7 @@ async fn killed(version: &str, local: bool) -> (Option, Option (Option, Option moq_net::time::Instant { - moq_clock::now() + kio::clock::now() } -/// Run a protocol driver in the background: on `moq-clock`'s sim in tests, on tokio in +/// Run a protocol driver in the background: on `kio::clock`'s sim in tests, on tokio in /// the benches. pub fn spawn(mut driver: D) { - match moq_clock::sim::is_running() { - true => drop(moq_clock::sim::spawn(moq_clock::drive(move |now, waiter| { + match kio::clock::sim::is_running() { + true => drop(kio::clock::sim::spawn(kio::clock::drive(move |now, waiter| { moq_net::time::Driver::poll(&mut driver, now, waiter) }))), false => drop(tokio::spawn(moq_net::time::run(driver))), diff --git a/rs/moq-net/tests/integration/support/mock.rs b/rs/moq-net/tests/integration/support/mock.rs index 0b3265cdcc7..435d79a3b68 100644 --- a/rs/moq-net/tests/integration/support/mock.rs +++ b/rs/moq-net/tests/integration/support/mock.rs @@ -363,8 +363,8 @@ impl MockChunks { if self.landing != Some(arrival) { self.landing = Some(arrival); let waker = cx.waker().clone(); - drop(moq_clock::sim::spawn(async move { - moq_clock::sleep_until(arrival).await; + drop(kio::clock::sim::spawn(async move { + kio::clock::sleep_until(arrival).await; waker.wake(); })); } @@ -388,8 +388,8 @@ impl MockChunks { poll::RecvStream::stop(&mut inner, code); return; } - drop(moq_clock::sim::spawn(async move { - moq_clock::sleep(latency).await; + drop(kio::clock::sim::spawn(async move { + kio::clock::sleep(latency).await; poll::RecvStream::stop(&mut inner, code); })); } diff --git a/rs/moq-net/tests/integration/synced.rs b/rs/moq-net/tests/integration/synced.rs index e906897dd0b..03a7d5d5a84 100644 --- a/rs/moq-net/tests/integration/synced.rs +++ b/rs/moq-net/tests/integration/synced.rs @@ -25,7 +25,7 @@ fn produce_origin(hop: u64) -> origin::Producer { async fn read_until_synced(announced: &mut announce::Consumer) -> BTreeSet { let mut seen = BTreeSet::new(); while !announced.poll_synced(&moq_net::kio::Waiter::noop()).is_ready() { - let event = moq_clock::timeout(SETTLE, announced.next()) + let event = kio::clock::timeout(SETTLE, announced.next()) .await .expect("synced in time") .expect("the cursor stays open"); @@ -66,7 +66,7 @@ fn both() -> BTreeSet { } /// Every version that marks the boundary syncs with the whole initial set. -#[moq_clock::test] +#[kio::test] async fn an_exact_boundary_catches_up_with_the_initial_set() { for version in [ "moq-lite-05", @@ -80,7 +80,7 @@ async fn an_exact_boundary_catches_up_with_the_initial_set() { } /// Versions without a boundary still sync, so nothing waiting on it hangs. -#[moq_clock::test] +#[kio::test] async fn a_best_effort_boundary_still_catches_up() { for version in ["moq-lite-03", "moq-lite-04"] { synced(version).await; @@ -89,7 +89,7 @@ async fn a_best_effort_boundary_still_catches_up() { /// A second session into the same origin, as a reconnect makes, syncs too: the /// consumer waits on every current session. -#[moq_clock::test] +#[kio::test] async fn a_second_session_catches_up() { let publisher = produce_origin(1); let a = publisher.create_broadcast("a").unwrap(); @@ -111,13 +111,13 @@ async fn a_second_session_catches_up() { let second = connect().await; drop(first); - moq_clock::sleep(SETTLE).await; + kio::clock::sleep(SETTLE).await; read_until_synced(&mut announced).await; drop(second); } /// A cold relay's empty set is complete before an upstream joins it. -#[moq_clock::test] +#[kio::test] async fn a_cold_relay_syncs_then_forwards_upstream_routes_as_live() { let relay = produce_origin(2); let subscriber = produce_origin(3); diff --git a/rs/moq-net/tests/integration/track_abort_over_session.rs b/rs/moq-net/tests/integration/track_abort_over_session.rs index 388c8a995d4..77d5e470203 100644 --- a/rs/moq-net/tests/integration/track_abort_over_session.rs +++ b/rs/moq-net/tests/integration/track_abort_over_session.rs @@ -48,7 +48,7 @@ async fn after_abort(version: &str, hops: u32) { track.abort(moq_net::Error::Cancel).unwrap(); drop(open); assert!( - moq_clock::timeout(Duration::from_secs(2), group.read_frame()) + kio::clock::timeout(Duration::from_secs(2), group.read_frame()) .await .expect("group-only read hung") .is_err() @@ -57,7 +57,7 @@ async fn after_abort(version: &str, hops: u32) { macro_rules! abort_test { ($name:ident, $version:literal, $hops:literal) => { - #[moq_clock::test] + #[kio::test] async fn $name() { after_abort($version, $hops).await; } @@ -95,7 +95,7 @@ async fn recreate(finish: bool) { next.write_frame(Timestamp::from_millis(1).unwrap(), b"next".as_ref()) .unwrap(); drop(open); - let result = moq_clock::timeout(Duration::from_secs(2), async { + let result = kio::clock::timeout(Duration::from_secs(2), async { if finish { group.finished().await.map(|_| ()) } else { @@ -109,12 +109,12 @@ async fn recreate(finish: bool) { assert_eq!(next.sequence, 3); } -#[moq_clock::test] +#[kio::test] async fn recreated_track_skips_old_group() { recreate(false).await; } -#[moq_clock::test] +#[kio::test] async fn recreated_track_finishes_old_group() { recreate(true).await; } diff --git a/rs/moq-net/tests/integration/track_info_cancel.rs b/rs/moq-net/tests/integration/track_info_cancel.rs index bd0af6e56d3..8292edf376a 100644 --- a/rs/moq-net/tests/integration/track_info_cancel.rs +++ b/rs/moq-net/tests/integration/track_info_cancel.rs @@ -33,7 +33,7 @@ async fn abandoned_request_reaches_the_publisher(version: &str, relays: u64) { let broadcast = nodes[0].create_broadcast("room").unwrap(); let mut dynamic = broadcast.requests(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let consumer = nodes[relays as usize] .consume() @@ -48,20 +48,20 @@ async fn abandoned_request_reaches_the_publisher(version: &str, relays: u64) { // The publisher never answers; the reader gives up. drop(waiting); - moq_clock::timeout(Duration::from_secs(5), crate::support::unwanted(request.demand())) + kio::clock::timeout(Duration::from_secs(5), crate::support::unwanted(request.demand())) .await .unwrap_or_else(|_| panic!("{version:?} over {relays} relays: the publisher's request is still wanted")) .expect("the pending request is still open"); } -#[moq_clock::test] +#[kio::test] async fn abandoned_request_reaches_the_publisher_lite05() { for relays in [1, 2] { abandoned_request_reaches_the_publisher("moq-lite-05", relays).await; } } -#[moq_clock::test] +#[kio::test] async fn abandoned_request_reaches_the_publisher_lite06() { for relays in [1, 2] { abandoned_request_reaches_the_publisher("moq-lite-06", relays).await; @@ -103,7 +103,7 @@ async fn withdrawn_broadcast_releases_track_info(version: &str, answered: bool, }; let finished = pair.client_transport.finished_streams(); broadcast.close(); - moq_clock::timeout(Duration::from_secs(5), crate::support::unwanted(demand)) + kio::clock::timeout(Duration::from_secs(5), crate::support::unwanted(demand)) .await .unwrap_or_else(|_| panic!("{version}, answered={answered}, explicit={explicit}: TRACK outlived its broadcast")) .expect("the publisher still owns its track"); @@ -119,7 +119,7 @@ async fn withdrawn_broadcast_releases_track_info(version: &str, answered: bool, drop(query); } -#[moq_clock::test] +#[kio::test] async fn a_pending_track_info_ends_with_its_broadcast() { for version in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip"] { for explicit in [false, true] { @@ -128,7 +128,7 @@ async fn a_pending_track_info_ends_with_its_broadcast() { } } -#[moq_clock::test] +#[kio::test] async fn an_answered_track_info_ends_with_its_broadcast() { for version in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip"] { for explicit in [false, true] { diff --git a/rs/moq-net/tests/integration/track_stream_demand.rs b/rs/moq-net/tests/integration/track_stream_demand.rs index c132853c31e..f58fdf7d056 100644 --- a/rs/moq-net/tests/integration/track_stream_demand.rs +++ b/rs/moq-net/tests/integration/track_stream_demand.rs @@ -50,7 +50,7 @@ macro_rules! record_track { let edges = Rc::new(RefCell::new(Vec::new())); let log = edges.clone(); let mut demand = $demand; - drop(moq_clock::sim::spawn(async move { + drop(kio::clock::sim::spawn(async move { let mut was = false; while let Ok(wanted) = demand.wanted_changed().await { if wanted.is_some() != was { @@ -88,13 +88,13 @@ async fn one_used_edge(version: &str, relays: usize, reorder: bool) { let requests = Rc::new(RefCell::new(Vec::new())); let track_edges = Rc::new(RefCell::new(None)); let served = (requests.clone(), track_edges.clone()); - let publisher = moq_clock::sim::spawn(async move { + let publisher = kio::clock::sim::spawn(async move { while let Ok(request) = dynamic.requested_track().await { served .1 .borrow_mut() .get_or_insert_with(|| record_track!(request.demand())); - moq_clock::sleep(STARTUP).await; + kio::clock::sleep(STARTUP).await; let track = request.accept(timed()); let mut group = track.append_group().unwrap(); group.write_frame(Timestamp::ZERO, b"key".as_ref()).unwrap(); @@ -103,7 +103,7 @@ async fn one_used_edge(version: &str, relays: usize, reorder: bool) { }); let consumer = nodes.last().unwrap().consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("room")) + kio::clock::timeout(TIMEOUT, consumer.routed("room")) .await .unwrap_or_else(|_| panic!("{label}: never announced")) .unwrap(); @@ -112,19 +112,19 @@ async fn one_used_edge(version: &str, relays: usize, reorder: bool) { let subscribing = remote.track("video").unwrap().subscribe(None); if reorder { // The TRACK stream opens at once; the SUBSCRIBE only once TRACK_INFO is back. - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; reader.hold_bidis(); } - let mut subscriber = moq_clock::timeout(TIMEOUT, subscribing) + let mut subscriber = kio::clock::timeout(TIMEOUT, subscribing) .await .unwrap_or_else(|_| panic!("{label}: subscribe stalled")) .unwrap_or_else(|err| panic!("{label}: subscribe failed: {err}")); if reorder { - moq_clock::sleep(LATENCY * 20).await; + kio::clock::sleep(LATENCY * 20).await; reader.release_bidis(); } - let mut received = moq_clock::timeout(TIMEOUT, subscriber.recv_group()) + let mut received = kio::clock::timeout(TIMEOUT, subscriber.recv_group()) .await .unwrap_or_else(|_| panic!("{label}: no group arrived")) .unwrap() @@ -132,7 +132,7 @@ async fn one_used_edge(version: &str, relays: usize, reorder: bool) { received.read_frame().await.unwrap().expect("the group has a frame"); // Stay subscribed while every hop settles. - moq_clock::sleep(Duration::from_secs(2)).await; + kio::clock::sleep(Duration::from_secs(2)).await; assert_eq!(requests.borrow().len(), 1, "{label}: asked for the track again"); let track_edges = track_edges.borrow().clone().expect("the track was requested"); assert_eq!(*track_edges.borrow(), [true], "{label}: track demand"); @@ -141,16 +141,16 @@ async fn one_used_edge(version: &str, relays: usize, reorder: bool) { drop(received); drop(subscriber); let track = requests.borrow()[0].0.clone(); - moq_clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) .await .unwrap_or_else(|_| panic!("{label}: demand outlived the reader")) .unwrap(); - moq_clock::sleep(Duration::from_millis(100)).await; + kio::clock::sleep(Duration::from_millis(100)).await; assert_eq!(*track_edges.borrow(), [true, false], "{label}: track demand"); publisher.abort(); } -#[moq_clock::test] +#[kio::test] async fn direct() { for version in VERSIONS { one_used_edge(version, 0, false).await; @@ -158,7 +158,7 @@ async fn direct() { } } -#[moq_clock::test] +#[kio::test] async fn through_a_relay() { for version in VERSIONS { one_used_edge(version, 1, false).await; @@ -184,7 +184,7 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { broadcast.announce(Default::default()).unwrap(); let requests = Rc::new(RefCell::new(Vec::new())); let served = requests.clone(); - let publisher = moq_clock::sim::spawn(async move { + let publisher = kio::clock::sim::spawn(async move { while let Ok(request) = dynamic.requested_track().await { let track = request.accept(timed()); let mut group = track.append_group().unwrap(); @@ -194,14 +194,14 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { }); let consumer = nodes.last().unwrap().consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("room")) + kio::clock::timeout(TIMEOUT, consumer.routed("room")) .await .unwrap_or_else(|_| panic!("{label}: never announced")) .unwrap(); let remote = consumer.request_broadcast("room", None).await.unwrap(); let handle = remote.track("video").unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert!( requests.borrow().is_empty(), "{label}: a bare handle asked for the track" @@ -209,11 +209,11 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { // A held query reaches the publisher, and holds the track there until dropped. let mut query = handle.info(); - moq_clock::timeout(TIMEOUT, &mut query) + kio::clock::timeout(TIMEOUT, &mut query) .await .unwrap_or_else(|_| panic!("{label}: query stalled")) .unwrap_or_else(|err| panic!("{label}: query failed: {err}")); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; assert_eq!( requests.borrow().len(), 1, @@ -222,17 +222,17 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { let track = requests.borrow()[0].0.clone(); assert!(track.demand().wanted().is_some(), "{label}: a held query let go"); drop(query); - moq_clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) .await .unwrap_or_else(|_| panic!("{label}: a dropped query is still demand")) .unwrap(); // A subscription ending leaves the held handle unread at both ends. - let mut subscriber = moq_clock::timeout(TIMEOUT, handle.subscribe(None)) + let mut subscriber = kio::clock::timeout(TIMEOUT, handle.subscribe(None)) .await .unwrap_or_else(|_| panic!("{label}: subscribe stalled")) .unwrap_or_else(|err| panic!("{label}: subscribe failed: {err}")); - moq_clock::timeout(TIMEOUT, subscriber.recv_group()) + kio::clock::timeout(TIMEOUT, subscriber.recv_group()) .await .unwrap_or_else(|_| panic!("{label}: no group arrived")) .unwrap() @@ -242,7 +242,7 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { "{label}: the subscription is not demand" ); drop(subscriber); - moq_clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) + kio::clock::timeout(TIMEOUT, crate::support::unwanted(track.demand())) .await .unwrap_or_else(|_| panic!("{label}: the publisher still reads the track as used")) .unwrap(); @@ -250,14 +250,14 @@ async fn bare_handle_is_lazy(version: &str, relays: usize) { publisher.abort(); } -#[moq_clock::test] +#[kio::test] async fn bare_handle_is_lazy_direct() { for version in VERSIONS { bare_handle_is_lazy(version, 0).await; } } -#[moq_clock::test] +#[kio::test] async fn bare_handle_is_lazy_through_a_relay() { for version in VERSIONS { bare_handle_is_lazy(version, 1).await; diff --git a/rs/moq-net/tests/integration/track_tail.rs b/rs/moq-net/tests/integration/track_tail.rs index 248541ee2a5..82f108ab834 100644 --- a/rs/moq-net/tests/integration/track_tail.rs +++ b/rs/moq-net/tests/integration/track_tail.rs @@ -86,11 +86,11 @@ async fn connect(version: &str) -> Pair { let pair = connect_mock(options).await; let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("bcast")) + kio::clock::timeout(TIMEOUT, consumer.routed("bcast")) .await .expect("announce timeout") .expect("routed"); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("bcast", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -113,7 +113,7 @@ async fn round(version: &str, late: Late, final_sequence: u64) -> Outcome { _keep, } = connect(version).await; - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let subscription = moq_net::track::Subscription::default().with_range(0..); let mut sub = remote .track("video") @@ -136,17 +136,17 @@ async fn round(version: &str, late: Late, final_sequence: u64) -> Outcome { } } }; - (frames, err, moq_clock::now()) + (frames, err, kio::clock::now()) }); - moq_clock::timeout(TIMEOUT, support::harness::subscribed(&track)) + kio::clock::timeout(TIMEOUT, support::harness::subscribed(&track)) .await .expect("no subscriber appeared"); // Let the publisher answer while the track is still empty. Before draft 22, a group // written first sits below SUBSCRIBE_OK's Largest Object, so it would arrive as a // joining FETCH, which the track ending first refuses, not as the subscription's own // late stream. Paused time advances only once every task is idle. - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; pair.server_transport.hold_unis(); if final_sequence > 0 { @@ -162,20 +162,20 @@ async fn round(version: &str, late: Late, final_sequence: u64) -> Outcome { if final_sequence > 0 { // Paused time advances only when every task is idle, after the publisher and // subscriber have processed the subscription's end. - moq_clock::sleep(GRACE / 10).await; + kio::clock::sleep(GRACE / 10).await; assert!( !reader.is_finished(), "{version}: the track ended before its group arrived" ); } - let released = moq_clock::now(); + let released = kio::clock::now(); match late { Late::Delivered => pair.server_transport.release_unis(), Late::Lost => pair.server_transport.drop_unis(), } - let (frames, err, ended) = moq_clock::timeout(TIMEOUT, reader) + let (frames, err, ended) = kio::clock::timeout(TIMEOUT, reader) .await .expect("the subscription never ended") .expect("reader panicked"); @@ -189,7 +189,7 @@ async fn round(version: &str, late: Late, final_sequence: u64) -> Outcome { /// A group whose header arrives after the subscription's end is delivered, then the track /// ends cleanly. -#[moq_clock::test] +#[kio::test] async fn a_group_after_the_end_is_delivered() { for version in VERSIONS { let outcome = round(version, Late::Delivered, 1).await; @@ -214,7 +214,7 @@ async fn a_group_after_the_end_is_delivered() { /// A group that never arrives is given up on after the grace, and the track still ends /// cleanly without it. -#[moq_clock::test] +#[kio::test] async fn a_lost_group_ends_the_track_after_the_grace() { for version in VERSIONS { let outcome = round(version, Late::Lost, 1).await; @@ -233,7 +233,7 @@ async fn a_lost_group_ends_the_track_after_the_grace() { } /// Skipped sequences have no stream, so lite-05+ publishers name them with SUBSCRIBE_DROP. -#[moq_clock::test] +#[kio::test] async fn skipped_groups_end_without_the_grace() { for version in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip"] { let outcome = round(version, Late::Delivered, 3).await; @@ -248,7 +248,7 @@ async fn skipped_groups_end_without_the_grace() { } /// An empty track leaves no tail to wait for. -#[moq_clock::test] +#[kio::test] async fn lite07_empty_track_ends_without_the_grace() { let outcome = round("moq-lite-07-wip", Late::Delivered, 0).await; assert!(outcome.err.is_none()); @@ -261,7 +261,7 @@ const IETF: &[&str] = &["moq-transport-18", "moq-transport-22"]; /// A subscriber that leaves while END_OF_TRACK waits for stream credit ends the publisher's /// request, instead of parking it until credit that may never come. -#[moq_clock::test] +#[kio::test] async fn ietf_leaving_cancels_a_blocked_end_of_track() { for version in IETF { let Pair { @@ -278,14 +278,14 @@ async fn ietf_leaving_cancels_a_blocked_end_of_track() { .subscribe(subscription) .await .expect("subscribe"); - moq_clock::timeout(TIMEOUT, support::harness::subscribed(&track)) + kio::clock::timeout(TIMEOUT, support::harness::subscribed(&track)) .await .expect("no subscriber appeared"); let mut group = track.append_group().unwrap(); group.write_frame(Timestamp::ZERO, PAYLOAD).unwrap(); group.finish().unwrap(); - let mut group = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() @@ -295,7 +295,7 @@ async fn ietf_leaving_cancels_a_blocked_end_of_track() { // Out of stream credit, so the marker cannot open. pair.server_transport.withhold_unis(); track.finish().unwrap(); - moq_clock::sleep(GRACE / 10).await; + kio::clock::sleep(GRACE / 10).await; assert!( track.subscription().is_some(), "{version}: the publisher is still ending the request" @@ -303,9 +303,9 @@ async fn ietf_leaving_cancels_a_blocked_end_of_track() { // The request task holds the publisher's subscription until it ends. drop((group, sub)); - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { while track.subscription().is_some() { - moq_clock::sleep(GRACE / 100).await; + kio::clock::sleep(GRACE / 100).await; } }) .await @@ -316,7 +316,7 @@ async fn ietf_leaving_cancels_a_blocked_end_of_track() { /// A lost datagram is indistinguishable from a reordered stream header, so its hole /// waits out the tail grace on every lite version. -#[moq_clock::test] +#[kio::test] async fn a_lost_datagram_delays_the_end() { for version in ["moq-lite-05", "moq-lite-07-wip"] { let Pair { @@ -326,7 +326,7 @@ async fn a_lost_datagram_delays_the_end() { _keep, } = connect(version).await; - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let subscription = moq_net::track::Subscription::default().with_range(0..); let mut sub = remote .track("video") @@ -338,9 +338,9 @@ async fn a_lost_datagram_delays_the_end() { while let Some(group) = sub.recv_group().await.expect("track aborted") { groups.push(group.sequence); } - (groups, moq_clock::now()) + (groups, kio::clock::now()) }); - moq_clock::timeout(TIMEOUT, support::harness::subscribed(&track)) + kio::clock::timeout(TIMEOUT, support::harness::subscribed(&track)) .await .expect("no subscriber appeared"); @@ -353,12 +353,12 @@ async fn a_lost_datagram_delays_the_end() { group.write_frame(Timestamp::ZERO, PAYLOAD).unwrap(); group.finish().unwrap(); } - moq_clock::sleep(GRACE / 100).await; + kio::clock::sleep(GRACE / 100).await; } - let finished = moq_clock::now(); + let finished = kio::clock::now(); track.finish().unwrap(); - let (groups, ended) = moq_clock::timeout(TIMEOUT, reader) + let (groups, ended) = kio::clock::timeout(TIMEOUT, reader) .await .expect("the subscription never ended") .expect("reader panicked"); @@ -375,7 +375,7 @@ async fn a_lost_datagram_delays_the_end() { /// A publisher can declare the end, then open each group's stream before writing its first /// frame. The subscriber withholds a group until that frame lands, and the end waits for /// it: a reader that ended at the boundary would miss every group. -#[moq_clock::test] +#[kio::test] async fn a_group_whose_first_frame_trails_its_header_is_delivered() { for version in ["moq-lite-05", "moq-lite-06", "moq-lite-07-wip"] { let Pair { @@ -385,7 +385,7 @@ async fn a_group_whose_first_frame_trails_its_header_is_delivered() { _keep, } = connect(version).await; - let reader = moq_clock::sim::spawn(async move { + let reader = kio::clock::sim::spawn(async move { let subscription = moq_net::track::Subscription::default() .with_range(0..) .with_max_delay(TIMEOUT); @@ -403,7 +403,7 @@ async fn a_group_whose_first_frame_trails_its_header_is_delivered() { } groups }); - moq_clock::timeout(TIMEOUT, support::harness::subscribed(&track)) + kio::clock::timeout(TIMEOUT, support::harness::subscribed(&track)) .await .expect("no subscriber appeared"); @@ -411,7 +411,7 @@ async fn a_group_whose_first_frame_trails_its_header_is_delivered() { let mut groups = [track.append_group().unwrap(), track.append_group().unwrap()]; // Paused time advances only once every task is idle: both headers and the end // have reached the subscriber, ahead of any frame. - moq_clock::sleep(GRACE / 10).await; + kio::clock::sleep(GRACE / 10).await; assert!( !reader.is_finished(), "{version}: the track ended before its groups showed" @@ -421,7 +421,7 @@ async fn a_group_whose_first_frame_trails_its_header_is_delivered() { group.write_frame(Timestamp::ZERO, PAYLOAD).unwrap(); group.finish().unwrap(); } - let mut groups = moq_clock::timeout(TIMEOUT, reader) + let mut groups = kio::clock::timeout(TIMEOUT, reader) .await .expect("the subscription never ended") .expect("reader panicked"); diff --git a/rs/moq-net/tests/integration/tracks.rs b/rs/moq-net/tests/integration/tracks.rs index 1dcbf5fa696..dc8864fba32 100644 --- a/rs/moq-net/tests/integration/tracks.rs +++ b/rs/moq-net/tests/integration/tracks.rs @@ -25,7 +25,7 @@ fn lite07() -> Version { /// The next event as `+name`, `-name`, `synced`, `end`, or `error: ..`. async fn next(tracks: &mut moq_net::broadcast::Tracks) -> String { - match moq_clock::timeout(TIMEOUT, tracks.next()) + match kio::clock::timeout(TIMEOUT, tracks.next()) .await .expect("listing stalled") { @@ -53,7 +53,7 @@ async fn connect( } async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Consumer { - moq_clock::timeout(TIMEOUT, origin.consume().routed_broadcast("bcast")) + kio::clock::timeout(TIMEOUT, origin.consume().routed_broadcast("bcast")) .await .expect("announce timeout") .expect("routed") @@ -61,7 +61,7 @@ async fn resolve(origin: &moq_net::origin::Producer) -> moq_net::broadcast::Cons /// A session syncs at once, then lists the peer's tracks and their changes until the /// broadcast ends. -#[moq_clock::test] +#[kio::test] async fn a_session_lists_its_peers_tracks() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -91,7 +91,7 @@ async fn a_session_lists_its_peers_tracks() { } /// TRACKS_ADD carries the track's whole TRACK_INFO, Refresh included. -#[moq_clock::test] +#[kio::test] async fn a_listing_carries_track_info() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -107,7 +107,7 @@ async fn a_listing_carries_track_info() { let (subscriber, _pair) = connect(&publisher, 2, lite07()).await; let mut tracks = resolve(&subscriber).await.tracks().unwrap(); assert_eq!(next(&mut tracks).await, "synced"); - let event = moq_clock::timeout(TIMEOUT, tracks.next()) + let event = kio::clock::timeout(TIMEOUT, tracks.next()) .await .expect("listing stalled") .unwrap(); @@ -124,7 +124,7 @@ async fn a_listing_carries_track_info() { /// A listed track is a track like any other: a SUBSCRIBE from the listing reads the /// group it already holds from the cache. -#[moq_clock::test] +#[kio::test] async fn a_listed_track_serves_its_cached_group() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -141,11 +141,11 @@ async fn a_listed_track_serves_its_cached_group() { group.finish().unwrap(); assert_eq!(next(&mut tracks).await, "+late"); - let mut sub = moq_clock::timeout(TIMEOUT, remote.track("late").unwrap().subscribe(None)) + let mut sub = kio::clock::timeout(TIMEOUT, remote.track("late").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - let mut group = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() @@ -157,7 +157,7 @@ async fn a_listed_track_serves_its_cached_group() { /// Through a relay: the relay answers each downstream listing at once from the one /// upstream listing it keeps, a cold relay's upstream tracks follow as live adds, and a /// removal reaches each downstream as its upstream reported it. -#[moq_clock::test] +#[kio::test] async fn a_relay_shares_its_upstream_listing() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -191,7 +191,7 @@ async fn a_relay_shares_its_upstream_listing() { } /// A version without the Tracks Stream refuses the listing rather than answer it empty. -#[moq_clock::test] +#[kio::test] async fn lite06_cannot_list() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -208,7 +208,7 @@ async fn lite06_cannot_list() { /// Each listed track counts against the session's `announces` cap: past it, the listing /// is reset rather than held, and the session stays. -#[moq_clock::test] +#[kio::test] async fn a_listing_past_the_announces_cap_is_reset() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -242,7 +242,7 @@ async fn a_listing_past_the_announces_cap_is_reset() { assert_eq!(end, format!("error: {}", moq_net::Error::TooManyRequests)); assert!( - moq_clock::timeout(Duration::from_millis(100), pair.server.closed()) + kio::clock::timeout(Duration::from_millis(100), pair.server.closed()) .await .is_err(), "the session closed" diff --git a/rs/moq-net/tests/integration/tracks_ietf.rs b/rs/moq-net/tests/integration/tracks_ietf.rs index 6eab3284ac4..bca26596368 100644 --- a/rs/moq-net/tests/integration/tracks_ietf.rs +++ b/rs/moq-net/tests/integration/tracks_ietf.rs @@ -33,7 +33,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { /// The next event as `+name`, `-name`, `synced`, `end`, or `error: ..`. async fn next(tracks: &mut moq_net::broadcast::Tracks) -> String { - match moq_clock::timeout(TIMEOUT, tracks.next()) + match kio::clock::timeout(TIMEOUT, tracks.next()) .await .expect("listing stalled") { @@ -48,7 +48,7 @@ async fn next(tracks: &mut moq_net::broadcast::Tracks) -> String { /// Whether the listing has nothing more to report for a while. async fn quiet(tracks: &mut moq_net::broadcast::Tracks) -> bool { - moq_clock::timeout(Duration::from_millis(500), tracks.next()) + kio::clock::timeout(Duration::from_millis(500), tracks.next()) .await .is_err() } @@ -64,7 +64,7 @@ async fn connect(publisher: &moq_net::origin::Producer, version: &str) -> (moq_n } async fn resolve(origin: &moq_net::origin::Producer, path: &str) -> moq_net::broadcast::Consumer { - moq_clock::timeout(TIMEOUT, origin.consume().routed_broadcast(path)) + kio::clock::timeout(TIMEOUT, origin.consume().routed_broadcast(path)) .await .expect("announce timeout") .expect("routed") @@ -86,11 +86,11 @@ fn subscribes(pair: &MockPair) -> usize { /// Read one frame of the next group, or `None` once the subscription ends. async fn read(sub: &mut moq_net::track::Subscriber) -> Option<(u64, Vec)> { - let mut group = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .ok()??; - let frame = moq_clock::timeout(TIMEOUT, group.read_frame()) + let frame = kio::clock::timeout(TIMEOUT, group.read_frame()) .await .expect("frame timeout") .ok()??; @@ -98,7 +98,7 @@ async fn read(sub: &mut moq_net::track::Subscriber) -> Option<(u64, Vec)> { } /// The listing syncs at once, then lists the peer's tracks as they appear. -#[moq_clock::test] +#[kio::test] async fn an_ietf_session_lists_its_peers_tracks() { for version in DRAFTS { let publisher = produce_origin(1); @@ -120,7 +120,7 @@ async fn an_ietf_session_lists_its_peers_tracks() { /// SUBSCRIBE_TRACKS goes out only for a listing, since many peers do not answer it yet: /// connecting, an announce, and a reader's SUBSCRIBE send none. -#[moq_clock::test] +#[kio::test] async fn only_a_listing_sends_subscribe_tracks() { for version in DRAFTS { let publisher = produce_origin(1); @@ -130,11 +130,11 @@ async fn only_a_listing_sends_subscribe_tracks() { let (subscriber, pair) = connect(&publisher, version).await; let remote = resolve(&subscriber, "bcast").await; - let mut sub = moq_clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) + let mut sub = kio::clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - moq_clock::timeout(TIMEOUT, support::wanted(video.demand())) + kio::clock::timeout(TIMEOUT, support::wanted(video.demand())) .await .expect("never subscribed") .unwrap(); @@ -153,7 +153,7 @@ async fn only_a_listing_sends_subscribe_tracks() { } /// A listed track carries the info its PUBLISH declared. -#[moq_clock::test] +#[kio::test] async fn a_listing_carries_track_info() { let publisher = produce_origin(1); let broadcast = publisher.create_broadcast("bcast").unwrap(); @@ -166,7 +166,7 @@ async fn a_listing_carries_track_info() { let (subscriber, _pair) = connect(&publisher, "moq-transport-22").await; let mut tracks = resolve(&subscriber, "bcast").await.tracks().unwrap(); assert_eq!(next(&mut tracks).await, "synced"); - let event = moq_clock::timeout(TIMEOUT, tracks.next()) + let event = kio::clock::timeout(TIMEOUT, tracks.next()) .await .expect("listing stalled") .unwrap(); @@ -182,7 +182,7 @@ async fn a_listing_carries_track_info() { /// SUBSCRIBE at all; draft-18 would refuse one as a second subscription to the track. /// Once the reader leaves, the PUBLISH pauses and stays listed, and the next reader /// resumes it again. -#[moq_clock::test] +#[kio::test] async fn a_reader_resumes_the_held_publish() { for version in DRAFTS { let publisher = produce_origin(1); @@ -196,11 +196,11 @@ async fn a_reader_resumes_the_held_publish() { assert_eq!(next(&mut tracks).await, "synced", "{version}"); assert_eq!(next(&mut tracks).await, "+video", "{version}"); - let mut sub = moq_clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) + let mut sub = kio::clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - moq_clock::timeout(TIMEOUT, support::wanted(video.demand())) + kio::clock::timeout(TIMEOUT, support::wanted(video.demand())) .await .expect("never resumed") .unwrap(); @@ -212,17 +212,17 @@ async fn a_reader_resumes_the_held_publish() { // The last reader leaving pauses the PUBLISH upstream, and the track stays listed. drop(sub); - moq_clock::timeout(TIMEOUT, support::unwanted(video.demand())) + kio::clock::timeout(TIMEOUT, support::unwanted(video.demand())) .await .expect("never paused") .unwrap(); assert!(quiet(&mut tracks).await, "{version}"); - let mut sub = moq_clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) + let mut sub = kio::clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - moq_clock::timeout(TIMEOUT, support::wanted(video.demand())) + kio::clock::timeout(TIMEOUT, support::wanted(video.demand())) .await .expect("never resumed again") .unwrap(); @@ -243,7 +243,7 @@ async fn a_reader_resumes_the_held_publish() { /// A reader joining a listed track mid-group gets the objects already published in it: on /// draft 18, whose filters deliver nothing already published, through a Joining /// FETCH on the held PUBLISH's Request ID, and from draft-22 through the resume's fill. -#[moq_clock::test] +#[kio::test] async fn a_join_gets_the_current_groups_head() { for version in DRAFTS { let publisher = produce_origin(1); @@ -260,26 +260,26 @@ async fn a_join_gets_the_current_groups_head() { let mut group = video.create_group(moq_net::group::Info { sequence: 5 }).unwrap(); group.write_frame(None, &b"head"[..]).unwrap(); - let mut sub = moq_clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) + let mut sub = kio::clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - moq_clock::timeout(TIMEOUT, support::wanted(video.demand())) + kio::clock::timeout(TIMEOUT, support::wanted(video.demand())) .await .expect("never resumed") .unwrap(); - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; group.write_frame(None, &b"tail"[..]).unwrap(); group.finish().unwrap(); - let mut joined = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut joined = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() .expect("the joined group"); assert_eq!(joined.sequence, 5, "{version}"); let mut frames = Vec::new(); - while let Some(frame) = moq_clock::timeout(TIMEOUT, joined.read_frame()) + while let Some(frame) = kio::clock::timeout(TIMEOUT, joined.read_frame()) .await .expect("frame timeout") .unwrap() @@ -293,7 +293,7 @@ async fn a_join_gets_the_current_groups_head() { /// A nested listing reuses the broader SUBSCRIBE_TRACKS and filters locally: the peer /// would refuse an overlapping prefix. -#[moq_clock::test] +#[kio::test] async fn a_nested_listing_reuses_the_broader_one() { for version in DRAFTS { let publisher = produce_origin(1); @@ -324,7 +324,7 @@ async fn a_nested_listing_reuses_the_broader_one() { /// A broader listing replaces the nested requests only once the peer has closed them, so it /// is never refused as overlapping, and the nested listings keep what they listed. -#[moq_clock::test] +#[kio::test] async fn a_broader_listing_replaces_the_nested_ones() { for version in DRAFTS { let publisher = produce_origin(1); @@ -361,7 +361,7 @@ async fn a_broader_listing_replaces_the_nested_ones() { /// A PUBLISH for a track we already SUBSCRIBEd is redundant: the SUBSCRIBE lists the track /// and keeps carrying its data. Draft-18 skips it instead, which lists it the same way. -#[moq_clock::test] +#[kio::test] async fn a_subscribed_track_is_listed_through_its_subscribe() { for version in DRAFTS { let publisher = produce_origin(1); @@ -371,11 +371,11 @@ async fn a_subscribed_track_is_listed_through_its_subscribe() { let (subscriber, pair) = connect(&publisher, version).await; let remote = resolve(&subscriber, "bcast").await; - let mut sub = moq_clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) + let mut sub = kio::clock::timeout(TIMEOUT, remote.track("video").unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe"); - moq_clock::timeout(TIMEOUT, support::wanted(video.demand())) + kio::clock::timeout(TIMEOUT, support::wanted(video.demand())) .await .expect("never subscribed") .unwrap(); @@ -397,7 +397,7 @@ async fn a_subscribed_track_is_listed_through_its_subscribe() { /// Each held PUBLISH counts against the session's `announces` cap, as a lite listed track /// does: past it, the PUBLISH is refused and the listing reset rather than left short, and /// the session stays. -#[moq_clock::test] +#[kio::test] async fn a_listing_past_the_announces_cap_is_reset() { for version in DRAFTS { let publisher = produce_origin(1); @@ -432,7 +432,7 @@ async fn a_listing_past_the_announces_cap_is_reset() { assert_eq!(end, format!("error: {}", moq_net::Error::TooManyRequests), "{version}"); assert!( - moq_clock::timeout(Duration::from_millis(100), pair.server.closed()) + kio::clock::timeout(Duration::from_millis(100), pair.server.closed()) .await .is_err(), "{version}: the session closed" @@ -444,7 +444,7 @@ async fn a_listing_past_the_announces_cap_is_reset() { /// finished: that one leaves the listing quietly. One that left unfinished may go on /// elsewhere, so its PUBLISH ends in error, which fails the listing loudly, and a reader /// listing again sees what is still listed. -#[moq_clock::test] +#[kio::test] async fn a_track_leaves_the_listing_as_it_ended() { for finish in [true, false] { for version in DRAFTS { diff --git a/rs/moq-net/tests/integration/unannounce_release.rs b/rs/moq-net/tests/integration/unannounce_release.rs index 551289eb499..aafa59c1975 100644 --- a/rs/moq-net/tests/integration/unannounce_release.rs +++ b/rs/moq-net/tests/integration/unannounce_release.rs @@ -34,17 +34,17 @@ async fn release(version: Version) { crate::support::wanted(track.demand()).await.unwrap(); broadcast.unannounce(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; drop(sub); drop(remote); - moq_clock::timeout(Duration::from_secs(600), crate::support::unwanted(track.demand())) + kio::clock::timeout(Duration::from_secs(600), crate::support::unwanted(track.demand())) .await .unwrap_or_else(|_| panic!("{version}: the relay kept its upstream subscription")) .unwrap(); } -#[moq_clock::test] +#[kio::test] async fn unannounced_remote_track_releases_demand() { for version in support::every_version() { release(version).await; diff --git a/rs/moq-net/tests/integration/untimed.rs b/rs/moq-net/tests/integration/untimed.rs index c313a31f23a..1d57c80be25 100644 --- a/rs/moq-net/tests/integration/untimed.rs +++ b/rs/moq-net/tests/integration/untimed.rs @@ -81,11 +81,11 @@ impl Chain { async fn subscribe(&self, track: &str) -> track::Subscriber { let consumer = self.nodes.last().unwrap().consume(); - let broadcast = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) + let broadcast = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); - moq_clock::timeout(TIMEOUT, broadcast.track(track).unwrap().subscribe(None)) + kio::clock::timeout(TIMEOUT, broadcast.track(track).unwrap().subscribe(None)) .await .expect("subscribe timeout") .expect("subscribe") @@ -94,7 +94,7 @@ impl Chain { /// The first frame's timestamp of the next group. async fn next_frame(subscriber: &mut track::Subscriber) -> Option { - let mut group = moq_clock::timeout(TIMEOUT, subscriber.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, subscriber.recv_group()) .await .expect("group timeout") .unwrap() @@ -110,7 +110,7 @@ async fn frame_through(hops: &[&str], info: track::Info) -> (Option, let broadcast = chain.nodes[0].create_broadcast("room").unwrap(); let mut producer = broadcast.create_track("data", info).unwrap(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let mut subscriber = chain.subscribe("data").await; producer.write_frame(timestamp, &b"frame"[..]).unwrap(); @@ -119,7 +119,7 @@ async fn frame_through(hops: &[&str], info: track::Info) -> (Option, (received, subscriber.info().clone()) } -#[moq_clock::test] +#[kio::test] async fn frames_arrive_as_published() { for version in VERSIONS { let (timed, timed_info) = frame_through(&[version], timed()).await; @@ -141,7 +141,7 @@ async fn frames_arrive_as_published() { /// A relay forwards an untimed track untimed, and a track it received without a timeline /// does not gain one downstream. -#[moq_clock::test] +#[kio::test] async fn a_relay_forwards_an_untimed_track_untimed() { for hops in [ &["moq-transport-18", "moq-transport-22"][..], @@ -164,7 +164,7 @@ async fn a_relay_forwards_an_untimed_track_untimed() { /// The subscription asks for history the way a resume does, with a budget covering it. /// moq-transport before draft 22 can only join a past group through a joining FETCH, /// which our publisher refuses for groups before the live one, so draft 22 stands in for it. -#[moq_clock::test] +#[kio::test] async fn an_explicit_start_holds_on_an_untimed_track() { for version in ["moq-lite-03", "moq-lite-06", "moq-lite-07-wip", "moq-transport-22"] { let chain = Chain::new(&[version]).await; @@ -174,20 +174,20 @@ async fn an_explicit_start_holds_on_an_untimed_track() { for _ in 0..5 { producer.write_frame(None, &b"untimed"[..]).unwrap(); } - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let consumer = chain.nodes[1].consume().request_broadcast("room", None).await.unwrap(); let subscription = track::Subscription::default() .with_range(2..) .with_max_delay(Duration::from_secs(30)); - let mut subscriber = moq_clock::timeout(TIMEOUT, consumer.track("data").unwrap().subscribe(subscription)) + let mut subscriber = kio::clock::timeout(TIMEOUT, consumer.track("data").unwrap().subscribe(subscription)) .await .expect("subscribe timeout") .expect("subscribe"); let mut got = Vec::new(); while got.len() < 3 { - let Ok(next) = moq_clock::timeout(TIMEOUT, subscriber.recv_group()).await else { + let Ok(next) = kio::clock::timeout(TIMEOUT, subscriber.recv_group()).await else { break; }; got.push(next.unwrap().expect("a group").sequence); @@ -199,14 +199,14 @@ async fn an_explicit_start_holds_on_an_untimed_track() { /// An untimed track's datagram arrives untimed, though lite-05 and lite-06 carry a send /// time that the receiver drops. -#[moq_clock::test] +#[kio::test] async fn datagrams_arrive_as_published() { for version in ["moq-lite-05", "moq-lite-07-wip", "moq-transport-22"] { let chain = Chain::new(&[version]).await; let broadcast = chain.nodes[0].create_broadcast("room").unwrap(); let mut producer = broadcast.create_track("data", untimed()).unwrap(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let mut subscriber = chain.subscribe("data").await; // A group first, so the subscription is bound before any datagram lands. @@ -214,7 +214,7 @@ async fn datagrams_arrive_as_published() { next_frame(&mut subscriber).await; producer.append_datagram(None, &b"untimed"[..]).unwrap(); - let datagram = moq_clock::timeout(TIMEOUT, subscriber.recv_datagram()) + let datagram = kio::clock::timeout(TIMEOUT, subscriber.recv_datagram()) .await .expect("datagram timeout") .unwrap() @@ -224,14 +224,14 @@ async fn datagrams_arrive_as_published() { } /// A standalone FETCH of an untimed track answers with untimed objects. -#[moq_clock::test] +#[kio::test] async fn a_fetched_untimed_frame_arrives_untimed() { for version in ["moq-lite-06", "moq-lite-07-wip", "moq-transport-18"] { let chain = Chain::new(&[version]).await; let broadcast = chain.nodes[0].create_broadcast("room").unwrap(); let mut dynamic = broadcast.requests(); broadcast.announce(Default::default()).unwrap(); - moq_clock::sleep(Duration::from_secs(1)).await; + kio::clock::sleep(Duration::from_secs(1)).await; let consumer = chain.nodes[1].consume().request_broadcast("room", None).await.unwrap(); let mut waiting = Box::pin(consumer.track("video").unwrap().fetch_group(0, None)); diff --git a/rs/moq-net/tests/integration/wide_hop.rs b/rs/moq-net/tests/integration/wide_hop.rs index 82657f75e04..d496b4b4413 100644 --- a/rs/moq-net/tests/integration/wide_hop.rs +++ b/rs/moq-net/tests/integration/wide_hop.rs @@ -19,7 +19,7 @@ fn produce(hop: u64) -> origin::Producer { /// A draft-18 peer declaring `u64::MAX` keeps its session and its place in the path. /// Forwarded on, the hop survives lite-07's leading-ones varint and becomes 0 on /// lite-06's QUIC varint, while the relay's own hop still follows it. -#[moq_clock::test] +#[kio::test] async fn widest_hop_crosses_each_varint_form() { for (downstream, forwarded) in [("moq-lite-06", Hop::UNKNOWN.id()), ("moq-lite-07-wip", u64::MAX)] { let source = produce(u64::MAX); @@ -29,7 +29,7 @@ async fn widest_hop_crosses_each_varint_form() { let _upstream = peer(upstream, &source, &relay).await; let _downstream = peer(downstream.parse().unwrap(), &relay, &sink).await; let _route = source.requests("room").unwrap(); - moq_clock::sim::idle().await; + kio::clock::sim::idle().await; let ids = |route: origin::Route| route.hops.iter().map(|hop| hop.id()).collect::>(); let at_relay = relay.consume().routed("room").await.expect("relay learned the route"); diff --git a/rs/moq-net/tests/integration/wide_sequence.rs b/rs/moq-net/tests/integration/wide_sequence.rs index f3c337aba5e..e59548b24ca 100644 --- a/rs/moq-net/tests/integration/wide_sequence.rs +++ b/rs/moq-net/tests/integration/wide_sequence.rs @@ -11,7 +11,7 @@ use support::harness::{MockConnectOptions, connect_mock}; /// Published QUIC-varint sequences keep all their bits on the live feed, directly /// and through a forwarding origin, even beyond JavaScript's exact number range. -#[moq_clock::test] +#[kio::test] async fn largest_quic_sequence_reaches_the_subscriber() { for alpn in ["moq-lite-02", "moq-lite-06", "moq-transport-18"] { for relayed in [false, true] { @@ -44,7 +44,7 @@ async fn largest_quic_sequence_reaches_the_subscriber() { let mut group = track.create_group(moq_net::group::Info { sequence }).unwrap(); group.write_frame(timestamp, b"ladder".as_ref()).unwrap(); group.finish().unwrap(); - let mut got = moq_clock::timeout(Duration::from_secs(5), sub.recv_group()) + let mut got = kio::clock::timeout(Duration::from_secs(5), sub.recv_group()) .await .unwrap_or_else(|_| panic!("{alpn} relayed={relayed} sequence={sequence} hung")) .unwrap() @@ -73,7 +73,7 @@ fn produce_origin(hop: u64) -> moq_net::origin::Producer { /// The relay accepts the wide sequence from lite-07, refuses that subscription to the /// lite-06 reader that cannot encode it, and keeps the session serving other tracks. -#[moq_clock::test] +#[kio::test] async fn wide_sequence_fails_only_its_subscription() { const WIDE: u64 = 1 << 62; @@ -109,7 +109,7 @@ async fn wide_sequence_fails_only_its_subscription() { consumer.routed("bench").await.unwrap(); let remote = consumer.request_broadcast("bench", None).await.unwrap(); - let result = moq_clock::timeout(Duration::from_secs(5), async { + let result = kio::clock::timeout(Duration::from_secs(5), async { let mut sub = remote.track("wide").unwrap().subscribe(None).await?; sub.recv_group().await.map(|group| group.map(|group| group.sequence)) }) @@ -129,7 +129,7 @@ async fn wide_sequence_fails_only_its_subscription() { /// A subscription that starts inside the QUIC range and later receives a group of /// `1 << 62` fails only that subscription. The session and the other track continue. -#[moq_clock::test] +#[kio::test] async fn a_later_wide_group_fails_only_that_subscription() { const WIDE: u64 = 1 << 62; @@ -167,7 +167,7 @@ async fn a_later_wide_group_fails_only_that_subscription() { let mut group = wide.create_group(moq_net::group::Info { sequence: WIDE }).unwrap(); group.write_frame(Timestamp::ZERO, b"wide".as_ref()).unwrap(); - let result = moq_clock::timeout(Duration::from_secs(5), sub.recv_group()) + let result = kio::clock::timeout(Duration::from_secs(5), sub.recv_group()) .await .expect("the wide group hung the subscription instead of failing it"); match result { diff --git a/rs/moq-net/tests/integration/widened_max_age.rs b/rs/moq-net/tests/integration/widened_max_age.rs index 579906df092..4f4555c9396 100644 --- a/rs/moq-net/tests/integration/widened_max_age.rs +++ b/rs/moq-net/tests/integration/widened_max_age.rs @@ -94,7 +94,7 @@ impl Chain { /// Every group `subscriber` receives until it goes quiet. async fn received(subscriber: &mut track::Subscriber) -> BTreeSet { let mut got = BTreeSet::new(); - while let Ok(group) = moq_clock::timeout(Duration::from_secs(1), subscriber.recv_group()).await { + while let Ok(group) = kio::clock::timeout(Duration::from_secs(1), subscriber.recv_group()).await { let group = group.unwrap().expect("the track is live"); assert!(got.insert(group.sequence), "group {} delivered twice", group.sequence); } @@ -102,58 +102,58 @@ async fn received(subscriber: &mut track::Subscriber) -> BTreeSet { } /// What the subscriber reads after widening its own max age, through a relay or not. -#[moq_clock::test] +#[kio::test] async fn a_widened_reader_gets_what_was_skipped() { for relay in [false, true] { let chain = Chain::new(relay).await; - let mut reader = moq_clock::timeout(TIMEOUT, chain.subscribe(NARROW)).await.unwrap(); - let first = moq_clock::timeout(TIMEOUT, received(&mut reader)).await.unwrap(); + let mut reader = kio::clock::timeout(TIMEOUT, chain.subscribe(NARROW)).await.unwrap(); + let first = kio::clock::timeout(TIMEOUT, received(&mut reader)).await.unwrap(); assert_eq!(first, (6..GROUPS).collect(), "relay={relay}"); let wide = Subscription::default() .with_max_delay(WIDE) .with_ranges([Range::oldest()]); reader.update(wide).unwrap(); - let widened = moq_clock::timeout(TIMEOUT, received(&mut reader)).await.unwrap(); + let widened = kio::clock::timeout(TIMEOUT, received(&mut reader)).await.unwrap(); assert_eq!(widened, (2..6).collect(), "relay={relay}: only what was skipped"); } } -#[moq_clock::test] +#[kio::test] async fn a_warm_relay_serves_a_wider_newcomer_what_a_cold_one_would() { let cold = Chain::new(true).await; - let mut wide = moq_clock::timeout(TIMEOUT, cold.subscribe(WIDE)).await.unwrap(); - let want = moq_clock::timeout(TIMEOUT, received(&mut wide)).await.unwrap(); + let mut wide = kio::clock::timeout(TIMEOUT, cold.subscribe(WIDE)).await.unwrap(); + let want = kio::clock::timeout(TIMEOUT, received(&mut wide)).await.unwrap(); assert_eq!(want, (2..GROUPS).collect(), "cold"); let warm = Chain::new(true).await; - let mut narrow = moq_clock::timeout(TIMEOUT, warm.subscribe(NARROW)).await.unwrap(); - let first = moq_clock::timeout(TIMEOUT, received(&mut narrow)).await.unwrap(); + let mut narrow = kio::clock::timeout(TIMEOUT, warm.subscribe(NARROW)).await.unwrap(); + let first = kio::clock::timeout(TIMEOUT, received(&mut narrow)).await.unwrap(); assert_eq!(first, (6..GROUPS).collect(), "the narrow reader warms the relay"); - let mut wide = moq_clock::timeout(TIMEOUT, warm.subscribe(WIDE)).await.unwrap(); - let got = moq_clock::timeout(TIMEOUT, received(&mut wide)).await.unwrap(); + let mut wide = kio::clock::timeout(TIMEOUT, warm.subscribe(WIDE)).await.unwrap(); + let got = kio::clock::timeout(TIMEOUT, received(&mut wide)).await.unwrap(); assert_eq!(got, want, "warm"); - let late = moq_clock::timeout(TIMEOUT, received(&mut narrow)).await.unwrap(); + let late = kio::clock::timeout(TIMEOUT, received(&mut narrow)).await.unwrap(); assert!(late.is_empty(), "the narrow reader still skips {late:?}"); } /// A reader joining with the max age the relay already asks for changes nothing upstream. -#[moq_clock::test] +#[kio::test] async fn the_same_max_age_sends_no_update() { let mut chain = Chain::new(true).await; - let mut narrow = moq_clock::timeout(TIMEOUT, chain.subscribe(NARROW)).await.unwrap(); - moq_clock::timeout(TIMEOUT, received(&mut narrow)).await.unwrap(); - while moq_clock::timeout(Duration::from_secs(1), chain.source.subscription_changed()) + let mut narrow = kio::clock::timeout(TIMEOUT, chain.subscribe(NARROW)).await.unwrap(); + kio::clock::timeout(TIMEOUT, received(&mut narrow)).await.unwrap(); + while kio::clock::timeout(Duration::from_secs(1), chain.source.subscription_changed()) .await .is_ok() {} - let mut same = moq_clock::timeout(TIMEOUT, chain.subscribe(NARROW)).await.unwrap(); + let mut same = kio::clock::timeout(TIMEOUT, chain.subscribe(NARROW)).await.unwrap(); assert_eq!( - moq_clock::timeout(TIMEOUT, received(&mut same)).await.unwrap(), + kio::clock::timeout(TIMEOUT, received(&mut same)).await.unwrap(), (6..GROUPS).collect() ); - let changed = moq_clock::timeout(Duration::from_secs(1), chain.source.subscription_changed()).await; + let changed = kio::clock::timeout(Duration::from_secs(1), chain.source.subscription_changed()).await; assert!(changed.is_err(), "the publisher saw {changed:?}"); } diff --git a/rs/moq-net/tests/integration/zero_copy.rs b/rs/moq-net/tests/integration/zero_copy.rs index 5e4c3212579..738dd66b6cd 100644 --- a/rs/moq-net/tests/integration/zero_copy.rs +++ b/rs/moq-net/tests/integration/zero_copy.rs @@ -22,7 +22,7 @@ fn produce_origin(hop: u64) -> origin::Producer { producer } -#[moq_clock::test] +#[kio::test] async fn frames_cross_without_a_copy() { for version in VERSIONS { let version: Version = version.parse().unwrap(); @@ -59,11 +59,11 @@ async fn frames_cross_without_a_copy() { broadcast.announce(Default::default()).unwrap(); let consumer = subscriber.consume(); - moq_clock::timeout(TIMEOUT, consumer.routed("room")) + kio::clock::timeout(TIMEOUT, consumer.routed("room")) .await .expect("announce timeout") .unwrap(); - let remote = moq_clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) + let remote = kio::clock::timeout(TIMEOUT, consumer.request_broadcast("room", None)) .await .expect("resolve timeout") .expect("broadcast resolves"); @@ -75,7 +75,7 @@ async fn frames_cross_without_a_copy() { group.write_frame(Timestamp::ZERO, payload.clone()).unwrap(); group.finish().unwrap(); - let mut group = moq_clock::timeout(TIMEOUT, sub.recv_group()) + let mut group = kio::clock::timeout(TIMEOUT, sub.recv_group()) .await .expect("group timeout") .unwrap() diff --git a/rs/moq-nvenc/clippy.toml b/rs/moq-nvenc/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-nvenc/clippy.toml +++ b/rs/moq-nvenc/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-pattern/clippy.toml b/rs/moq-pattern/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-pattern/clippy.toml +++ b/rs/moq-pattern/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-quic/Cargo.toml b/rs/moq-quic/Cargo.toml index 014db7bf599..d0c189096ad 100644 --- a/rs/moq-quic/Cargo.toml +++ b/rs/moq-quic/Cargo.toml @@ -47,7 +47,7 @@ fastbloom = { version = "0.17", default-features = false } indexmap = { workspace = true } lru-slab = "0.1.2" # Without the runtime, which is meant for dev-dependencies; a driver brings its own. -moq-clock = { version = "0.11.0", path = "../moq-clock", default-features = false } +kio = { workspace = true } moq-congestion = { workspace = true } qlog = { version = "0.18", optional = true } rand = { workspace = true } @@ -73,7 +73,7 @@ assert_matches = "1.1" criterion = { workspace = true } hex-literal = "1" # The tests and benches read time through the runtime, as the drivers do. -moq-clock = { path = "../moq-clock", features = ["sim"] } +kio = { path = "../kio", features = ["runtime", "sim"] } # The tests seed BBR3's probe phases. moq-congestion = { workspace = true, features = ["testing"] } # The mux module's tests run in the default merge gate. diff --git a/rs/moq-quic/MIGRATE.md b/rs/moq-quic/MIGRATE.md index 11a13e91236..e48541053a2 100644 --- a/rs/moq-quic/MIGRATE.md +++ b/rs/moq-quic/MIGRATE.md @@ -24,7 +24,7 @@ Nothing public decodes a `VarInt` or the other former `Codec` types (`StreamId`, Packet parsers and headers, `HashedConnectionIdGenerator` (with `set_lifetime`), `BloomTokenLog`, `TokenMemoryCache`, token policy traits (`TokenLog`, `TokenStore`, and `TokenReuseError`), `NoneTokenLog`, `NoneTokenStore`, `ClientConfig::token_store`, and `ValidationTokenConfig::log` are internal. Use `Endpoint` to parse incoming datagrams, `RandomConnectionIdGenerator` or a consumer's `ConnectionIdGenerator`, and the default token policy. -`TimeSource`, `StdSystemTime`, and `ServerConfig::time_source` are gone; address validation uses `moq_clock::wall()`, including an installed simulated clock. +`TimeSource`, `StdSystemTime`, and `ServerConfig::time_source` are gone; address validation uses `kio::clock::wall()`, including an installed simulated clock. Unused `Connection::local_ip`, `min_rtt`, `has_pending_retransmits`, `ping`, `force_key_update`, `path_changed`, and `max_concurrent_streams` accessors are no longer public. `Endpoint::set_server_config`, `incoming_buffer_bytes`, and `Incoming::orig_dst_cid` are also internal or removed; configure the endpoint at construction. To rotate TLS certificates on a running endpoint, give the `ServerConfig`'s rustls config a `ResolvesServerCert` that returns the current certificate, as moq-tokio's `tls::Serve` does. diff --git a/rs/moq-quic/README.md b/rs/moq-quic/README.md index 4419a731fe7..08163214898 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -57,7 +57,7 @@ Changes on top of the upstream commit, besides the renames: - **Probes on the peer heard again**: a 1-RTT probe that times out with nothing heard from the peer since the packet it probes for went out lets the next packet heard send the next probe at once, rather than leave a path back from an outage idle for the rest of the backoff, which still doubles with each probe (RFC 9002 section 6.2.1), up to 2^16 times its base. A packet acknowledging anything new already resets the backoff; this covers one that does not, as after an outage that began with everything acknowledged. A peer heard while the probes still go unanswered says nothing of their path, so it leaves the backoff alone. Not offered upstream yet. - `TransportConfig::handshake_idle_timeout` (default 10s, as msquic's `HandshakeIdleTimeoutMs`) governs the idle timer until the handshake completes, and the negotiated idle timeout takes over once established. A 2s idle timeout otherwise expires 3x the initial PTO in, just before the second Initial probe, leaving a client two flights. A server also drops an Initial left waiting for `accept` past it, and a deadline too far out to represent never fires instead of panicking. Also [moq-dev/noq#34](https://github.com/moq-dev/noq/pull/34), whose third change (the handshake idle timeout picks noq's idle-based PTO interval cap) has nothing to apply to here, since quinn's PTO backoff has no such cap. quinn's `handshake_timeout` test in its async layer expects the handshake to end at the idle timeout, so the driver's copy sets both timeouts. -- **Time on [moq-clock](../moq-clock)**: the crate's `Instant` is `moq_clock::Instant`, so one clock steps every timer, tokio's paused clock and the simulator included. qlog stamps events relative to `QlogConfig::start_time` on that clock rather than the streamer's own `std::time::Instant`. Address-validation tokens and their log read `moq_clock::wall()` instead of quinn's `TimeSource`, for portable 1970-2554 wall times; the simulator steps wall time with its clock, but paused tokio does not, so token expiry there follows the host's wall clock. +- **Time on [`kio::clock`](../kio)**: the crate's `Instant` is `kio::clock::Instant`, so one clock steps every timer, tokio's paused clock and the simulator included. qlog stamps events relative to `QlogConfig::start_time` on that clock rather than the streamer's own `std::time::Instant`. Address-validation tokens and their log read `kio::clock::wall()` instead of quinn's `TimeSource`, for portable 1970-2554 wall times; the simulator steps wall time with its clock, but paused tokio does not, so token expiry there follows the host's wall clock. - **Send groups** (`streams/schedule.rs`, `Connection::send_groups`): streams outside every group go first, in quinn's order; groups are served strictly by priority, with equal priorities sharing bytes by deficit round robin. A stream's priority is an `i64` ordering it only within its group, and `Streams::open` takes a `SendOptions { group, priority }` to start it there, like W3C WebTransport's send options. This replaces quinn's single pending-stream heap, so a port touching `PendingStreamsQueue` has to be redone against the schedule. moq-tokio's `quic::driver` and moq-uring's driver wrap a group in a shared `SendGroup` handle that closes on drop. - **Scheduled datagrams** (`Datagrams::send`): a datagram is queued by its `SendOptions`, in a send group (or ungrouped) at an `i64` priority, and scheduled with the group's streams, winning a tie with a stream of equal priority and spending the group's byte credit, instead of quinn's datagram-first FIFO in `populate_packet`. Sending never blocks: `datagram_send_buffer_size` is shared, and an overflow evicts the oldest datagram of the lowest-priority group. `SendDatagramError::Blocked` and `Event::DatagramsUnblocked` are gone, and a port touching the `// DATAGRAM` loop has to be redone against `StreamsState::write_frames`. - **Sharded connection IDs** (`RandomConnectionIdGenerator::set_shard`): every CID names shard `index` of a `count`-endpoint group in its first byte, modulo `count`, and sets a marker in its fourth byte, so a `SO_REUSEPORT` steering filter delivers a packet to the endpoint that issued its CID. `validate` refuses a CID without this shard's prefix and marker, so a misrouted packet is dropped instead of answered with a stateless reset. Not offered upstream; it serves moq-sock's per-core sharding. diff --git a/rs/moq-quic/benches/common/mod.rs b/rs/moq-quic/benches/common/mod.rs index 9b01efd13ae..cc1fda3ce6c 100644 --- a/rs/moq-quic/benches/common/mod.rs +++ b/rs/moq-quic/benches/common/mod.rs @@ -21,7 +21,7 @@ use criterion::{ Criterion, measurement::{Measurement, ValueFormatter, WallTime}, }; -use moq_clock::Instant; +use kio::clock::Instant; use moq_congestion::{Ack, Ce, Controller, ControllerFactory, ControllerMetrics, Init, Loss, Packet, Sent}; use moq_quic::{ ClientConfig, Connection, ConnectionHandle, ConnectionId, ConnectionIdGenerator, DatagramEvent, Endpoint, diff --git a/rs/moq-quic/clippy.toml b/rs/moq-quic/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-quic/clippy.toml +++ b/rs/moq-quic/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-quic/src/config/transport.rs b/rs/moq-quic/src/config/transport.rs index ea0850dab29..9c83e91765e 100644 --- a/rs/moq-quic/src/config/transport.rs +++ b/rs/moq-quic/src/config/transport.rs @@ -663,7 +663,7 @@ impl QlogConfig { let mut streamer = QlogStreamer::new( self.title, self.description, - moq_clock::now().into_std(), + kio::clock::now().into_std(), trace, qlog::events::EventImportance::Core, // `Instant` should have sub-microsecond precision on most platforms diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index f5d6bfa7881..95e477916c0 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -3470,7 +3470,7 @@ impl Connection { let token = Token::new( TokenPayload::Validation { ip: remote_addr.ip(), - issued: moq_clock::wall(), + issued: kio::clock::wall(), }, &mut self.rng, ); diff --git a/rs/moq-quic/src/endpoint.rs b/rs/moq-quic/src/endpoint.rs index 9bdd92cc8f9..cfcf9623529 100644 --- a/rs/moq-quic/src/endpoint.rs +++ b/rs/moq-quic/src/endpoint.rs @@ -824,7 +824,7 @@ impl Endpoint { let payload = TokenPayload::Retry { address: incoming.addresses.remote, orig_dst_cid: incoming.packet.header.dst_cid, - issued: moq_clock::wall(), + issued: kio::clock::wall(), }; let token = Token::new(payload, &mut self.rng).encode(&*server_config.token_key); diff --git a/rs/moq-quic/src/lib.rs b/rs/moq-quic/src/lib.rs index 4bb57c09f65..d4e5fbd8c8b 100644 --- a/rs/moq-quic/src/lib.rs +++ b/rs/moq-quic/src/lib.rs @@ -1,7 +1,7 @@ //! Low-level protocol logic for the QUIC protocol //! //! moq-quic has no networking code: the caller supplies transport timestamps, and address -//! validation reads the ambient `moq-clock` wall time. Most applications use the Tokio driver +//! validation reads the ambient `kio::clock` wall time. Most applications use the Tokio driver //! in `moq_tokio::quic::driver` instead. //! //! Use `moq_tokio::quic::driver` for Tokio, or drive this state machine from another runtime. @@ -100,7 +100,7 @@ use token_memory_cache::TokenMemoryCache; // Deal with time // MoQ's clock, so a caller-driven clock (a test's or the simulator's) reaches the state machine. -pub(crate) use moq_clock::{Instant, Wall}; +pub(crate) use kio::clock::{Instant, Wall}; pub(crate) use std::time::Duration; pub(crate) const UNIX_EPOCH: Wall = Wall::UNIX_EPOCH; diff --git a/rs/moq-quic/src/tests/token.rs b/rs/moq-quic/src/tests/token.rs index 2008fbfd966..b8f256b46a7 100644 --- a/rs/moq-quic/src/tests/token.rs +++ b/rs/moq-quic/src/tests/token.rs @@ -133,7 +133,7 @@ fn stateless_retry() { assert_eq!(pair.server.known_cids(), 0); } -#[moq_clock::test] +#[kio::test] async fn retry_token_expired() { let _guard = subscribe(); @@ -152,7 +152,7 @@ async fn retry_token_expired() { pair.drive_client(); // to expire retry token - moq_clock::sleep(retry_token_lifetime + Duration::from_millis(1)).await; + kio::clock::sleep(retry_token_lifetime + Duration::from_millis(1)).await; pair.drive(); assert_matches!( @@ -356,7 +356,7 @@ fn use_same_token_twice() { assert_eq!(pair.server.known_cids(), 0); } -#[moq_clock::test] +#[kio::test] async fn use_token_expired() { let _guard = subscribe(); let lifetime = Duration::from_secs(10000); @@ -393,7 +393,7 @@ async fn use_token_expired() { assert_eq!(pair.server.known_connections(), 0); assert_eq!(pair.server.known_cids(), 0); - moq_clock::sleep(lifetime + Duration::from_secs(1)).await; + kio::clock::sleep(lifetime + Duration::from_secs(1)).await; pair.server.handle_incoming = Box::new(|incoming| { assert!(!incoming.remote_address_validated()); diff --git a/rs/moq-quic/src/token.rs b/rs/moq-quic/src/token.rs index 7c9a5f8834a..44ab7cbbe57 100644 --- a/rs/moq-quic/src/token.rs +++ b/rs/moq-quic/src/token.rs @@ -141,7 +141,7 @@ impl IncomingToken { } if issued .checked_add(server_config.retry_token_lifetime) - .is_none_or(|expires| expires < moq_clock::wall()) + .is_none_or(|expires| expires < kio::clock::wall()) { return Err(InvalidRetryTokenError); } @@ -158,7 +158,7 @@ impl IncomingToken { } if issued .checked_add(server_config.validation_token.lifetime) - .is_none_or(|expires| expires < moq_clock::wall()) + .is_none_or(|expires| expires < kio::clock::wall()) { return Ok(unvalidated); } diff --git a/rs/moq-relay/Cargo.toml b/rs/moq-relay/Cargo.toml index bf0f01f892d..85698aa7208 100644 --- a/rs/moq-relay/Cargo.toml +++ b/rs/moq-relay/Cargo.toml @@ -70,7 +70,7 @@ http-cache-reqwest = { version = "1.0.0-alpha.6", features = ["manager-moka", "r humantime = { workspace = true } hyper-util = { workspace = true } moq-auth = { workspace = true, features = ["client"] } -moq-clock = { workspace = true, features = ["serde"] } +kio = { workspace = true, features = ["runtime", "serde"] } moq-net = { workspace = true } # The flow-control limits both QUIC runtimes take, for widening a peer's connection. moq-quic = { workspace = true, optional = true } @@ -109,10 +109,9 @@ sd-notify = { workspace = true } criterion = { workspace = true } # An HTTP/2 client, so the admission bench can hold many requests on one connection. h2 = { workspace = true } -kio = { path = "../kio" } -moq-auth = { path = "../moq-auth", features = ["client", "serve"] } # Clocks only the test moves, wall time included, so a grant's life is exact. -moq-clock = { path = "../moq-clock", features = ["manual", "sim"] } +kio = { path = "../kio", features = ["manual", "sim"] } +moq-auth = { path = "../moq-auth", features = ["client", "serve"] } moq-congestion = { path = "../moq-congestion" } # The shared session bench fills FETCH runs through the hidden `fuzz` module. moq-net = { path = "../moq-net", features = ["fuzz"] } diff --git a/rs/moq-relay/clippy.toml b/rs/moq-relay/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-relay/clippy.toml +++ b/rs/moq-relay/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-relay/src/acme/client.rs b/rs/moq-relay/src/acme/client.rs index 9e0f78eae62..00bd3a35c3a 100644 --- a/rs/moq-relay/src/acme/client.rs +++ b/rs/moq-relay/src/acme/client.rs @@ -5,7 +5,7 @@ //! that resolver to every TLS listener, so QUIC, HTTPS, and every worker serve //! the same certificate and pick up a renewal on their next handshake. -use moq_clock::Wall; +use kio::clock::Wall; use std::{ io, net::SocketAddr, @@ -161,8 +161,8 @@ impl Acme { let health = moq_tokio::accept::Health::new("acme"); // Readiness waits on issuance, so keep extending systemd's start timeout // rather than letting the unit's default kill the relay inside the budget. - let mut extend = moq_clock::interval(EXTEND_INTERVAL); - let deadline = moq_clock::sleep(self.timeout); + let mut extend = kio::clock::interval(EXTEND_INTERVAL); + let deadline = kio::clock::sleep(self.timeout); tokio::pin!(deadline); let mut last = None; let mut issued = false; @@ -211,13 +211,13 @@ impl Acme { let handshake = challenge.accept(stream); // The validator only needs the handshake, then closes. handshakes.spawn(async move { - let _ = moq_clock::timeout(CHALLENGE_TIMEOUT, handshake).await; + let _ = kio::clock::timeout(CHALLENGE_TIMEOUT, handshake).await; }); } } Err(err) => { if let Some(pause) = health.failed(&err) { - moq_clock::sleep(pause).await; + kio::clock::sleep(pause).await; } } }, @@ -265,7 +265,7 @@ async fn renew( // An unknown budget counts as spent, rather than risk the directory's limit. Err(err) => { tracing::error!(err = format!("{err:#}"), %domains, "failed to read the ACME failure record"); - Some(moq_clock::wall().saturating_add(FAILURE_WINDOW)) + Some(kio::clock::wall().saturating_add(FAILURE_WINDOW)) } }; if let Some(resume) = resume { @@ -274,7 +274,7 @@ async fn renew( resume = %humantime::format_rfc3339_seconds(resume.into()), "ACME renewal paused after {FAILURE_LIMIT} failed validations within the hour, short of the directory's limit; still serving the previous certificate" ); - moq_clock::sleep(resume.saturating_duration_since(moq_clock::wall())).await; + kio::clock::sleep(resume.saturating_duration_since(kio::clock::wall())).await; continue; } @@ -298,7 +298,7 @@ async fn renew( // Unrecorded, it would never count, so assume the budget is spent. Err(record) => { tracing::error!(%err, record = format!("{record:#}"), %domains, "ACME renewal validation failed and could not be recorded; pausing renewal for an hour"); - moq_clock::sleep(FAILURE_WINDOW).await; + kio::clock::sleep(FAILURE_WINDOW).await; } } } @@ -335,7 +335,7 @@ impl Failures { let Some(contents) = Cache::read(&self.path)? else { return Ok(Vec::new()); }; - let cutoff = moq_clock::wall() + let cutoff = kio::clock::wall() .checked_sub(FAILURE_WINDOW) .unwrap_or(Wall::UNIX_EPOCH); let mut recent = Vec::new(); @@ -357,7 +357,7 @@ impl Failures { /// Record a failure now, returning the recent ones including it. fn record(&self) -> anyhow::Result> { let mut recent = self.recent()?; - recent.push(moq_clock::wall()); + recent.push(kio::clock::wall()); let lines: String = recent .iter() .map(|at| format!("{}\n", at.saturating_duration_since(Wall::UNIX_EPOCH).as_secs())) @@ -377,7 +377,7 @@ impl Failures { fn refuse(&self, failed: &[Wall], domains: &str, addr: SocketAddr, last: Option<&str>) -> anyhow::Error { let retry = failed .first() - .map_or(Some(moq_clock::wall()), |oldest| oldest.checked_add(FAILURE_WINDOW)) + .map_or(Some(kio::clock::wall()), |oldest| oldest.checked_add(FAILURE_WINDOW)) .map(|retry| humantime::format_rfc3339_seconds(retry.into()).to_string()) .unwrap_or_else(|| "the supported wall-time range".to_string()); let last = last.map(|last| format!("; last error: {last}")).unwrap_or_default(); diff --git a/rs/moq-relay/src/acme/tests.rs b/rs/moq-relay/src/acme/tests.rs index 5a5e73a4194..6ba65d38c48 100644 --- a/rs/moq-relay/src/acme/tests.rs +++ b/rs/moq-relay/src/acme/tests.rs @@ -736,7 +736,7 @@ fn bad_auth() -> rustls_acme::EventError { /// Failed renewal validations stop ordering at the startup budget, which a start /// inside the window honors too, and renewal resumes once the oldest leaves it. -#[moq_clock::test] +#[kio::test] async fn renewal_pauses_once_failed_validations_spend_the_budget() { let dir = tempfile::tempdir().unwrap(); let mut acme = uncontacted(dir.path()); @@ -755,15 +755,15 @@ async fn renewal_pauses_once_failed_validations_spend_the_budget() { .chain(futures::stream::pending()) .inspect({ let polled = polled.clone(); - move |_| polled.borrow_mut().push(moq_clock::wall()) + move |_| polled.borrow_mut().push(kio::clock::wall()) }); - let start = moq_clock::wall(); + let start = kio::clock::wall(); let failures = Failures { path: acme.failures.path.clone(), }; - let renewal = moq_clock::sim::spawn(renew(events, failures, DOMAIN.into())); + let renewal = kio::clock::sim::spawn(renew(events, failures, DOMAIN.into())); - moq_clock::sleep(FAILURE_WINDOW - Duration::from_secs(1)).await; + kio::clock::sleep(FAILURE_WINDOW - Duration::from_secs(1)).await; assert_eq!( *polled.borrow(), [start; FAILURE_LIMIT], @@ -780,8 +780,8 @@ async fn renewal_pauses_once_failed_validations_spend_the_budget() { "{message}" ); - moq_clock::sleep(Duration::from_secs(1)).await; - moq_clock::sim::idle().await; + kio::clock::sleep(Duration::from_secs(1)).await; + kio::clock::sim::idle().await; let resumed = start + FAILURE_WINDOW; assert_eq!(*polled.borrow(), [start, start, start, resumed, resumed]); assert!( diff --git a/rs/moq-relay/src/auth.rs b/rs/moq-relay/src/auth.rs index 3e978f447df..888df95ec77 100644 --- a/rs/moq-relay/src/auth.rs +++ b/rs/moq-relay/src/auth.rs @@ -515,7 +515,7 @@ pub struct Lease { /// grant has no driver, and an auth server's may be mid-outage. Fixed on the ambient /// clock when the grant arrives, so re-polling [`ended`](Self::ended) never /// restarts the countdown. - expires: Option, + expires: Option, /// The session's stats context, moved to a re-checked tier. stats: moq_net::stats::Session, } @@ -618,7 +618,7 @@ impl Lease { loop { let expire = async { match self.expires { - Some(at) => moq_clock::sleep_until(at).await, + Some(at) => kio::clock::sleep_until(at).await, None => std::future::pending().await, } }; @@ -1408,37 +1408,41 @@ mod tests { /// The session supervisor re-polls `ended` on every nudge; that must not /// restart the countdown to `expires`. - #[moq_clock::test] + #[kio::test] async fn re_polling_keeps_the_expiry_deadline() { use std::time::Duration; - let start = moq_clock::now(); + let start = kio::clock::now(); let mut grant = Grant::new(patterns(&["**"]), patterns(&["**"])); - grant.expires = Some(moq_clock::wall() + Duration::from_secs(10)); + grant.expires = Some(kio::clock::wall() + Duration::from_secs(10)); let mut lease = Lease::new("/room", lease::Consumer::fixed(grant)).unwrap(); for _ in 0..9 { - assert!(moq_clock::timeout(Duration::from_secs(1), lease.ended()).await.is_err()); + assert!( + kio::clock::timeout(Duration::from_secs(1), lease.ended()) + .await + .is_err() + ); } assert_eq!(lease.ended().await, lease::Reason::Expired); assert_eq!( - moq_clock::now(), + kio::clock::now(), start + Duration::from_secs(10), "expired at the deadline despite re-polling" ); } - #[moq_clock::test] + #[kio::test] async fn an_expired_grant_ends_at_once() { use std::time::Duration; let mut grant = Grant::new(patterns(&["**"]), patterns(&["**"])); - grant.expires = Some(moq_clock::wall() - Duration::from_secs(1)); + grant.expires = Some(kio::clock::wall() - Duration::from_secs(1)); assert!(matches!(grant.validate(), Err(moq_auth::Error::GrantExpired))); - let start = moq_clock::now(); + let start = kio::clock::now(); let mut lease = Lease::new("/room", lease::Consumer::fixed(grant)).unwrap(); assert_eq!(lease.ended().await, lease::Reason::Expired); - assert_eq!(moq_clock::now(), start, "no grace after expiry"); + assert_eq!(kio::clock::now(), start, "no grace after expiry"); } #[test] diff --git a/rs/moq-relay/src/auth/refresh.rs b/rs/moq-relay/src/auth/refresh.rs index be3ae4845b6..dbb0480ceae 100644 --- a/rs/moq-relay/src/auth/refresh.rs +++ b/rs/moq-relay/src/auth/refresh.rs @@ -41,7 +41,7 @@ struct Waiting { request: auth::Request, facts: moq_auth::Request, /// When its admission times out, counted from its arrival. - deadline: moq_clock::Instant, + deadline: kio::clock::Instant, } impl Waiting { @@ -53,7 +53,7 @@ impl Waiting { struct Credential { consumer: lease::Consumer, grant: Grant, - expires: Option, + expires: Option, issued: Option, initial: bool, } @@ -217,7 +217,7 @@ impl Refresh { self.waiting.push_back(Waiting { request, facts, - deadline: moq_clock::now() + super::ATTACH_TIMEOUT, + deadline: kio::clock::now() + super::ATTACH_TIMEOUT, }); self.dispatch(); } @@ -240,7 +240,7 @@ impl Refresh { facts, deadline, } = waiting; - if deadline <= moq_clock::now() { + if deadline <= kio::clock::now() { refuse(request, super::timed_out()); continue; } @@ -257,7 +257,7 @@ impl Refresh { let answered = tokio::select! { biased; answered = &mut answer => Some(answered), - () = moq_clock::sleep_until(deadline) => None, + () = kio::clock::sleep_until(deadline) => None, }; let (result, settling) = match answered { Some(answered) => (super::answered_with(answered).map(|(consumer, _)| consumer), None), @@ -276,7 +276,7 @@ impl Refresh { /// Refuse the waiting tokens whose admission timed out before a slot freed. fn expire(&mut self) { - let now = moq_clock::now(); + let now = kio::clock::now(); while let Some(waiting) = self.waiting.front() && (waiting.deadline <= now || waiting.withdrawn()) { @@ -308,7 +308,7 @@ impl Refresh { let expiry = self.waiting.front().map(|waiting| waiting.deadline); let expired = async { match expiry { - Some(at) => moq_clock::sleep_until(at).await, + Some(at) => kio::clock::sleep_until(at).await, None => std::future::pending().await, } }; @@ -414,10 +414,10 @@ impl Refresh { } /// A credential's grant changed, expired, or was revoked by the decider. -async fn changed(consumer: &mut lease::Consumer, expires: Option) -> Change { +async fn changed(consumer: &mut lease::Consumer, expires: Option) -> Change { let expire = async { match expires { - Some(at) => moq_clock::sleep_until(at).await, + Some(at) => kio::clock::sleep_until(at).await, None => std::future::pending().await, } }; @@ -481,14 +481,14 @@ mod tests { fn grant(prefix: &str, seconds: u64) -> Grant { let mut grant = Grant::new(prefix.parse::().unwrap(), moq_auth::Patterns::new()); - grant.expires = Some(moq_clock::wall() + Duration::from_secs(seconds)); + grant.expires = Some(kio::clock::wall() + Duration::from_secs(seconds)); grant } /// Make the test runtime's clock one that only the test moves, wall time included, /// so a grant's life is measured exactly. Call it before anything reads the clock. - fn manual() -> moq_clock::Installed { - moq_clock::Manual::new().install(&tokio::runtime::Handle::current()) + fn manual() -> kio::clock::Installed { + kio::clock::Manual::new().install(&tokio::runtime::Handle::current()) } /// Whether `future` is still pending once every task has settled. Paused tokio @@ -938,7 +938,7 @@ mod tests { /// replacement token granted on `replacement` and its owner's grant expired, so only /// the in-band credential holds it. Returns the owner, which hears how the lease ended. async fn renewed( - clock: &moq_clock::Installed, + clock: &kio::clock::Installed, replacement: lease::Consumer, ) -> ( lease::Producer, diff --git a/rs/moq-relay/src/cache.rs b/rs/moq-relay/src/cache.rs index deab5256d8f..381a2cec0f8 100644 --- a/rs/moq-relay/src/cache.rs +++ b/rs/moq-relay/src/cache.rs @@ -168,8 +168,8 @@ fn total_memory() -> u64 { /// relay's construction shapes. Returns on the first tick after that. async fn governor(pool: cache::PoolWeak, capacity: Option, headroom: u64) { let mut sys = sysinfo::System::new(); - let mut interval = moq_clock::interval(GOVERNOR_INTERVAL); - interval.set_missed_tick_behavior(moq_clock::MissedTickBehavior::Delay); + let mut interval = kio::clock::interval(GOVERNOR_INTERVAL); + interval.set_missed_tick_behavior(kio::clock::MissedTickBehavior::Delay); loop { interval.tick().await; diff --git a/rs/moq-relay/src/cluster.rs b/rs/moq-relay/src/cluster.rs index 9a86b5e1846..9d0b78ac2e6 100644 --- a/rs/moq-relay/src/cluster.rs +++ b/rs/moq-relay/src/cluster.rs @@ -1841,10 +1841,10 @@ impl Cluster { dialed: DialMap, http: ClientWithMiddleware, ) { - let mut tick = moq_clock::interval(CONNECT_API_POLL_INTERVAL); + let mut tick = kio::clock::interval(CONNECT_API_POLL_INTERVAL); // A slow fetch must not bank missed ticks into a catch-up burst; just resume // the cadence from the next whole interval. - tick.set_missed_tick_behavior(moq_clock::MissedTickBehavior::Skip); + tick.set_missed_tick_behavior(kio::clock::MissedTickBehavior::Skip); loop { tick.tick().await; @@ -1975,7 +1975,7 @@ impl Cluster { let mut redial = Redial::default(); loop { - let started = moq_clock::now(); + let started = kio::clock::now(); let result = self.run_remote_once(&addrs, target).await; let elapsed = started.elapsed(); @@ -1986,7 +1986,7 @@ impl Cluster { } let wait = redial.next(&mut rand::rng()); - moq_clock::sleep(wait).await; + kio::clock::sleep(wait).await; } } diff --git a/rs/moq-relay/src/listener.rs b/rs/moq-relay/src/listener.rs index 88f4258c31e..75e2b0c90bb 100644 --- a/rs/moq-relay/src/listener.rs +++ b/rs/moq-relay/src/listener.rs @@ -189,7 +189,7 @@ impl AddrListener for Listener { } Err(err) => { if let Some(delay) = self.health.failed(&err) { - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; } } } diff --git a/rs/moq-relay/src/listener/idle.rs b/rs/moq-relay/src/listener/idle.rs index 49483094657..82966e36ee0 100644 --- a/rs/moq-relay/src/listener/idle.rs +++ b/rs/moq-relay/src/listener/idle.rs @@ -7,7 +7,7 @@ use axum::{ use axum_server::accept::Accept; use futures::{future::BoxFuture, task::AtomicWaker}; use http_body::Body as _; -use moq_clock::{Instant, Sleep}; +use kio::clock::{Instant, Sleep}; use std::{ io, pin::Pin, @@ -56,7 +56,7 @@ where let since = Instant::now(); Box::pin(async move { let (inner, service) = match timeout.and_then(|timeout| since.checked_add(timeout)) { - Some(deadline) => moq_clock::timeout_at(deadline, accepted) + Some(deadline) => kio::clock::timeout_at(deadline, accepted) .await .map_err(|_| io::Error::new(io::ErrorKind::TimedOut, "HTTP connection idle deadline"))??, None => accepted.await?, @@ -70,7 +70,7 @@ where }), wake: AtomicWaker::new(), }); - let timer = Box::pin(moq_clock::sleep(Duration::ZERO)); + let timer = Box::pin(kio::clock::sleep(Duration::ZERO)); Ok(( Io { inner, diff --git a/rs/moq-relay/src/session.rs b/rs/moq-relay/src/session.rs index c6ad0101aa2..e25a98918ac 100644 --- a/rs/moq-relay/src/session.rs +++ b/rs/moq-relay/src/session.rs @@ -5,7 +5,7 @@ //! a push asks the lease to re-check now, and the server's reply is the verdict. //! One-shot HTTP and LAN peers are not sessions and stay out. -use moq_clock::Wall; +use kio::clock::Wall; use std::collections::HashMap; use std::net::{IpAddr, SocketAddr}; use std::sync::atomic::{AtomicU64, Ordering}; @@ -98,7 +98,7 @@ impl Registry { id.clone(), Entry { request, - started: moq_clock::wall(), + started: kio::clock::wall(), handle: handle.clone(), }, ); @@ -439,7 +439,7 @@ pub struct View { /// The verified client certificate, when one was presented. pub tls: Option, /// When the session was admitted, as unix seconds. - #[serde_as(as = "moq_clock::serde::UnixSeconds")] + #[serde_as(as = "kio::clock::serde::UnixSeconds")] pub started: Wall, } diff --git a/rs/moq-relay/src/shutdown.rs b/rs/moq-relay/src/shutdown.rs index cec15abfa13..c6bdf4829f9 100644 --- a/rs/moq-relay/src/shutdown.rs +++ b/rs/moq-relay/src/shutdown.rs @@ -14,7 +14,7 @@ use std::{sync::Arc, time::Duration}; -use moq_clock::Instant; +use kio::clock::Instant; use tokio::sync::watch; /// Fires the relay-wide shutdown broadcast. Held by `Relay::run` for the OS @@ -198,7 +198,7 @@ impl Observer { Err(_) => None, }; match deadline { - Some(deadline) => moq_clock::sleep_until(deadline).await, + Some(deadline) => kio::clock::sleep_until(deadline).await, None => std::future::pending().await, } } @@ -324,7 +324,7 @@ impl Observer { tokio::select! { biased; _ = session.closed() => return, - () = moq_clock::sleep_until(deadline) => {} + () = kio::clock::sleep_until(deadline) => {} } tracing::debug!("peer did not leave before the drain deadline; closing"); session.abort(moq_net::Error::GoawayTimeout); diff --git a/rs/moq-relay/src/stun.rs b/rs/moq-relay/src/stun.rs index 01facab555c..79483c68d85 100644 --- a/rs/moq-relay/src/stun.rs +++ b/rs/moq-relay/src/stun.rs @@ -7,7 +7,7 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::time::Duration; use anyhow::Context; -use moq_clock::Instant; +use kio::clock::Instant; use serde::{Deserialize, Serialize}; use stun_types::attribute::XorMappedAddress; use stun_types::message::{BINDING, Message, MessageClass, MessageHeader, MessageWriteMutSlice}; diff --git a/rs/moq-relay/src/web.rs b/rs/moq-relay/src/web.rs index 92d78a7961c..ec3b49ff7ab 100644 --- a/rs/moq-relay/src/web.rs +++ b/rs/moq-relay/src/web.rs @@ -366,7 +366,7 @@ impl Web { let state = Arc::get_mut(&mut self.state).expect("with_timeout called after routes were built"); // hyper adds the header timeout to the clock unchecked, so an unreachable // one would panic on every connection. - state.timeout = timeout.filter(|timeout| moq_clock::now().checked_add(*timeout).is_some()); + state.timeout = timeout.filter(|timeout| kio::clock::now().checked_add(*timeout).is_some()); self } @@ -1012,7 +1012,7 @@ async fn admit_http( // HTTP read has no handshake deadline to inherit, so the bound starts here. let admit = state.auth.admit(request); let lease = match state.timeout { - Some(timeout) => moq_clock::timeout(timeout, admit) + Some(timeout) => kio::clock::timeout(timeout, admit) .await .unwrap_or_else(|_| Err(auth::Error::Unavailable("the admission timed out".into()))), None => admit.await, @@ -1093,11 +1093,11 @@ async fn serve_fetch( tracing::info!(%broadcast, %track, "fetching track"); - let deadline = moq_clock::now() + tokio::time::Duration::from_secs(30); + let deadline = kio::clock::now() + tokio::time::Duration::from_secs(30); // The lease outlives this handler: the body streams after it returns, so the // response holds the lease and ends it when the last frame is served. - let result = moq_clock::timeout_at(deadline, async { + let result = kio::clock::timeout_at(deadline, async { // NOTE: The auth token is already scoped to the broadcast. // Block until a route covers the broadcast (within the fetch deadline) so // freshly-connected subscribers don't get a spurious 404 before the announce arrives. @@ -1152,7 +1152,7 @@ async fn serve_fetch( /// `end` event carries the outcome. struct ServeGroup { group: moq_net::group::Consumer, - deadline: moq_clock::Instant, + deadline: kio::clock::Instant, /// Taken when the body ends, so the reason is reported once. lease: Option, } @@ -1163,7 +1163,7 @@ impl ServeGroup { return Ok(None); }; tokio::select! { - res = moq_clock::timeout_at(self.deadline, self.group.read_frame()) => match res { + res = kio::clock::timeout_at(self.deadline, self.group.read_frame()) => match res { Ok(res) => Ok(res?.map(|frame| frame.payload)), Err(_) => Err(moq_net::Error::Timeout), }, diff --git a/rs/moq-relay/tests/integration/auth_lifetime.rs b/rs/moq-relay/tests/integration/auth_lifetime.rs index 2fcd90c8104..ef23042e33f 100644 --- a/rs/moq-relay/tests/integration/auth_lifetime.rs +++ b/rs/moq-relay/tests/integration/auth_lifetime.rs @@ -149,7 +149,7 @@ fn all() -> Patterns { /// Everything under the dialed path, re-checked every second, good for `expires_in`. fn grant(expires_in: Duration) -> Grant { let mut grant = Grant::new(all(), all()); - grant.expires = Some(moq_clock::wall() + expires_in); + grant.expires = Some(kio::clock::wall() + expires_in); grant.revalidate = Some(Duration::from_secs(1)); grant } @@ -1501,20 +1501,20 @@ const EXPIRES: Duration = Duration::from_secs(3); /// Make the test runtime's clock one that only the test moves, wall time included, /// so a grant's life is measured exactly. Call it before anything reads the clock. -fn manual() -> moq_clock::Installed { - moq_clock::Manual::new().install(&tokio::runtime::Handle::current()) +fn manual() -> kio::clock::Installed { + kio::clock::Manual::new().install(&tokio::runtime::Handle::current()) } /// Everything under the dialed path, until [`EXPIRES`] from now on the ambient clock. fn expiring() -> Grant { let mut grant = Grant::new(all(), all()); - grant.expires = Some(moq_clock::wall() + EXPIRES); + grant.expires = Some(kio::clock::wall() + EXPIRES); grant } /// Supervise an in-memory session admitted on `consumer`, whose grant nobody renews, /// and assert it closes at exactly [`EXPIRES`] on `clock`. -async fn closes_at_expires(clock: &moq_clock::Installed, consumer: moq_auth::lease::Consumer) { +async fn closes_at_expires(clock: &kio::clock::Installed, consumer: moq_auth::lease::Consumer) { let (auth, mut admissions) = moq_relay::auth::Auth::embedded("test-relay"); let (lease, ()) = tokio::join!(auth.admit(auth.request(moq_auth::Transport::Tcp, "/room")), async { admissions.next().await.expect("an admission").grant(consumer); @@ -1724,7 +1724,7 @@ async fn quic_and_webtransport_report_distinct_auth_transports() { async fn in_band_tokens_widen_and_withdraw_live_prefixes() { for scheme in ["tcp", "ws"] { let mut initial = Grant::new(all(), "a/**".parse::().unwrap()); - initial.expires = Some(moq_clock::wall() + Duration::from_secs(3600)); + initial.expires = Some(kio::clock::wall() + Duration::from_secs(3600)); let script = Script::new(initial); let auth = build_auth(script.spawn().await); let (port, relay) = if scheme == "tcp" { @@ -1776,7 +1776,7 @@ async fn in_band_tokens_widen_and_withdraw_live_prefixes() { .unwrap(); let mut a_sub = a_read.track("video").unwrap().subscribe(None).await.unwrap(); let mut replacement = Grant::new(all(), "b/**".parse::().unwrap()); - replacement.expires = Some(moq_clock::wall() + Duration::from_secs(3600)); + replacement.expires = Some(kio::clock::wall() + Duration::from_secs(3600)); script.on_connect(Answer::Grant(replacement)); let token = tokio::time::timeout(TIMEOUT, subscriber.auth().add("replacement")) .await diff --git a/rs/moq-relay/tests/integration/cluster_drain.rs b/rs/moq-relay/tests/integration/cluster_drain.rs index 30c4c1fd54d..0145a9f56ba 100644 --- a/rs/moq-relay/tests/integration/cluster_drain.rs +++ b/rs/moq-relay/tests/integration/cluster_drain.rs @@ -132,7 +132,7 @@ async fn peer(name: &str, forwarder: &Forwarder) -> (cluster::Cluster, moq_net:: } /// Advance the manual clock by `total`, one [`STEP`] at a time. -async fn pass(clock: &moq_clock::Installed, total: Duration) { +async fn pass(clock: &kio::clock::Installed, total: Duration) { let mut passed = Duration::ZERO; while passed < total { clock.advance(STEP); @@ -147,7 +147,7 @@ fn draining_relay_keeps_its_peers_until_it_restarts() { } async fn draining_relay_keeps_its_peers_until_it_restarts_inner() { - let clock = moq_clock::Manual::new().install(&tokio::runtime::Handle::current()); + let clock = kio::clock::Manual::new().install(&tokio::runtime::Handle::current()); let (b, b_addr, _b_broadcast) = relay("b").await; let b_origin = b.cluster().origin.clone(); diff --git a/rs/moq-relay/tests/integration/refusals.rs b/rs/moq-relay/tests/integration/refusals.rs index 9db71a5a70f..896db42c066 100644 --- a/rs/moq-relay/tests/integration/refusals.rs +++ b/rs/moq-relay/tests/integration/refusals.rs @@ -375,7 +375,7 @@ async fn expired_verified_tokens_count_under_the_token_root_and_auth_tier() { let mut claims = moq_auth::Claims::default() .with_root("verified/tenant") .with_subscribe([moq_auth::Pattern::all()]); - claims.expires = Some(moq_clock::Wall::UNIX_EPOCH + Duration::from_secs(1)); + claims.expires = Some(kio::clock::Wall::UNIX_EPOCH + Duration::from_secs(1)); let token = key.sign(&claims).unwrap(); for tier in [None, Some("edge")] { let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); diff --git a/rs/moq-relay/tests/integration/runtime_uring.rs b/rs/moq-relay/tests/integration/runtime_uring.rs index 75fcebe8ed5..624b1a9ee33 100644 --- a/rs/moq-relay/tests/integration/runtime_uring.rs +++ b/rs/moq-relay/tests/integration/runtime_uring.rs @@ -1062,7 +1062,7 @@ fn uring_workers_bound_stalled_handshakes() { .enable_all() .build() .expect("runtime"); - let clock = moq_clock::Manual::new().install(runtime.handle()); + let clock = kio::clock::Manual::new().install(runtime.handle()); runtime.block_on(async move { let dir = tempfile::tempdir().expect("tempdir"); let (cert, key) = certificate(dir.path()); diff --git a/rs/moq-relay/tests/integration/session_revalidate.rs b/rs/moq-relay/tests/integration/session_revalidate.rs index c9ac5dbcc54..dc1cc3dc6ef 100644 --- a/rs/moq-relay/tests/integration/session_revalidate.rs +++ b/rs/moq-relay/tests/integration/session_revalidate.rs @@ -99,7 +99,7 @@ fn all() -> Patterns { /// A grant that lasts an hour and would not re-check on its own during a test. fn grant() -> Grant { let mut grant = Grant::new(all(), all()); - grant.expires = Some(moq_clock::wall() + Duration::from_secs(3600)); + grant.expires = Some(kio::clock::wall() + Duration::from_secs(3600)); grant.revalidate = Some(Duration::from_secs(3600)); grant } diff --git a/rs/moq-room/Cargo.toml b/rs/moq-room/Cargo.toml index 23bb15d19c4..fed15448a0d 100644 --- a/rs/moq-room/Cargo.toml +++ b/rs/moq-room/Cargo.toml @@ -14,9 +14,8 @@ keywords = ["quic", "webtransport", "conferencing", "live"] categories = ["multimedia", "network-programming"] [dependencies] -kio = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-auth = { workspace = true } -moq-clock = { workspace = true } moq-json = { workspace = true } moq-net = { workspace = true } thiserror = { workspace = true } diff --git a/rs/moq-room/clippy.toml b/rs/moq-room/clippy.toml index 9460b0fd5c8..1fc5f0c2931 100644 --- a/rs/moq-room/clippy.toml +++ b/rs/moq-room/clippy.toml @@ -1,11 +1,11 @@ disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, ] -disallowed-types = [{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" }] +disallowed-types = [{ path = "std::time::SystemTime", reason = "use kio::clock::Wall" }] diff --git a/rs/moq-room/src/chat.rs b/rs/moq-room/src/chat.rs index 82b6c807e43..5d35bfd5b36 100644 --- a/rs/moq-room/src/chat.rs +++ b/rs/moq-room/src/chat.rs @@ -2,7 +2,7 @@ //! Sender identity comes from the broadcast, not the payload. use crate::Error; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::{broadcast, track}; use std::{ collections::VecDeque, @@ -24,7 +24,7 @@ pub type Event = moq_json::window::Event; /// module left kio. Built on web-async so tokio::time::pause advances it in tests. struct Deadline { at: Option, - sleep: Option>>, + sleep: Option>>, } impl Deadline { @@ -44,8 +44,8 @@ impl Deadline { fn poll(&mut self, waiter: &kio::Waiter) -> Poll<()> { let Some(at) = self.at else { return Poll::Pending }; - let sleep = self.sleep.get_or_insert_with(|| Box::pin(moq_clock::sleep_until(at))); - if at <= moq_clock::now() { + let sleep = self.sleep.get_or_insert_with(|| Box::pin(kio::clock::sleep_until(at))); + if at <= kio::clock::now() { return Poll::Ready(()); } waiter.poll_future(sleep.as_mut()) @@ -92,12 +92,12 @@ impl Publisher { self.prune()?; self.producer .push(moq_net::Timed::from(&text.to_owned()).at(moq_net::Timestamp::now()))?; - self.expires.push_back(moq_clock::now() + HISTORY); + self.expires.push_back(kio::clock::now() + HISTORY); Ok(()) } fn prune(&mut self) -> Result<(), Error> { - let now = moq_clock::now(); + let now = kio::clock::now(); let count = self.expires.iter().take_while(|expires| **expires <= now).count(); if count == 0 { return Ok(()); diff --git a/rs/moq-rtc/Cargo.toml b/rs/moq-rtc/Cargo.toml index e3ec0e5385b..9f73a89af70 100644 --- a/rs/moq-rtc/Cargo.toml +++ b/rs/moq-rtc/Cargo.toml @@ -27,7 +27,7 @@ axum = { workspace = true, optional = true } bytes = { workspace = true } hang = { workspace = true } # Drives each str0m connection over its UDP socket. -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-ice = { workspace = true } moq-mux = { workspace = true } moq-net = { workspace = true } diff --git a/rs/moq-rtc/clippy.toml b/rs/moq-rtc/clippy.toml index d66a788c262..f67f578fea2 100644 --- a/rs/moq-rtc/clippy.toml +++ b/rs/moq-rtc/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. # str0m sender reports carry SystemTime; convert at that boundary. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-rtc/src/client/whep.rs b/rs/moq-rtc/src/client/whep.rs index 444232eebc3..4c89f58d4fc 100644 --- a/rs/moq-rtc/src/client/whep.rs +++ b/rs/moq-rtc/src/client/whep.rs @@ -22,7 +22,7 @@ pub(crate) async fn dial(client: &Client, url: Url, broadcast: moq_net::broadcas let sink = Box::new(IngestSink::new(broadcast, config)?); let socket = session::bind_udp(&client.config().ice_candidates).await?; - let mut rtc = Rtc::new(moq_clock::now().into_std()); + let mut rtc = Rtc::new(kio::clock::now().into_std()); for addr in socket.locals() { let cand = Candidate::host(*addr, "udp").map_err(Error::rtc)?; rtc.add_local_candidate(cand); diff --git a/rs/moq-rtc/src/egress.rs b/rs/moq-rtc/src/egress.rs index 7806aab986e..993d4070178 100644 --- a/rs/moq-rtc/src/egress.rs +++ b/rs/moq-rtc/src/egress.rs @@ -14,7 +14,7 @@ use std::collections::VecDeque; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use bytes::Bytes; use hang::catalog::{AudioCodec, VideoCodecKind}; diff --git a/rs/moq-rtc/src/server/whep.rs b/rs/moq-rtc/src/server/whep.rs index bbadda817fb..9c097e987ff 100644 --- a/rs/moq-rtc/src/server/whep.rs +++ b/rs/moq-rtc/src/server/whep.rs @@ -157,7 +157,7 @@ pub async fn accept( let (creds, inbound, registration) = mux.register(); let mut rtc = session::rtc_config_with_codecs(&codecs) .set_local_ice_credentials(creds) - .build(moq_clock::now().into_std()); + .build(kio::clock::now().into_std()); for addr in mux.candidates() { let cand = Candidate::host(*addr, "udp").map_err(Error::rtc)?; rtc.add_local_candidate(cand); @@ -206,11 +206,11 @@ fn is_sdp(headers: &HeaderMap) -> bool { /// one, would park the handler forever. No route by the deadline is /// [`moq_net::Error::Unroutable`], so the WHEP client sees a 404 and retries (typical). async fn resolve(subscriber: &moq_net::origin::Consumer, path: moq_net::Path) -> Result { - let deadline = moq_clock::now() + CATALOG_TIMEOUT; - let broadcast = moq_clock::timeout_at(deadline, subscriber.routed_broadcast(path)) + let deadline = kio::clock::now() + CATALOG_TIMEOUT; + let broadcast = kio::clock::timeout_at(deadline, subscriber.routed_broadcast(path)) .await .map_err(|_| Error::Moq(moq_net::Error::Unroutable))??; - moq_clock::timeout_at( + kio::clock::timeout_at( deadline, EgressSource::new(moq_mux::Source::new(subscriber.clone(), broadcast)), ) @@ -276,7 +276,7 @@ mod tests { .with_subscriber(sub_origin.clone()) .with_reconnect(false); let url: url::Url = format!("tcp://{addr}/").parse().expect("url"); - let connection = moq_clock::timeout(TIMEOUT, client.connect(url).established()) + let connection = kio::clock::timeout(TIMEOUT, client.connect(url).established()) .await .expect("connect timed out") .expect("connect"); @@ -328,7 +328,7 @@ mod tests { let _router = super::router(crate::server::Server::new(Default::default()), sub_origin.consume()); let missing = sub_origin.consume().follow("missing").expect("follow"); - moq_clock::timeout(TIMEOUT, missing.synced()) + kio::clock::timeout(TIMEOUT, missing.synced()) .await .expect("sync timed out"); diff --git a/rs/moq-rtc/src/server/whip.rs b/rs/moq-rtc/src/server/whip.rs index 2c0835f67c5..b3f02aa11a7 100644 --- a/rs/moq-rtc/src/server/whip.rs +++ b/rs/moq-rtc/src/server/whip.rs @@ -142,7 +142,7 @@ pub async fn accept( let (creds, inbound, registration) = mux.register(); let mut rtc = RtcConfig::new() .set_local_ice_credentials(creds) - .build(moq_clock::now().into_std()); + .build(kio::clock::now().into_std()); for addr in mux.candidates() { let cand = Candidate::host(*addr, "udp").map_err(Error::rtc)?; rtc.add_local_candidate(cand); diff --git a/rs/moq-rtc/src/session.rs b/rs/moq-rtc/src/session.rs index 5307ae84fd7..c32da6f4d98 100644 --- a/rs/moq-rtc/src/session.rs +++ b/rs/moq-rtc/src/session.rs @@ -12,7 +12,7 @@ use std::collections::{HashMap, HashSet}; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; use std::sync::Arc; -use moq_clock::Instant; +use kio::clock::Instant; use str0m::{Candidate, Event, Rtc}; use tokio::net::UdpSocket; @@ -431,10 +431,10 @@ struct SenderAnchor { } impl SenderAnchor { - fn new(sender: str0m::rtp::rtcp::SenderInfo) -> std::result::Result { - let wall = moq_clock::Wall::try_from(sender.ntp_time)?; + fn new(sender: str0m::rtp::rtcp::SenderInfo) -> std::result::Result { + let wall = kio::clock::Wall::try_from(sender.ntp_time)?; Ok(Self { - ntp_us: wall.saturating_duration_since(moq_clock::Wall::UNIX_EPOCH).as_micros() as i128, + ntp_us: wall.saturating_duration_since(kio::clock::Wall::UNIX_EPOCH).as_micros() as i128, rtp_us: media_time_to_micros(&sender.rtp_time) as i128, }) } @@ -556,7 +556,7 @@ pub fn rtc_config_with_codecs(codecs: &[str0m::format::Codec]) -> str0m::RtcConf /// [`rtc_config_with_codecs`] directly so it can inject the mux's known /// credentials before building. pub fn rtc_with_codecs(codecs: &[str0m::format::Codec]) -> Rtc { - rtc_config_with_codecs(codecs).build(moq_clock::now().into_std()) + rtc_config_with_codecs(codecs).build(kio::clock::now().into_std()) } /// Bind an ephemeral UDP socket for a single client session, read by its own diff --git a/rs/moq-rtmp/Cargo.toml b/rs/moq-rtmp/Cargo.toml index 9dc64a44eb4..08caf86f3ae 100644 --- a/rs/moq-rtmp/Cargo.toml +++ b/rs/moq-rtmp/Cargo.toml @@ -35,7 +35,7 @@ bytes = { workspace = true } futures = { workspace = true } hang = { workspace = true } hmac = "0.13" -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-mux = { workspace = true } moq-net = { workspace = true } rand = { workspace = true } @@ -54,7 +54,7 @@ tracing = { workspace = true } [dev-dependencies] criterion = { workspace = true } -moq-clock = { path = "../moq-clock", features = ["sim"] } +kio = { path = "../kio", features = ["sim"] } # The RTMPS test borrows moq-tokio's self-signed cert generation to build a # `rustls::ServerConfig`. No transport feature: a QUIC backend here would be # unified into every other crate a `--workspace` build selects, which is exactly diff --git a/rs/moq-rtmp/clippy.toml b/rs/moq-rtmp/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-rtmp/clippy.toml +++ b/rs/moq-rtmp/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-rtmp/src/rml/sessions/client/mod.rs b/rs/moq-rtmp/src/rml/sessions/client/mod.rs index 1ee83dab3ce..79abe973e08 100644 --- a/rs/moq-rtmp/src/rml/sessions/client/mod.rs +++ b/rs/moq-rtmp/src/rml/sessions/client/mod.rs @@ -24,7 +24,7 @@ use crate::rml::messages::{RtmpMessage, UserControlEventType}; use crate::rml::sessions::StreamMetadata; use crate::rml::time::RtmpTimestamp; use bytes::Bytes; -use moq_clock::Instant; +use kio::clock::Instant; use std::collections::HashMap; use std::mem; @@ -887,14 +887,14 @@ impl ClientSession { mod clock_tests { use super::*; - #[moq_clock::test] + #[kio::test] async fn session_epoch_uses_the_timer_clock() { let (session, _) = ClientSession::new(ClientSessionConfig::new()).unwrap(); - moq_clock::sleep(std::time::Duration::from_millis(12_345)).await; + kio::clock::sleep(std::time::Duration::from_millis(12_345)).await; assert_eq!(session.get_epoch(), RtmpTimestamp::new(12_345)); - moq_clock::sim::step_wall(moq_clock::Wall::UNIX_EPOCH); + kio::clock::sim::step_wall(kio::clock::Wall::UNIX_EPOCH); assert_eq!(session.get_epoch(), RtmpTimestamp::new(12_345)); - moq_clock::sleep(std::time::Duration::from_millis(1 << 32)).await; + kio::clock::sleep(std::time::Duration::from_millis(1 << 32)).await; assert_eq!(session.get_epoch(), RtmpTimestamp::new(12_345)); } } diff --git a/rs/moq-rtmp/src/rml/sessions/server/mod.rs b/rs/moq-rtmp/src/rml/sessions/server/mod.rs index 7c3c0425516..c55d0a83129 100644 --- a/rs/moq-rtmp/src/rml/sessions/server/mod.rs +++ b/rs/moq-rtmp/src/rml/sessions/server/mod.rs @@ -20,7 +20,7 @@ use crate::rml::messages::{PeerBandwidthLimitType, RtmpMessage, UserControlEvent use crate::rml::sessions::StreamMetadata; use crate::rml::time::RtmpTimestamp; use bytes::Bytes; -use moq_clock::Instant; +use kio::clock::Instant; use std::collections::{HashMap, HashSet}; const FOURCC_CAN_DECODE: u32 = 0x01; @@ -1419,14 +1419,14 @@ fn create_status_object(level: &str, code: &str, description: &str) -> HashMap, + accept_retry: Option, } impl Server { @@ -355,7 +355,7 @@ impl Server { self.pending.push(Box::pin(async move { // The TLS handshake (if any) and the RTMP handshake share one // budget, so a client that stalls either is dropped. - let outcome = moq_clock::timeout(REQUEST_TIMEOUT, async move { + let outcome = kio::clock::timeout(REQUEST_TIMEOUT, async move { #[cfg(feature = "tls")] let conn = match tls { Some(acceptor) if starts_tls(&stream).await? => Conn::Tls(Box::new( @@ -402,7 +402,7 @@ impl Server { tracing::warn!(%err, "failed to accept RTMP connection; continuing"); let wait = self.accept_delay.mul_f64(0.5 + rand::rng().random::() / 2.0); self.accept_delay = (self.accept_delay * 2).min(ACCEPT_RETRY_MAX); - self.accept_retry = Some(moq_clock::Instant::now() + wait); + self.accept_retry = Some(kio::clock::Instant::now() + wait); } }, } @@ -429,9 +429,9 @@ async fn starts_tls(stream: &TcpStream) -> io::Result { /// /// The `select!` arm that uses this is guarded on `at` being set; the pending branch keeps the arm /// well-formed rather than leaving the macro with a `None` to unwrap. -async fn sleep_until(at: Option) { +async fn sleep_until(at: Option) { match at { - Some(at) => moq_clock::sleep_until(at).await, + Some(at) => kio::clock::sleep_until(at).await, None => std::future::pending().await, } } @@ -471,7 +471,7 @@ pub fn configure_socket(stream: &TcpStream, peer: SocketAddr) { /// /// Returns `Ok(None)` if the client disconnects before issuing `publish` or /// `play`. Unlike [`Server`], this applies no timeout: wrap the call in -/// [`moq_clock::timeout`] to bound how long a connected-but-idle client can +/// [`kio::clock::timeout`] to bound how long a connected-but-idle client can /// hold the task. pub async fn accept_stream(stream: S, peer: SocketAddr) -> Result>> { Ok(accept_until_request(stream, peer).await?) @@ -801,7 +801,7 @@ impl Play { tracing::debug!(peer = %self.peer, %path, "viewer disconnected before play started"); return Ok(()); } - resolved = moq_clock::timeout(PLAY_RESOLVE_TIMEOUT, origin.routed_broadcast(&path)) => { + resolved = kio::clock::timeout(PLAY_RESOLVE_TIMEOUT, origin.routed_broadcast(&path)) => { match resolved { Ok(resolved) => resolved, Err(_) => { @@ -828,7 +828,7 @@ impl Play { tracing::debug!(peer = %self.peer, %path, "viewer disconnected before play started"); return Ok(()); } - catalog = moq_clock::timeout(PLAY_RESOLVE_TIMEOUT, CatalogStream::next(&mut check)) => { + catalog = kio::clock::timeout(PLAY_RESOLVE_TIMEOUT, CatalogStream::next(&mut check)) => { match catalog { Ok(Ok(Some(catalog))) => catalog, Ok(Ok(None)) => { @@ -876,7 +876,7 @@ impl Play { tracing::debug!(peer = %self.peer, %path, "viewer disconnected before play started"); return Ok(()); } - chunk = moq_clock::timeout(PLAY_RESOLVE_TIMEOUT, export.next()) => { + chunk = kio::clock::timeout(PLAY_RESOLVE_TIMEOUT, export.next()) => { match chunk { Ok(Ok(Some(chunk))) => chunk, Ok(Ok(None)) => { @@ -1234,7 +1234,7 @@ async fn pump( peer: SocketAddr, ) -> anyhow::Result { let mut buffer = [0u8; READ_BUFFER]; - let mut media_deadline = moq_clock::Instant::now() + PUBLISH_IDLE_TIMEOUT; + let mut media_deadline = kio::clock::Instant::now() + PUBLISH_IDLE_TIMEOUT; loop { let mut finished = false; while let Some(result) = work.pop_front() { @@ -1247,13 +1247,13 @@ async fn pump( // consumes whole tags atomically, so one bad frame doesn't desync // the stream, and tearing down a live publish over it would be worse. ServerSessionEvent::AudioDataReceived { data, timestamp, .. } => { - media_deadline = moq_clock::Instant::now() + PUBLISH_IDLE_TIMEOUT; + media_deadline = kio::clock::Instant::now() + PUBLISH_IDLE_TIMEOUT; if let Err(err) = publisher.push(flv::TAG_AUDIO, timestamp.value, &data) { tracing::warn!(%peer, %err, "dropping RTMP audio frame that failed to demux"); } } ServerSessionEvent::VideoDataReceived { data, timestamp, .. } => { - media_deadline = moq_clock::Instant::now() + PUBLISH_IDLE_TIMEOUT; + media_deadline = kio::clock::Instant::now() + PUBLISH_IDLE_TIMEOUT; if let Err(err) = publisher.push(flv::TAG_VIDEO, timestamp.value, &data) { tracing::warn!(%peer, %err, "dropping RTMP video frame that failed to demux"); } @@ -1277,7 +1277,7 @@ async fn pump( let n = tokio::select! { res = stream.read(&mut buffer) => res?, - _ = moq_clock::sleep_until(media_deadline) => { + _ = kio::clock::sleep_until(media_deadline) => { anyhow::bail!("peer {peer} sent no RTMP media for {:?}", PUBLISH_IDLE_TIMEOUT); } }; diff --git a/rs/moq-rtsp/Cargo.toml b/rs/moq-rtsp/Cargo.toml index 29ffbee6b2f..ae60c1cd91c 100644 --- a/rs/moq-rtsp/Cargo.toml +++ b/rs/moq-rtsp/Cargo.toml @@ -22,7 +22,7 @@ test-support = ["dep:base64", "dep:tokio", "tokio/io-util", "tokio/macros", "tok base64 = { workspace = true, optional = true } futures = { workspace = true } hang = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-mux = { workspace = true } moq-net = { workspace = true } # Only for `RedactedUrl`, so the session URL logs without its query. @@ -38,7 +38,7 @@ url = { workspace = true } [dev-dependencies] base64 = { workspace = true } # A clock only the stall tests move, so a loaded runner never fires a deadline early. -moq-clock = { path = "../moq-clock", features = ["manual"] } +kio = { path = "../kio", features = ["manual"] } tokio = { workspace = true, features = ["full", "test-util"] } tracing-test = { workspace = true, features = ["no-env-filter"] } diff --git a/rs/moq-rtsp/clippy.toml b/rs/moq-rtsp/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-rtsp/clippy.toml +++ b/rs/moq-rtsp/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-rtsp/src/client.rs b/rs/moq-rtsp/src/client.rs index 291e7b1b618..b957799df9f 100644 --- a/rs/moq-rtsp/src/client.rs +++ b/rs/moq-rtsp/src/client.rs @@ -222,16 +222,16 @@ impl Client { let result: Result = async { let mut session = self.within(session.play(play)).await??.demuxed()?; tracing::info!(%url, streams = tracks.len(), "RTSP session playing"); - let playing = moq_clock::now(); + let playing = kio::clock::now(); // Measured from the last frame, so RTCP reports alone cannot keep a dead camera alive. let mut deadline = playing + self.timeout; - while let Some(item) = moq_clock::timeout(deadline - moq_clock::now(), session.next()) + while let Some(item) = kio::clock::timeout(deadline - kio::clock::now(), session.next()) .await .map_err(|_| Error::Stalled(self.timeout))? { let item = item?; if matches!(item, CodecItem::VideoFrame(_) | CodecItem::AudioFrame(_)) { - deadline = moq_clock::now() + self.timeout; + deadline = kio::clock::now() + self.timeout; } if ingest.push(item, session.streams())?.is_some() { tracing::warn!(%url, "RTSP timeline jumped, ending the session"); @@ -261,7 +261,7 @@ impl Client { impl Client { /// Fail `step` once it takes longer than the timeout. async fn within(&self, step: impl Future) -> Result { - moq_clock::timeout(self.timeout, step) + kio::clock::timeout(self.timeout, step) .await .map_err(|_| Error::Stalled(self.timeout)) } @@ -368,11 +368,11 @@ struct Stream { track: Track, /// The previous frame's timestamp, in the stream's clock units since the session start, and /// when it arrived. - last: Option<(i64, moq_clock::Instant)>, + last: Option<(i64, kio::clock::Instant)>, /// Whether a keyframe has been published (video) or the session started (audio). started: bool, /// When a lost packet broke the video's reference chain, so it waits for a keyframe. - held: Option, + held: Option, /// Whether retina's parameter sets still need inserting: until the splitter emits a keyframe /// carrying them, after which it re-inserts them ahead of every keyframe itself. fresh: bool, @@ -416,7 +416,7 @@ impl Ingest { frame.timestamp(), frame.data(), frame.has_new_parameters(), - moq_clock::Instant::from_std(frame.end_ctx().received()), + kio::clock::Instant::from_std(frame.end_ctx().received()), frame.loss(), ), CodecItem::AudioFrame(frame) => ( @@ -424,7 +424,7 @@ impl Ingest { frame.timestamp(), frame.data(), false, - moq_clock::Instant::from_std(frame.ctx().received()), + kio::clock::Instant::from_std(frame.ctx().received()), // AAC packets decode alone, and the decoder conceals a lost one. 0, ), @@ -467,7 +467,7 @@ impl Ingest { // access unit is damaged too, even when it is a keyframe, so drop it. if stream.started && stream.held.is_none() { tracing::warn!(stream_id, loss, "RTP packets lost, waiting for the next keyframe"); - stream.held = Some(moq_clock::now()); + stream.held = Some(kio::clock::now()); } video.reset(); return Ok(None); @@ -511,7 +511,7 @@ impl Ingest { /// Whether a video stream has waited longer than `timeout` for a keyframe: its first since /// `playing`, or its next since a loss held it. - fn awaiting_keyframe(&self, playing: moq_clock::Instant, timeout: std::time::Duration) -> bool { + fn awaiting_keyframe(&self, playing: kio::clock::Instant, timeout: std::time::Duration) -> bool { self.streams.iter().flatten().any(|stream| { let since = match stream.held { Some(held) => held, @@ -560,8 +560,8 @@ mod tests { /// Make the test runtime's clock one only the test moves, so a setup step on a loaded runner /// never reaches a deadline. Call it before anything reads the clock. - fn manual() -> moq_clock::Installed { - moq_clock::Manual::new().install(&tokio::runtime::Handle::current()) + fn manual() -> kio::clock::Installed { + kio::clock::Manual::new().install(&tokio::runtime::Handle::current()) } fn broadcast() -> (moq_net::broadcast::Producer, moq_mux::catalog::Producer) { diff --git a/rs/moq-scene/Cargo.toml b/rs/moq-scene/Cargo.toml index 1fc6845e0ba..aceb936a597 100644 --- a/rs/moq-scene/Cargo.toml +++ b/rs/moq-scene/Cargo.toml @@ -33,9 +33,8 @@ hang = { workspace = true } humantime-serde = { workspace = true } # PNG and JPEG still images. Already in a studio's graph through eframe. image = { version = "0.25", default-features = false, features = ["png", "jpeg"] } -kio = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-audio = { workspace = true, features = ["bus"] } -moq-clock = { workspace = true } moq-mux = { workspace = true } moq-net = { workspace = true } # `render` is the compositor's whole input path: it turns every decoded or diff --git a/rs/moq-scene/src/compositor.rs b/rs/moq-scene/src/compositor.rs index 10c6fcdd656..baa5721184a 100644 --- a/rs/moq-scene/src/compositor.rs +++ b/rs/moq-scene/src/compositor.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::num::NonZeroU64; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use moq_video::render::{Renderer, wgpu}; use crate::Error; diff --git a/rs/moq-shaper/Cargo.toml b/rs/moq-shaper/Cargo.toml index 54184d88d4a..6194b81cc0a 100644 --- a/rs/moq-shaper/Cargo.toml +++ b/rs/moq-shaper/Cargo.toml @@ -25,7 +25,7 @@ anyhow = { workspace = true } clap = { workspace = true } humantime = { workspace = true } humantime-serde = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } rand = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } diff --git a/rs/moq-shaper/clippy.toml b/rs/moq-shaper/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-shaper/clippy.toml +++ b/rs/moq-shaper/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-shaper/src/lib.rs b/rs/moq-shaper/src/lib.rs index 1a7980b6498..711388cc287 100644 --- a/rs/moq-shaper/src/lib.rs +++ b/rs/moq-shaper/src/lib.rs @@ -42,9 +42,9 @@ mod preset; pub use preset::Preset; use anyhow::Context; +use kio::clock::Instant; #[cfg(test)] use mem::UdpSocket; -use moq_clock::Instant; use rand::{RngExt, SeedableRng, rngs::Xoshiro256PlusPlus}; use serde::{Deserialize, Serialize}; #[cfg(not(test))] @@ -898,7 +898,7 @@ async fn deliver( None => ready.push(parcel), } } - _ = moq_clock::sleep_until(wake.unwrap_or_else(Instant::now)), if wake.is_some() => { + _ = kio::clock::sleep_until(wake.unwrap_or_else(Instant::now)), if wake.is_some() => { // The window closes a batch that never filled. if let Some(closes) = held.closes.filter(|&closes| closes <= Instant::now()) { held.release(closes, &mut ready, &tally[direction]); diff --git a/rs/moq-shaper/src/main.rs b/rs/moq-shaper/src/main.rs index 1c652de50f8..19da706ec9f 100644 --- a/rs/moq-shaper/src/main.rs +++ b/rs/moq-shaper/src/main.rs @@ -128,7 +128,7 @@ async fn main() -> anyhow::Result<()> { // The first tick is a full period in, so a line reports traffic, not the start. let mut interval = args .report_interval - .map(|period| moq_clock::interval_at(moq_clock::now() + period, period)); + .map(|period| kio::clock::interval_at(kio::clock::now() + period, period)); let shutdown = shutdown(); tokio::pin!(shutdown); loop { @@ -201,7 +201,7 @@ struct Report<'a> { } /// The next report tick, or never without an interval. -async fn tick(interval: &mut Option) { +async fn tick(interval: &mut Option) { match interval { Some(interval) => { interval.tick().await; diff --git a/rs/moq-sock/clippy.toml b/rs/moq-sock/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-sock/clippy.toml +++ b/rs/moq-sock/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-srt/clippy.toml b/rs/moq-srt/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-srt/clippy.toml +++ b/rs/moq-srt/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-stats/Cargo.toml b/rs/moq-stats/Cargo.toml index 194ebd6f839..c4ec402f7f8 100644 --- a/rs/moq-stats/Cargo.toml +++ b/rs/moq-stats/Cargo.toml @@ -19,7 +19,7 @@ categories = ["multimedia", "network-programming", "web-programming"] bench = ["moq-net/fuzz"] [dependencies] -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-json = { workspace = true } moq-net = { workspace = true } serde = { workspace = true } diff --git a/rs/moq-stats/clippy.toml b/rs/moq-stats/clippy.toml index 9460b0fd5c8..1fc5f0c2931 100644 --- a/rs/moq-stats/clippy.toml +++ b/rs/moq-stats/clippy.toml @@ -1,11 +1,11 @@ disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, ] -disallowed-types = [{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" }] +disallowed-types = [{ path = "std::time::SystemTime", reason = "use kio::clock::Wall" }] diff --git a/rs/moq-stats/src/aggregate.rs b/rs/moq-stats/src/aggregate.rs index ae48146fefc..a7702a4be14 100644 --- a/rs/moq-stats/src/aggregate.rs +++ b/rs/moq-stats/src/aggregate.rs @@ -11,7 +11,7 @@ use std::collections::{BTreeMap, HashMap}; use std::task::Poll; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::kio::{self, Pending, Waiter}; use moq_net::stats::{Presence, Traffic}; use moq_net::track::Subscribing; @@ -861,7 +861,7 @@ impl Merged { // then fold every departed node whose grace elapsed. A fold leaves the // merged view unchanged, and only an announce adds a node, which polls // here, so no timer is needed to keep the map bounded. - let now = moq_clock::now(); + let now = kio::clock::now(); let config = &self.config; let name = self.name.as_str(); let origin = &self.origin; @@ -918,7 +918,7 @@ impl Merged { // grace re-arms it. return match self.nodes.get_mut(&key) { Some(node) => { - node.departed = Some(moq_clock::now()); + node.departed = Some(kio::clock::now()); node.depart() } None => false, @@ -960,7 +960,7 @@ impl Merged { let node = entry.get_mut(); // A return after the grace starts over, even when this announce // is the first poll since the grace elapsed. - node.fold_expired(&mut self.retired, self.grace, moq_clock::now()); + node.fold_expired(&mut self.retired, self.grace, kio::clock::now()); node.departed = None; if matches!(node.reader, Reader::Ended) { node.reader = resolve(&self.origin, &node.path, node.epoch.clone()); @@ -1700,7 +1700,7 @@ mod tests { fn replacement_while_reader_retries(drop_epoch: bool) { use std::sync::Barrier; - let now = moq_clock::now(); + let now = kio::clock::now(); // The clock never advances here, so nothing may wait out the update hold. let mut config = origin::Config::default(); config.update_hold = std::time::Duration::ZERO; diff --git a/rs/moq-stats/src/produce.rs b/rs/moq-stats/src/produce.rs index 41c7f0717e7..ddd5207392b 100644 --- a/rs/moq-stats/src/produce.rs +++ b/rs/moq-stats/src/produce.rs @@ -6,7 +6,7 @@ use std::time::Duration; use std::task::Poll; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::stats::{Presence, Registry, Report, Tier, Traffic, TrafficEntry}; use moq_net::{Epoch, Path, broadcast, kio, origin, track}; use serde::Serialize; @@ -233,8 +233,8 @@ impl Task { return; }; - let mut ticker = moq_clock::interval(interval); - ticker.set_missed_tick_behavior(moq_clock::MissedTickBehavior::Delay); + let mut ticker = kio::clock::interval(interval); + ticker.set_missed_tick_behavior(kio::clock::MissedTickBehavior::Delay); loop { // Scheduled instants are at least an interval apart, even after a late tick, @@ -282,7 +282,7 @@ impl Drain { /// `None` if the origin refused it. fn new(task: Task) -> Option { let node = NodePublisher::create(&task)?; - let now = moq_clock::now(); + let now = kio::clock::now(); Some(Self { task, node, @@ -1364,7 +1364,7 @@ mod tests { /// A drain at the current instant, numbered `group`. fn stamp(group: u64) -> Stamp { Stamp { - at: moq_clock::now(), + at: kio::clock::now(), group, } } @@ -1447,12 +1447,12 @@ mod tests { .with_versions(version.into()) .with_publisher(upstream.consume().with_hidden(true)); let client = async { - let (session, driver) = client.connect(moq_clock::now(), client_transport).await.unwrap(); + let (session, driver) = client.connect(kio::clock::now(), client_transport).await.unwrap(); tokio::spawn(moq_net::time::run(driver)); session }; let server = async { - let (session, driver) = server.accept(moq_clock::now(), server_transport).await.unwrap(); + let (session, driver) = server.accept(kio::clock::now(), server_transport).await.unwrap(); tokio::spawn(moq_net::time::run(driver)); session }; @@ -1873,7 +1873,7 @@ mod tests { #[tokio::test(start_paused = true)] async fn a_late_drain_leaves_the_next_its_own_interval() { // Schedule the drains a millisecond before an interval boundary. - let phase = Duration::from(Timestamp::from(moq_clock::now())).as_millis() % 1000; + let phase = Duration::from(Timestamp::from(kio::clock::now())).as_millis() % 1000; tokio::time::advance(Duration::from_millis(((1999 - phase) % 1000) as u64)).await; let origin = produce_origin(); @@ -1934,7 +1934,7 @@ mod tests { interval, }) .unwrap(); - let start = moq_clock::now(); + let start = kio::clock::now(); for phase in (0..1500).step_by(100) { let at = start + Duration::from_micros(phase); assert_eq!( @@ -2412,7 +2412,7 @@ mod tests { .expect("drain"); let mut tick = || { drain.collect(); - drain.publish(moq_clock::now()); + drain.publish(kio::clock::now()); drain.node.presence.len() }; let broadcast = origin @@ -2689,7 +2689,7 @@ mod tests { .expect("drain"); let mut tick = || { drain.collect(); - drain.publish(moq_clock::now()); + drain.publish(kio::clock::now()); drain.node.prefixes.len() }; let broadcast = origin @@ -2923,12 +2923,12 @@ mod tests { // Warm up: create the groups and tracks and grow every buffer. for _ in 0..3 { drain.collect(); - drain.publish(moq_clock::now()); + drain.publish(kio::clock::now()); } // Hold a prefix with a child per tier, as a reader would. let _held = hold.then(|| { let tick = drain.tick; - let stamp = drain.stamp(moq_clock::now()); + let stamp = drain.stamp(kio::clock::now()); drain.node.adopt_prefix( &drain.report, Path::from_static("room0"), @@ -2939,12 +2939,12 @@ mod tests { drain.node.prefixes["room0"].pair.plain.track.subscribe(None) }); drain.collect(); - drain.publish(moq_clock::now()); + drain.publish(kio::clock::now()); let before = counting::allocs(); drain.collect(); let allocs = counting::allocs() - before; - drain.publish(moq_clock::now()); + drain.publish(kio::clock::now()); assert!(!drain.report.traffic.is_empty(), "the drain carried entries"); assert_eq!( diff --git a/rs/moq-stats/src/produce_bench.rs b/rs/moq-stats/src/produce_bench.rs index 843aa240d81..3ee8565c911 100644 --- a/rs/moq-stats/src/produce_bench.rs +++ b/rs/moq-stats/src/produce_bench.rs @@ -3,7 +3,7 @@ use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::{Path, origin, stats::Registry, track}; use super::{Drain, PendingPair, Task}; @@ -45,7 +45,7 @@ impl Driver { }; Some(Self { drain: Drain::new(task)?, - now: moq_clock::now(), + now: kio::clock::now(), }) } diff --git a/rs/moq-studio/Cargo.toml b/rs/moq-studio/Cargo.toml index 348f39d50f2..6598629f29c 100644 --- a/rs/moq-studio/Cargo.toml +++ b/rs/moq-studio/Cargo.toml @@ -45,7 +45,7 @@ egui = "0.36" # Docked, rearrangeable panels. 0.21 is the newest release and pins egui 0.36. egui_dock = "0.21" moq-audio = { workspace = true, features = ["bus"] } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-mux = { workspace = true } moq-net = { workspace = true } moq-scene = { workspace = true } diff --git a/rs/moq-studio/src/engine.rs b/rs/moq-studio/src/engine.rs index 47797713f58..82946b9e135 100644 --- a/rs/moq-studio/src/engine.rs +++ b/rs/moq-studio/src/engine.rs @@ -17,7 +17,7 @@ use std::time::Duration; use anyhow::Context; use bytes::Bytes; -use moq_clock::Instant; +use kio::clock::Instant; use moq_scene::source::{self, Driver, Sources}; use moq_scene::{Collection, Compositor, wgpu}; use moq_video::render::export::{Exporter, Pending, Route}; @@ -292,8 +292,8 @@ impl Engine { ) { let canvas = self.state.lock().unwrap().collection.canvas; let period = Duration::from_secs(1) / canvas.framerate; - let mut clock = moq_clock::interval_at(start, period); - clock.set_missed_tick_behavior(moq_clock::MissedTickBehavior::Skip); + let mut clock = kio::clock::interval_at(start, period); + clock.set_missed_tick_behavior(kio::clock::MissedTickBehavior::Skip); let mut watched = false; loop { @@ -356,8 +356,8 @@ impl Engine { let config = self.bus.config().clone(); let rate = u128::from(config.sample_rate); let channels = config.layout.channels() as usize; - let mut clock = moq_clock::interval_at(start, AUDIO_PERIOD); - clock.set_missed_tick_behavior(moq_clock::MissedTickBehavior::Skip); + let mut clock = kio::clock::interval_at(start, AUDIO_PERIOD); + clock.set_missed_tick_behavior(kio::clock::MissedTickBehavior::Skip); let mut samples = Vec::new(); let mut written: u128 = 0; diff --git a/rs/moq-studio/src/ui.rs b/rs/moq-studio/src/ui.rs index cf149e50446..3effd3a8950 100644 --- a/rs/moq-studio/src/ui.rs +++ b/rs/moq-studio/src/ui.rs @@ -224,7 +224,7 @@ impl Panels { state.compositor.cut(); } if ui.button(format!("Fade ({} ms)", fade.as_millis())).clicked() { - state.compositor.fade(fade, moq_clock::Instant::now()); + state.compositor.fade(fade, kio::clock::Instant::now()); } ui.label(format!( "Program: {}", diff --git a/rs/moq-tokio/Cargo.toml b/rs/moq-tokio/Cargo.toml index 80782f665ad..9e23840764f 100644 --- a/rs/moq-tokio/Cargo.toml +++ b/rs/moq-tokio/Cargo.toml @@ -26,7 +26,6 @@ quic = [ "_certs", "driver", "dep:http", - "dep:kio", "dep:rustls-native-certs", "dep:web-transport-proto", "dep:reqwest", @@ -78,10 +77,8 @@ http = { version = "1", optional = true } humantime = "2.3" humantime-serde = { workspace = true } if-addrs = { workspace = true, optional = true } -kio = { workspace = true, optional = true } +kio = { workspace = true, features = ["runtime"] } mdns-sd = { workspace = true, optional = true } - -moq-clock = { workspace = true } moq-congestion = { workspace = true, optional = true } # The ICE agent behind the `webrtc` module. Private, like str0m: neither appears in this crate's API. moq-ice = { workspace = true, optional = true } @@ -147,7 +144,7 @@ chrono = "0.4" # Use the channel type behind `mdns_sd::Receiver` so the mDNS readiness gate can # be driven with synthetic daemon events. flume = "0.12" -moq-clock = { path = "../moq-clock", features = ["sim"] } +kio = { path = "../kio", features = ["sim"] } # A bufferbloated path for the receive-credit tests and benchmark. moq-shaper = { path = "../moq-shaper" } rcgen = { workspace = true, features = ["pem", "aws_lc_rs"] } diff --git a/rs/moq-tokio/clippy.toml b/rs/moq-tokio/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-tokio/clippy.toml +++ b/rs/moq-tokio/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-tokio/examples/chat.rs b/rs/moq-tokio/examples/chat.rs index 7e025da587e..b892cc85fbc 100644 --- a/rs/moq-tokio/examples/chat.rs +++ b/rs/moq-tokio/examples/chat.rs @@ -73,7 +73,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()> tracing::info!("wrote hello + world"); // Sleep before sending our next message. - moq_clock::sleep(tokio::time::Duration::from_secs(10)).await; + kio::clock::sleep(tokio::time::Duration::from_secs(10)).await; // There's also a helper method to create a group with a single frame. track.write_frame( @@ -83,7 +83,7 @@ async fn run_broadcast(origin: moq_net::origin::Producer) -> anyhow::Result<()> tracing::info!("wrote foobarbaz"); // Sleep before exiting and closing the broadcast. - moq_clock::sleep(tokio::time::Duration::from_secs(10)).await; + kio::clock::sleep(tokio::time::Duration::from_secs(10)).await; // End the broadcast. Dropping the producer does the same; closing is explicit. broadcast.close(); diff --git a/rs/moq-tokio/examples/clock.rs b/rs/moq-tokio/examples/clock.rs index 62dce53dabf..f76dc749d89 100644 --- a/rs/moq-tokio/examples/clock.rs +++ b/rs/moq-tokio/examples/clock.rs @@ -163,7 +163,7 @@ impl Publisher { let next = next.with_second(0).unwrap().with_nanosecond(0).unwrap(); let delay = (next - now).to_std().unwrap(); - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; now = next; // just assume we didn't undersleep } @@ -183,7 +183,7 @@ impl Publisher { let next = next.with_nanosecond(0).unwrap(); let delay = (next - now).to_std().unwrap(); - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; // Get the current time again to check if we overslept let actual = Utc::now(); diff --git a/rs/moq-tokio/src/accept.rs b/rs/moq-tokio/src/accept.rs index cd53c208c58..f2ea69f90bd 100644 --- a/rs/moq-tokio/src/accept.rs +++ b/rs/moq-tokio/src/accept.rs @@ -32,7 +32,7 @@ use std::{ time::Duration, }; -use moq_clock::Instant; +use kio::clock::Instant; /// Delay after an accept failure that is not one connection's fault, escalating /// while they continue and reset by the next successful accept. @@ -470,11 +470,11 @@ mod tests { } #[cfg(unix)] - #[moq_clock::test] + #[kio::test] async fn exhaustion_stall_uses_the_retry_clock() { let health = Health::new("test"); let _ = health.failed(&io(libc::EMFILE)); - moq_clock::sleep(Duration::from_secs(30)).await; + kio::clock::sleep(Duration::from_secs(30)).await; assert_eq!(health.stalled(), Some(Duration::from_secs(30))); } } diff --git a/rs/moq-tokio/src/client.rs b/rs/moq-tokio/src/client.rs index 7e45b517dd6..94b87f9fbbb 100644 --- a/rs/moq-tokio/src/client.rs +++ b/rs/moq-tokio/src/client.rs @@ -354,7 +354,7 @@ impl Client { let session = match self.timeout.is_zero() { true => attempt.await?, - false => moq_clock::timeout(self.timeout, attempt) + false => kio::clock::timeout(self.timeout, attempt) .await .map_err(|_| Error::ConnectTimeout(self.timeout))??, }; @@ -424,7 +424,7 @@ impl Client { // arm was still pending. let dialed = match self.timeout.is_zero() { true => attempt.await?, - false => match moq_clock::timeout(self.timeout, attempt).await { + false => match kio::clock::timeout(self.timeout, attempt).await { Ok(res) => res?, Err(_) => return Err(Error::ConnectTimeout(self.timeout)), }, diff --git a/rs/moq-tokio/src/connection.rs b/rs/moq-tokio/src/connection.rs index 8886a1045ab..bda8678e7ce 100644 --- a/rs/moq-tokio/src/connection.rs +++ b/rs/moq-tokio/src/connection.rs @@ -606,7 +606,7 @@ struct State { session: Option, /// The loop's [`Draining`] predecessor and its handover deadline, so /// [`Connection::close`] drains it too without overstaying that window. - predecessor: Option<(moq_net::Session, moq_clock::Instant)>, + predecessor: Option<(moq_net::Session, kio::clock::Instant)>, } /// The producer side of everything a [`Connection`] handle can observe. @@ -1093,7 +1093,7 @@ impl Connection { let mut close = std::pin::pin!(session.close()); tokio::select! { res = &mut close => res, - _ = moq_clock::sleep_until(deadline) => { + _ = kio::clock::sleep_until(deadline) => { abort.abort(moq_net::Error::GoawayTimeout); close.await } @@ -1139,7 +1139,7 @@ impl Connection { shared.tokens.connected(&dialed.session); let session = dialed.session; - let connected = moq_clock::now(); + let connected = kio::clock::now(); // Wait for the session to end, forwarding its bandwidth estimates into the // persistent producers meanwhile so consumers track the live stats across the // connection, and draining any predecessor left over from a migration. @@ -1269,7 +1269,7 @@ impl Connection { if restarting { // After the sleep, so the window counts only the time after the // peer stops answering. - retry.start = moq_clock::now(); + retry.start = kio::clock::now(); } continue; } @@ -1400,7 +1400,7 @@ impl Connection { let dialed = match attempt_timeout(index, candidates.len()) { None => dialed.await, - Some(limit) => match moq_clock::timeout(limit, dialed).await { + Some(limit) => match kio::clock::timeout(limit, dialed).await { Ok(dialed) => dialed, Err(_) => Err(Error::Reconnect(format!("timed out connecting to {}", Endpoint(url)))), }, @@ -1614,7 +1614,7 @@ struct Retry { /// The wait before the next attempt, before jitter. delay: Duration, /// When this run of failures began; the give-up timeout counts from here. - start: moq_clock::Instant, + start: kio::clock::Instant, /// The latest failure, so giving up reports a real cause. last_error: Option, } @@ -1623,7 +1623,7 @@ impl Retry { fn new(initial: Duration) -> Self { Self { delay: initial, - start: moq_clock::now(), + start: kio::clock::now(), last_error: None, } } @@ -1648,7 +1648,7 @@ fn timeout_error(timeout: Duration, last_error: Option<&Error>) -> Error { } /// Jitter the next delay and cap it at the retry window. `None` means the window is exhausted. -fn retry_wait(delay: Duration, retry_start: moq_clock::Instant, timeout: Duration) -> Option { +fn retry_wait(delay: Duration, retry_start: kio::clock::Instant, timeout: Duration) -> Option { let wait = delay.mul_f64(0.5 + rand::rng().random::() / 2.0); if timeout.is_zero() { return Some(wait); @@ -1728,14 +1728,14 @@ enum Ended { struct Draining { session: moq_net::Session, closed: std::pin::Pin + Send>>, - deadline: std::pin::Pin>, + deadline: std::pin::Pin>, /// Mirrors the session into [`State::predecessor`] for as long as this lives. state: kio::Producer, } impl Draining { fn new(session: moq_net::Session, handover: Duration, state: &kio::Producer) -> Self { - let deadline = Box::pin(moq_clock::sleep(handover)); + let deadline = Box::pin(kio::clock::sleep(handover)); if let Ok(mut state) = state.write() { state.predecessor = Some((session.clone(), deadline.deadline())); } @@ -1805,7 +1805,7 @@ fn poll_draining(draining: &mut Option, waiter: &kio::Waiter) -> bool /// to reach would leave the old session holding its connection well past the /// handover window. async fn sleep_draining(delay: Duration, draining: &mut Option, shared: &Shared) { - let mut sleep = std::pin::pin!(moq_clock::sleep(delay)); + let mut sleep = std::pin::pin!(kio::clock::sleep(delay)); kio::wait(|waiter| { // Nothing is serving once it retires: the predecessor closed or overstayed // its handover, and the replacement is still a dial away. Leaving the state @@ -3661,7 +3661,7 @@ mod tests { .expect("the dial failed"); let mut announced = server_origin.consume().announced(); - let arrived = moq_clock::timeout(Duration::from_secs(5), announced.next()) + let arrived = kio::clock::timeout(Duration::from_secs(5), announced.next()) .await .expect("the broadcast never reached the server") .expect("the server's origin closed"); diff --git a/rs/moq-tokio/src/failover.rs b/rs/moq-tokio/src/failover.rs index 09e1fd0686c..1d25be0f03f 100644 --- a/rs/moq-tokio/src/failover.rs +++ b/rs/moq-tokio/src/failover.rs @@ -108,7 +108,7 @@ where // When the next attempt may start: the first as soon as an address resolves, // each later one a stagger after the one before it. - let mut ready = moq_clock::now(); + let mut ready = kio::clock::now(); let mut next_index = 0; let mut start = |addr: SocketAddr, attempts: &mut FuturesUnordered<_>| { @@ -151,7 +151,7 @@ where failures.push((index, Attempt { addr, error: err })); // A failure starts the next candidate immediately (RFC 8305 // section 5) rather than waiting out the stagger delay. - ready = moq_clock::now(); + ready = kio::clock::now(); } } } @@ -162,7 +162,7 @@ where match addr { Some(addr) => { start(addr, &mut attempts); - ready = moq_clock::now() + delay; + ready = kio::clock::now() + delay; } None => exhausted = true, } @@ -175,8 +175,8 @@ where /// /// Resolution can outlast the stagger, in which case the attempt starts as soon /// as an address lands. -async fn pull(candidates: &mut Candidates, ready: moq_clock::Instant) -> Option { - moq_clock::sleep_until(ready).await; +async fn pull(candidates: &mut Candidates, ready: kio::clock::Instant) -> Option { + kio::clock::sleep_until(ready).await; candidates.next().await } diff --git a/rs/moq-tokio/src/listen.rs b/rs/moq-tokio/src/listen.rs index 82779c4e759..8b74f087962 100644 --- a/rs/moq-tokio/src/listen.rs +++ b/rs/moq-tokio/src/listen.rs @@ -475,7 +475,7 @@ impl Config { /// forever: for zero, and for a timeout too long for the clock to reach. pub fn resolved_timeout(&self) -> Option { let timeout = self.timeout.map(Into::into).unwrap_or(DEFAULT_TIMEOUT); - (!timeout.is_zero() && moq_clock::now().checked_add(timeout).is_some()).then_some(timeout) + (!timeout.is_zero() && kio::clock::now().checked_add(timeout).is_some()).then_some(timeout) } #[cfg(feature = "quic")] diff --git a/rs/moq-tokio/src/mdns.rs b/rs/moq-tokio/src/mdns.rs index 947fe09694c..b8b8500b633 100644 --- a/rs/moq-tokio/src/mdns.rs +++ b/rs/moq-tokio/src/mdns.rs @@ -712,12 +712,12 @@ fn addr_url(addr: SocketAddr) -> Option { /// refusing to start over one of those would be wrong; an error only decides the /// outcome if *nothing* announces. async fn announced(monitor: &mdns_sd::Receiver) -> Result<()> { - let deadline = moq_clock::now() + ANNOUNCE_TIMEOUT; + let deadline = kio::clock::now() + ANNOUNCE_TIMEOUT; // Kept so a total failure reports why rather than just "timed out". let mut failure = None; loop { - let event = match moq_clock::timeout_at(deadline, monitor.recv_async()).await { + let event = match kio::clock::timeout_at(deadline, monitor.recv_async()).await { Ok(Ok(event)) => event, // The daemon died, or nothing announced in time. Either way the mesh is // not live, which is exactly what the caller is gating on. diff --git a/rs/moq-tokio/src/quic/backend.rs b/rs/moq-tokio/src/quic/backend.rs index 28f8951374d..c4f23c5e1e7 100644 --- a/rs/moq-tokio/src/quic/backend.rs +++ b/rs/moq-tokio/src/quic/backend.rs @@ -1212,7 +1212,7 @@ mod tests { #[test] fn congestion_factory_maps_each_family() { let init = moq_congestion::Init { - now: moq_clock::Instant::now(), + now: kio::clock::Instant::now(), mtu: 1200, rtt: std::time::Duration::from_millis(333), max_pacing_rate: None, diff --git a/rs/moq-tokio/src/quic/driver/connection.rs b/rs/moq-tokio/src/quic/driver/connection.rs index 5c038876501..0246e2094ee 100644 --- a/rs/moq-tokio/src/quic/driver/connection.rs +++ b/rs/moq-tokio/src/quic/driver/connection.rs @@ -838,7 +838,7 @@ pub(crate) struct State { handle: ConnectionHandle, on_handshake_data: Option>, connected: bool, - timer: Option, + timer: Option, timer_deadline: Option, conn_events: mpsc::UnboundedReceiver, endpoint_events: mpsc::UnboundedSender<(ConnectionHandle, EndpointEvent)>, @@ -1037,7 +1037,7 @@ impl State { delay.reset(deadline); } None => { - self.timer = Some(moq_clock::sleep_until(deadline)); + self.timer = Some(kio::clock::sleep_until(deadline)); } _ => {} } diff --git a/rs/moq-tokio/src/quic/driver/mod.rs b/rs/moq-tokio/src/quic/driver/mod.rs index babdf4a4dc5..3b36897e9be 100644 --- a/rs/moq-tokio/src/quic/driver/mod.rs +++ b/rs/moq-tokio/src/quic/driver/mod.rs @@ -55,7 +55,7 @@ mod send_group; mod send_stream; mod work_limiter; -pub(crate) use moq_clock::Instant; +pub(crate) use kio::clock::Instant; pub(crate) use std::time::Duration; pub use moq_quic::{ diff --git a/rs/moq-tokio/src/quic/web/session.rs b/rs/moq-tokio/src/quic/web/session.rs index 4b722dbf75f..fecae990cd4 100644 --- a/rs/moq-tokio/src/quic/web/session.rs +++ b/rs/moq-tokio/src/quic/web/session.rs @@ -509,7 +509,7 @@ impl Session { } // Wait for the peer to close the CONNECT stream after receiving the capsule. - if moq_clock::timeout(timeout, self.conn.closed()).await.is_err() { + if kio::clock::timeout(timeout, self.conn.closed()).await.is_err() { tracing::debug!("timeout waiting for peer to close; force-closing connection"); self.conn.close(http3_code, b""); } diff --git a/rs/moq-tokio/src/resolve.rs b/rs/moq-tokio/src/resolve.rs index 5f65c6254b7..e2568ad539b 100644 --- a/rs/moq-tokio/src/resolve.rs +++ b/rs/moq-tokio/src/resolve.rs @@ -329,7 +329,7 @@ impl Candidates { // stagger between attempts dwarfs this. if self.count == 0 && !self.delayed && self.full.pending() { self.delayed = true; - let _ = moq_clock::timeout(self.delay, self.answer_full()).await; + let _ = kio::clock::timeout(self.delay, self.answer_full()).await; continue; } @@ -588,7 +588,7 @@ impl Query { Self { call: Some(tokio::spawn(async move { - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; Ok(addrs) })), ..Default::default() diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 176d1fcd092..c3fe02721a8 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -916,7 +916,9 @@ impl Listener { if !server.versions.alpns().contains(&peer.protocol()) { return Err(WebRtcError::Protocol(peer.protocol().to_string()).into()); } - let deadline = server.timeout.and_then(|timeout| moq_clock::now().checked_add(timeout)); + let deadline = server + .timeout + .and_then(|timeout| kio::clock::now().checked_add(timeout)); let handshake = async { let opened = peer.channel().await?; @@ -1037,8 +1039,8 @@ struct Setup { impl Setup { /// When a connection accepted now must finish its handshake, or `None` to wait /// forever, including past the clock's range. - fn deadline(&self) -> Option { - moq_clock::now().checked_add(self.timeout?) + fn deadline(&self) -> Option { + kio::clock::now().checked_add(self.timeout?) } } @@ -1056,7 +1058,7 @@ impl Setup { async fn accept_request( server: &moq_net::Server, session: S, - deadline: Option, + deadline: Option, ) -> crate::Result<(moq_net::server::Handshake, Option)> where S: moq_net::transport::poll::Boxable + Send + Sync, @@ -1071,7 +1073,7 @@ where pub(crate) async fn accept_websocket( session: qmux::Session, options: crate::websocket::Options, - deadline: Option, + deadline: Option, ) -> crate::Result { let (request, deadline) = accept_request(&options.server, session, deadline).await?; let authority = options.url.host_str().filter(|h| !h.is_empty()).map(str::to_owned); @@ -1092,7 +1094,7 @@ pub(crate) async fn accept_websocket( /// When an accepted connection's handshake must be done, and how to tell the peer /// it wasn't. struct Deadline { - at: moq_clock::Instant, + at: kio::clock::Instant, /// Closes the session with the timeout code. close: Box, } @@ -1106,7 +1108,7 @@ impl Deadline { all(feature = "uds", unix), feature = "webrtc" ))] - fn new(at: moq_clock::Instant, session: S) -> Self + fn new(at: kio::clock::Instant, session: S) -> Self where S: moq_net::transport::poll::Session + Send + Sync, { @@ -1130,7 +1132,7 @@ impl Deadline { let Some(deadline) = deadline else { return handshake.await; }; - match moq_clock::timeout_at(deadline.at, handshake).await { + match kio::clock::timeout_at(deadline.at, handshake).await { Ok(res) => res, Err(_) => { (deadline.close)(); @@ -1153,7 +1155,7 @@ impl Deadline { feature = "webrtc" ))] async fn within( - deadline: Option, + deadline: Option, handshake: impl Future>, ) -> crate::Result where @@ -1162,7 +1164,7 @@ where let Some(deadline) = deadline else { return Ok(handshake.await?); }; - match moq_clock::timeout_at(deadline, handshake).await { + match kio::clock::timeout_at(deadline, handshake).await { Ok(res) => Ok(res?), Err(_) => Err(moq_net::Error::Timeout.into()), } @@ -1540,7 +1542,7 @@ fn spawn_unix_loop( struct Incoming { transport: Transport, link: Link, - deadline: Option, + deadline: Option, active: moq_net::server::Active, } diff --git a/rs/moq-tokio/src/tcp.rs b/rs/moq-tokio/src/tcp.rs index 355f74960a9..1a72d5d973a 100644 --- a/rs/moq-tokio/src/tcp.rs +++ b/rs/moq-tokio/src/tcp.rs @@ -336,7 +336,7 @@ impl Listener { } Err(err) => { if let Some(delay) = self.health.failed(&err) { - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; } } } diff --git a/rs/moq-tokio/src/tls.rs b/rs/moq-tokio/src/tls.rs index 395e27bd4ab..37e53f4b11b 100644 --- a/rs/moq-tokio/src/tls.rs +++ b/rs/moq-tokio/src/tls.rs @@ -1741,13 +1741,13 @@ impl PeerIdentity { } /// The leaf certificate's `notAfter`, if it parses, saturated to the wall range. - pub fn expiry(&self) -> Option { + pub fn expiry(&self) -> Option { let leaf = self.chain.first()?; let (_, cert) = x509_parser::parse_x509_certificate(leaf).ok()?; // Before 1970 reads as the epoch and past 2554 as the last wall time: no // representable now compares differently against the saturated value. let secs = u64::try_from(cert.validity().not_after.timestamp()).unwrap_or(0); - Some(moq_clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::from_secs(secs))) + Some(kio::clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::from_secs(secs))) } } @@ -2321,7 +2321,7 @@ mod tests { let parsed = PeerIdentity::from_any(Some(identity)).expect("chain parsed"); let expiry = parsed.expiry().expect("expiry parsed"); assert_eq!( - expiry.saturating_duration_since(moq_clock::Wall::UNIX_EPOCH).as_secs(), + expiry.saturating_duration_since(kio::clock::Wall::UNIX_EPOCH).as_secs(), 2_000_000_000 ); } @@ -2329,10 +2329,10 @@ mod tests { #[cfg(feature = "quic")] #[test] fn peer_expiry_saturates_to_the_wall_range() { - let last = moq_clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::MAX); + let last = kio::clock::Wall::UNIX_EPOCH.saturating_add(std::time::Duration::MAX); // rcgen's default notAfter is in 4096. for (seconds, expected) in [ - (-1, moq_clock::Wall::UNIX_EPOCH), + (-1, kio::clock::Wall::UNIX_EPOCH), (18_446_744_074, last), (67_090_118_400, last), ] { diff --git a/rs/moq-tokio/src/unix.rs b/rs/moq-tokio/src/unix.rs index 883e7918a9e..7a9fdc701cf 100644 --- a/rs/moq-tokio/src/unix.rs +++ b/rs/moq-tokio/src/unix.rs @@ -376,7 +376,7 @@ impl Listener { } Err(err) => { if let Some(delay) = self.health.failed(&err) { - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; } } } diff --git a/rs/moq-tokio/src/webrtc.rs b/rs/moq-tokio/src/webrtc.rs index afa7a69aa75..098e6bd8fcd 100644 --- a/rs/moq-tokio/src/webrtc.rs +++ b/rs/moq-tokio/src/webrtc.rs @@ -811,7 +811,7 @@ async fn next_write(writes: Option<&mut mpsc::Receiver>) -> Option /// A str0m connection with this socket's host candidates. fn rtc(locals: &[SocketAddr]) -> Result { - let mut rtc = Rtc::builder().build(moq_clock::now().into_std()); + let mut rtc = Rtc::builder().build(kio::clock::now().into_std()); for &addr in locals { let candidate = str0m::Candidate::host(addr, "udp").map_err(|err| Error::Candidate(err.to_string()))?; rtc.add_local_candidate(candidate); diff --git a/rs/moq-tokio/src/webrtc/resolver.rs b/rs/moq-tokio/src/webrtc/resolver.rs index bc3899e2e1f..b95da1d4617 100644 --- a/rs/moq-tokio/src/webrtc/resolver.rs +++ b/rs/moq-tokio/src/webrtc/resolver.rs @@ -181,7 +181,7 @@ mod tests { let now = self.in_flight.fetch_add(1, Ordering::SeqCst) + 1; let _in_flight = InFlight(self.in_flight.clone()); self.most_in_flight.fetch_max(now, Ordering::SeqCst); - moq_clock::sleep(DELAY).await; + kio::clock::sleep(DELAY).await; let index: u8 = host .trim_start_matches("host") .trim_end_matches(".local") @@ -223,7 +223,7 @@ mod tests { let (tx, mut commands) = mpsc::channel(1); let resolver = Resolver::spawn(tx, fake.clone()); - let start = moq_clock::now(); + let start = kio::clock::now(); resolver.add((0..10).map(|i| line(i, i)).collect()).await.unwrap(); for i in 0..10 { let candidate = next(&mut commands).await.unwrap(); @@ -244,7 +244,7 @@ mod tests { resolver.add(vec![line(1, 1)]).await.unwrap(); // The third waits for the first to finish, rather than queueing. - let start = moq_clock::now(); + let start = kio::clock::now(); resolver.add(vec![line(2, 2)]).await.unwrap(); assert_eq!(start.elapsed(), DELAY); assert_eq!(fake.most_in_flight.load(Ordering::SeqCst), 1); @@ -282,7 +282,7 @@ mod tests { // The query in flight is cancelled before it answers, the rest of the batch // is skipped, and signaling sees the peer is closed. - moq_clock::sleep(DELAY / 2).await; + kio::clock::sleep(DELAY / 2).await; assert_eq!(fake.in_flight.load(Ordering::SeqCst), 0); assert!(matches!(resolver.add(vec![line(2, 2)]).await, Err(Error::Closed))); assert_eq!(fake.queries(), ["host0.local"]); diff --git a/rs/moq-tokio/src/websocket.rs b/rs/moq-tokio/src/websocket.rs index eaf5ee1004e..2be105f88f4 100644 --- a/rs/moq-tokio/src/websocket.rs +++ b/rs/moq-tokio/src/websocket.rs @@ -168,7 +168,7 @@ where { let timeout = options.timeout.unwrap_or(crate::listen::DEFAULT_TIMEOUT); let deadline = (!timeout.is_zero()) - .then(|| moq_clock::now().checked_add(timeout)) + .then(|| kio::clock::now().checked_add(timeout)) .flatten(); // A vanished peer sends no FIN. Ping and timeout bound the same stale-session // lifetime that QUIC's idle timeout bounds on the native path. @@ -410,7 +410,7 @@ pub(crate) async fn connect( // TODO if let chain match resolved.delay { delay if !delay.is_zero() && !WEBSOCKET_WON.lock().unwrap().contains(&key) => { - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; tracing::debug!(peer = %crate::connect::Endpoint(&url), delay_ms = %delay.as_millis(), "QUIC not yet connected, attempting WebSocket fallback"); } _ => {} @@ -748,7 +748,7 @@ impl Listener { } Err(err) => { if let Some(delay) = self.health.failed(&err) { - moq_clock::sleep(delay).await; + kio::clock::sleep(delay).await; } } } diff --git a/rs/moq-transcode/Cargo.toml b/rs/moq-transcode/Cargo.toml index 8bab35ab297..613c1ee9e78 100644 --- a/rs/moq-transcode/Cargo.toml +++ b/rs/moq-transcode/Cargo.toml @@ -45,7 +45,7 @@ tracing = { workspace = true } [dev-dependencies] anyhow = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-tokio = { path = "../moq-tokio", default-features = false, features = ["quic", "aws-lc-rs", "websocket"] } # The tests encode with OpenH264, the one encoder a GPU-less host has, so they # turn it on without making it a default of the library. diff --git a/rs/moq-transcode/clippy.toml b/rs/moq-transcode/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-transcode/clippy.toml +++ b/rs/moq-transcode/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-transcode/src/catalog.rs b/rs/moq-transcode/src/catalog.rs index 9575d64932b..79d6a64541d 100644 --- a/rs/moq-transcode/src/catalog.rs +++ b/rs/moq-transcode/src/catalog.rs @@ -1011,7 +1011,7 @@ mod tests { let ago = Duration::from_secs(60); let _ = moq_net::time::Instant::now(); tokio::time::advance(ago).await; - let clock = moq_mux::Clock::at(moq_net::time::Instant::now() - ago, moq_clock::wall() - ago).unwrap(); + let clock = moq_mux::Clock::at(moq_net::time::Instant::now() - ago, kio::clock::wall() - ago).unwrap(); let mut input = moq_net::broadcast::Info::default().produce(); let source = moq_mux::catalog::Producer::new(&mut input, moq_mux::catalog::Config::default().with_clock(clock)).unwrap(); diff --git a/rs/moq-uring/Cargo.toml b/rs/moq-uring/Cargo.toml index 092b17e6058..55b1c43e18b 100644 --- a/rs/moq-uring/Cargo.toml +++ b/rs/moq-uring/Cargo.toml @@ -20,18 +20,17 @@ quic = ["dep:moq-congestion", "dep:moq-quic", "dep:rustls", "dep:rustls-platform # qlog crate and its serde_json encoder into moq-quic, which a production build has # no use for. qlog = ["moq-quic?/qlog"] -# Workers created inside a tokio runtime with a `moq_clock::Manual` clock installed +# Workers created inside a tokio runtime with a `kio::clock::Manual` clock installed # run on that clock, so a test decides when their time passes. For test builds. -_manual = ["moq-clock/manual"] +_manual = ["kio/manual"] [target.'cfg(target_os = "linux")'.dependencies] bytes = "1" http = "1" io-uring = { workspace = true } -kio = { workspace = true } +# The worker is a kio clock backend: its turn's instant is the ambient clock. +kio = { workspace = true, features = ["runtime"] } libc = { workspace = true } -# The worker is a moq-clock backend: its turn's instant is the ambient clock. -moq-clock = { workspace = true } moq-congestion = { workspace = true, optional = true } moq-net = { workspace = true } moq-quic = { workspace = true, features = ["rustls-aws-lc-rs"], optional = true } diff --git a/rs/moq-uring/MIGRATE.md b/rs/moq-uring/MIGRATE.md index 1b7f9489404..b889d2beff2 100644 --- a/rs/moq-uring/MIGRATE.md +++ b/rs/moq-uring/MIGRATE.md @@ -26,11 +26,11 @@ Pass a received `Packet::dst_ip()` as `src_ip` to answer from the address the pe moq-net dropped `connect_lite`, `accept_lite`, and `accept_request_lite`, and every session now needs a `Send` transport. Wrap the worker's session as `transport::Local::new(transport::Session::new(conn, address))` and call `connect`, `accept`, or `accept_request`. -### Timers run on moq-clock +### Timers run on `kio::clock` -The worker is a moq-clock backend, so its deadlines are `moq_clock::Instant`s instead of `std::time::Instant`s. -`Timer::set` takes an `Option`, and `quic::handshake::Info::deadline` is one. -Read the worker's time with `moq_clock::now()` inside it. +The worker is a `kio::clock` backend, so its deadlines are `kio::clock::Instant`s instead of `std::time::Instant`s. +`Timer::set` takes an `Option`, and `quic::handshake::Info::deadline` is one. +Read the worker's time with `kio::clock::now()` inside it. ### Datagrams take `SendOptions` (#5770, #5872) diff --git a/rs/moq-uring/README.md b/rs/moq-uring/README.md index c3491b6bd52..bd47fb53c30 100644 --- a/rs/moq-uring/README.md +++ b/rs/moq-uring/README.md @@ -2,7 +2,7 @@ Experimental Linux io\_uring support for the native MoQ stack: a thread-per-core `Worker` that owns a `SINGLE_ISSUER | DEFER_TASKRUN | -COOP_TASKRUN | TASKRUN_FLAG` ring, a userspace timer queue on moq-clock, a +COOP_TASKRUN | TASKRUN_FLAG` ring, a userspace timer queue on `kio::clock`, a local (`!Send`) task set, and the UDP sockets bound through it. - **Receive**: one persistent multishot `recvmsg` per socket, fed from a @@ -15,7 +15,7 @@ local (`!Send`) task set, and the UDP sockets bound through it. - **Send**: `sendmsg` with an explicit `UDP_SEGMENT` control message per call, staged in a fixed pool of buffers owned by id and released on completion (the shape a later `SENDMSG_ZC` needs). -- **Timers**: a `moq_clock::Deadlines` queue the worker advances once per +- **Timers**: a `kio::clock::Deadlines` queue the worker advances once per turn, from its one clock read; the earliest deadline rides `io_uring_enter` as an absolute timeout. Zero timeout SQEs. The queue is the worker's ambient clock, and `Handle::run` drives MoQ with it and a single timer. diff --git a/rs/moq-uring/benches/timers.rs b/rs/moq-uring/benches/timers.rs index a5132630377..5fbe5705cab 100644 --- a/rs/moq-uring/benches/timers.rs +++ b/rs/moq-uring/benches/timers.rs @@ -25,7 +25,7 @@ fn benchmark(c: &mut criterion::Criterion) { for armed in [1, 64, 1024, 16384] { // The rest of the table, spread across a minute so the re-armed timer // lands among them. - let now = moq_clock::now(); + let now = kio::clock::now(); let _others: Vec<_> = (0..armed) .map(|i| { let mut timer = handle.timer(); diff --git a/rs/moq-uring/clippy.toml b/rs/moq-uring/clippy.toml index 68e9ded5fd7..68724639f92 100644 --- a/rs/moq-uring/clippy.toml +++ b/rs/moq-uring/clippy.toml @@ -1,16 +1,16 @@ # Only the worker's clock backend (`clock.rs`, behind `#[allow]`) reads a host -# clock; everything else reads the worker's turn through moq-clock. +# clock; everything else reads the worker's turn through `kio::clock`. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the worker's clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the worker's clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the worker's clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the worker's clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the worker's clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the worker's clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, ] -disallowed-types = [{ path = "std::time::SystemTime", reason = "use moq_clock::Wall" }] +disallowed-types = [{ path = "std::time::SystemTime", reason = "use kio::clock::Wall" }] diff --git a/rs/moq-uring/src/clock.rs b/rs/moq-uring/src/clock.rs index 3712bfd7250..f4fc4b652b5 100644 --- a/rs/moq-uring/src/clock.rs +++ b/rs/moq-uring/src/clock.rs @@ -1,7 +1,7 @@ //! The worker's clock: the only module that reads the host clock. //! //! The worker samples it once per turn and hands that instant to its -//! [`moq_clock::Deadlines`] queue, which it enters as the thread's ambient clock, +//! [`kio::clock::Deadlines`] queue, which it enters as the thread's ambient clock, //! so everything it runs reads the sample instead of the host clock. The host //! clock is `CLOCK_MONOTONIC`, read directly so the park can hand the next //! deadline to the kernel as an absolute timeout without a second read. @@ -9,7 +9,7 @@ use std::task::Context; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; /// Where a worker's time comes from. #[derive(Clone)] @@ -21,7 +21,7 @@ pub(crate) enum Clock { /// The host clock alongside bounds teardown, which must end however long /// the test leaves its clock alone. #[cfg(feature = "_manual")] - Installed(moq_clock::Installed, Host), + Installed(kio::clock::Installed, Host), } /// How the worker waits for its next deadline while parked. @@ -42,7 +42,7 @@ impl Clock { /// The clock installed on the current tokio runtime, or else the host's. pub fn new() -> Self { #[cfg(feature = "_manual")] - if let Some(clock) = moq_clock::Installed::current() { + if let Some(clock) = kio::clock::Installed::current() { return Self::Installed(clock, Host::calibrate()); } Self::Host(Host::calibrate()) @@ -69,7 +69,7 @@ impl Clock { /// How to park for `deadline`. A manual clock keeps its alarm in `alarm`, so /// advancing it wakes the worker through `cx`. - pub fn wait(&self, deadline: Option, alarm: &mut Option, cx: &mut Context<'_>) -> Wait { + pub fn wait(&self, deadline: Option, alarm: &mut Option, cx: &mut Context<'_>) -> Wait { match self { Self::Host(host) => { let _ = (alarm, cx); @@ -96,23 +96,23 @@ impl Clock { } } -/// `CLOCK_MONOTONIC`, mapped onto moq-clock's instants at one calibration point. +/// `CLOCK_MONOTONIC`, mapped onto `kio::clock`'s instants at one calibration point. /// -/// moq-clock's host clock reads the same monotonic clock from an origin it keeps +/// `kio::clock`'s host clock reads the same monotonic clock from an origin it keeps /// to itself, so the two differ by a constant that one reading of each pins down /// to within the gap between them. #[derive(Clone, Copy)] pub(crate) struct Host { /// A monotonic reading. monotonic: Duration, - /// moq-clock's instant at that reading. + /// `kio::clock`'s instant at that reading. instant: Instant, } impl Host { fn calibrate() -> Self { let before = monotonic(); - let instant = moq_clock::now(); + let instant = kio::clock::now(); let after = monotonic(); Self { monotonic: before + (after - before) / 2, @@ -142,18 +142,18 @@ fn monotonic() -> Duration { mod tests { use super::*; - /// The calibrated clock agrees with moq-clock's host clock, which reads the same + /// The calibrated clock agrees with `kio::clock`'s host clock, which reads the same /// monotonic clock from another origin. #[test] - fn host_tracks_moq_clock() { + fn host_tracks_kio_clock() { // Off by at most the gap between the two calibration reads, which a // preemption can stretch, so measure it rather than assume one. let start = monotonic(); let host = Host::calibrate(); let slack = monotonic() - start; - let before = moq_clock::now(); + let before = kio::clock::now(); let now = host.now(); - let after = moq_clock::now(); + let after = kio::clock::now(); assert!( before <= now + slack && now <= after + slack, "{before:?} <= {now:?} <= {after:?}" @@ -166,7 +166,7 @@ mod tests { #[test] fn host_time_passes_on_a_standing_manual_clock() { let runtime = tokio::runtime::Builder::new_current_thread().build().unwrap(); - let manual = moq_clock::Manual::new().install(runtime.handle()); + let manual = kio::clock::Manual::new().install(runtime.handle()); let _entered = runtime.enter(); let clock = Clock::new(); let start = clock.host_now(); diff --git a/rs/moq-uring/src/quic/driver/connection.rs b/rs/moq-uring/src/quic/driver/connection.rs index bef35adab27..a0835ed378c 100644 --- a/rs/moq-uring/src/quic/driver/connection.rs +++ b/rs/moq-uring/src/quic/driver/connection.rs @@ -1,6 +1,6 @@ //! The connection: shared state, the driver task, and the session handle. -use moq_clock::Instant; +use kio::clock::Instant; use std::cell::RefCell; use std::net::SocketAddr; use std::rc::{Rc, Weak}; diff --git a/rs/moq-uring/src/quic/handshake.rs b/rs/moq-uring/src/quic/handshake.rs index 6e0d0f61ec5..0fca8519f70 100644 --- a/rs/moq-uring/src/quic/handshake.rs +++ b/rs/moq-uring/src/quic/handshake.rs @@ -7,7 +7,7 @@ use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; /// How an endpoint bounds the handshakes it accepts. #[derive(Clone, Debug, Default)] diff --git a/rs/moq-uring/src/quic/qlog.rs b/rs/moq-uring/src/quic/qlog.rs index 0332daf9da1..d1ca2b6ad18 100644 --- a/rs/moq-uring/src/quic/qlog.rs +++ b/rs/moq-uring/src/quic/qlog.rs @@ -80,8 +80,8 @@ impl Sink { let dir = dir.into(); let process = std::process::id(); let sink = NEXT_SINK.fetch_add(1, Ordering::Relaxed); - let started = moq_clock::wall() - .saturating_duration_since(moq_clock::Wall::UNIX_EPOCH) + let started = kio::clock::wall() + .saturating_duration_since(kio::clock::Wall::UNIX_EPOCH) .as_millis(); // A read-only or missing directory is reported here, where the diff --git a/rs/moq-uring/src/shared.rs b/rs/moq-uring/src/shared.rs index f4268efffba..2e888946fa9 100644 --- a/rs/moq-uring/src/shared.rs +++ b/rs/moq-uring/src/shared.rs @@ -5,7 +5,7 @@ //! ring (submitting inline when the queue is full), while completions are only //! reaped by the worker loop. -use moq_clock::Instant; +use kio::clock::Instant; use std::cell::{Cell, RefCell}; use std::collections::VecDeque; use std::io; @@ -58,7 +58,7 @@ pub(crate) struct Shared { pub clock: Clock, /// The worker's timers, at the instant of its current turn. Entered as the /// ambient clock while the worker polls. - pub deadlines: moq_clock::Deadlines, + pub deadlines: kio::clock::Deadlines, /// Whether a turn is running, so `deadlines` already holds its instant. pub turning: Cell, /// Tasks handed to [`crate::Handle::spawn`], drained by the worker loop. diff --git a/rs/moq-uring/src/timer.rs b/rs/moq-uring/src/timer.rs index eeed61508fc..bd23cde6e55 100644 --- a/rs/moq-uring/src/timer.rs +++ b/rs/moq-uring/src/timer.rs @@ -1,6 +1,6 @@ //! Userspace timers on the worker's deadline queue, never a timeout SQE. //! -//! Every armed deadline lives in the worker's [`moq_clock::Deadlines`]. The +//! Every armed deadline lives in the worker's [`kio::clock::Deadlines`]. The //! worker advances it to each turn's instant, firing the due prefix, and parks //! with the earliest remaining deadline as the absolute `io_uring_enter` //! timeout, so timers cost zero submissions and re-arming is a pure memory @@ -9,7 +9,7 @@ use std::sync::Arc; use std::task::Poll; -use moq_clock::{Deadline, Deadlines, Instant}; +use kio::clock::{Deadline, Deadlines, Instant}; use crate::metrics::Counters; diff --git a/rs/moq-uring/src/udp.rs b/rs/moq-uring/src/udp.rs index c3183fa820a..6bd2bca0255 100644 --- a/rs/moq-uring/src/udp.rs +++ b/rs/moq-uring/src/udp.rs @@ -461,7 +461,7 @@ pub(crate) struct SockShared { /// datagrams go out alone: the route or driver cannot segment. gso: Cell, /// When a lost send was last logged, so a flood of them logs once per interval. - lost_logged: Cell>, + lost_logged: Cell>, bgid: u16, closed: Cell, rx: RefCell, @@ -553,7 +553,7 @@ impl SockShared { tracing::debug!(%err, to = %op.to, "send lost"); return; } - let now = moq_clock::now(); + let now = kio::clock::now(); if self .lost_logged .get() diff --git a/rs/moq-uring/src/worker.rs b/rs/moq-uring/src/worker.rs index 8f21a95b716..022abf7554d 100644 --- a/rs/moq-uring/src/worker.rs +++ b/rs/moq-uring/src/worker.rs @@ -7,7 +7,7 @@ use std::task::{Context, Poll}; use std::time::Duration; use io_uring::{EnterFlags, IoUring, opcode, types}; -use moq_clock::Instant; +use kio::clock::Instant; use crate::clock::{Clock, Wait}; use crate::metrics::Metrics; @@ -110,7 +110,7 @@ pub struct Worker { /// parked wakes the worker to re-park for it. owner: kio::Waiter, /// A manual clock's wake for the next deadline; the host clock needs none. - alarm: Option, + alarm: Option, } impl Worker { @@ -153,7 +153,7 @@ impl Worker { } let clock = Clock::new(); - let deadlines = moq_clock::Deadlines::new(clock.now()); + let deadlines = kio::clock::Deadlines::new(clock.now()); let unpark = Unpark::new(metrics.clone()); // A wake CQE can join a larger batch after warmup. Reserve the kernel's // actual queue size so copying those completions does not allocate. @@ -195,8 +195,8 @@ impl Worker { /// is fatal to the worker. /// /// While it runs, the worker's clock is the thread's ambient - /// [`moq_clock`] clock: [`moq_clock::now`] reads the instant the current - /// turn sampled, and [`moq_clock::sleep`] arms this worker's timers. + /// [`kio::clock`] clock: [`kio::clock::now`] reads the instant the current + /// turn sampled, and [`kio::clock::sleep`] arms this worker's timers. pub fn block_on(&mut self, future: F) -> Result { let mut future = std::pin::pin!(future); let waker = self.shared.unpark.waker(); @@ -519,7 +519,7 @@ impl Worker { /// current instant until this drops. struct Turn { shared: Rc, - _ambient: moq_clock::Entered, + _ambient: kio::clock::Entered, } impl Turn { @@ -654,7 +654,7 @@ pub(crate) struct Owner { /// the driver that owns it is torn down by the same drop that would need /// it. #[cfg_attr(not(feature = "quic"), allow(dead_code, reason = "only the `quic` feature uses it"))] - deadlines: moq_clock::Deadlines, + deadlines: kio::clock::Deadlines, #[cfg_attr(not(feature = "quic"), allow(dead_code, reason = "only the `quic` feature uses it"))] metrics: std::sync::Arc, } @@ -786,9 +786,9 @@ mod tests { } /// A worker on a manual clock, which only `advance` moves. - fn manual() -> Option<(Worker, moq_clock::Installed)> { + fn manual() -> Option<(Worker, kio::clock::Installed)> { let runtime = tokio::runtime::Builder::new_current_thread().build().unwrap(); - let clock = moq_clock::Manual::new().install(runtime.handle()); + let clock = kio::clock::Manual::new().install(runtime.handle()); let _entered = runtime.enter(); Some((worker()?, clock)) } @@ -1011,11 +1011,11 @@ mod tests { let handle = worker.handle(); let at = worker .block_on(async move { - let at = moq_clock::now() + Duration::from_millis(50); + let at = kio::clock::now() + Duration::from_millis(50); let mut timer = handle.timer(); timer.set(Some(at)); timer.wait().await; - assert!(moq_clock::now() >= at, "fired before the turn reached it"); + assert!(kio::clock::now() >= at, "fired before the turn reached it"); at }) .unwrap(); @@ -1042,8 +1042,8 @@ mod tests { }); let woke = worker .block_on(async move { - moq_clock::sleep(Duration::from_secs(5)).await; - moq_clock::now() + kio::clock::sleep(Duration::from_secs(5)).await; + kio::clock::now() }) .unwrap(); advancer.join().unwrap(); @@ -1058,14 +1058,14 @@ mod tests { let handle = worker.handle(); let (now, timed_out) = worker .block_on(async move { - let now = moq_clock::now(); + let now = kio::clock::now(); // Due at once, so this needs no advance. - let timed_out = moq_clock::timeout(Duration::ZERO, std::future::pending::<()>()).await; + let timed_out = kio::clock::timeout(Duration::ZERO, std::future::pending::<()>()).await; assert_eq!(handle.now(), now); (now, timed_out.is_err()) }) .unwrap(); - assert_eq!(now, moq_clock::Instant::ZERO + Duration::from_secs(1)); + assert_eq!(now, kio::clock::Instant::ZERO + Duration::from_secs(1)); assert!(timed_out); } @@ -1076,7 +1076,7 @@ mod tests { let Some((mut worker, clock)) = manual() else { return }; clock.advance(Duration::from_secs(5)); let (wall, origin) = worker - .block_on(async { (moq_clock::wall(), moq_clock::origin()) }) + .block_on(async { (kio::clock::wall(), kio::clock::origin()) }) .unwrap(); assert_eq!(wall, clock.wall(), "the worker read the host's wall time"); assert_eq!(origin.0, clock.now()); @@ -1176,7 +1176,7 @@ mod tests { result: 0, flags: 0, }; - let before = moq_clock::Instant::ZERO; + let before = kio::clock::Instant::ZERO; let deadline = before + Duration::from_millis(1); let mut now = [before, deadline].into_iter(); @@ -1763,7 +1763,7 @@ mod tests { fn metrics_count_an_unpolled_expiry_as_fired() { let metrics = Metrics::default(); let runtime = tokio::runtime::Builder::new_current_thread().build().unwrap(); - let clock = moq_clock::Manual::new().install(runtime.handle()); + let clock = kio::clock::Manual::new().install(runtime.handle()); let _entered = runtime.enter(); let Some(mut worker) = worker_with(Config { metrics: metrics.clone(), diff --git a/rs/moq-uring/tests/integration/endpoint.rs b/rs/moq-uring/tests/integration/endpoint.rs index 3d8ac6d6261..9dd24bd291f 100644 --- a/rs/moq-uring/tests/integration/endpoint.rs +++ b/rs/moq-uring/tests/integration/endpoint.rs @@ -690,9 +690,9 @@ fn connections_share_one_tx_buffer_fairly() { .expect("second client socket"); let mut second_config = dial_config(server); second_config.transport.idle_timeout = Duration::from_millis(500); - let started = moq_clock::now(); + let started = kio::clock::now(); let second = quic::client::connect(second_sock, &second_config).await; - let elapsed = moq_clock::now() - started; + let elapsed = kio::clock::now() - started; running.set(false); let second = second.expect("the second connection must not starve"); assert!( diff --git a/rs/moq-uring/tests/integration/local_addr.rs b/rs/moq-uring/tests/integration/local_addr.rs index a6f5434a363..905d6799ab2 100644 --- a/rs/moq-uring/tests/integration/local_addr.rs +++ b/rs/moq-uring/tests/integration/local_addr.rs @@ -184,7 +184,7 @@ fn a_wildcard_endpoint_handshakes_on_a_secondary_address() { let request = moq_tokio::quic::web::proto::ConnectRequest::new( url::Url::parse(&format!("https://{addr}/")).expect("url"), ); - moq_clock::timeout(TIMEOUT, client.connect(request)) + kio::clock::timeout(TIMEOUT, client.connect(request)) .await .expect("handshake stalled") .expect("connect"); diff --git a/rs/moq-v4l/clippy.toml b/rs/moq-v4l/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-v4l/clippy.toml +++ b/rs/moq-v4l/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-video/Cargo.toml b/rs/moq-video/Cargo.toml index e86356cdb0a..aa603bc021d 100644 --- a/rs/moq-video/Cargo.toml +++ b/rs/moq-video/Cargo.toml @@ -34,7 +34,7 @@ default = ["mediacodec", "nvidia"] # frameworks (Windows display/window capture requires Windows 10 2004+ WGC). # Still off by default until every distribution ships it, which is # a packaging decision rather than a build cost. moq-cli's `capture` turns it on. -capture = ["dep:kio", "dep:libc", "dep:moq-v4l", "dep:x11rb", "dep:zune-jpeg"] +capture = ["dep:libc", "dep:moq-v4l", "dep:x11rb", "dep:zune-jpeg"] # Android MediaCodec encode/decode and its AHardwareBuffer frame surface. Kept # behind a feature because these NDK entry points require API 26, while the # language-binding artifacts still support API 24 and disable default features. @@ -122,12 +122,10 @@ fast_image_resize = "6" h264-reader = "0.9.0" # Catalog types (VideoConfig / VideoCodec) the decode consumer reads. hang = { workspace = true } -# The capture publish's control handle. -kio = { workspace = true, optional = true } +kio = { workspace = true, features = ["runtime"] } # libvpx bindings for the `vpx` feature. The library itself comes from the build # host; see the feature above. libvpx-native-sys = { version = "5.0.17", optional = true } -moq-clock = { workspace = true } moq-mux = { workspace = true } moq-net = { workspace = true } # Vendored, statically linked software H.264 fallback (no system dependency). diff --git a/rs/moq-video/clippy.toml b/rs/moq-video/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-video/clippy.toml +++ b/rs/moq-video/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/moq-video/src/capture/avfoundation.rs b/rs/moq-video/src/capture/avfoundation.rs index 0e853ce1637..cf7a1415250 100644 --- a/rs/moq-video/src/capture/avfoundation.rs +++ b/rs/moq-video/src/capture/avfoundation.rs @@ -126,7 +126,7 @@ pub(super) async fn open(config: &Config, device: Option<&str>) -> Result frame, Ok(Err(error)) => return Err(error), Ok(Ok(None)) | Err(_) => { @@ -179,7 +179,7 @@ async fn ensure_camera_access(media: &AVMediaType) -> Result<(), Error> { }); unsafe { AVCaptureDevice::requestAccessForMediaType_completionHandler(media, &handler) }; - return match moq_clock::timeout(ACCESS_TIMEOUT, rx).await { + return match kio::clock::timeout(ACCESS_TIMEOUT, rx).await { Ok(Ok(true)) => Ok(()), Ok(Ok(false)) => Err(Error::PermissionDenied( "camera access; enable it in System Settings > Privacy & Security > Camera".to_string(), diff --git a/rs/moq-video/src/capture/channel.rs b/rs/moq-video/src/capture/channel.rs index c0463b423ae..707bd080932 100644 --- a/rs/moq-video/src/capture/channel.rs +++ b/rs/moq-video/src/capture/channel.rs @@ -8,7 +8,7 @@ //! the [`Stream`](super::Stream) drops, the device is released, and no //! blocking thread is left pinned. -use moq_clock::Instant; +use kio::clock::Instant; use std::sync::{Arc, Mutex}; use tokio::sync::Notify; diff --git a/rs/moq-video/src/capture/mod.rs b/rs/moq-video/src/capture/mod.rs index 5f017b2ad1b..1bd7b6e773a 100644 --- a/rs/moq-video/src/capture/mod.rs +++ b/rs/moq-video/src/capture/mod.rs @@ -412,7 +412,7 @@ impl Synthetic { } /// Deliver a frame acquired at `captured`. - pub(crate) fn push_at(&self, surface: crate::frame::Surface, captured: moq_clock::Instant) { + pub(crate) fn push_at(&self, surface: crate::frame::Surface, captured: kio::clock::Instant) { self.chan.push_at(surface, captured); } diff --git a/rs/moq-video/src/capture/pipewire.rs b/rs/moq-video/src/capture/pipewire.rs index f67d804b16a..491a769c0fb 100644 --- a/rs/moq-video/src/capture/pipewire.rs +++ b/rs/moq-video/src/capture/pipewire.rs @@ -175,7 +175,7 @@ async fn start(config: &Config, capture: Capture, session: Option) _session: session, }; - let geo = match moq_clock::timeout(FORMAT_TIMEOUT, geo_rx).await { + let geo = match kio::clock::timeout(FORMAT_TIMEOUT, geo_rx).await { Ok(Ok(result)) => result?, Ok(Err(_)) => { return Err(Error::Codec(anyhow::anyhow!( @@ -190,7 +190,7 @@ async fn start(config: &Config, capture: Capture, session: Option) } }; - let first = match moq_clock::timeout(FIRST_FRAME_TIMEOUT, chan.recv()).await { + let first = match kio::clock::timeout(FIRST_FRAME_TIMEOUT, chan.recv()).await { Ok(Ok(Some(frame))) => frame, Ok(Err(error)) => return Err(error), Ok(Ok(None)) | Err(_) => { diff --git a/rs/moq-video/src/capture/screencapture.rs b/rs/moq-video/src/capture/screencapture.rs index 675a00b72c9..17c75cccf4b 100644 --- a/rs/moq-video/src/capture/screencapture.rs +++ b/rs/moq-video/src/capture/screencapture.rs @@ -191,7 +191,7 @@ async fn open(config: &Config, filter: &SCContentFilter, size: (u32, u32)) -> Re }; let label = config.source.label(); - let first = match moq_clock::timeout(FIRST_FRAME_TIMEOUT, chan.recv()).await { + let first = match kio::clock::timeout(FIRST_FRAME_TIMEOUT, chan.recv()).await { Ok(Ok(Some(frame))) => frame, Ok(Err(error)) => return Err(error), Ok(Ok(None)) | Err(_) => { @@ -376,7 +376,7 @@ async fn shareable_content() -> Result, Error> { }); unsafe { SCShareableContent::getShareableContentWithCompletionHandler(&handler) }; - match moq_clock::timeout(ASYNC_TIMEOUT, rx).await { + match kio::clock::timeout(ASYNC_TIMEOUT, rx).await { Ok(Ok(Ok(content))) => Ok(content.0), Ok(Ok(Err(msg))) => Err(Error::Codec(anyhow::anyhow!("shareable content: {msg}"))), Ok(Err(_)) => Err(Error::Codec(anyhow::anyhow!("shareable content handler dropped"))), @@ -398,7 +398,7 @@ async fn start_capture(stream: &SCStream) -> Result<(), Error> { }); unsafe { stream.startCaptureWithCompletionHandler(Some(&handler)) }; - match moq_clock::timeout(ASYNC_TIMEOUT, rx).await { + match kio::clock::timeout(ASYNC_TIMEOUT, rx).await { Ok(Ok(None)) => Ok(()), Ok(Ok(Some(msg))) => Err(Error::Codec(anyhow::anyhow!("start capture: {msg}"))), Ok(Err(_)) => Err(Error::Codec(anyhow::anyhow!("start-capture handler dropped"))), diff --git a/rs/moq-video/src/capture/settle.rs b/rs/moq-video/src/capture/settle.rs index 8336fc40de6..9a526bb999f 100644 --- a/rs/moq-video/src/capture/settle.rs +++ b/rs/moq-video/src/capture/settle.rs @@ -8,7 +8,7 @@ //! again. So hold instead: once the geometry moves, stop capturing but keep //! polling, and only end once it has stayed put. -use moq_clock::Instant; +use kio::clock::Instant; use std::time::Duration; /// How long a new geometry has to hold still before the stream ends. diff --git a/rs/moq-video/src/capture/wgc.rs b/rs/moq-video/src/capture/wgc.rs index 5064aa9d1cf..84ab832cfef 100644 --- a/rs/moq-video/src/capture/wgc.rs +++ b/rs/moq-video/src/capture/wgc.rs @@ -4,7 +4,7 @@ use std::sync::{Condvar, Mutex}; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::Timestamp; diff --git a/rs/moq-video/src/capture/wgc/native.rs b/rs/moq-video/src/capture/wgc/native.rs index 452a5083bca..cbd25a4158e 100644 --- a/rs/moq-video/src/capture/wgc/native.rs +++ b/rs/moq-video/src/capture/wgc/native.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use std::thread::JoinHandle; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use windows::Foundation::{Metadata::ApiInformation, TypedEventHandler}; use windows::Graphics::Capture::{ diff --git a/rs/moq-video/src/capture/x11.rs b/rs/moq-video/src/capture/x11.rs index 1c296c63405..52ca675934b 100644 --- a/rs/moq-video/src/capture/x11.rs +++ b/rs/moq-video/src/capture/x11.rs @@ -7,7 +7,7 @@ //! memory. It is the only Linux backend for `Source::Display`, so a display //! that X11 cannot reach is refused rather than handed to the portal. -use moq_clock::Instant; +use kio::clock::Instant; use std::os::fd::AsRawFd; use std::ptr::NonNull; use std::sync::Arc; diff --git a/rs/moq-video/src/decode/backend/v4l2.rs b/rs/moq-video/src/decode/backend/v4l2.rs index 38e2379dc68..2f68e9043c1 100644 --- a/rs/moq-video/src/decode/backend/v4l2.rs +++ b/rs/moq-video/src/decode/backend/v4l2.rs @@ -32,7 +32,7 @@ //! sequence follows the kernel's stateful decoder documentation and an //! implementation that also ran on a Pi Zero 2 W and a Pi 3. -use moq_clock::Instant; +use kio::clock::Instant; use std::collections::VecDeque; use std::time::Duration; diff --git a/rs/moq-video/src/decode/consumer.rs b/rs/moq-video/src/decode/consumer.rs index 8acb7af0f13..bd50b8daf9a 100644 --- a/rs/moq-video/src/decode/consumer.rs +++ b/rs/moq-video/src/decode/consumer.rs @@ -5,7 +5,7 @@ use std::pin::Pin; use std::task::{Context, Poll, ready}; use hang::catalog::VideoConfig; -use moq_clock::Instant; +use kio::clock::Instant; use moq_mux::container::Read as Encoded; use super::decoder::Config; @@ -218,7 +218,7 @@ impl Consumer { fn poll_read( &mut self, cx: &mut Context<'_>, - sleep: &mut Option>>, + sleep: &mut Option>>, ) -> Poll, Error>> { loop { let deadline = match self.selector.next(Instant::now()) { @@ -265,7 +265,7 @@ impl Consumer { let Some(deadline) = deadline else { return Poll::Pending; }; - let sleep = sleep.get_or_insert_with(|| Box::pin(moq_clock::sleep_until(deadline))); + let sleep = sleep.get_or_insert_with(|| Box::pin(kio::clock::sleep_until(deadline))); sleep.as_mut().reset(deadline); ready!(sleep.as_mut().poll(cx)); } diff --git a/rs/moq-video/src/decode/select.rs b/rs/moq-video/src/decode/select.rs index 6b522568c15..480e5423f3d 100644 --- a/rs/moq-video/src/decode/select.rs +++ b/rs/moq-video/src/decode/select.rs @@ -15,7 +15,7 @@ use std::collections::VecDeque; use std::time::Duration; -use moq_clock::Instant; +use kio::clock::Instant; use super::Read; diff --git a/rs/moq-video/src/encode/backend/v4l2.rs b/rs/moq-video/src/encode/backend/v4l2.rs index 4f82dbf5500..4efa14a4e43 100644 --- a/rs/moq-video/src/encode/backend/v4l2.rs +++ b/rs/moq-video/src/encode/backend/v4l2.rs @@ -34,7 +34,7 @@ //! from an implementation that also ran on a Pi Zero 2 W and a Pi 3; those two //! have not been re-run with this port. -use moq_clock::Instant; +use kio::clock::Instant; use std::collections::VecDeque; use std::time::Duration; diff --git a/rs/moq-video/src/encode/producer.rs b/rs/moq-video/src/encode/producer.rs index 3acba2f2f75..e71764df051 100644 --- a/rs/moq-video/src/encode/producer.rs +++ b/rs/moq-video/src/encode/producer.rs @@ -1145,10 +1145,10 @@ mod tests { /// published timestamp may land up to `SAMPLING` early, never late. #[cfg(all(feature = "capture", feature = "openh264"))] mod clock { - use moq_clock::Wall; + use kio::clock::Wall; use std::time::Duration; - use moq_clock::Instant; + use kio::clock::Instant; use super::*; use crate::capture::Synthetic; @@ -1186,7 +1186,7 @@ mod tests { impl Fixture { /// Start the capture loop on a broadcast whose clock began `behind` ago, at `wall`. async fn start(behind: Duration, wall: Wall) -> Self { - let epoch = moq_clock::now() + let epoch = kio::clock::now() .checked_sub(behind) .expect("a monotonic clock that far back"); let clock = moq_mux::Clock::at(epoch, wall).unwrap(); @@ -1338,7 +1338,7 @@ mod tests { async fn a_late_first_frame_publishes_its_acquisition() { tokio::task::LocalSet::new() .run_until(async { - let fixture = Fixture::start(Duration::from_secs(5), moq_clock::wall()).await; + let fixture = Fixture::start(Duration::from_secs(5), kio::clock::wall()).await; let mut track = fixture.subscribe().await; let camera = fixture.camera(); @@ -1361,7 +1361,7 @@ mod tests { async fn a_device_clock_restart_continues_forward() { tokio::task::LocalSet::new() .run_until(async { - let fixture = Fixture::start(Duration::from_secs(1), moq_clock::wall()).await; + let fixture = Fixture::start(Duration::from_secs(1), kio::clock::wall()).await; let mut track = fixture.subscribe().await; let camera = fixture.camera(); @@ -1404,7 +1404,7 @@ mod tests { tokio::task::LocalSet::new() .run_until(async { let idle = Duration::from_millis(300); - let fixture = Fixture::start(Duration::from_secs(1), moq_clock::wall()).await; + let fixture = Fixture::start(Duration::from_secs(1), kio::clock::wall()).await; let mut track = fixture.subscribe().await; let camera = fixture.camera(); @@ -1440,7 +1440,7 @@ mod tests { tokio::task::LocalSet::new() .run_until(async { // Whole seconds, so the advertised mapping holds it exactly. - let now = moq_clock::wall().checked_duration_since(Wall::UNIX_EPOCH).unwrap(); + let now = kio::clock::wall().checked_duration_since(Wall::UNIX_EPOCH).unwrap(); let wall = Wall::UNIX_EPOCH + Duration::from_secs(now.as_secs() - 3600); let fixture = Fixture::start(Duration::from_secs(1), wall).await; let advertised = fixture.catalog.snapshot().clock; @@ -1468,7 +1468,7 @@ mod tests { async fn hls_records_keep_the_live_timestamps() { tokio::task::LocalSet::new() .run_until(async { - let fixture = Fixture::start(Duration::from_secs(1), moq_clock::wall()).await; + let fixture = Fixture::start(Duration::from_secs(1), kio::clock::wall()).await; // The encoder's GOP hint declares the duration up front. let hls = fixture.catalog.snapshot().video.renditions["video"] .hls @@ -1936,7 +1936,7 @@ mod tests { probe::refuse_once(ceiling.as_bps()); // A minute without a wake is far past anything the ramp still needs. - while let Ok(next) = moq_clock::timeout(Duration::from_secs(60), next_target(&mut rate)).await { + while let Ok(next) = kio::clock::timeout(Duration::from_secs(60), next_target(&mut rate)).await { apply_target(&mut sink, &mut rate, next).await; } let bitrates = probe::bitrates(); diff --git a/rs/moq-video/src/frame.rs b/rs/moq-video/src/frame.rs index a14adc693df..7b082bc6c4e 100644 --- a/rs/moq-video/src/frame.rs +++ b/rs/moq-video/src/frame.rs @@ -180,11 +180,11 @@ pub(crate) fn wait_dma_buf_readable(fd: BorrowedFd<'_>) -> std::io::Result<()> { events: libc::POLLIN, revents: 0, }; - let deadline = moq_clock::now() + DMA_BUF_FENCE_TIMEOUT; + let deadline = kio::clock::now() + DMA_BUF_FENCE_TIMEOUT; loop { // A signal restarts the wait against the same deadline rather than // granting a fresh budget, so the total stall stays bounded. - let remaining = deadline.saturating_duration_since(moq_clock::now()); + let remaining = deadline.saturating_duration_since(kio::clock::now()); if remaining.is_zero() { return Err(std::io::Error::from(std::io::ErrorKind::TimedOut)); } diff --git a/rs/moq-wasm/README.md b/rs/moq-wasm/README.md index 267b2ba5010..5a4813619e3 100644 --- a/rs/moq-wasm/README.md +++ b/rs/moq-wasm/README.md @@ -53,8 +53,8 @@ What works today: ### Timestamp fallback -`moq_net::time::Instant` is the logical `moq_clock::Instant` on every -target. In the browser, moq-clock reads it from `performance.now()` through +`moq_net::time::Instant` is the logical `kio::clock::Instant` on every +target. In the browser, kio's clock reads it from `performance.now()` through `web_async::time`, since `std::time::Instant` panics there. `model/time.rs` anchors its timestamps on it. diff --git a/rs/moq-wasm/clippy.toml b/rs/moq-wasm/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/moq-wasm/clippy.toml +++ b/rs/moq-wasm/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/qmux/Cargo.toml b/rs/qmux/Cargo.toml index 5042b92682b..d257d70bcec 100644 --- a/rs/qmux/Cargo.toml +++ b/rs/qmux/Cargo.toml @@ -23,8 +23,7 @@ wss = ["ws", "dep:rustls", "tokio-tungstenite/rustls-tls-native-roots"] [dependencies] bytes = { workspace = true } futures = { workspace = true, optional = true } -kio = { workspace = true } -moq-clock = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-net = { workspace = true } # The stream state machine, shared with QUIC. `mux` drives it over a reliable transport. moq-quic = { workspace = true, features = ["mux"] } diff --git a/rs/qmux/clippy.toml b/rs/qmux/clippy.toml index 43c935eacb3..2a906f5558d 100644 --- a/rs/qmux/clippy.toml +++ b/rs/qmux/clippy.toml @@ -1,22 +1,22 @@ disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/rs/qmux/examples/common/mod.rs b/rs/qmux/examples/common/mod.rs index f667d7a51af..6570c741768 100644 --- a/rs/qmux/examples/common/mod.rs +++ b/rs/qmux/examples/common/mod.rs @@ -32,7 +32,7 @@ pub fn payload(seed: usize) -> Vec { /// Write all of `data` then the FIN, bounded by [`TIMEOUT`]. pub async fn send_all(send: &mut SendStream, data: &[u8], what: &str) -> anyhow::Result<()> { let mut data = Bytes::copy_from_slice(data); - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { while !data.is_empty() { send.write_buf(&mut data).await?; } @@ -47,7 +47,7 @@ pub async fn send_all(send: &mut SendStream, data: &[u8], what: &str) -> anyhow: /// Read until the FIN, bounded by [`TIMEOUT`]. pub async fn recv_all(recv: &mut RecvStream, what: &str) -> anyhow::Result { let mut buf = BytesMut::new(); - moq_clock::timeout(TIMEOUT, async { + kio::clock::timeout(TIMEOUT, async { while let Some(chunk) = recv.read_chunk(usize::MAX).await? { buf.extend_from_slice(&chunk); } diff --git a/rs/qmux/examples/interop-client.rs b/rs/qmux/examples/interop-client.rs index 80dd33e8dd4..25d7ef3e2a9 100644 --- a/rs/qmux/examples/interop-client.rs +++ b/rs/qmux/examples/interop-client.rs @@ -19,7 +19,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { } // Rust -> TypeScript. - let mut send = moq_clock::timeout(TIMEOUT, session.open_uni(SendOptions::default())) + let mut send = kio::clock::timeout(TIMEOUT, session.open_uni(SendOptions::default())) .await .context("timed out opening the client unidirectional stream")??; send_all(&mut send, &payload(CLIENT_SEED), "the client flow-control payload").await?; @@ -27,7 +27,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { // TypeScript -> Rust. Server-initiated streams are the ids only a // `Session::accept` session may mint; a client-role server would be rejected // here rather than accepted. - let mut recv = moq_clock::timeout(TIMEOUT, session.accept_uni()) + let mut recv = kio::clock::timeout(TIMEOUT, session.accept_uni()) .await .context("timed out accepting the server unidirectional stream")??; let received = recv_all(&mut recv, "the server flow-control payload").await?; @@ -36,7 +36,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { } // Exercise both halves of one bidirectional stream and FIN propagation. - let (mut send, mut recv) = moq_clock::timeout(TIMEOUT, session.open_bi(SendOptions::default())) + let (mut send, mut recv) = kio::clock::timeout(TIMEOUT, session.open_bi(SendOptions::default())) .await .context("timed out opening the bidirectional stream")??; let request = format!("ping:{}", version.alpn()); @@ -49,7 +49,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { // DATAGRAM is available only on record-framed drafts (QMux01+). if version.uses_records() { session.send_datagram(Bytes::from_static(b"rust-datagram"), SendOptions::default())?; - let datagram = moq_clock::timeout(TIMEOUT, session.recv_datagram()) + let datagram = kio::clock::timeout(TIMEOUT, session.recv_datagram()) .await .context("timed out receiving the TypeScript datagram")??; if datagram.as_ref() != b"typescript-datagram" { @@ -59,7 +59,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { bail!("QMux00 unexpectedly negotiated datagram support"); } - let closed = moq_clock::timeout(TIMEOUT, session.closed()) + let closed = kio::clock::timeout(TIMEOUT, session.closed()) .await .context("timed out waiting for the TypeScript server to close")?; match closed { diff --git a/rs/qmux/examples/interop-server.rs b/rs/qmux/examples/interop-server.rs index f1720444d78..14eb9f04b13 100644 --- a/rs/qmux/examples/interop-server.rs +++ b/rs/qmux/examples/interop-server.rs @@ -22,7 +22,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { } // TypeScript -> Rust, with the default Rust windows. - let mut recv = moq_clock::timeout(TIMEOUT, session.accept_uni()) + let mut recv = kio::clock::timeout(TIMEOUT, session.accept_uni()) .await .context("timed out accepting the client unidirectional stream")??; let received = recv_all(&mut recv, "the client flow-control payload").await?; @@ -32,13 +32,13 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { // Rust -> TypeScript. The client advertises deliberately small receive // windows, so this cannot finish unless it consumes and replenishes credit. - let mut send = moq_clock::timeout(TIMEOUT, session.open_uni(SendOptions::default())) + let mut send = kio::clock::timeout(TIMEOUT, session.open_uni(SendOptions::default())) .await .context("timed out opening the server unidirectional stream")??; send_all(&mut send, &payload(SERVER_SEED), "the server flow-control payload").await?; // Exercise both halves of one bidirectional stream and FIN propagation. - let (mut send, mut recv) = moq_clock::timeout(TIMEOUT, session.accept_bi()) + let (mut send, mut recv) = kio::clock::timeout(TIMEOUT, session.accept_bi()) .await .context("timed out accepting the bidirectional stream")??; let request = recv_all(&mut recv, "the bidirectional request").await?; @@ -51,7 +51,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { // DATAGRAM is available only on record-framed drafts (QMux01+). if version.uses_records() { session.send_datagram(Bytes::from_static(b"rust-datagram"), SendOptions::default())?; - let datagram = moq_clock::timeout(TIMEOUT, session.recv_datagram()) + let datagram = kio::clock::timeout(TIMEOUT, session.recv_datagram()) .await .context("timed out receiving the TypeScript datagram")??; if datagram.as_ref() != b"typescript-datagram" { @@ -61,7 +61,7 @@ async fn run(mut session: Session, version: Version) -> anyhow::Result<()> { bail!("QMux00 unexpectedly negotiated datagram support"); } - let closed = moq_clock::timeout(TIMEOUT, session.closed()) + let closed = kio::clock::timeout(TIMEOUT, session.closed()) .await .context("timed out waiting for the TypeScript client to close")?; match closed { diff --git a/rs/qmux/src/session.rs b/rs/qmux/src/session.rs index d60c8b2f97c..3b3596b9e71 100644 --- a/rs/qmux/src/session.rs +++ b/rs/qmux/src/session.rs @@ -12,7 +12,7 @@ use std::task::{Context, Poll}; use std::time::Duration; use bytes::{Buf, Bytes}; -use moq_clock::Instant; +use kio::clock::Instant; use moq_net::transport::{self as net, Address, poll}; use moq_quic::{Dir, Side, StreamId, TransportError, TransportErrorCode, VarInt, mux}; use rustc_hash::FxHashMap; @@ -207,7 +207,7 @@ impl Inner { // Register first: a handle mutating the connection after this sweep re-polls us. waiter.register(&mut state.driver); loop { - let now = moq_clock::now(); + let now = kio::clock::now(); if state.conn.poll_timeout().is_some_and(|at| now >= at) { state.conn.handle_timeout(now); } @@ -245,7 +245,7 @@ impl Inner { state.conn.set_backpressured(true); } loop { - let now = moq_clock::now(); + let now = kio::clock::now(); if state.conn.is_closed() && timer.closing.is_none() { timer.closing = Some(now + CLOSE_TIMEOUT); } @@ -296,7 +296,7 @@ impl Inner { /// The writer's timers. #[derive(Default)] struct Timer { - sleep: Option, + sleep: Option, /// When a closing session gives up on delivering its close frame. closing: Option, /// The current write is stalled on the transport. @@ -309,7 +309,7 @@ impl Timer { let Some(deadline) = deadline else { return false; }; - if moq_clock::now() >= deadline { + if kio::clock::now() >= deadline { return true; } let sleep = match &mut self.sleep { @@ -319,7 +319,7 @@ impl Timer { } sleep } - None => self.sleep.insert(moq_clock::sleep_until(deadline)), + None => self.sleep.insert(kio::clock::sleep_until(deadline)), }; waiter.poll_future(Pin::new(sleep)).is_ready() } @@ -377,12 +377,12 @@ async fn run_writer(inner: Arc, mut writer: W, reader: tokio:: if result.is_ok() { let bound = timer .closing - .map_or(CLOSE_TIMEOUT, |at| at.saturating_duration_since(moq_clock::now())); + .map_or(CLOSE_TIMEOUT, |at| at.saturating_duration_since(kio::clock::now())); let close = async { let _ = reader.await; writer.close().await }; - let _ = moq_clock::timeout(bound, close).await; + let _ = kio::clock::timeout(bound, close).await; } inner.writer_done(result); } @@ -402,7 +402,7 @@ async fn run_reader(inner: Arc, mut reader: R) { Ok(record) => { state.received_bytes += record.len() as u64; inner.wire.set_received_bytes(state.received_bytes); - state.conn.handle_record(record, moq_clock::now()); + state.conn.handle_record(record, kio::clock::now()); } Err(Error::FrameTooLarge) => state.conn.handle_oversized(), Err(Error::FlowControlError) => state.conn.handle_violation(violation( @@ -474,7 +474,7 @@ impl Session { /// Start a session over the transport without waiting for the handshake, for callers /// that resolved the protocol out of band (the WebSocket subprotocol, say). pub(crate) fn new(transport: T, side: Side, config: Config) -> Result { - let conn = mux::Connection::new(config.to_mux()?, side, moq_clock::now()); + let conn = mux::Connection::new(config.to_mux()?, side, kio::clock::now()); let inner = Arc::new(Inner { state: Mutex::new(State { conn, diff --git a/rs/qmux/src/session/tests.rs b/rs/qmux/src/session/tests.rs index 8bd74b22fa1..007e7ac0d16 100644 --- a/rs/qmux/src/session/tests.rs +++ b/rs/qmux/src/session/tests.rs @@ -192,7 +192,7 @@ async fn resets_and_stops_carry_their_codes() { write_all(&mut send, Bytes::from_static(b"refused")).await; let mut recv = server.accept_uni().await.unwrap(); recv.stop(11); - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; assert!(matches!(send.finish(), Err(Error::StreamStop(11)))); assert!(matches!(send.closed().await, Err(Error::StreamStop(11)))); } @@ -272,7 +272,7 @@ async fn a_request_before_the_handshake_waits_for_credit() { /// Poll `future` once, after letting every other task run. async fn futures_poll_once(future: &mut F) -> Option { - moq_clock::sleep(Duration::from_millis(10)).await; + kio::clock::sleep(Duration::from_millis(10)).await; std::future::poll_fn(|cx| { Poll::Ready(match Pin::new(&mut *future).poll(cx) { Poll::Ready(output) => Some(output), @@ -341,7 +341,7 @@ async fn websocket_keep_alive_runs_during_continuous_output() { if b_write.write_all(&buf[..n]).await.is_err() { return; } - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } }); tokio::spawn(async move { tokio::io::copy(&mut b_read, &mut a_write).await }); @@ -359,7 +359,7 @@ async fn websocket_keep_alive_runs_during_continuous_output() { let mut sender = Session::new(a, Side::Client, config.clone()).unwrap(); let _receiver = Session::new(b, Side::Server, config).unwrap(); while sender.max_datagram_size() == 0 { - moq_clock::sleep(Duration::from_millis(1)).await; + kio::clock::sleep(Duration::from_millis(1)).await; } // Far past the 500ms deadline, queueing more each tick than one batch carries @@ -439,10 +439,10 @@ async fn a_close_behind_a_stalled_peer_is_bounded() { up.send(Flow::Stall).unwrap(); // Fill the pipe so the writer is mid-write when the close comes. let mut send = client.open_uni(SendOptions::default()).await.unwrap(); - let _ = moq_clock::timeout(Duration::from_millis(100), send.write(&payload(1 << 20, 0))).await; - moq_clock::sleep(Duration::from_millis(100)).await; + let _ = kio::clock::timeout(Duration::from_millis(100), send.write(&payload(1 << 20, 0))).await; + kio::clock::sleep(Duration::from_millis(100)).await; - let start = moq_clock::now(); + let start = kio::clock::now(); client.close(5, "stalled"); let err = client.closed().await; assert!(matches!(err, Error::ConnectionClosed { code: 5, .. }), "got {err:?}"); @@ -460,7 +460,7 @@ async fn a_silent_peer_times_out() { up.send(Flow::Drop).unwrap(); down.send(Flow::Drop).unwrap(); - let start = moq_clock::now(); + let start = kio::clock::now(); assert!(matches!(client.closed().await, Error::IdleTimeout)); assert!(matches!(server.closed().await, Error::IdleTimeout)); assert!(start.elapsed() >= Duration::from_secs(30) - Duration::from_secs(1)); @@ -470,7 +470,7 @@ async fn a_silent_peer_times_out() { #[tokio::test(start_paused = true)] async fn an_idle_session_stays_up() { let (mut client, _server) = pair(config(Version::QMux01), config(Version::QMux01)).await; - let closed = moq_clock::timeout(Duration::from_secs(120), client.closed()).await; + let closed = kio::clock::timeout(Duration::from_secs(120), client.closed()).await; assert!(closed.is_err(), "closed with {closed:?}"); } @@ -478,7 +478,7 @@ async fn an_idle_session_stays_up() { async fn a_peer_that_never_sends_parameters_times_out_the_handshake() { let (client, _silent) = tokio::io::duplex(PIPE); let config = config(Version::QMux02); - let start = moq_clock::now(); + let start = kio::clock::now(); let err = Session::connect(Stream::new(client), config).await.unwrap_err(); assert!(matches!(err, Error::HandshakeTimeout), "got {err:?}"); assert!(start.elapsed() >= Duration::from_secs(10)); diff --git a/rs/qmux/src/socket.rs b/rs/qmux/src/socket.rs index 99228421d8f..593ce824a91 100644 --- a/rs/qmux/src/socket.rs +++ b/rs/qmux/src/socket.rs @@ -42,7 +42,7 @@ pub type SharedSocketStats = Arc; #[cfg(any(target_os = "linux", test))] pub(crate) struct RateFilter { /// Strictly decreasing rates from front to back; the front is the maximum. - samples: std::collections::VecDeque<(moq_clock::Instant, u64)>, + samples: std::collections::VecDeque<(kio::clock::Instant, u64)>, } #[cfg(any(target_os = "linux", test))] @@ -51,8 +51,8 @@ impl RateFilter { pub(crate) const WINDOW: Duration = Duration::from_secs(10); /// Fold in one sample and return the current estimate, if there is one yet. - pub(crate) fn update(&mut self, now: moq_clock::Instant, rate: u64, app_limited: bool) -> Option { - let expired = |at: &moq_clock::Instant| now.saturating_duration_since(*at) > Self::WINDOW; + pub(crate) fn update(&mut self, now: kio::clock::Instant, rate: u64, app_limited: bool) -> Option { + let expired = |at: &kio::clock::Instant| now.saturating_duration_since(*at) > Self::WINDOW; let usable = rate > 0 && (!app_limited || self.samples.front().is_none_or(|(_, max)| rate >= *max)); // A rejected sample changes nothing, not even expiry: it is no evidence the // path got slower, so only a usable sample may retire an old maximum. @@ -307,7 +307,7 @@ mod unix { // The kernel reports bytes per second; the trait wants bits. let rate = info.delivery_rate.saturating_mul(8); let mut filter = self.rate.lock().unwrap_or_else(|poisoned| poisoned.into_inner()); - filter.update(moq_clock::now(), rate, app_limited) + filter.update(kio::clock::now(), rate, app_limited) } #[cfg(not(target_os = "linux"))] @@ -344,7 +344,7 @@ mod unix { #[cfg(test)] mod rate_filter_tests { use super::*; - use moq_clock::Instant; + use kio::clock::Instant; fn at(start: Instant, ms: u64) -> Instant { start + Duration::from_millis(ms) @@ -352,7 +352,7 @@ mod rate_filter_tests { #[test] fn app_limited_samples_do_not_lower_the_estimate() { - let t = moq_clock::now(); + let t = kio::clock::now(); let mut f = RateFilter::default(); assert_eq!(f.update(t, 80_000_000, true), Some(80_000_000)); // A live stream mostly trickles: these samples measure the sender, not the path. @@ -363,7 +363,7 @@ mod rate_filter_tests { #[test] fn app_limited_samples_can_raise_the_estimate() { - let t = moq_clock::now(); + let t = kio::clock::now(); let mut f = RateFilter::default(); assert_eq!(f.update(t, 1_000_000, true), Some(1_000_000)); assert_eq!(f.update(at(t, 100), 50_000_000, true), Some(50_000_000)); @@ -371,7 +371,7 @@ mod rate_filter_tests { #[test] fn measured_samples_lower_it_after_the_window() { - let t = moq_clock::now(); + let t = kio::clock::now(); let mut f = RateFilter::default(); assert_eq!(f.update(t, 80_000_000, false), Some(80_000_000)); // A real, lower measurement waits for the older maximum to expire. @@ -381,7 +381,7 @@ mod rate_filter_tests { #[test] fn app_limited_samples_do_not_expire_the_maximum() { - let t = moq_clock::now(); + let t = kio::clock::now(); let mut f = RateFilter::default(); f.update(t, 80_000_000, false); f.update(at(t, 1_000), 5_000_000, false); @@ -394,7 +394,7 @@ mod rate_filter_tests { #[test] fn the_window_keeps_the_largest_recent_measurement() { - let t = moq_clock::now(); + let t = kio::clock::now(); let mut f = RateFilter::default(); f.update(t, 30_000_000, false); f.update(at(t, 4_000), 20_000_000, false); @@ -406,7 +406,7 @@ mod rate_filter_tests { #[test] fn zero_rate_keeps_the_estimate() { - let t = moq_clock::now(); + let t = kio::clock::now(); let mut f = RateFilter::default(); // The kernel reports zero until it has a sample. assert_eq!(f.update(t, 0, false), None); diff --git a/rs/qmux/src/transport.rs b/rs/qmux/src/transport.rs index dbfc3f88087..f5984597272 100644 --- a/rs/qmux/src/transport.rs +++ b/rs/qmux/src/transport.rs @@ -821,7 +821,7 @@ mod ws_transport { use bytes::Bytes; use futures::stream::SplitSink; - use moq_clock::{Interval, MissedTickBehavior, Sleep}; + use kio::clock::{Interval, MissedTickBehavior, Sleep}; use tokio::sync::mpsc; use tokio::task::JoinHandle; use tokio_tungstenite::tungstenite; @@ -901,7 +901,7 @@ mod ws_transport { impl PingState { fn new(config: KeepAlive) -> Self { // The first tick is one interval out, so we don't ping on connect. - let mut interval = moq_clock::interval_at(moq_clock::now() + config.interval, config.interval); + let mut interval = kio::clock::interval_at(kio::clock::now() + config.interval, config.interval); // Skip catch-up bursts after a long pause; we just want one Ping per tick. interval.set_missed_tick_behavior(MissedTickBehavior::Delay); Self { interval } @@ -919,13 +919,13 @@ mod ws_transport { fn new(config: KeepAlive) -> Self { let timeout = config.timeout; Self { - deadline: moq_clock::sleep(timeout), + deadline: kio::clock::sleep(timeout), timeout, } } fn observe_recv(&mut self) { - self.deadline.reset(moq_clock::now() + self.timeout); + self.deadline.reset(kio::clock::now() + self.timeout); } } @@ -1196,7 +1196,7 @@ mod ws_transport { // Model a session wedged on a full accept channel: don't read for well // over the 50ms keep-alive timeout while the pump is parked on delivery. - moq_clock::sleep(Duration::from_millis(150)).await; + kio::clock::sleep(Duration::from_millis(150)).await; assert_eq!( rx.recv().await.expect("channel open").expect("no timeout"), @@ -1222,7 +1222,7 @@ mod ws_transport { let (tx, mut rx) = mpsc::channel(4); let pump = tokio::spawn(ws_pump(stream, Some(DeadlineState::new(ka)), usize::MAX, tx)); - let result = moq_clock::timeout(Duration::from_secs(1), rx.recv()) + let result = kio::clock::timeout(Duration::from_secs(1), rx.recv()) .await .expect("keep-alive deadline should fire on a silent peer"); assert!( @@ -1244,7 +1244,7 @@ mod ws_transport { let pump = tokio::spawn(ws_pump(stream, None, usize::MAX, tx)); // No deadline, so recv stays pending well past any keep-alive window. - let pending = moq_clock::timeout(Duration::from_millis(100), rx.recv()).await; + let pending = kio::clock::timeout(Duration::from_millis(100), rx.recv()).await; assert!(pending.is_err(), "recv must not resolve without activity"); pump.abort(); diff --git a/rs/qmux/src/ws.rs b/rs/qmux/src/ws.rs index ae60e642fd7..4cafc32d3f2 100644 --- a/rs/qmux/src/ws.rs +++ b/rs/qmux/src/ws.rs @@ -522,7 +522,7 @@ mod tests { frame.extend_from_slice(&[0; 4]); client.write_all(&frame).await.unwrap(); - moq_clock::timeout(Duration::from_secs(1), session.closed()) + kio::clock::timeout(Duration::from_secs(1), session.closed()) .await .expect("the socket waited to buffer a frame larger than a record"); } diff --git a/rs/uniffi-bindgen/clippy.toml b/rs/uniffi-bindgen/clippy.toml index d5a7b48f913..efe1d9a7379 100644 --- a/rs/uniffi-bindgen/clippy.toml +++ b/rs/uniffi-bindgen/clippy.toml @@ -1,23 +1,23 @@ # Production uses the ambient clock; legacy test-only clock cleanup is tracked separately. disallowed-methods = [ - { path = "std::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "std::time::Instant::elapsed", reason = "read the ambient clock: moq_clock::Instant::elapsed()" }, - { path = "std::time::SystemTime::now", reason = "read the ambient clock: moq_clock::wall()" }, + { path = "std::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "std::time::Instant::elapsed", reason = "read the ambient clock: kio::clock::Instant::elapsed()" }, + { path = "std::time::SystemTime::now", reason = "read the ambient clock: kio::clock::wall()" }, { path = "std::time::SystemTime::elapsed", reason = "wall time never measures elapsed time" }, - { path = "std::thread::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::Instant::now", reason = "read the ambient clock: moq_clock::now()" }, - { path = "tokio::time::sleep", reason = "sleep on the ambient clock: moq_clock::sleep()" }, - { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: moq_clock::sleep_until()" }, - { path = "tokio::time::timeout", reason = "use the ambient clock: moq_clock::timeout()" }, - { path = "tokio::time::interval", reason = "use the ambient clock: moq_clock::interval()" }, + { path = "std::thread::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::Instant::now", reason = "read the ambient clock: kio::clock::now()" }, + { path = "tokio::time::sleep", reason = "sleep on the ambient clock: kio::clock::sleep()" }, + { path = "tokio::time::sleep_until", reason = "sleep on the ambient clock: kio::clock::sleep_until()" }, + { path = "tokio::time::timeout", reason = "use the ambient clock: kio::clock::timeout()" }, + { path = "tokio::time::interval", reason = "use the ambient clock: kio::clock::interval()" }, { path = "tokio::time::timeout_at", reason = "use deadlines from the ambient clock" }, { path = "tokio::time::interval_at", reason = "tick on the ambient clock" }, ] disallowed-types = [ - { path = "std::time::SystemTime", reason = "use moq_clock::Wall" }, - { path = "std::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Instant", reason = "use moq_clock::Instant" }, - { path = "tokio::time::Sleep", reason = "use moq_clock::Sleep" }, - { path = "tokio::time::Interval", reason = "use moq_clock::Interval" }, + { path = "std::time::SystemTime", reason = "use kio::clock::Wall" }, + { path = "std::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Instant", reason = "use kio::clock::Instant" }, + { path = "tokio::time::Sleep", reason = "use kio::clock::Sleep" }, + { path = "tokio::time::Interval", reason = "use kio::clock::Interval" }, ] diff --git a/sh/dispatch-query.test.py b/sh/dispatch-query.test.py index 0dab2a9a3b6..7204b06d09a 100644 --- a/sh/dispatch-query.test.py +++ b/sh/dispatch-query.test.py @@ -350,7 +350,7 @@ def test_terminating_the_run_stops_the_running_phase(self): "rs lint-changed "*) echo $$ >"{pid}"; echo >"{started}"; exec sleep 600 ;; esac ''') - self.change("rs/moq-clock/src/lib.rs") + self.change("rs/kio/src/clock/mod.rs") for jobs in ("1", "3"): with self.subTest(jobs=jobs): run = subprocess.Popen(["bash", "sh/dispatch.sh", "ci", "origin/main"], @@ -366,7 +366,7 @@ def test_terminating_the_run_stops_the_running_phase(self): os.kill(int(pid.read_text()), 0) def test_ci_runs_one_lint_preamble_and_one_test_pass(self): - self.change("rs/moq-clock/src/lib.rs") + self.change("rs/kio/src/clock/mod.rs") calls = self.run_ci() self.assertTrue(any(call.startswith("rs lint-changed ") for call in calls), calls) self.assertFalse(any(call.startswith("rs check-changed ") for call in calls), calls) diff --git a/sh/rs/select.sh b/sh/rs/select.sh index ff26d988040..96511f6bbba 100755 --- a/sh/rs/select.sh +++ b/sh/rs/select.sh @@ -143,9 +143,9 @@ case "$action" in if wants moq-tokio; then just rs tokio-features; fi if wants '(moq-video|moq-audio|moq-transcode)'; then just rs media-features; fi # moq-wasm's crate root is `#![cfg(target_arch = "wasm32")]`, so only a - # wasm32 pass checks it. moq-mux, moq-ffi, and moq-clock ride along in that pass, and + # wasm32 pass checks it. moq-mux, moq-ffi, and kio ride along in that pass, and # nothing depends on moq-ffi, so each has to reach it on its own. - if wants '(moq-wasm|moq-mux|moq-ffi|moq-clock)'; then just rs wasm; fi + if wants '(moq-wasm|moq-mux|moq-ffi|kio)'; then just rs wasm; fi # Device code behind the off-by-default `capture` feature. check-test # lints it through the test build, as for the default features. if [[ "$action" != lint ]] && wants '(moq-video|moq-audio|moq-scene|moq-studio)'; then @@ -158,7 +158,7 @@ case "$action" in ;; fix) just rs fix "${flags[@]}" - if wants '(moq-wasm|moq-mux|moq-ffi|moq-clock)'; then just rs wasm-fix; fi + if wants '(moq-wasm|moq-mux|moq-ffi|kio)'; then just rs wasm-fix; fi ;; test) # A selection can hold nothing testable, and diff --git a/test/interop/clients/rust/finish.rs b/test/interop/clients/rust/finish.rs index 6e6deb4712d..253bf2d1ce3 100644 --- a/test/interop/clients/rust/finish.rs +++ b/test/interop/clients/rust/finish.rs @@ -115,7 +115,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"); - moq_clock::timeout(args.timeout, async { + kio::clock::timeout(args.timeout, async { let mut routes = consumer.announced(); let broadcast = consumer.routed_broadcast(&args.broadcast).await?; let mut catalogs = diff --git a/test/wasm/README.md b/test/wasm/README.md index ebf38eff7bf..89585935f17 100644 --- a/test/wasm/README.md +++ b/test/wasm/README.md @@ -33,7 +33,7 @@ failing page, and CI uploads it; a passing run deletes its own. See ## Rust clock -`moq-clock`'s browser backend also runs here, using `wasm-bindgen-test` and the +kio's browser clock backend also runs here, using `wasm-bindgen-test` and the same Chromium supplied by the root devShell: ```bash diff --git a/test/wasm/generator.md b/test/wasm/generator.md index 18b236417b2..d33ed9fa958 100644 --- a/test/wasm/generator.md +++ b/test/wasm/generator.md @@ -247,7 +247,7 @@ targets, over one dual-annotated crate. - **moq-ffi panicked creating any broadcast in the browser.** `moq_mux`'s catalog clock called `std::time::SystemTime::now`, which wasm32-unknown-unknown does not implement. The measurements above used a workaround in the pin patch. Since - [#5681](https://github.com/moq-dev/moq/pull/5681), moq-mux reads moq-clock's browser + [#5681](https://github.com/moq-dev/moq/pull/5681), moq-mux reads kio's browser wall clock instead, and the cases pass without the workaround. - **On moq-lite-06, group sequence 2^62-1 never arrived.** The cases also stamped it as the frame timestamp, which lite-05/06 cannot zigzag as a group's first frame, so the From 3ac6eeccd3d6f31923e41ef751fa481f47b0506c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 23:47:36 -0700 Subject: [PATCH 3/5] chore: sort manifests, retire the kio-clock quest, and fix moq-clock mentions Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release-gate.yml | 2 -- .github/workflows/wasm.yml | 4 +-- .oss-scanner/Dockerfile | 2 +- .oss-scanner/threat_model.md | 4 +-- quest/m0/ci/slow-tests.md | 2 +- quest/m0/test-flakes-2/README.md | 4 +-- quest/m1/README.md | 1 - quest/m1/binding-timestamps.md | 2 +- quest/m1/kio-clock.md | 45 --------------------------- quest/m1/poll-first/async-feature.md | 2 +- quest/m1/poll-first/no-spawn.md | 9 ++---- quest/m1/poll-first/sansio-compare.md | 2 +- quest/m2/audit-test-coverage.md | 2 +- quest/m2/perf/README.md | 2 +- quest/m2/perf/stream/driver.md | 2 +- quest/m2/quic-sim.md | 2 +- quest/m2/rs2ts/README.md | 2 +- quest/m2/rs2ts/wasm-bindings.md | 2 +- quest/m2/sim-seed.md | 2 +- quest/m2/time-test-sweep.md | 8 ++--- quest/m3/rs2ts-model-subset.md | 2 +- rs/moq-auth/Cargo.toml | 2 +- rs/moq-boy/Cargo.toml | 2 +- rs/moq-cli/Cargo.toml | 2 +- rs/moq-quic/Cargo.toml | 2 +- rs/moq-relay/Cargo.toml | 2 +- rs/moq-studio/Cargo.toml | 2 +- 27 files changed, 32 insertions(+), 83 deletions(-) delete mode 100644 quest/m1/kio-clock.md diff --git a/.github/workflows/release-gate.yml b/.github/workflows/release-gate.yml index f8d91b7ef38..0104178bd7b 100644 --- a/.github/workflows/release-gate.yml +++ b/.github/workflows/release-gate.yml @@ -232,7 +232,6 @@ jobs: - "rs/moq-archive/**" - "rs/moq-auth/**" - "rs/moq-cli/**" - - "rs/moq-clock/**" - "rs/moq-congestion/**" - "rs/moq-flate/**" - "rs/moq-hls/**" @@ -294,7 +293,6 @@ jobs: - ".github/workflows/video.yml" wasm: - "rs/moq-wasm/**" - - "rs/moq-clock/**" - "rs/moq-net/**" - "rs/kio/**" - "js/wasm/**" diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index a2d96cbf5c5..da3b4567583 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -1,7 +1,7 @@ name: WASM # Runs the @moq/wasm bindings in a real browser, which nothing in `just check` -# can do, and moq-clock's browser timers and wall clock through +# can do, and kio's browser timers and wall clock through # wasm-bindgen-test on the same Chromium. rs/moq-wasm is # `#![cfg(target_arch = "wasm32")]`, so a host-target `cargo check --workspace` # compiles it to nothing, and `just rs wasm` is a compile gate: it catches a @@ -13,7 +13,7 @@ name: WASM # review (they are a thin wrapper over it, and every other gate compiles them to # nothing), and kio underneath it, because a lost wakeup or a timer regression # reaches the browser through moq-net without touching a file named here -# otherwise. moq-clock supplies the browser clock below those layers. +# otherwise. kio also supplies the browser clock below those layers. # # The rest of the filter is the machinery that turns the crate into the package # under test, which is just as able to break it: the root `justfile` owns the diff --git a/.oss-scanner/Dockerfile b/.oss-scanner/Dockerfile index 5b368eed864..549fb6efde0 100644 --- a/.oss-scanner/Dockerfile +++ b/.oss-scanner/Dockerfile @@ -20,7 +20,7 @@ RUN rustup show active-toolchain || rustup toolchain install \ && curl -LsSf "https://get.nexte.st/latest/$nextest" | tar zxf - -C "$CARGO_HOME/bin" \ && cargo nextest --version -ARG CRATES="kio hang moq-auth moq-clock moq-e2ee moq-flate moq-hls moq-ice moq-json moq-loc moq-msf moq-mux moq-net moq-pattern moq-quic moq-relay moq-rtc moq-rtmp moq-rtsp moq-sock moq-srt moq-stats moq-tokio moq-uring moq-cli" +ARG CRATES="kio hang moq-auth moq-e2ee moq-flate moq-hls moq-ice moq-json moq-loc moq-msf moq-mux moq-net moq-pattern moq-quic moq-relay moq-rtc moq-rtmp moq-rtsp moq-sock moq-srt moq-stats moq-tokio moq-uring moq-cli" # Path specs, because the lockfile also has published copies of some workspace crates. # io-uring compiles the relay's io_uring QUIC workers (`--runtime-io-uring`), which the default features leave out. diff --git a/.oss-scanner/threat_model.md b/.oss-scanner/threat_model.md index cbde6250dc8..5af095516c4 100644 --- a/.oss-scanner/threat_model.md +++ b/.oss-scanner/threat_model.md @@ -35,7 +35,7 @@ Most important, in this order: 2. Authorization: a session publishing, subscribing, or seeing announcements outside its grant, or reaching another root (tenant) through path tricks, revalidation, mounts, or cluster links. 3. `rs/moq-mux` and `rs/hang`: container, codec, and catalog parsing of publisher-controlled bytes. 4. The ingest gateways: `rs/moq-rtmp`, `rs/moq-rtsp`, `rs/moq-srt`, `rs/moq-rtc`, `rs/moq-ice`, `rs/moq-hls`. -5. `rs/moq-e2ee`, `rs/moq-cli`, `rs/moq-flate`, `rs/moq-json`, `rs/moq-stats`, `rs/kio`, `rs/moq-clock`. +5. `rs/moq-e2ee`, `rs/moq-cli`, `rs/moq-flate`, `rs/moq-json`, `rs/moq-stats`, `rs/kio`. `unsafe` is rare and worth reading closely where it appears: `rs/moq-quic`, `rs/moq-net/src/model`, `rs/moq-net/src/util/cell.rs`, `rs/moq-net/src/transport.rs`, and `rs/moq-relay/src/uring.rs`. @@ -45,7 +45,7 @@ Out of scope: `js/` and the other language bindings (`py/`, `swift/`, `kt/`, `go The image is offline, with every crate fetched and `CARGO_NET_OFFLINE` set. The debug build of the in-scope crates, their test binaries, and the `moq-relay` and `moq` binaries are already built in `/src/target/debug`. Debug builds keep overflow checks on. -- **Tests**: `cargo nextest run -p path+file:///src/rs/moq-net` (or any in-scope crate; the path spec is needed because the lockfile also has published copies of some crates). Use nextest as CI does: some tests install process-global state and fail under plain `cargo test`. Add `--features moq-relay/io-uring` for the relay and `moq-uring` so the io\_uring backend's tests run (they skip on a kernel without io\_uring support). Unit tests use the deterministic clock in `moq-clock` rather than wall time, so they are fast and reproducible. +- **Tests**: `cargo nextest run -p path+file:///src/rs/moq-net` (or any in-scope crate; the path spec is needed because the lockfile also has published copies of some crates). Use nextest as CI does: some tests install process-global state and fail under plain `cargo test`. Add `--features moq-relay/io-uring` for the relay and `moq-uring` so the io\_uring backend's tests run (they skip on a kernel without io\_uring support). Unit tests use the deterministic clock in `kio::clock` rather than wall time, so they are fast and reproducible. - **A relay to attack**: `./target/debug/moq-relay demo/relay/localhost.toml` listens on UDP and TCP `[::]:4443` with a self-signed certificate and anonymous access to every path. The binary is built with io\_uring support; pass `--runtime-io-uring` to serve QUIC from the io\_uring workers in `rs/moq-uring` and `rs/moq-relay/src/uring.rs` instead of tokio. For authorization testing, grant a narrow anonymous pattern with `[auth] public_subscribe` / `public_publish`, or run the reference auth server (`moq auth generate`, `moq auth sign`, `moq auth serve`, then `[auth] url`; see `doc/bin/cli.md`) and try to escape a signed token's root and patterns. `doc/bin/relay/` documents the config, auth, cluster, and HTTP endpoints. - **A client**: `./target/debug/moq --help` publishes, subscribes, fetches, and lists announcements against a relay. `curl http://localhost:4443/announced/` and `curl http://localhost:4443/fetch//` hit the HTTP endpoints. - **Fuzz harnesses**: `rs/moq-net/fuzz` and `rs/moq-quic/fuzz` hold cargo-fuzz targets for the wire codecs and the QUIC state machine. cargo-fuzz and a nightly toolchain are not in the image, but the targets show the parser entry points. diff --git a/quest/m0/ci/slow-tests.md b/quest/m0/ci/slow-tests.md index 9a41aa83fbf..db82251b1d4 100644 --- a/quest/m0/ci/slow-tests.md +++ b/quest/m0/ci/slow-tests.md @@ -39,7 +39,7 @@ the tests a change touches. 137.83 s to 116.83 s with fixture-only changes: the two MPEG-TS reset tests in `container::ts::import` drain on the exporter's deadlines with a retention derived from their stimulus instead of an hour of idle output (12.98 s to 0.18 s), and the jitter -`drift` and `feed` helpers advance a `moq_clock::Deadlines` queue instead of the tokio +`drift` and `feed` helpers advance a `kio::clock::Deadlines` queue instead of the tokio paused clock (10.16 s to 6.80 s across 8 tests). About 48 s remains to cut. Tried and dropped, so don't redo them without new evidence: diff --git a/quest/m0/test-flakes-2/README.md b/quest/m0/test-flakes-2/README.md index 9df1c1b33da..9c0e8271e52 100644 --- a/quest/m0/test-flakes-2/README.md +++ b/quest/m0/test-flakes-2/README.md @@ -21,8 +21,8 @@ Rules every child keeps: slow, fix that. - A paused clock auto-advances while the runtime idles, so it can fire a timer before a real socket delivers. Where real sockets fight the paused - clock, drive the timers with a `moq_clock::Manual` clock or the sim (every - crate's timers run on `moq-clock`), or move the test off real sockets. + clock, drive the timers with a `kio::clock::Manual` clock or the sim (every + crate's timers run on `kio::clock`), or move the test off real sockets. - A mocked clock still flakes when the code jitters its timers with `rand` (one cancel race was a retry sweep jittered past a fixed settle budget). Wait out the jitter's whole window, not a count of small steps. diff --git a/quest/m1/README.md b/quest/m1/README.md index 8990c91aa21..e3c769f846b 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -164,7 +164,6 @@ surface and zero-copy texture import, land before the cut. - [Settled copies versus whole groups](/quest/m1/settled-copies.md) - every model check of whether a group is done means either a settled copy or the whole group, as it needs - [An HLS viewer starts capture](/quest/m1/hls-record-demand.md) - a record-track subscriber counts as demand for its rendition's media - [One moq-ffi build definition](/quest/m1/ffi-build-flags.md) - every binding takes moq-ffi's default features from one place -- [moq-clock moves into kio::clock](/quest/m1/kio-clock.md) - moq-clock and its test macro become `kio::clock` and `#[kio::test]` before the cut publishes them - [Poll-first async](/quest/m1/poll-first/README.md) - library crates compile no coroutines by default: async wrappers are generated from `poll_*` and gated behind an `async` feature ## Related diff --git a/quest/m1/binding-timestamps.md b/quest/m1/binding-timestamps.md index 9b75e4b5baa..65a84f2c3aa 100644 --- a/quest/m1/binding-timestamps.md +++ b/quest/m1/binding-timestamps.md @@ -69,5 +69,5 @@ keep "untimed as absent" until then too. At the cut timed, and [bindings by start](/quest/m1/time-addressing/bindings.md) drops that `Option` from reads only. -Wall and monotonic times stay `moq_clock::Wall` and `moq_clock::Instant`, not +Wall and monotonic times stay `kio::clock::Wall` and `kio::clock::Instant`, not media timestamps; keep the types distinct. diff --git a/quest/m1/kio-clock.md b/quest/m1/kio-clock.md deleted file mode 100644 index 816f03ec4cc..00000000000 --- a/quest/m1/kio-clock.md +++ /dev/null @@ -1,45 +0,0 @@ -# [M] moq-clock moves into kio::clock - -## Goal - -moq-clock and moq-clock-macros become `kio::clock` and kio's test attribute -(`#[kio::test]`), behind kio features that mirror moq-clock's today -(`runtime`, `sim`, `manual`, `serde`). kio's private `_sim` feature goes, every -dependent imports `kio::clock`, and both crates are deleted before the cut -publishes them. - -## Plan - -Decided with the maintainer on 2026-10-25: - -- **Why kio.** Waiting and time are the two halves of "easy async": a - `Deadlines` queue parks kio waiters, and the simulator drives kio tasks. - They're already coupled through kio's `_sim` feature, which exists only for - moq-clock's simulator. Zig's `std.Io` carries the clock with its waits for - the same reason. moq-clock is infrastructure, not a MoQ component, so the - `moq-` prefix was wrong too. -- **Now.** moq-clock is not on `release`, so the move is free before the cut - and a break after it. -- **moq-sock stays.** It is synchronous OS socket plumbing tuned for QUIC (a - quinn-udp fork, connection-id sharding, CPU pinning), not waiting, and would - pull libc and socket2 into a dependency-light crate that also targets wasm. -- **No generic I/O.** kio gets no socket or file seam: tokio's readiness model - and io_uring's completion model (the kernel owns the buffer) can't share a - zero-cost API, and moq's I/O is UDP and TCP under sans-IO cores already split - per runtime by moq-sock. - -Mechanics: keep default features lean, so a kio user that doesn't want a clock -compiles no runtime backend. The 31 dependents, the `clippy.toml` disallowed -methods that name `moq_clock::now()` and friends, and `#[moq_clock::test]` -call sites move over. Move `doc/lib/rs/moq-clock.md` to a kio page (or into -kio's), and fix `doc/lib/rs/index.md`, `doc/setup/repository.md`, and -`doc/setup/upgrade.md`. JS keeps `@moq/clock`: it has no kio, and the -`clock` name still mirrors. - -Public API: moq-clock's items move to `kio::clock` unchanged; kio gains -features. Describe the kio migration in the PR's Impact section. Wire: none. - -## Related - -- [Libraries spawn nothing](/quest/m1/poll-first/no-spawn.md) - removes web-async from the clock's browser backend after this -- [Poll-first async](/quest/m1/poll-first/README.md) - the direction kio carries diff --git a/quest/m1/poll-first/async-feature.md b/quest/m1/poll-first/async-feature.md index 68b834924b4..50f47586b2c 100644 --- a/quest/m1/poll-first/async-feature.md +++ b/quest/m1/poll-first/async-feature.md @@ -23,7 +23,7 @@ ergonomic layer, and the gating proceeds regardless of the build measurement. - **Logic in `async fn` bodies:** an `async fn` that does more than call one `poll_*` becomes a `poll_*` first, or moves out of the library to the edges. List each one in the PR. -- **Tests:** `#[moq_clock::test]` and `#[tokio::test]` bodies stay async, so test +- **Tests:** `#[kio::test]` and `#[tokio::test]` bodies stay async, so test targets enable the feature. - **Cargo:** feature unification means one dependent enabling `async` enables it for the whole build. Make sure library-only builds, such as `cargo check -p diff --git a/quest/m1/poll-first/no-spawn.md b/quest/m1/poll-first/no-spawn.md index 0c9a23a9baa..f4e803ad7c5 100644 --- a/quest/m1/poll-first/no-spawn.md +++ b/quest/m1/poll-first/no-spawn.md @@ -19,10 +19,11 @@ Decided with the maintainer on 2026-10-25, replacing the m2 runtime trait - **Poll everywhere, no spawn.** A spawn trait keeps `'static` detached tasks in the library, which poll-first rejects; `kio::Tasks` already gives a library structured children with no runtime. Time is - [kio::clock](/quest/m1/kio-clock.md), so nothing is left for a runtime trait. + `kio::clock`, so nothing is left for a runtime trait. `rs/AGENTS.md` already treats `tokio::spawn` in a library as a smell. - **No I/O seam.** I/O stays at moq-net's `transport::poll` traits and - moq-sock (see kio::clock's Plan). + moq-sock: tokio's readiness model and io_uring's completion model (the + kernel owns the buffer) can't share a zero-cost API. - **Blocking work is out of scope.** OS threads for blocking capture, encode, or file I/O are not async tasks and stay. @@ -36,10 +37,6 @@ Public API: constructors that spawned return a handle to poll or await instead. The PR's Impact section describes migration for the published crates whose API changes. Wire: none. -## Required - -- [moq-clock moves into kio::clock](/quest/m1/kio-clock.md) - the clock backend this rewrites, in its final place - ## Related - [The remaining spawns](/quest/m2/spawn-audit.md) - the same rule for every other library crate diff --git a/quest/m1/poll-first/sansio-compare.md b/quest/m1/poll-first/sansio-compare.md index 00406ce75f3..4881e27e420 100644 --- a/quest/m1/poll-first/sansio-compare.md +++ b/quest/m1/poll-first/sansio-compare.md @@ -8,7 +8,7 @@ control flow, to a sans-IO core (synchronous `handle_*` and `poll_transmit` / by a thin kio layer. It compares this with the kio `poll_*` version on: - implementation effort; -- testability (deterministic replay without moq-clock); +- testability (deterministic replay without kio::clock); - rust2's TypeScript translation and FFI export of the result; - compile time; - runtime cost. diff --git a/quest/m2/audit-test-coverage.md b/quest/m2/audit-test-coverage.md index 45b76199ca9..a5946fecddf 100644 --- a/quest/m2/audit-test-coverage.md +++ b/quest/m2/audit-test-coverage.md @@ -45,7 +45,7 @@ which is expensive on a shared machine. binding facades below in minutes. Per-file uncovered line counts mostly point at GPU code and generated bindings instead. - When sampling `fix` commits for regression tests, count - `#[moq_clock::test]` as well as `#[test]` and `#[tokio::test]`. + `#[kio::test]` as well as `#[test]` and `#[tokio::test]`. ### m1 baselines diff --git a/quest/m2/perf/README.md b/quest/m2/perf/README.md index 67fe89ec339..16b62ba889e 100644 --- a/quest/m2/perf/README.md +++ b/quest/m2/perf/README.md @@ -57,7 +57,7 @@ profile shows no pool contention. #3122's per-turn clock read landed in [#5926](https://github.com/moq-dev/moq/pull/5926): the io_uring worker is a -`moq-clock` backend that samples the clock once per turn, cutting +`kio::clock` backend that samples the clock once per turn, cutting `clock_gettime` from 44.7 to 1.05 calls per turn. `perf` was unavailable there, so [Profile the io_uring clock read](/quest/m2/perf/uring-clock-profile.md) owns the `[vdso]` share and relay CPU measurement. diff --git a/quest/m2/perf/stream/driver.md b/quest/m2/perf/stream/driver.md index 373835df296..a8fb96afb51 100644 --- a/quest/m2/perf/stream/driver.md +++ b/quest/m2/perf/stream/driver.md @@ -32,7 +32,7 @@ What goes, per the audit in the [epic](/quest/m2/perf/stream/README.md): - the separate `run_reader` and `run_writer` tasks - `tokio::io::split` and the `reader_loop` task on plain streams - `tokio::select!` and `tokio::time`. The WebSocket keep-alive moves to - `moq_clock` like the mux timers. + `kio::clock` like the mux timers. Buffers: parse inbound records from one reusable read buffer into `Bytes` slices, with no zeroed allocation per record. Encode outbound records and diff --git a/quest/m2/quic-sim.md b/quest/m2/quic-sim.md index bcf3ecc3509..600251f22b1 100644 --- a/quest/m2/quic-sim.md +++ b/quest/m2/quic-sim.md @@ -2,7 +2,7 @@ ## Goal -The `moq-clock` sim drives MoQ sessions and the relay over `moq-quic`, with +The `kio::clock` sim drives MoQ sessions and the relay over `moq-quic`, with configurable latency, loss, reordering, and bandwidth, so MoQ over real QUIC (the transport race, relay hops, recovery) is tested deterministically with no sockets. diff --git a/quest/m2/rs2ts/README.md b/quest/m2/rs2ts/README.md index 4ae9502b11e..35fe7cee163 100644 --- a/quest/m2/rs2ts/README.md +++ b/quest/m2/rs2ts/README.md @@ -43,7 +43,7 @@ Rust async, kio, integer representations, and storage unless evidence calls for a source change. A batched boundary is an optimization candidate, not a reason to require a full sans-IO rewrite. -The Rust and JS clocks (`moq-clock` and `@moq/clock`) must agree on origin and +The Rust and JS clocks (`kio::clock` and `@moq/clock`) must agree on origin and units under either backend. WASM keeps Rust's time types; a source translator chooses its `Instant` mapping with its backend. A JS `number` of nanoseconds is exact for 104 days of uptime and only loses sub-microsecond precision after. diff --git a/quest/m2/rs2ts/wasm-bindings.md b/quest/m2/rs2ts/wasm-bindings.md index c2eae337ee1..a6b2c7ab1a6 100644 --- a/quest/m2/rs2ts/wasm-bindings.md +++ b/quest/m2/rs2ts/wasm-bindings.md @@ -35,7 +35,7 @@ Keep compiler-specific source refactors out until a selected backend needs them. Benchmark any hot-path changes, including publisher/subscriber sweeps. Rust and JS must agree on clock origin, units, deadlines, and controlled-time -behavior across the boundary. Integrate with moq-clock/@moq/clock if available; +behavior across the boundary. Integrate with kio::clock/@moq/clock if available; otherwise preserve current semantics without blocking on the whole time line. Extend the [backend baseline](/test/wasm/README.md#backend-baseline) for full API parity. diff --git a/quest/m2/sim-seed.md b/quest/m2/sim-seed.md index a6e02cee0c2..ac37f573c41 100644 --- a/quest/m2/sim-seed.md +++ b/quest/m2/sim-seed.md @@ -2,7 +2,7 @@ ## Goal -Under the `moq-clock` sim, every source of randomness that affects behavior +Under the `kio::clock` sim, every source of randomness that affects behavior (moq-net's clock anchor jitter, backoff jitter, alert jitter) draws from one seeded generator the sim owns, and a failing sim test prints its seed so it replays bit-exact. diff --git a/quest/m2/time-test-sweep.md b/quest/m2/time-test-sweep.md index 6ada071d840..64a863d5dd4 100644 --- a/quest/m2/time-test-sweep.md +++ b/quest/m2/time-test-sweep.md @@ -7,15 +7,15 @@ workspace lint prevents new direct reads outside backends and measurements. ## Plan -Production code and exported APIs already read time through `moq-clock` and +Production code and exported APIs already read time through `kio::clock` and `@moq/clock`. This follow-up owns the legacy test conversions, the workspace-wide lint ratchet, and the final audit of harness exceptions. Decided with the m1 migrations, so this sweep doesn't reopen them: -- **Sim first.** A test with no real I/O runs on the `moq-clock` sim - (`#[moq_clock::test]`). One that cannot run there yet uses paused tokio, - whose clock `moq-clock` reads. +- **Sim first.** A test with no real I/O runs on the `kio::clock` sim + (`#[kio::test]`). One that cannot run there yet uses paused tokio, + whose clock `kio::clock` reads. - **Real I/O syncs on events.** A test with sockets, browsers, codecs, or hardware never uses paused tokio, which auto-advances to the next timer while the OS event is still in flight. Wall time is allowed only for its watchdog diff --git a/quest/m3/rs2ts-model-subset.md b/quest/m3/rs2ts-model-subset.md index ff28f35378c..724964701f3 100644 --- a/quest/m3/rs2ts-model-subset.md +++ b/quest/m3/rs2ts-model-subset.md @@ -2,7 +2,7 @@ ## Goal -moq-net's model, and the kio, moq-clock, and moq-pattern code it calls, stay inside the +moq-net's model, and the kio (clock included) and moq-pattern code it calls, stay inside the subset [rust2-ts](https://github.com/kixelated/rust2/blob/main/ts/README.md) translates, so the [source-translator route](/quest/m2/rs2ts-wasm2js.md) can be measured on the model with no hand-written stand-ins for moq's own logic. diff --git a/rs/moq-auth/Cargo.toml b/rs/moq-auth/Cargo.toml index d5459641b27..4a78d98fd8f 100644 --- a/rs/moq-auth/Cargo.toml +++ b/rs/moq-auth/Cargo.toml @@ -40,9 +40,9 @@ url = { workspace = true } [dev-dependencies] anyhow = { workspace = true } +kio = { path = "../kio", features = ["runtime", "sim"] } moq-auth = { path = ".", features = ["client", "serve"] } moq-auth-published = { package = "moq-auth", version = "=0.2.1", default-features = false } -kio = { path = "../kio", features = ["runtime", "sim"] } moq-token = "0.7" tempfile = { workspace = true } tokio = { workspace = true, features = ["macros", "rt-multi-thread", "test-util"] } diff --git a/rs/moq-boy/Cargo.toml b/rs/moq-boy/Cargo.toml index 280d1bc654e..2e1df4f2fd1 100644 --- a/rs/moq-boy/Cargo.toml +++ b/rs/moq-boy/Cargo.toml @@ -33,8 +33,8 @@ anyhow = { workspace = true, features = ["backtrace"] } boytacean = { version = "0.13", features = ["gen-mock"] } bytes = { workspace = true } hang = { workspace = true } -moq-audio = { workspace = true } kio = { workspace = true, features = ["runtime"] } +moq-audio = { workspace = true } moq-json = { workspace = true } moq-mux = { workspace = true } moq-net = { workspace = true } diff --git a/rs/moq-cli/Cargo.toml b/rs/moq-cli/Cargo.toml index 4087224dcc4..5c2a12e8945 100644 --- a/rs/moq-cli/Cargo.toml +++ b/rs/moq-cli/Cargo.toml @@ -107,10 +107,10 @@ bytes = { workspace = true } futures = { workspace = true } hang = { workspace = true } humantime = { workspace = true } +kio = { workspace = true, features = ["runtime"] } moq-archive = { workspace = true } moq-audio = { workspace = true, optional = true, features = ["aac"] } moq-auth = { workspace = true, features = ["serve"] } -kio = { workspace = true, features = ["runtime"] } # `server` enables the HTTP egress server for `moq export hls`; the importer is always available. moq-hls = { workspace = true, features = ["server"] } # Writes and reads the stats and feedback snapshots. diff --git a/rs/moq-quic/Cargo.toml b/rs/moq-quic/Cargo.toml index d0c189096ad..b6f29cfcf8d 100644 --- a/rs/moq-quic/Cargo.toml +++ b/rs/moq-quic/Cargo.toml @@ -45,9 +45,9 @@ aws-lc-rs = { version = "1.9", default-features = false, optional = true } bytes = { workspace = true } fastbloom = { version = "0.17", default-features = false } indexmap = { workspace = true } -lru-slab = "0.1.2" # Without the runtime, which is meant for dev-dependencies; a driver brings its own. kio = { workspace = true } +lru-slab = "0.1.2" moq-congestion = { workspace = true } qlog = { version = "0.18", optional = true } rand = { workspace = true } diff --git a/rs/moq-relay/Cargo.toml b/rs/moq-relay/Cargo.toml index 85698aa7208..9f80ba2536c 100644 --- a/rs/moq-relay/Cargo.toml +++ b/rs/moq-relay/Cargo.toml @@ -69,8 +69,8 @@ http-body = "1.0.1" http-cache-reqwest = { version = "1.0.0-alpha.6", features = ["manager-moka", "reqwest-middleware", "url-standard"], default-features = false } humantime = { workspace = true } hyper-util = { workspace = true } -moq-auth = { workspace = true, features = ["client"] } kio = { workspace = true, features = ["runtime", "serde"] } +moq-auth = { workspace = true, features = ["client"] } moq-net = { workspace = true } # The flow-control limits both QUIC runtimes take, for widening a peer's connection. moq-quic = { workspace = true, optional = true } diff --git a/rs/moq-studio/Cargo.toml b/rs/moq-studio/Cargo.toml index 6598629f29c..60b37380595 100644 --- a/rs/moq-studio/Cargo.toml +++ b/rs/moq-studio/Cargo.toml @@ -44,8 +44,8 @@ eframe = { version = "0.36", default-features = false, features = ["default_font egui = "0.36" # Docked, rearrangeable panels. 0.21 is the newest release and pins egui 0.36. egui_dock = "0.21" -moq-audio = { workspace = true, features = ["bus"] } kio = { workspace = true, features = ["runtime"] } +moq-audio = { workspace = true, features = ["bus"] } moq-mux = { workspace = true } moq-net = { workspace = true } moq-scene = { workspace = true } From a95782d42625eb69f02376e58a036222d5043247 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 23:56:55 -0700 Subject: [PATCH 4/5] chore(tokio): format manifest Co-Authored-By: Claude Opus 5.5 --- rs/moq-tokio/Cargo.toml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/rs/moq-tokio/Cargo.toml b/rs/moq-tokio/Cargo.toml index 9e23840764f..782a9894b7c 100644 --- a/rs/moq-tokio/Cargo.toml +++ b/rs/moq-tokio/Cargo.toml @@ -21,17 +21,7 @@ net = ["dep:moq-net", "dep:web-transport-trait"] # the MoQ backend. Needs a crypto-provider feature. driver = ["dep:moq-congestion", "dep:moq-quic", "dep:pin-project-lite", "dep:rustc-hash", "dep:socket2"] # QUIC and WebTransport over moq-quic, for `https://`, `moqt://`, and `moql://`. -quic = [ - "_transport", - "_certs", - "driver", - "dep:http", - "dep:rustls-native-certs", - "dep:web-transport-proto", - "dep:reqwest", - "watch", - "dep:dns-lookup", -] +quic = ["_transport", "_certs", "driver", "dep:http", "dep:rustls-native-certs", "dep:web-transport-proto", "dep:reqwest", "watch", "dep:dns-lookup"] # Server-side certificate handling: chains loaded from disk, self-signed generation, # in-memory identities, and per-SNI selection. Not one to enable on its own, since # nothing turns it into a listener: every QUIC backend needs it for its own TLS, and From bfb99984b5e6d013749ecdcdee875bf0bbcca1e0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 01:53:45 -0700 Subject: [PATCH 5/5] fix(kio): keep criterion off the browser test build Co-Authored-By: Claude Opus 5.5 --- rs/kio/Cargo.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rs/kio/Cargo.toml b/rs/kio/Cargo.toml index fd5af944545..800b04fdc09 100644 --- a/rs/kio/Cargo.toml +++ b/rs/kio/Cargo.toml @@ -61,7 +61,6 @@ loom = { workspace = true } [dev-dependencies] # Bench-only: the FuturesUnordered comparison in benches/tasks.rs. -criterion = { workspace = true } futures = "0.3" # Enable the simulator so the clock's tests run in the merge gate. The browser # leaves the runtime to `--features runtime`, so it tests the clock both ways. @@ -79,6 +78,11 @@ wasm-bindgen-test = "=0.3.79" kio = { path = ".", features = ["manual", "sim", "serde"] } tokio = { workspace = true, features = ["rt-multi-thread"] } +# The benches run natively; rayon under criterion refuses to build for wasm, where +# the browser runner compiles the clock's tests. +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +criterion = { workspace = true } + [[bench]] name = "tasks" harness = false