@meshagent/meshagent 0.0.11

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.
@@ -0,0 +1,64 @@
1
+
2
+ import { Protocol, ProtocolMessageStream, StreamProtocolChannel, Completer } from "../protocol.js";
3
+ import { assertEqual } from "./assert.js";
4
+
5
+ test("can receive large packets", async () => {
6
+ const input = new ProtocolMessageStream()
7
+ const output = new ProtocolMessageStream();
8
+
9
+ let lastData;
10
+ let lastType;
11
+ let lastMessageId;
12
+
13
+ const client = new Protocol({
14
+ channel: new StreamProtocolChannel({
15
+ input: input,
16
+ output: output,
17
+ }),
18
+ });
19
+
20
+ client.start(async (protocol, messageId, type, data) => {
21
+
22
+ });
23
+
24
+ const server = new Protocol({
25
+ channel: new StreamProtocolChannel({
26
+ input: output,
27
+ output: input,
28
+ }),
29
+ });
30
+
31
+ server.start(async (protocol, messageId, type, data) => {
32
+ lastMessageId = messageId;
33
+ lastType = type;
34
+ lastData = data;
35
+ });
36
+
37
+ try {
38
+ const size = 1000 * 100;
39
+
40
+ const data = new Uint8Array(size);
41
+ for(let i = 0; i < size; i++) {
42
+ data[i] = 1;
43
+ }
44
+ await client.send("hello", data, 2);
45
+
46
+ const c = new Completer();
47
+
48
+ setTimeout(()=> {
49
+ c.resolve();
50
+ }, 1000*1);
51
+ await c.fut;
52
+
53
+ assertEqual(lastData != null, true);
54
+ assertEqual(lastType, "hello");
55
+ assertEqual(lastMessageId, 2);
56
+
57
+ for (let i = 0; i < size; i++) {
58
+ assertEqual(lastData[i], 1);
59
+ }
60
+ } finally {
61
+ server.dispose();
62
+ client.dispose();
63
+ }
64
+ });