@moq/net 0.2.7 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/connection/accept.js +8 -3
- package/connection/accept.js.map +1 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +5 -2
- package/connection/connect.js.map +1 -1
- package/connection/handshake.d.ts +9 -1
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +18 -14
- package/connection/handshake.js.map +1 -1
- package/consume.d.ts +1 -1
- package/consume.js +1 -1
- package/consume.js.map +1 -1
- package/ietf/connection.d.ts +7 -1
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +23 -3
- package/ietf/connection.js.map +1 -1
- package/ietf/index.d.ts +1 -0
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +1 -0
- package/ietf/index.js.map +1 -1
- package/ietf/parameters.d.ts +1 -0
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +2 -0
- package/ietf/parameters.js.map +1 -1
- package/ietf/publisher.d.ts +22 -8
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +294 -77
- package/ietf/publisher.js.map +1 -1
- package/ietf/solicit.d.ts +41 -0
- package/ietf/solicit.d.ts.map +1 -0
- package/ietf/solicit.js +47 -0
- package/ietf/solicit.js.map +1 -0
- package/ietf/subscriber.d.ts +4 -0
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +122 -50
- package/ietf/subscriber.js.map +1 -1
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +43 -9
- package/lite/publisher.js.map +1 -1
- package/lite/subscriber.js +3 -3
- package/lite/subscriber.js.map +1 -1
- package/package.json +2 -2
- package/path.d.ts +19 -11
- package/path.d.ts.map +1 -1
- package/path.js +43 -15
- package/path.js.map +1 -1
- package/stream.d.ts +46 -2
- package/stream.d.ts.map +1 -1
- package/stream.js +71 -6
- package/stream.js.map +1 -1
- package/track.d.ts +20 -7
- package/track.d.ts.map +1 -1
- package/track.js +63 -27
- package/track.js.map +1 -1
- package/announced.test.d.ts +0 -2
- package/announced.test.d.ts.map +0 -1
- package/announced.test.js +0 -37
- package/announced.test.js.map +0 -1
- package/broadcast.test.d.ts +0 -2
- package/broadcast.test.d.ts.map +0 -1
- package/broadcast.test.js +0 -243
- package/broadcast.test.js.map +0 -1
- package/connection/browser.test.d.ts +0 -2
- package/connection/browser.test.d.ts.map +0 -1
- package/connection/browser.test.js +0 -29
- package/connection/browser.test.js.map +0 -1
- package/connection/cert.test.d.ts +0 -2
- package/connection/cert.test.d.ts.map +0 -1
- package/connection/cert.test.js +0 -26
- package/connection/cert.test.js.map +0 -1
- package/connection/connect.test.d.ts +0 -2
- package/connection/connect.test.d.ts.map +0 -1
- package/connection/connect.test.js +0 -118
- package/connection/connect.test.js.map +0 -1
- package/connection/reload.test.d.ts +0 -2
- package/connection/reload.test.d.ts.map +0 -1
- package/connection/reload.test.js +0 -160
- package/connection/reload.test.js.map +0 -1
- package/connection/stats.test.d.ts +0 -2
- package/connection/stats.test.d.ts.map +0 -1
- package/connection/stats.test.js +0 -120
- package/connection/stats.test.js.map +0 -1
- package/error.test.d.ts +0 -2
- package/error.test.d.ts.map +0 -1
- package/error.test.js +0 -89
- package/error.test.js.map +0 -1
- package/group.test.d.ts +0 -2
- package/group.test.d.ts.map +0 -1
- package/group.test.js +0 -152
- package/group.test.js.map +0 -1
- package/ietf/aliases.test.d.ts +0 -2
- package/ietf/aliases.test.d.ts.map +0 -1
- package/ietf/aliases.test.js +0 -30
- package/ietf/aliases.test.js.map +0 -1
- package/ietf/ietf.test.d.ts +0 -2
- package/ietf/ietf.test.d.ts.map +0 -1
- package/ietf/ietf.test.js +0 -983
- package/ietf/ietf.test.js.map +0 -1
- package/ietf/priority.test.d.ts +0 -2
- package/ietf/priority.test.d.ts.map +0 -1
- package/ietf/priority.test.js +0 -18
- package/ietf/priority.test.js.map +0 -1
- package/integration.test.d.ts +0 -2
- package/integration.test.d.ts.map +0 -1
- package/integration.test.js +0 -1006
- package/integration.test.js.map +0 -1
- package/lite/announce.test.d.ts +0 -2
- package/lite/announce.test.d.ts.map +0 -1
- package/lite/announce.test.js +0 -91
- package/lite/announce.test.js.map +0 -1
- package/lite/datagram.test.d.ts +0 -2
- package/lite/datagram.test.d.ts.map +0 -1
- package/lite/datagram.test.js +0 -26
- package/lite/datagram.test.js.map +0 -1
- package/lite/datagram_stream.test.d.ts +0 -2
- package/lite/datagram_stream.test.d.ts.map +0 -1
- package/lite/datagram_stream.test.js +0 -15
- package/lite/datagram_stream.test.js.map +0 -1
- package/lite/fetch.test.d.ts +0 -2
- package/lite/fetch.test.d.ts.map +0 -1
- package/lite/fetch.test.js +0 -41
- package/lite/fetch.test.js.map +0 -1
- package/lite/priority.test.d.ts +0 -2
- package/lite/priority.test.d.ts.map +0 -1
- package/lite/priority.test.js +0 -77
- package/lite/priority.test.js.map +0 -1
- package/lite/publisher.test.d.ts +0 -2
- package/lite/publisher.test.d.ts.map +0 -1
- package/lite/publisher.test.js +0 -334
- package/lite/publisher.test.js.map +0 -1
- package/lite/setup.test.d.ts +0 -2
- package/lite/setup.test.d.ts.map +0 -1
- package/lite/setup.test.js +0 -134
- package/lite/setup.test.js.map +0 -1
- package/lite/subscribe.test.d.ts +0 -2
- package/lite/subscribe.test.d.ts.map +0 -1
- package/lite/subscribe.test.js +0 -110
- package/lite/subscribe.test.js.map +0 -1
- package/lite/subscriber.test.d.ts +0 -2
- package/lite/subscriber.test.d.ts.map +0 -1
- package/lite/subscriber.test.js +0 -108
- package/lite/subscriber.test.js.map +0 -1
- package/lite/track.test.d.ts +0 -2
- package/lite/track.test.d.ts.map +0 -1
- package/lite/track.test.js +0 -55
- package/lite/track.test.js.map +0 -1
- package/path.test.d.ts +0 -2
- package/path.test.d.ts.map +0 -1
- package/path.test.js +0 -210
- package/path.test.js.map +0 -1
- package/stream.test.d.ts +0 -2
- package/stream.test.d.ts.map +0 -1
- package/stream.test.js +0 -252
- package/stream.test.js.map +0 -1
- package/time.test.d.ts +0 -2
- package/time.test.d.ts.map +0 -1
- package/time.test.js +0 -12
- package/time.test.js.map +0 -1
- package/track.test.d.ts +0 -2
- package/track.test.d.ts.map +0 -1
- package/track.test.js +0 -212
- package/track.test.js.map +0 -1
- package/util/timeout.test.d.ts +0 -2
- package/util/timeout.test.d.ts.map +0 -1
- package/util/timeout.test.js +0 -18
- package/util/timeout.test.js.map +0 -1
- package/varint.test.d.ts +0 -2
- package/varint.test.d.ts.map +0 -1
- package/varint.test.js +0 -106
- package/varint.test.js.map +0 -1
package/lite/publisher.test.js
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./publisher.test.d.ts" */
|
|
2
|
-
import { expect, test } from "bun:test";
|
|
3
|
-
import { Producer as BroadcastProducer } from "../broadcast.js";
|
|
4
|
-
import { Producer as GroupProducer } from "../group.js";
|
|
5
|
-
import { createMockTransportPair } from "../mock.js";
|
|
6
|
-
import * as Path from "../path.js";
|
|
7
|
-
import { Stream } from "../stream.js";
|
|
8
|
-
import { Fetch } from "./fetch.js";
|
|
9
|
-
import { randomOrigin } from "./origin.js";
|
|
10
|
-
import { sendOrder } from "./priority.js";
|
|
11
|
-
import { Publisher } from "./publisher.js";
|
|
12
|
-
import { decodeSubscribeResponse, Subscribe, SubscribeUpdate } from "./subscribe.js";
|
|
13
|
-
import { ALPN_05, Version } from "./version.js";
|
|
14
|
-
// Delivers `sequences` in the given order, finishes the track, and returns the
|
|
15
|
-
// SUBSCRIBE_END boundary the publisher put on the wire.
|
|
16
|
-
async function subscribeEnd(sequences) {
|
|
17
|
-
const pair = createMockTransportPair(ALPN_05);
|
|
18
|
-
const publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());
|
|
19
|
-
const broadcast = new BroadcastProducer();
|
|
20
|
-
const track = broadcast.createTrack("video");
|
|
21
|
-
publisher.publish(Path.from("test"), broadcast);
|
|
22
|
-
const client = await Stream.open(pair.client);
|
|
23
|
-
const server = await Stream.accept(pair.server);
|
|
24
|
-
if (!server)
|
|
25
|
-
throw new Error("publisher never accepted the subscribe stream");
|
|
26
|
-
const msg = new Subscribe({ id: 0n, broadcast: Path.from("test"), track: "video", priority: 0 });
|
|
27
|
-
void publisher.runSubscribe(msg, server);
|
|
28
|
-
// Finish the track only once it's being served, so the publisher observes a live
|
|
29
|
-
// track ending rather than resolving a subscribe against an already-closed one.
|
|
30
|
-
for (const sequence of sequences) {
|
|
31
|
-
const group = new GroupProducer(sequence);
|
|
32
|
-
group.writeString("hello");
|
|
33
|
-
group.close();
|
|
34
|
-
track.writeGroup(group);
|
|
35
|
-
// Let the publisher drain this group before the next, so arrival order is the
|
|
36
|
-
// order given rather than whatever the cache hands over in one batch. A group that
|
|
37
|
-
// arrives late opens no stream at all, so there is nothing firmer to wait on.
|
|
38
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
39
|
-
}
|
|
40
|
-
track.close();
|
|
41
|
-
try {
|
|
42
|
-
for (;;) {
|
|
43
|
-
const resp = await decodeSubscribeResponse(client.reader, Version.DRAFT_05);
|
|
44
|
-
if ("end" in resp)
|
|
45
|
-
return resp.end.group;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
publisher.close();
|
|
50
|
-
client.close();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// Wait for the publisher to start serving the next group.
|
|
54
|
-
//
|
|
55
|
-
// The peer end of the stream arrives while the publisher is still opening it, so that alone
|
|
56
|
-
// says nothing about the ranking. Its first byte does: the header is written only after the
|
|
57
|
-
// group has joined the subscription's ranking.
|
|
58
|
-
async function servingNextGroup(opened) {
|
|
59
|
-
const next = await opened.read();
|
|
60
|
-
if (next.done)
|
|
61
|
-
throw new Error("publisher never opened the group stream");
|
|
62
|
-
const reader = next.value.getReader();
|
|
63
|
-
if ((await reader.read()).done)
|
|
64
|
-
throw new Error("publisher never wrote the group header");
|
|
65
|
-
reader.releaseLock();
|
|
66
|
-
}
|
|
67
|
-
// Serves `sequences` under the given subscription, optionally raising its priority via
|
|
68
|
-
// SUBSCRIBE_UPDATE after the first group, and returns the send order of each group stream in
|
|
69
|
-
// the order the publisher opened them.
|
|
70
|
-
//
|
|
71
|
-
// Every group is left open, so all of their streams are in flight and ranked against each
|
|
72
|
-
// other. A group that finished would leave the ranking, which is the point of it.
|
|
73
|
-
async function groupSendOrders(options) {
|
|
74
|
-
const { priority, sequences, update, ordered } = options;
|
|
75
|
-
const groups = sequences.map((sequence) => new GroupProducer(sequence));
|
|
76
|
-
const pair = createMockTransportPair(ALPN_05);
|
|
77
|
-
const publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());
|
|
78
|
-
const broadcast = new BroadcastProducer();
|
|
79
|
-
const track = broadcast.createTrack("video");
|
|
80
|
-
publisher.publish(Path.from("test"), broadcast);
|
|
81
|
-
const client = await Stream.open(pair.client);
|
|
82
|
-
const server = await Stream.accept(pair.server);
|
|
83
|
-
if (!server)
|
|
84
|
-
throw new Error("publisher never accepted the subscribe stream");
|
|
85
|
-
const msg = new Subscribe({ id: 0n, broadcast: Path.from("test"), track: "video", priority, ordered });
|
|
86
|
-
void publisher.runSubscribe(msg, server);
|
|
87
|
-
// The peer end of each group stream, which arrives as the publisher opens it.
|
|
88
|
-
const opened = pair.client.incomingUnidirectionalStreams.getReader();
|
|
89
|
-
try {
|
|
90
|
-
for (const [index, group] of groups.entries()) {
|
|
91
|
-
if (index === 1 && update !== undefined) {
|
|
92
|
-
await new SubscribeUpdate({ priority: update, ordered }).encode(client.writer, Version.DRAFT_05);
|
|
93
|
-
// Wait for the publisher to apply it, rather than assuming it beat the next group.
|
|
94
|
-
while (track.subscription.peek()?.priority !== update)
|
|
95
|
-
await track.subscription.changed();
|
|
96
|
-
}
|
|
97
|
-
group.writeString("hello");
|
|
98
|
-
track.writeGroup(group);
|
|
99
|
-
// One stream per group, in the order given: wait for this one before queuing the next.
|
|
100
|
-
await servingNextGroup(opened);
|
|
101
|
-
}
|
|
102
|
-
return pair.server.sendStreams.uni.map((stream) => {
|
|
103
|
-
if (stream.sendOrder === undefined)
|
|
104
|
-
throw new Error("group stream opened without a send order");
|
|
105
|
-
return stream.sendOrder;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
opened.releaseLock();
|
|
110
|
-
for (const group of groups)
|
|
111
|
-
group.close();
|
|
112
|
-
publisher.close();
|
|
113
|
-
client.close();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// Without a send order every group stream ranks the same, so the transport round-robins them
|
|
117
|
-
// and a stalled low-priority track steals bandwidth from the one the subscriber asked for.
|
|
118
|
-
// Live playback wants the newest group, so it is the one at position 0.
|
|
119
|
-
test("lite draft-05: group streams are ranked newest-first", async () => {
|
|
120
|
-
const orders = await groupSendOrders({ priority: 7, sequences: [0, 1, 2] });
|
|
121
|
-
expect(orders).toEqual([
|
|
122
|
-
sendOrder({ priority: 7, position: 2 }),
|
|
123
|
-
sendOrder({ priority: 7, position: 1 }),
|
|
124
|
-
sendOrder({ priority: 7, position: 0 }),
|
|
125
|
-
]);
|
|
126
|
-
expect(orders[2]).toBeGreaterThan(orders[1]);
|
|
127
|
-
});
|
|
128
|
-
// An ordered subscriber is playing through in sequence, so the oldest group in flight is the
|
|
129
|
-
// one it needs next.
|
|
130
|
-
test("lite draft-05: an ordered subscription is ranked oldest-first", async () => {
|
|
131
|
-
const orders = await groupSendOrders({ priority: 7, sequences: [0, 1, 2], ordered: true });
|
|
132
|
-
expect(orders).toEqual([
|
|
133
|
-
sendOrder({ priority: 7, position: 0 }),
|
|
134
|
-
sendOrder({ priority: 7, position: 1 }),
|
|
135
|
-
sendOrder({ priority: 7, position: 2 }),
|
|
136
|
-
]);
|
|
137
|
-
expect(orders[2]).toBeLessThan(orders[1]);
|
|
138
|
-
});
|
|
139
|
-
// Two tracks the subscriber values equally each get their next group out, whatever their group
|
|
140
|
-
// numbering: ranking by sequence would let the one with larger numbers starve the other.
|
|
141
|
-
test("lite draft-05: equal priorities tie regardless of group numbering", async () => {
|
|
142
|
-
const [fresh, ongoing] = await Promise.all([
|
|
143
|
-
groupSendOrders({ priority: 7, sequences: [0, 1] }),
|
|
144
|
-
groupSendOrders({ priority: 7, sequences: [900_000, 900_001] }),
|
|
145
|
-
]);
|
|
146
|
-
expect(fresh).toEqual(ongoing);
|
|
147
|
-
});
|
|
148
|
-
// SUBSCRIBE_UPDATE re-ranks the subscription, so every group it is serving picks up the new
|
|
149
|
-
// priority, including one opened after the update landed.
|
|
150
|
-
test("lite draft-05: a subscribe update re-ranks the whole subscription", async () => {
|
|
151
|
-
const orders = await groupSendOrders({ priority: 1, sequences: [0, 1], update: 9 });
|
|
152
|
-
expect(orders).toEqual([sendOrder({ priority: 9, position: 1 }), sendOrder({ priority: 9, position: 0 })]);
|
|
153
|
-
});
|
|
154
|
-
// A group can outlive the priority it opened with, so an update has to reach the stream that
|
|
155
|
-
// is already on the wire. Otherwise (say) an active-speaker change waits for the next group.
|
|
156
|
-
test("lite draft-05: a subscribe update re-ranks a group already on the wire", async () => {
|
|
157
|
-
const pair = createMockTransportPair(ALPN_05);
|
|
158
|
-
const publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());
|
|
159
|
-
const broadcast = new BroadcastProducer();
|
|
160
|
-
const track = broadcast.createTrack("video");
|
|
161
|
-
publisher.publish(Path.from("test"), broadcast);
|
|
162
|
-
const client = await Stream.open(pair.client);
|
|
163
|
-
const server = await Stream.accept(pair.server);
|
|
164
|
-
if (!server)
|
|
165
|
-
throw new Error("publisher never accepted the subscribe stream");
|
|
166
|
-
const msg = new Subscribe({ id: 0n, broadcast: Path.from("test"), track: "video", priority: 1 });
|
|
167
|
-
void publisher.runSubscribe(msg, server);
|
|
168
|
-
// Leave the group open, so its stream is still being served when the update lands.
|
|
169
|
-
const group = new GroupProducer(4);
|
|
170
|
-
group.writeString("hello");
|
|
171
|
-
track.writeGroup(group);
|
|
172
|
-
const opened = pair.client.incomingUnidirectionalStreams.getReader();
|
|
173
|
-
await servingNextGroup(opened);
|
|
174
|
-
opened.releaseLock();
|
|
175
|
-
// The only group in flight, so it is the one to send next.
|
|
176
|
-
const stream = pair.server.sendStreams.uni[0];
|
|
177
|
-
expect(stream.sendOrder).toBe(sendOrder({ priority: 1 }));
|
|
178
|
-
try {
|
|
179
|
-
await new SubscribeUpdate({ priority: 9 }).encode(client.writer, Version.DRAFT_05);
|
|
180
|
-
while (track.subscription.peek()?.priority !== 9)
|
|
181
|
-
await track.subscription.changed();
|
|
182
|
-
// The publisher re-ranks from that same signal, so wait on the send order itself rather
|
|
183
|
-
// than on the dispatch order between its subscriber and this one.
|
|
184
|
-
for (let i = 0; i < 200 && stream.sendOrder === sendOrder({ priority: 1 }); i++) {
|
|
185
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
186
|
-
}
|
|
187
|
-
expect(stream.sendOrder).toBe(sendOrder({ priority: 9 }));
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
group.close();
|
|
191
|
-
publisher.close();
|
|
192
|
-
client.close();
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
// Opening a stream can block on transport capacity, and a subscription listener only sees
|
|
196
|
-
// later changes, so an update landing in that window would otherwise be lost until the next one.
|
|
197
|
-
test("lite draft-05: a subscribe update during the stream open still ranks the group", async () => {
|
|
198
|
-
const pair = createMockTransportPair(ALPN_05);
|
|
199
|
-
const publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());
|
|
200
|
-
const broadcast = new BroadcastProducer();
|
|
201
|
-
const track = broadcast.createTrack("video");
|
|
202
|
-
publisher.publish(Path.from("test"), broadcast);
|
|
203
|
-
// Hold the group's stream open call until the test releases it.
|
|
204
|
-
let release = () => { };
|
|
205
|
-
const opening = new Promise((resolve) => {
|
|
206
|
-
release = resolve;
|
|
207
|
-
});
|
|
208
|
-
const open = pair.server.createUnidirectionalStream.bind(pair.server);
|
|
209
|
-
pair.server.createUnidirectionalStream = async (options) => {
|
|
210
|
-
await opening;
|
|
211
|
-
return open(options);
|
|
212
|
-
};
|
|
213
|
-
const client = await Stream.open(pair.client);
|
|
214
|
-
const server = await Stream.accept(pair.server);
|
|
215
|
-
if (!server)
|
|
216
|
-
throw new Error("publisher never accepted the subscribe stream");
|
|
217
|
-
const msg = new Subscribe({ id: 0n, broadcast: Path.from("test"), track: "video", priority: 1 });
|
|
218
|
-
void publisher.runSubscribe(msg, server);
|
|
219
|
-
const group = new GroupProducer(4);
|
|
220
|
-
group.writeString("hello");
|
|
221
|
-
track.writeGroup(group);
|
|
222
|
-
try {
|
|
223
|
-
// The publisher is now parked inside the open, having already read priority 1.
|
|
224
|
-
await new SubscribeUpdate({ priority: 9 }).encode(client.writer, Version.DRAFT_05);
|
|
225
|
-
while (track.subscription.peek()?.priority !== 9)
|
|
226
|
-
await track.subscription.changed();
|
|
227
|
-
release();
|
|
228
|
-
const opened = pair.client.incomingUnidirectionalStreams.getReader();
|
|
229
|
-
if ((await opened.read()).done)
|
|
230
|
-
throw new Error("publisher never opened the group stream");
|
|
231
|
-
opened.releaseLock();
|
|
232
|
-
for (let i = 0; i < 200 && pair.server.sendStreams.uni[0]?.sendOrder !== sendOrder({ priority: 9 }); i++) {
|
|
233
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
234
|
-
}
|
|
235
|
-
expect(pair.server.sendStreams.uni[0]?.sendOrder).toBe(sendOrder({ priority: 9 }));
|
|
236
|
-
}
|
|
237
|
-
finally {
|
|
238
|
-
group.close();
|
|
239
|
-
publisher.close();
|
|
240
|
-
client.close();
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
// A stalled track piles up open groups, and the signals leak guard throws at 100 subscribers
|
|
244
|
-
// on one signal, so the subscription is ranked by a single listener rather than one per group.
|
|
245
|
-
test("lite draft-05: many concurrent groups share one subscription listener", async () => {
|
|
246
|
-
const count = 120;
|
|
247
|
-
const pair = createMockTransportPair(ALPN_05);
|
|
248
|
-
const publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());
|
|
249
|
-
const broadcast = new BroadcastProducer();
|
|
250
|
-
const track = broadcast.createTrack("video");
|
|
251
|
-
publisher.publish(Path.from("test"), broadcast);
|
|
252
|
-
const client = await Stream.open(pair.client);
|
|
253
|
-
const server = await Stream.accept(pair.server);
|
|
254
|
-
if (!server)
|
|
255
|
-
throw new Error("publisher never accepted the subscribe stream");
|
|
256
|
-
const msg = new Subscribe({ id: 0n, broadcast: Path.from("test"), track: "video", priority: 1 });
|
|
257
|
-
void publisher.runSubscribe(msg, server);
|
|
258
|
-
// Leave every group open, so all of their streams are in flight at once.
|
|
259
|
-
const groups = Array.from({ length: count }, (_, sequence) => new GroupProducer(sequence));
|
|
260
|
-
const opened = pair.client.incomingUnidirectionalStreams.getReader();
|
|
261
|
-
try {
|
|
262
|
-
for (const group of groups) {
|
|
263
|
-
group.writeString("hello");
|
|
264
|
-
track.writeGroup(group);
|
|
265
|
-
await servingNextGroup(opened);
|
|
266
|
-
}
|
|
267
|
-
opened.releaseLock();
|
|
268
|
-
expect(pair.server.sendStreams.uni.length).toBe(count);
|
|
269
|
-
await new SubscribeUpdate({ priority: 9 }).encode(client.writer, Version.DRAFT_05);
|
|
270
|
-
while (track.subscription.peek()?.priority !== 9)
|
|
271
|
-
await track.subscription.changed();
|
|
272
|
-
// Newest-first, so the last group opened is at position 0 and the first is at the back.
|
|
273
|
-
const expected = groups.map((group) => sendOrder({ priority: 9, position: count - 1 - group.sequence }));
|
|
274
|
-
for (let i = 0; i < 200; i++) {
|
|
275
|
-
if (pair.server.sendStreams.uni.every((stream, at) => stream.sendOrder === expected[at]))
|
|
276
|
-
break;
|
|
277
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
278
|
-
}
|
|
279
|
-
expect(pair.server.sendStreams.uni.map((stream) => stream.sendOrder)).toEqual(expected);
|
|
280
|
-
}
|
|
281
|
-
finally {
|
|
282
|
-
for (const group of groups)
|
|
283
|
-
group.close();
|
|
284
|
-
publisher.close();
|
|
285
|
-
client.close();
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
// A send order only schedules the local end, so the subscriber's FETCH stream ranks its own
|
|
289
|
-
// request; without this the response competes with the group streams at the default order.
|
|
290
|
-
test("lite draft-05: the fetch response ranks the publisher's own writes", async () => {
|
|
291
|
-
const pair = createMockTransportPair(ALPN_05);
|
|
292
|
-
const publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());
|
|
293
|
-
const broadcast = new BroadcastProducer();
|
|
294
|
-
const track = broadcast.createTrack("video");
|
|
295
|
-
publisher.publish(Path.from("test"), broadcast);
|
|
296
|
-
const group = new GroupProducer(7);
|
|
297
|
-
group.writeString("hello");
|
|
298
|
-
group.close();
|
|
299
|
-
track.writeGroup(group);
|
|
300
|
-
const client = await Stream.open(pair.client);
|
|
301
|
-
// Accept by hand rather than via Stream.accept, so the test keeps the writable the
|
|
302
|
-
// publisher ranks (a real WebTransportSendStream takes the same assignment).
|
|
303
|
-
const incoming = pair.server.incomingBidirectionalStreams.getReader();
|
|
304
|
-
const accepted = await incoming.read();
|
|
305
|
-
incoming.releaseLock();
|
|
306
|
-
if (accepted.done)
|
|
307
|
-
throw new Error("publisher never saw the fetch stream");
|
|
308
|
-
const server = new Stream(accepted.value);
|
|
309
|
-
const msg = new Fetch(Path.from("test"), "video", 3, 7);
|
|
310
|
-
try {
|
|
311
|
-
await publisher.runFetch(msg, server);
|
|
312
|
-
expect(accepted.value.writable.sendOrder).toBe(sendOrder({ priority: 3 }));
|
|
313
|
-
}
|
|
314
|
-
finally {
|
|
315
|
-
publisher.close();
|
|
316
|
-
client.close();
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
// A Rust subscriber feeds this value straight into `track::Producer::finish_at`, which is
|
|
320
|
-
// exclusive, so an inclusive bound here silently truncates the final group across languages.
|
|
321
|
-
test("lite draft-05: subscribe end is the exclusive boundary", async () => {
|
|
322
|
-
expect(await subscribeEnd([0, 1, 2])).toBe(3);
|
|
323
|
-
});
|
|
324
|
-
// recvGroup is arrival-ordered, so the boundary has to clear the max sequence delivered,
|
|
325
|
-
// not the last one seen. Otherwise the boundary lands on a group already on the wire.
|
|
326
|
-
test("lite draft-05: subscribe end clears the max sequence when groups arrive out of order", async () => {
|
|
327
|
-
expect(await subscribeEnd([0, 2, 1])).toBe(3);
|
|
328
|
-
});
|
|
329
|
-
// 0 is the only encoding for "no groups at all"; an inclusive bound cannot express it
|
|
330
|
-
// without colliding with a track whose sole group was sequence 0.
|
|
331
|
-
test("lite draft-05: subscribe end is 0 when no groups were produced", async () => {
|
|
332
|
-
expect(await subscribeEnd([])).toBe(0);
|
|
333
|
-
});
|
|
334
|
-
//# sourceMappingURL=publisher.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publisher.test.js","sourceRoot":"","sources":["../../src/lite/publisher.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,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AC,CAAC;AAEH,sFAAsF;AACtF,kEAAkE;AAClE,IAAI,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;IACjF,MAAM,CAAC,MAAM,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Producer as BroadcastProducer } from \"../broadcast.ts\";\nimport { Producer as GroupProducer } from \"../group.ts\";\nimport { createMockTransportPair } from \"../mock.ts\";\nimport * as Path from \"../path.ts\";\nimport { Stream } from \"../stream.ts\";\nimport { Fetch } from \"./fetch.ts\";\nimport { randomOrigin } from \"./origin.ts\";\nimport { sendOrder } from \"./priority.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { decodeSubscribeResponse, Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { ALPN_05, Version } from \"./version.ts\";\n\n// Delivers `sequences` in the given order, finishes the track, and returns the\n// SUBSCRIBE_END boundary the publisher put on the wire.\nasync function subscribeEnd(sequences: number[]): Promise<number> {\n\tconst pair = createMockTransportPair(ALPN_05);\n\tconst publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());\n\n\tconst broadcast = new BroadcastProducer();\n\tconst track = broadcast.createTrack(\"video\");\n\tpublisher.publish(Path.from(\"test\"), broadcast);\n\n\tconst client = await Stream.open(pair.client);\n\tconst server = await Stream.accept(pair.server);\n\tif (!server) throw new Error(\"publisher never accepted the subscribe stream\");\n\n\tconst msg = new Subscribe({ id: 0n, broadcast: Path.from(\"test\"), track: \"video\", priority: 0 });\n\tvoid publisher.runSubscribe(msg, server);\n\n\t// Finish the track only once it's being served, so the publisher observes a live\n\t// track ending rather than resolving a subscribe against an already-closed one.\n\tfor (const sequence of sequences) {\n\t\tconst group = new GroupProducer(sequence);\n\t\tgroup.writeString(\"hello\");\n\t\tgroup.close();\n\t\ttrack.writeGroup(group);\n\n\t\t// Let the publisher drain this group before the next, so arrival order is the\n\t\t// order given rather than whatever the cache hands over in one batch. A group that\n\t\t// arrives late opens no stream at all, so there is nothing firmer to wait on.\n\t\tawait new Promise((resolve) => setTimeout(resolve, 5));\n\t}\n\ttrack.close();\n\n\ttry {\n\t\tfor (;;) {\n\t\t\tconst resp = await decodeSubscribeResponse(client.reader, Version.DRAFT_05);\n\t\t\tif (\"end\" in resp) return resp.end.group;\n\t\t}\n\t} finally {\n\t\tpublisher.close();\n\t\tclient.close();\n\t}\n}\n\n// Wait for the publisher to start serving the next group.\n//\n// The peer end of the stream arrives while the publisher is still opening it, so that alone\n// says nothing about the ranking. Its first byte does: the header is written only after the\n// group has joined the subscription's ranking.\nasync function servingNextGroup(opened: ReadableStreamDefaultReader<ReadableStream<Uint8Array>>) {\n\tconst next = await opened.read();\n\tif (next.done) throw new Error(\"publisher never opened the group stream\");\n\n\tconst reader = next.value.getReader();\n\tif ((await reader.read()).done) throw new Error(\"publisher never wrote the group header\");\n\treader.releaseLock();\n}\n\n// Serves `sequences` under the given subscription, optionally raising its priority via\n// SUBSCRIBE_UPDATE after the first group, and returns the send order of each group stream in\n// the order the publisher opened them.\n//\n// Every group is left open, so all of their streams are in flight and ranked against each\n// other. A group that finished would leave the ranking, which is the point of it.\nasync function groupSendOrders(options: { priority: number; sequences: number[]; update?: number; ordered?: boolean }) {\n\tconst { priority, sequences, update, ordered } = options;\n\tconst groups = sequences.map((sequence) => new GroupProducer(sequence));\n\tconst pair = createMockTransportPair(ALPN_05);\n\tconst publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());\n\n\tconst broadcast = new BroadcastProducer();\n\tconst track = broadcast.createTrack(\"video\");\n\tpublisher.publish(Path.from(\"test\"), broadcast);\n\n\tconst client = await Stream.open(pair.client);\n\tconst server = await Stream.accept(pair.server);\n\tif (!server) throw new Error(\"publisher never accepted the subscribe stream\");\n\n\tconst msg = new Subscribe({ id: 0n, broadcast: Path.from(\"test\"), track: \"video\", priority, ordered });\n\tvoid publisher.runSubscribe(msg, server);\n\n\t// The peer end of each group stream, which arrives as the publisher opens it.\n\tconst opened = pair.client.incomingUnidirectionalStreams.getReader();\n\n\ttry {\n\t\tfor (const [index, group] of groups.entries()) {\n\t\t\tif (index === 1 && update !== undefined) {\n\t\t\t\tawait new SubscribeUpdate({ priority: update, ordered }).encode(client.writer, Version.DRAFT_05);\n\t\t\t\t// Wait for the publisher to apply it, rather than assuming it beat the next group.\n\t\t\t\twhile (track.subscription.peek()?.priority !== update) await track.subscription.changed();\n\t\t\t}\n\n\t\t\tgroup.writeString(\"hello\");\n\t\t\ttrack.writeGroup(group);\n\n\t\t\t// One stream per group, in the order given: wait for this one before queuing the next.\n\t\t\tawait servingNextGroup(opened);\n\t\t}\n\n\t\treturn pair.server.sendStreams.uni.map((stream) => {\n\t\t\tif (stream.sendOrder === undefined) throw new Error(\"group stream opened without a send order\");\n\t\t\treturn stream.sendOrder;\n\t\t});\n\t} finally {\n\t\topened.releaseLock();\n\t\tfor (const group of groups) group.close();\n\t\tpublisher.close();\n\t\tclient.close();\n\t}\n}\n\n// Without a send order every group stream ranks the same, so the transport round-robins them\n// and a stalled low-priority track steals bandwidth from the one the subscriber asked for.\n// Live playback wants the newest group, so it is the one at position 0.\ntest(\"lite draft-05: group streams are ranked newest-first\", async () => {\n\tconst orders = await groupSendOrders({ priority: 7, sequences: [0, 1, 2] });\n\texpect(orders).toEqual([\n\t\tsendOrder({ priority: 7, position: 2 }),\n\t\tsendOrder({ priority: 7, position: 1 }),\n\t\tsendOrder({ priority: 7, position: 0 }),\n\t]);\n\n\texpect(orders[2]).toBeGreaterThan(orders[1]);\n});\n\n// An ordered subscriber is playing through in sequence, so the oldest group in flight is the\n// one it needs next.\ntest(\"lite draft-05: an ordered subscription is ranked oldest-first\", async () => {\n\tconst orders = await groupSendOrders({ priority: 7, sequences: [0, 1, 2], ordered: true });\n\texpect(orders).toEqual([\n\t\tsendOrder({ priority: 7, position: 0 }),\n\t\tsendOrder({ priority: 7, position: 1 }),\n\t\tsendOrder({ priority: 7, position: 2 }),\n\t]);\n\n\texpect(orders[2]).toBeLessThan(orders[1]);\n});\n\n// Two tracks the subscriber values equally each get their next group out, whatever their group\n// numbering: ranking by sequence would let the one with larger numbers starve the other.\ntest(\"lite draft-05: equal priorities tie regardless of group numbering\", async () => {\n\tconst [fresh, ongoing] = await Promise.all([\n\t\tgroupSendOrders({ priority: 7, sequences: [0, 1] }),\n\t\tgroupSendOrders({ priority: 7, sequences: [900_000, 900_001] }),\n\t]);\n\n\texpect(fresh).toEqual(ongoing);\n});\n\n// SUBSCRIBE_UPDATE re-ranks the subscription, so every group it is serving picks up the new\n// priority, including one opened after the update landed.\ntest(\"lite draft-05: a subscribe update re-ranks the whole subscription\", async () => {\n\tconst orders = await groupSendOrders({ priority: 1, sequences: [0, 1], update: 9 });\n\texpect(orders).toEqual([sendOrder({ priority: 9, position: 1 }), sendOrder({ priority: 9, position: 0 })]);\n});\n\n// A group can outlive the priority it opened with, so an update has to reach the stream that\n// is already on the wire. Otherwise (say) an active-speaker change waits for the next group.\ntest(\"lite draft-05: a subscribe update re-ranks a group already on the wire\", async () => {\n\tconst pair = createMockTransportPair(ALPN_05);\n\tconst publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());\n\n\tconst broadcast = new BroadcastProducer();\n\tconst track = broadcast.createTrack(\"video\");\n\tpublisher.publish(Path.from(\"test\"), broadcast);\n\n\tconst client = await Stream.open(pair.client);\n\tconst server = await Stream.accept(pair.server);\n\tif (!server) throw new Error(\"publisher never accepted the subscribe stream\");\n\n\tconst msg = new Subscribe({ id: 0n, broadcast: Path.from(\"test\"), track: \"video\", priority: 1 });\n\tvoid publisher.runSubscribe(msg, server);\n\n\t// Leave the group open, so its stream is still being served when the update lands.\n\tconst group = new GroupProducer(4);\n\tgroup.writeString(\"hello\");\n\ttrack.writeGroup(group);\n\n\tconst opened = pair.client.incomingUnidirectionalStreams.getReader();\n\tawait servingNextGroup(opened);\n\topened.releaseLock();\n\n\t// The only group in flight, so it is the one to send next.\n\tconst stream = pair.server.sendStreams.uni[0];\n\texpect(stream.sendOrder).toBe(sendOrder({ priority: 1 }));\n\n\ttry {\n\t\tawait new SubscribeUpdate({ priority: 9 }).encode(client.writer, Version.DRAFT_05);\n\t\twhile (track.subscription.peek()?.priority !== 9) await track.subscription.changed();\n\n\t\t// The publisher re-ranks from that same signal, so wait on the send order itself rather\n\t\t// than on the dispatch order between its subscriber and this one.\n\t\tfor (let i = 0; i < 200 && stream.sendOrder === sendOrder({ priority: 1 }); i++) {\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, 5));\n\t\t}\n\n\t\texpect(stream.sendOrder).toBe(sendOrder({ priority: 9 }));\n\t} finally {\n\t\tgroup.close();\n\t\tpublisher.close();\n\t\tclient.close();\n\t}\n});\n\n// Opening a stream can block on transport capacity, and a subscription listener only sees\n// later changes, so an update landing in that window would otherwise be lost until the next one.\ntest(\"lite draft-05: a subscribe update during the stream open still ranks the group\", async () => {\n\tconst pair = createMockTransportPair(ALPN_05);\n\tconst publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());\n\n\tconst broadcast = new BroadcastProducer();\n\tconst track = broadcast.createTrack(\"video\");\n\tpublisher.publish(Path.from(\"test\"), broadcast);\n\n\t// Hold the group's stream open call until the test releases it.\n\tlet release: () => void = () => {};\n\tconst opening = new Promise<void>((resolve) => {\n\t\trelease = resolve;\n\t});\n\tconst open = pair.server.createUnidirectionalStream.bind(pair.server);\n\tpair.server.createUnidirectionalStream = async (options) => {\n\t\tawait opening;\n\t\treturn open(options);\n\t};\n\n\tconst client = await Stream.open(pair.client);\n\tconst server = await Stream.accept(pair.server);\n\tif (!server) throw new Error(\"publisher never accepted the subscribe stream\");\n\n\tconst msg = new Subscribe({ id: 0n, broadcast: Path.from(\"test\"), track: \"video\", priority: 1 });\n\tvoid publisher.runSubscribe(msg, server);\n\n\tconst group = new GroupProducer(4);\n\tgroup.writeString(\"hello\");\n\ttrack.writeGroup(group);\n\n\ttry {\n\t\t// The publisher is now parked inside the open, having already read priority 1.\n\t\tawait new SubscribeUpdate({ priority: 9 }).encode(client.writer, Version.DRAFT_05);\n\t\twhile (track.subscription.peek()?.priority !== 9) await track.subscription.changed();\n\n\t\trelease();\n\t\tconst opened = pair.client.incomingUnidirectionalStreams.getReader();\n\t\tif ((await opened.read()).done) throw new Error(\"publisher never opened the group stream\");\n\t\topened.releaseLock();\n\n\t\tfor (let i = 0; i < 200 && pair.server.sendStreams.uni[0]?.sendOrder !== sendOrder({ priority: 9 }); i++) {\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, 5));\n\t\t}\n\n\t\texpect(pair.server.sendStreams.uni[0]?.sendOrder).toBe(sendOrder({ priority: 9 }));\n\t} finally {\n\t\tgroup.close();\n\t\tpublisher.close();\n\t\tclient.close();\n\t}\n});\n\n// A stalled track piles up open groups, and the signals leak guard throws at 100 subscribers\n// on one signal, so the subscription is ranked by a single listener rather than one per group.\ntest(\"lite draft-05: many concurrent groups share one subscription listener\", async () => {\n\tconst count = 120;\n\tconst pair = createMockTransportPair(ALPN_05);\n\tconst publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());\n\n\tconst broadcast = new BroadcastProducer();\n\tconst track = broadcast.createTrack(\"video\");\n\tpublisher.publish(Path.from(\"test\"), broadcast);\n\n\tconst client = await Stream.open(pair.client);\n\tconst server = await Stream.accept(pair.server);\n\tif (!server) throw new Error(\"publisher never accepted the subscribe stream\");\n\n\tconst msg = new Subscribe({ id: 0n, broadcast: Path.from(\"test\"), track: \"video\", priority: 1 });\n\tvoid publisher.runSubscribe(msg, server);\n\n\t// Leave every group open, so all of their streams are in flight at once.\n\tconst groups = Array.from({ length: count }, (_, sequence) => new GroupProducer(sequence));\n\tconst opened = pair.client.incomingUnidirectionalStreams.getReader();\n\n\ttry {\n\t\tfor (const group of groups) {\n\t\t\tgroup.writeString(\"hello\");\n\t\t\ttrack.writeGroup(group);\n\t\t\tawait servingNextGroup(opened);\n\t\t}\n\t\topened.releaseLock();\n\n\t\texpect(pair.server.sendStreams.uni.length).toBe(count);\n\n\t\tawait new SubscribeUpdate({ priority: 9 }).encode(client.writer, Version.DRAFT_05);\n\t\twhile (track.subscription.peek()?.priority !== 9) await track.subscription.changed();\n\n\t\t// Newest-first, so the last group opened is at position 0 and the first is at the back.\n\t\tconst expected = groups.map((group) => sendOrder({ priority: 9, position: count - 1 - group.sequence }));\n\t\tfor (let i = 0; i < 200; i++) {\n\t\t\tif (pair.server.sendStreams.uni.every((stream, at) => stream.sendOrder === expected[at])) break;\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, 5));\n\t\t}\n\n\t\texpect(pair.server.sendStreams.uni.map((stream) => stream.sendOrder)).toEqual(expected);\n\t} finally {\n\t\tfor (const group of groups) group.close();\n\t\tpublisher.close();\n\t\tclient.close();\n\t}\n});\n\n// A send order only schedules the local end, so the subscriber's FETCH stream ranks its own\n// request; without this the response competes with the group streams at the default order.\ntest(\"lite draft-05: the fetch response ranks the publisher's own writes\", async () => {\n\tconst pair = createMockTransportPair(ALPN_05);\n\tconst publisher = new Publisher(pair.server, Version.DRAFT_05, randomOrigin());\n\n\tconst broadcast = new BroadcastProducer();\n\tconst track = broadcast.createTrack(\"video\");\n\tpublisher.publish(Path.from(\"test\"), broadcast);\n\n\tconst group = new GroupProducer(7);\n\tgroup.writeString(\"hello\");\n\tgroup.close();\n\ttrack.writeGroup(group);\n\n\tconst client = await Stream.open(pair.client);\n\n\t// Accept by hand rather than via Stream.accept, so the test keeps the writable the\n\t// publisher ranks (a real WebTransportSendStream takes the same assignment).\n\tconst incoming = pair.server.incomingBidirectionalStreams.getReader();\n\tconst accepted = await incoming.read();\n\tincoming.releaseLock();\n\tif (accepted.done) throw new Error(\"publisher never saw the fetch stream\");\n\tconst server = new Stream(accepted.value);\n\n\tconst msg = new Fetch(Path.from(\"test\"), \"video\", 3, 7);\n\ttry {\n\t\tawait publisher.runFetch(msg, server);\n\n\t\texpect((accepted.value.writable as { sendOrder?: number }).sendOrder).toBe(sendOrder({ priority: 3 }));\n\t} finally {\n\t\tpublisher.close();\n\t\tclient.close();\n\t}\n});\n\n// A Rust subscriber feeds this value straight into `track::Producer::finish_at`, which is\n// exclusive, so an inclusive bound here silently truncates the final group across languages.\ntest(\"lite draft-05: subscribe end is the exclusive boundary\", async () => {\n\texpect(await subscribeEnd([0, 1, 2])).toBe(3);\n});\n\n// recvGroup is arrival-ordered, so the boundary has to clear the max sequence delivered,\n// not the last one seen. Otherwise the boundary lands on a group already on the wire.\ntest(\"lite draft-05: subscribe end clears the max sequence when groups arrive out of order\", async () => {\n\texpect(await subscribeEnd([0, 2, 1])).toBe(3);\n});\n\n// 0 is the only encoding for \"no groups at all\"; an inclusive bound cannot express it\n// without colliding with a track whose sole group was sequence 0.\ntest(\"lite draft-05: subscribe end is 0 when no groups were produced\", async () => {\n\texpect(await subscribeEnd([])).toBe(0);\n});\n"]}
|
package/lite/setup.test.d.ts
DELETED
package/lite/setup.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.test.d.ts","sourceRoot":"","sources":["../../src/lite/setup.test.ts"],"names":[],"mappings":""}
|
package/lite/setup.test.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./setup.test.d.ts" */
|
|
2
|
-
import { expect, test } from "bun:test";
|
|
3
|
-
import { Reader, Writer } from "../stream.js";
|
|
4
|
-
import * as Varint from "../varint.js";
|
|
5
|
-
import { OriginSchema } from "./origin.js";
|
|
6
|
-
import { ProbeLevel, Role, Setup } from "./setup.js";
|
|
7
|
-
import { Version } from "./version.js";
|
|
8
|
-
// Parameter ids, duplicated from setup.ts so a typo there fails a test rather than
|
|
9
|
-
// silently agreeing with itself.
|
|
10
|
-
const PARAM_PROBE = 0x1n;
|
|
11
|
-
const PARAM_PATH = 0x2n;
|
|
12
|
-
const PARAM_ROLE = 0x3n;
|
|
13
|
-
const PARAM_ORIGIN = 0x5n;
|
|
14
|
-
function concat(chunks) {
|
|
15
|
-
const total = chunks.reduce((sum, c) => sum + c.byteLength, 0);
|
|
16
|
-
const out = new Uint8Array(total);
|
|
17
|
-
let offset = 0;
|
|
18
|
-
for (const c of chunks) {
|
|
19
|
-
out.set(c, offset);
|
|
20
|
-
offset += c.byteLength;
|
|
21
|
-
}
|
|
22
|
-
return out;
|
|
23
|
-
}
|
|
24
|
-
async function bytes(f) {
|
|
25
|
-
const written = [];
|
|
26
|
-
const writer = new Writer(new WritableStream({ write: (chunk) => void written.push(new Uint8Array(chunk)) }));
|
|
27
|
-
await f(writer);
|
|
28
|
-
writer.close();
|
|
29
|
-
await writer.closed;
|
|
30
|
-
return concat(written);
|
|
31
|
-
}
|
|
32
|
-
async function roundTrip(msg) {
|
|
33
|
-
const reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));
|
|
34
|
-
const got = await Setup.decode(reader, Version.DRAFT_05);
|
|
35
|
-
expect(await reader.done()).toBe(true);
|
|
36
|
-
return got;
|
|
37
|
-
}
|
|
38
|
-
// Hand-frame a SETUP carrying a single raw parameter, so we can feed the decoder values
|
|
39
|
-
// our own encoder would never produce (unknown levels, empty paths).
|
|
40
|
-
async function decodeParam(id, value) {
|
|
41
|
-
const body = await bytes(async (w) => {
|
|
42
|
-
await w.u53(1); // parameter count
|
|
43
|
-
await w.u62(id);
|
|
44
|
-
await w.u53(value.byteLength);
|
|
45
|
-
if (value.byteLength > 0)
|
|
46
|
-
await w.write(value);
|
|
47
|
-
});
|
|
48
|
-
const framed = await bytes(async (w) => {
|
|
49
|
-
await w.u53(body.byteLength); // Message size prefix
|
|
50
|
-
await w.write(body);
|
|
51
|
-
});
|
|
52
|
-
return await Setup.decode(new Reader(undefined, framed), Version.DRAFT_05);
|
|
53
|
-
}
|
|
54
|
-
test("empty SETUP round-trips on draft-05", async () => {
|
|
55
|
-
const got = await roundTrip(new Setup());
|
|
56
|
-
expect(got.probe).toBe(ProbeLevel.None);
|
|
57
|
-
expect(got.path).toBeUndefined();
|
|
58
|
-
expect(got.role).toBe(Role.Both);
|
|
59
|
-
});
|
|
60
|
-
test("each probe level round-trips on draft-05", async () => {
|
|
61
|
-
for (const probe of [ProbeLevel.None, ProbeLevel.Report, ProbeLevel.Increase]) {
|
|
62
|
-
const got = await roundTrip(new Setup({ probe }));
|
|
63
|
-
expect(got.probe).toBe(probe);
|
|
64
|
-
expect(got.path).toBeUndefined();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
test("SETUP with path round-trips on draft-05", async () => {
|
|
68
|
-
const got = await roundTrip(new Setup({ probe: ProbeLevel.Report, path: "/room/123" }));
|
|
69
|
-
expect(got.probe).toBe(ProbeLevel.Report);
|
|
70
|
-
expect(got.path).toBe("/room/123");
|
|
71
|
-
});
|
|
72
|
-
test("each role round-trips on draft-05", async () => {
|
|
73
|
-
for (const role of [Role.Both, Role.Publisher, Role.Subscriber]) {
|
|
74
|
-
const got = await roundTrip(new Setup({ role }));
|
|
75
|
-
expect(got.role).toBe(role);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
test("SETUP carries role alongside probe and path", async () => {
|
|
79
|
-
const got = await roundTrip(new Setup({ probe: ProbeLevel.Increase, path: "/room/123", role: Role.Publisher }));
|
|
80
|
-
expect(got.probe).toBe(ProbeLevel.Increase);
|
|
81
|
-
expect(got.path).toBe("/room/123");
|
|
82
|
-
expect(got.role).toBe(Role.Publisher);
|
|
83
|
-
});
|
|
84
|
-
test("Both is the wire default, so it is omitted rather than encoded", async () => {
|
|
85
|
-
// Both must be the absence of the parameter, so a server that predates it decodes a
|
|
86
|
-
// Both client back to Both. Assert the empty bag directly: comparing against another
|
|
87
|
-
// default-constructed Setup would agree with itself even if we encoded Both.
|
|
88
|
-
const both = await bytes((w) => new Setup({ role: Role.Both }).encode(w, Version.DRAFT_05));
|
|
89
|
-
const emptyBag = await bytes(async (w) => {
|
|
90
|
-
await w.u53(1); // Message size prefix: one byte of body follows
|
|
91
|
-
await w.u53(0); // parameter count
|
|
92
|
-
});
|
|
93
|
-
expect(both).toEqual(emptyBag);
|
|
94
|
-
// A directional role is still encoded, so the check above can actually fail.
|
|
95
|
-
const publisher = await bytes((w) => new Setup({ role: Role.Publisher }).encode(w, Version.DRAFT_05));
|
|
96
|
-
expect(publisher.byteLength).toBeGreaterThan(both.byteLength);
|
|
97
|
-
});
|
|
98
|
-
test("unknown role falls back to Both", async () => {
|
|
99
|
-
// Hand-frame a SETUP carrying an unrecognized role (99). The draft requires a receiver
|
|
100
|
-
// that doesn't know the value to treat it as Both, so a newer client can't break us.
|
|
101
|
-
const got = await decodeParam(PARAM_ROLE, Varint.encode(99));
|
|
102
|
-
expect(got.role).toBe(Role.Both);
|
|
103
|
-
});
|
|
104
|
-
test("role 0 decodes as Both", async () => {
|
|
105
|
-
const got = await decodeParam(PARAM_ROLE, Varint.encode(0));
|
|
106
|
-
expect(got.role).toBe(Role.Both);
|
|
107
|
-
});
|
|
108
|
-
test("unknown probe level saturates to Increase", async () => {
|
|
109
|
-
const got = await decodeParam(PARAM_PROBE, Varint.encode(99));
|
|
110
|
-
expect(got.probe).toBe(ProbeLevel.Increase);
|
|
111
|
-
});
|
|
112
|
-
test("SETUP with origin round-trips", async () => {
|
|
113
|
-
const origin = OriginSchema.parse(42n);
|
|
114
|
-
const got = await roundTrip(new Setup({ origin }));
|
|
115
|
-
expect(got.origin).toBe(origin);
|
|
116
|
-
});
|
|
117
|
-
test("origin 0 decodes as absent", async () => {
|
|
118
|
-
// 0 carries no identity (it cannot be excluded), so it decodes as undefined.
|
|
119
|
-
const got = await decodeParam(PARAM_ORIGIN, Varint.encode(0));
|
|
120
|
-
expect(got.origin).toBeUndefined();
|
|
121
|
-
});
|
|
122
|
-
test("SETUP is rejected before draft-05", async () => {
|
|
123
|
-
await expect(bytes((w) => new Setup().encode(w, Version.DRAFT_04))).rejects.toThrow();
|
|
124
|
-
});
|
|
125
|
-
test("SETUP decode is rejected before draft-05", async () => {
|
|
126
|
-
const framed = await bytes((w) => new Setup().encode(w, Version.DRAFT_05));
|
|
127
|
-
await expect(Setup.decode(new Reader(undefined, framed), Version.DRAFT_04)).rejects.toThrow();
|
|
128
|
-
});
|
|
129
|
-
test("empty path decodes as the root", async () => {
|
|
130
|
-
// Valid on the wire and equivalent to omitting the parameter.
|
|
131
|
-
const got = await decodeParam(PARAM_PATH, new Uint8Array());
|
|
132
|
-
expect(got.path).toBe("");
|
|
133
|
-
});
|
|
134
|
-
//# sourceMappingURL=setup.test.js.map
|
package/lite/setup.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.test.js","sourceRoot":"","sources":["../../src/lite/setup.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,mFAAmF;AACnF,iCAAiC;AACjC,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B,SAAS,MAAM,CAAC,MAAoB;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,CAA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AC7C,6EAA6E;IAC7E,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;AACpC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;IACpD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AACvF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;IAC3D,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3E,MAAM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;AAC/F,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;IACjD,8DAA8D;IAC9D,MAAM,GAAG,GAAG,MAAM,WAAW,CAAC,UAAU,EAAE,IAAI,UAAU,EAAE,CAAC,CAAC;IAC5D,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"bun:test\";\nimport { Reader, Writer } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { OriginSchema } from \"./origin.ts\";\nimport { ProbeLevel, Role, Setup } from \"./setup.ts\";\nimport { Version } from \"./version.ts\";\n\n// Parameter ids, duplicated from setup.ts so a typo there fails a test rather than\n// silently agreeing with itself.\nconst PARAM_PROBE = 0x1n;\nconst PARAM_PATH = 0x2n;\nconst PARAM_ROLE = 0x3n;\nconst PARAM_ORIGIN = 0x5n;\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n\tconst total = chunks.reduce((sum, c) => sum + c.byteLength, 0);\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const c of chunks) {\n\t\tout.set(c, offset);\n\t\toffset += c.byteLength;\n\t}\n\treturn out;\n}\n\nasync function bytes(f: (w: Writer) => Promise<void>): Promise<Uint8Array> {\n\tconst written: Uint8Array[] = [];\n\tconst writer = new Writer(\n\t\tnew WritableStream<Uint8Array>({ write: (chunk) => void written.push(new Uint8Array(chunk)) }),\n\t);\n\tawait f(writer);\n\twriter.close();\n\tawait writer.closed;\n\treturn concat(written);\n}\n\nasync function roundTrip(msg: Setup): Promise<Setup> {\n\tconst reader = new Reader(undefined, await bytes((w) => msg.encode(w, Version.DRAFT_05)));\n\tconst got = await Setup.decode(reader, Version.DRAFT_05);\n\texpect(await reader.done()).toBe(true);\n\treturn got;\n}\n\n// Hand-frame a SETUP carrying a single raw parameter, so we can feed the decoder values\n// our own encoder would never produce (unknown levels, empty paths).\nasync function decodeParam(id: bigint, value: Uint8Array): Promise<Setup> {\n\tconst body = await bytes(async (w) => {\n\t\tawait w.u53(1); // parameter count\n\t\tawait w.u62(id);\n\t\tawait w.u53(value.byteLength);\n\t\tif (value.byteLength > 0) await w.write(value);\n\t});\n\n\tconst framed = await bytes(async (w) => {\n\t\tawait w.u53(body.byteLength); // Message size prefix\n\t\tawait w.write(body);\n\t});\n\n\treturn await Setup.decode(new Reader(undefined, framed), Version.DRAFT_05);\n}\n\ntest(\"empty SETUP round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup());\n\texpect(got.probe).toBe(ProbeLevel.None);\n\texpect(got.path).toBeUndefined();\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"each probe level round-trips on draft-05\", async () => {\n\tfor (const probe of [ProbeLevel.None, ProbeLevel.Report, ProbeLevel.Increase]) {\n\t\tconst got = await roundTrip(new Setup({ probe }));\n\t\texpect(got.probe).toBe(probe);\n\t\texpect(got.path).toBeUndefined();\n\t}\n});\n\ntest(\"SETUP with path round-trips on draft-05\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Report, path: \"/room/123\" }));\n\texpect(got.probe).toBe(ProbeLevel.Report);\n\texpect(got.path).toBe(\"/room/123\");\n});\n\ntest(\"each role round-trips on draft-05\", async () => {\n\tfor (const role of [Role.Both, Role.Publisher, Role.Subscriber]) {\n\t\tconst got = await roundTrip(new Setup({ role }));\n\t\texpect(got.role).toBe(role);\n\t}\n});\n\ntest(\"SETUP carries role alongside probe and path\", async () => {\n\tconst got = await roundTrip(new Setup({ probe: ProbeLevel.Increase, path: \"/room/123\", role: Role.Publisher }));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n\texpect(got.path).toBe(\"/room/123\");\n\texpect(got.role).toBe(Role.Publisher);\n});\n\ntest(\"Both is the wire default, so it is omitted rather than encoded\", async () => {\n\t// Both must be the absence of the parameter, so a server that predates it decodes a\n\t// Both client back to Both. Assert the empty bag directly: comparing against another\n\t// default-constructed Setup would agree with itself even if we encoded Both.\n\tconst both = await bytes((w) => new Setup({ role: Role.Both }).encode(w, Version.DRAFT_05));\n\tconst emptyBag = await bytes(async (w) => {\n\t\tawait w.u53(1); // Message size prefix: one byte of body follows\n\t\tawait w.u53(0); // parameter count\n\t});\n\texpect(both).toEqual(emptyBag);\n\n\t// A directional role is still encoded, so the check above can actually fail.\n\tconst publisher = await bytes((w) => new Setup({ role: Role.Publisher }).encode(w, Version.DRAFT_05));\n\texpect(publisher.byteLength).toBeGreaterThan(both.byteLength);\n});\n\ntest(\"unknown role falls back to Both\", async () => {\n\t// Hand-frame a SETUP carrying an unrecognized role (99). The draft requires a receiver\n\t// that doesn't know the value to treat it as Both, so a newer client can't break us.\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(99));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"role 0 decodes as Both\", async () => {\n\tconst got = await decodeParam(PARAM_ROLE, Varint.encode(0));\n\texpect(got.role).toBe(Role.Both);\n});\n\ntest(\"unknown probe level saturates to Increase\", async () => {\n\tconst got = await decodeParam(PARAM_PROBE, Varint.encode(99));\n\texpect(got.probe).toBe(ProbeLevel.Increase);\n});\n\ntest(\"SETUP with origin round-trips\", async () => {\n\tconst origin = OriginSchema.parse(42n);\n\tconst got = await roundTrip(new Setup({ origin }));\n\texpect(got.origin).toBe(origin);\n});\n\ntest(\"origin 0 decodes as absent\", async () => {\n\t// 0 carries no identity (it cannot be excluded), so it decodes as undefined.\n\tconst got = await decodeParam(PARAM_ORIGIN, Varint.encode(0));\n\texpect(got.origin).toBeUndefined();\n});\n\ntest(\"SETUP is rejected before draft-05\", async () => {\n\tawait expect(bytes((w) => new Setup().encode(w, Version.DRAFT_04))).rejects.toThrow();\n});\n\ntest(\"SETUP decode is rejected before draft-05\", async () => {\n\tconst framed = await bytes((w) => new Setup().encode(w, Version.DRAFT_05));\n\tawait expect(Setup.decode(new Reader(undefined, framed), Version.DRAFT_04)).rejects.toThrow();\n});\n\ntest(\"empty path decodes as the root\", async () => {\n\t// Valid on the wire and equivalent to omitting the parameter.\n\tconst got = await decodeParam(PARAM_PATH, new Uint8Array());\n\texpect(got.path).toBe(\"\");\n});\n"]}
|
package/lite/subscribe.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.test.d.ts","sourceRoot":"","sources":["../../src/lite/subscribe.test.ts"],"names":[],"mappings":""}
|