Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions doc/lib/js/clock.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ description: Logical time and timers with a manual clock for deterministic tests

Use `@moq/clock` when a deadline and the elapsed time beside it must come from
one clock. Its default backend reads the host's monotonic and wall clocks;
a test installs a `Manual` clock without patching the host's timers.
a test installs a `Manual` clock from `@moq/clock/test` without patching the host's timers.

```sh
bun add @moq/clock
```

```ts
import { Duration, Manual, now, sleep } from "@moq/clock";
import { Duration, now, sleep } from "@moq/clock";
import { Manual } from "@moq/clock/test";

const clock = new Manual();
const installed = clock.install();
Expand Down
3 changes: 2 additions & 1 deletion js/auth/src/key.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Manual, Wall, wall } from "@moq/clock";
import { Wall, wall } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { base64url, exportJWK, generateKeyPair, SignJWT } from "jose";
import type { Algorithm } from "./algorithm.ts";
import { authorize, type Claims } from "./claims.ts";
Expand Down
5 changes: 3 additions & 2 deletions js/clock/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# @moq/clock

Logical monotonic time, wall time, and timers from one clock per JavaScript realm.
Use `Manual` to test time without replacing the host's timers.
Use `Manual` from `@moq/clock/test` to test time without replacing the host's timers.

```ts
import { Duration, Instant, Manual, now, sleep } from "@moq/clock";
import { Duration, Instant, now, sleep } from "@moq/clock";
import { Manual } from "@moq/clock/test";

const clock = new Manual();
const installed = clock.install();
Expand Down
13 changes: 0 additions & 13 deletions js/clock/api/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,6 @@ export class Interval {
tick(): Promise<Instant>;
}

export class Manual {
constructor();
static readonly WALL_START: Wall;
advance(duration: Duration): Promise<void>;
drive<T>(work: PromiseLike<T>): Promise<T>;
fire(): Promise<Instant>;
install(): Installed;
jump(duration: Duration): void;
now(): Instant;
stepWall(wall: Wall): void;
wall(): Wall;
}

export const MissedTickBehavior: {
readonly Burst: "burst";
readonly Delay: "delay";
Expand Down
18 changes: 18 additions & 0 deletions js/clock/api/test.api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# `@moq/clock/test`

```ts
import { Duration } from "@moq/clock";
import { Installed } from "@moq/clock";
import { Instant } from "@moq/clock";
import { Wall } from "@moq/clock";

export class Manual {
constructor();
static readonly WALL_START: Wall;
advance(duration: Duration): Promise<void>;
drive<T>(work: PromiseLike<T>): Promise<T>;
fire(): Promise<Instant>;
install(): Installed;
jump(duration: Duration): void;
now(): Instant;
stepWall(wall: Wall): void;
wall(): Wall;
}

export function hostTime(): void;
```
3 changes: 2 additions & 1 deletion js/clock/bench/timers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Sweep armed timers x timers made ready, with independent and shared abort scopes.
import { Duration, Manual, sleep } from "../src/index.ts";
import { Duration, sleep } from "../src/index.ts";
import { Manual } from "../src/test.ts";

console.log("mode,scope,armed,ready,arm_us,advance_us,cancel_us");
for (const mode of ["jump", "advance"]) {
Expand Down
3 changes: 1 addition & 2 deletions js/clock/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
type Installed,
Instant,
interval,
Manual,
MissedTickBehavior,
now,
origin,
Expand All @@ -19,7 +18,7 @@ import {
wall,
yieldNow,
} from "./index.ts";
import { hostTime } from "./test.ts";
import { hostTime, Manual } from "./test.ts";

const installs: Installed[] = [];
afterEach(() => {
Expand Down
3 changes: 1 addition & 2 deletions js/clock/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Logical monotonic time, wall time, and timers from one clock per JS realm.
* Install a Manual clock for deterministic tests without replacing host timers.
* Tests install a `Manual` clock from `@moq/clock/test` without replacing host timers.
*
* @module
*/
Expand All @@ -9,7 +9,6 @@ import { backend } from "./ambient.ts";
import { type Wall, wallOf } from "./types.ts";

export type { Installed } from "./ambient.ts";
export { Manual } from "./manual.ts";
export {
Elapsed,
Interval,
Expand Down
2 changes: 2 additions & 0 deletions js/clock/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import { guard } from "./host.ts";

export { Manual } from "./manual.ts";

/**
* Let the current test's timers fire on the host clock, for real sockets, devices, or processes.
* Call it in the test or a `beforeEach`; it does nothing without the `@moq/clock` test preload.
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.backpressure.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, spyOn, test } from "bun:test";
import { Duration, Elapsed, Instant, Manual, timeout } from "@moq/clock";
import { Duration, Elapsed, Instant, timeout } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Time, Track } from "@moq/net";
import { Consumer, type Read } from "./consumer.ts";
import { encodeFrame, Format } from "./legacy.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.holes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Time, Track } from "@moq/net";
import { Consumer, type Read } from "./consumer.ts";
import { encodeFrame, Format } from "./legacy.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.nonsequential.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, expect, test } from "bun:test";
import { Duration, type Installed, Manual } from "@moq/clock";
import { Duration, type Installed } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { type Group, Time, Track, Varint } from "@moq/net";
import { Consumer } from "./consumer.ts";
import { Format as LegacyFormat } from "./legacy.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.outoforder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, expect, test } from "bun:test";
import { Duration, type Installed, Manual } from "@moq/clock";
import { Duration, type Installed } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { type Group, Time, Track, Varint } from "@moq/net";
import { Consumer } from "./consumer.ts";
import { Format as LegacyFormat } from "./legacy.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.rewind.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, expect, test } from "bun:test";
import { Duration, type Installed, Manual } from "@moq/clock";
import { Duration, type Installed } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Time, Track } from "@moq/net";
import { Consumer } from "./consumer";
import { encodeFrame, Format, Producer } from "./legacy";
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.startup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, onTestFinished, spyOn, test } from "bun:test";
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { type Group, Error as NetError, StreamCode, Time, Track } from "@moq/net";
import { Consumer, type Read } from "./consumer.ts";
import { encodeFrame, Format } from "./legacy.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { afterEach, beforeEach, expect, spyOn, test } from "bun:test";
import { readFileSync } from "node:fs";
import { Duration, type Installed, Manual } from "@moq/clock";
import { Duration, type Installed } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Format as LocFormat } from "@moq/loc";
import { type Group, Error as NetError, SessionCode, StreamCode, Time, Track, Varint } from "@moq/net";
import { decodeInitSegment, type InitSegment } from "../cmaf/decode.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/hang/src/container/consumer.warmup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, onTestFinished, spyOn, test } from "bun:test";
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { type Group, Time, Track } from "@moq/net";
import { Consumer, type Read } from "./consumer.ts";
import { encodeFrame, Format } from "./legacy.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/json/src/snapshot/snapshot.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Error as NetError, StreamCode, Time, Track } from "@moq/net";
import { hooks } from "../../../net/src/internal.ts";
import { Consumer } from "./consumer.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/bench/drift.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Sweep publishers, readers, and retained history for a parked frame read's drift check. */
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { type Group, Time, Track } from "@moq/net";
import { hooks } from "../src/internal.ts";

Expand Down
2 changes: 1 addition & 1 deletion js/net/bench/forward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* a watch coming and going over held watches and attached sessions.
*/

import { Manual } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { announcedView } from "../src/announced.test-util";
import * as Announce from "../src/announced.ts";
import { AuthSession } from "../src/auth_session.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/bench/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Sweep retained groups, unrelated tracks, and joined readers for a refresh crossing one lite hop. */
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { accept } from "../src/connection/accept.ts";
import { connect } from "../src/connection/connect.ts";
import { ALPN_07_WIP } from "../src/lite/version.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/bench/replay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** Sweep cached-group replay to joining subscribers, and arrivals into unread backlogs. */
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Track } from "@moq/net";

type Order = "monotonic" | "reverse" | "mixed";
Expand Down
3 changes: 2 additions & 1 deletion js/net/bench/resume-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* exposes `gc` and fails once a retired route stays reachable. Bun scans its stack conservatively,
* so a dead reference there can survive a collection.
*/
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import type { Producer as BroadcastProducer } from "../src/broadcast.ts";
import { accept } from "../src/connection/accept.ts";
import { connect } from "../src/connection/connect.ts";
Expand Down
3 changes: 1 addition & 2 deletions js/net/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"@moq/pattern": "workspace:^",
"@moq/qmux": "workspace:^",
"@moq/signals": "workspace:*",
"pako": "^3.0.3",
"sorted-btree": "^2.1.0"
"pako": "^3.0.3"
},
"peerDependencies": {
"zod": "^4.5.0"
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, spyOn, test } from "bun:test";
import { Duration, Manual, yieldNow } from "@moq/clock";
import { Duration, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import {
type Credential,
Duplicate,
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/broadcast.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual, yieldNow } from "@moq/clock";
import { Duration, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast.ts";
import * as cache from "./cache.ts";
import { NotFound, StreamCode, toStreamCode } from "./error.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual, yieldNow } from "@moq/clock";
import { Duration, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import * as cache from "./cache.ts";
import { StreamCode, StreamError, TooFarBehind } from "./error.ts";
import { hooks, staleHole } from "./internal.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/bandwidth.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, expect, spyOn, test } from "bun:test";
import { Duration, Manual, now, yieldNow } from "@moq/clock";
import { Duration, now, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import * as Lite from "../lite/index.ts";
import { createMockTransportPair, type MockTransport } from "../mock.ts";
import { Producer as TrackProducer } from "../track.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/close.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, type Installed, Manual } from "@moq/clock";
import { Duration, type Installed } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import * as Ietf from "../ietf/index.ts";
import * as Lite from "../lite/index.ts";
import { createMockTransportPair, type MockTransport } from "../mock.ts";
Expand Down
4 changes: 2 additions & 2 deletions js/net/src/connection/connect.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Instant, Manual, sleep, yieldNow } from "@moq/clock";
import { hostTime } from "@moq/clock/test";
import { Duration, Instant, sleep, yieldNow } from "@moq/clock";
import { hostTime, Manual } from "@moq/clock/test";
import { Session as Qmux, selectSubprotocol, type WebSocketLike } from "@moq/qmux";
import { ConnectTimeout, SessionCode, SessionError } from "../error.ts";
import * as Ietf from "../ietf/index.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/forward.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, expect, jest, spyOn, test } from "bun:test";
import { Duration, type Installed, Manual } from "@moq/clock";
import { Duration, type Installed } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import * as Announce from "../announced.ts";
import { AuthSession } from "../auth_session.ts";
import { type Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "../broadcast.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/migrate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, expect, spyOn, test } from "bun:test";
import { Duration, Manual, now, yieldNow } from "@moq/clock";
import { Duration, now, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { RefusedRedirect } from "../error.ts";
import * as Lite from "../lite/index.ts";
import { createMockTransportPair } from "../mock.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/pool.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, expect, test } from "bun:test";
import { Duration, type Installed, Manual } from "@moq/clock";
import { Duration, type Installed } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Signal } from "@moq/signals";
import { SessionCode, SessionError } from "../error.ts";
import * as Lite from "../lite/index.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/reload.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, spyOn, test } from "bun:test";
import { Duration, type Instant, Manual, now, yieldNow } from "@moq/clock";
import { Duration, type Instant, now, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Session as Qmux, type WebSocketStreamLike } from "@moq/qmux";
import { Effect, type Getter, Signal } from "@moq/signals";
import * as Announce from "../announced.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/stats.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, spyOn, test } from "bun:test";
import { Duration, Manual, yieldNow } from "@moq/clock";
import { Duration, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Session as QmuxSession } from "@moq/qmux";
import { Effect } from "@moq/signals";
import * as Ietf from "../ietf/index.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/connection/ticker.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual } from "@moq/clock";
import { Duration } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { tick } from "./ticker.ts";

test("subscribers share one tick and the loop stops with the last", async () => {
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/fill.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual, yieldNow } from "@moq/clock";
import { Duration, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Producer as BroadcastProducer } from "./broadcast.ts";
import { accept as acceptSession, connect as connectSession } from "./connection/index.ts";
import { NotFound, StreamCode, StreamError, toStreamCode } from "./error.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/goaway-requests.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual, now, yieldNow } from "@moq/clock";
import { Duration, now, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Once } from "@moq/signals";
import { accept } from "./connection/accept.ts";
import { connect } from "./connection/connect.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from "bun:test";
import { Duration, Manual, yieldNow } from "@moq/clock";
import { Duration, yieldNow } from "@moq/clock";
import { Manual } from "@moq/clock/test";
import { Signal } from "@moq/signals";
import { FrameTooLarge, StreamCode, StreamError } from "./error.ts";
import { encodable } from "./flate/group.ts";
Expand Down
Loading