@dxos/network-manager 0.6.11 → 0.6.12-main.5cc132e
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/dist/lib/browser/{chunk-XYSYUN63.mjs → chunk-NMDGRINN.mjs} +41 -26
- package/dist/lib/browser/{chunk-XYSYUN63.mjs.map → chunk-NMDGRINN.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-4YAYC7WN.cjs → chunk-4K3JQNY3.cjs} +55 -40
- package/dist/lib/node/chunk-4K3JQNY3.cjs.map +7 -0
- package/dist/lib/node/index.cjs +28 -28
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -18
- package/dist/lib/node-esm/chunk-X2RY5LSM.mjs +4319 -0
- package/dist/lib/node-esm/chunk-X2RY5LSM.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +59 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +290 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/signal/integration.node.test.d.ts +2 -0
- package/dist/types/src/signal/integration.node.test.d.ts.map +1 -0
- package/dist/types/src/signal/swarm-messenger.node.test.d.ts +2 -0
- package/dist/types/src/signal/swarm-messenger.node.test.d.ts.map +1 -0
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/tcp-transport.node.test.d.ts +2 -0
- package/dist/types/src/tests/tcp-transport.node.test.d.ts.map +1 -0
- package/dist/types/src/tests/utils.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.node.test.d.ts +2 -0
- package/dist/types/src/transport/libdatachannel-transport.node.test.d.ts.map +1 -0
- package/dist/types/src/transport/simplepeer-simple-peer.node.test.d.ts +2 -0
- package/dist/types/src/transport/simplepeer-simple-peer.node.test.d.ts.map +1 -0
- package/dist/types/src/transport/simplepeer-transport-proxy.node.test.d.ts +2 -0
- package/dist/types/src/transport/simplepeer-transport-proxy.node.test.d.ts.map +1 -0
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/package.json +33 -34
- package/src/signal/ice.test.ts +1 -3
- package/src/signal/{integration.test.ts → integration.node.test.ts} +9 -15
- package/src/signal/{swarm-messenger.test.ts → swarm-messenger.node.test.ts} +12 -22
- package/src/swarm/connection-limiter.test.ts +3 -6
- package/src/swarm/connection.test.ts +2 -1
- package/src/swarm/swarm.test.ts +7 -8
- package/src/tests/basic-test-suite.ts +34 -33
- package/src/tests/memory-transport.test.ts +40 -42
- package/src/tests/property-test-suite.ts +21 -22
- package/src/tests/tcp-transport.node.test.ts +65 -0
- package/src/tests/utils.ts +3 -2
- package/src/tests/webrtc-transport.test.ts +9 -9
- package/src/transport/{libdatachannel-transport.test.ts → libdatachannel-transport.node.test.ts} +16 -25
- package/src/transport/libdatachannel-transport.ts +2 -6
- package/src/transport/memory-transport.test.ts +6 -5
- package/src/transport/simplepeer-simple-peer.node.test.ts +22 -0
- package/src/transport/{simplepeer-transport-proxy-test.ts → simplepeer-transport-proxy.node.test.ts} +14 -15
- package/src/transport/simplepeer-transport.test.ts +10 -14
- package/src/transport/simplepeer-transport.ts +1 -1
- package/src/typings.d.ts +8 -2
- package/dist/lib/node/chunk-4YAYC7WN.cjs.map +0 -7
- package/dist/types/src/signal/integration.test.d.ts +0 -2
- package/dist/types/src/signal/integration.test.d.ts.map +0 -1
- package/dist/types/src/signal/swarm-messenger.test.d.ts +0 -2
- package/dist/types/src/signal/swarm-messenger.test.d.ts.map +0 -1
- package/dist/types/src/tests/tcp-transport.test.d.ts +0 -2
- package/dist/types/src/tests/tcp-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/libdatachannel-transport.test.d.ts +0 -2
- package/dist/types/src/transport/libdatachannel-transport.test.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-simple-peer.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-simple-peer.d.ts.map +0 -1
- package/dist/types/src/transport/simplepeer-transport-proxy-test.d.ts +0 -2
- package/dist/types/src/transport/simplepeer-transport-proxy-test.d.ts.map +0 -1
- package/src/globals.d.ts +0 -7
- package/src/tests/tcp-transport.test.ts +0 -67
- package/src/transport/simplepeer-simple-peer.ts +0 -26
package/package.json
CHANGED
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/network-manager",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12-main.5cc132e",
|
|
4
4
|
"description": "Network Manager",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "DXOS.org",
|
|
9
|
+
"imports": {
|
|
10
|
+
"#node-datachannel": {
|
|
11
|
+
"browser": "./module-stub.js",
|
|
12
|
+
"workerd": "./module-stub.js",
|
|
13
|
+
"default": "node-datachannel"
|
|
14
|
+
},
|
|
15
|
+
"#node-datachannel/*": {
|
|
16
|
+
"browser": "./module-stub.js",
|
|
17
|
+
"workerd": "./module-stub.js",
|
|
18
|
+
"default": "node-datachannel/*"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
9
21
|
"exports": {
|
|
10
22
|
".": {
|
|
11
23
|
"browser": "./dist/lib/browser/index.mjs",
|
|
12
24
|
"node": {
|
|
13
|
-
"
|
|
25
|
+
"require": "./dist/lib/node/index.cjs",
|
|
26
|
+
"default": "./dist/lib/node-esm/index.mjs"
|
|
14
27
|
},
|
|
15
28
|
"types": "./dist/types/src/index.d.ts"
|
|
16
29
|
},
|
|
17
30
|
"./testing": {
|
|
18
31
|
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
19
32
|
"node": {
|
|
20
|
-
"
|
|
33
|
+
"require": "./dist/lib/node/testing/index.cjs",
|
|
34
|
+
"default": "./dist/lib/node-esm/testing/index.mjs"
|
|
21
35
|
},
|
|
22
36
|
"types": "./dist/types/src/testing/index.d.ts"
|
|
23
37
|
}
|
|
24
38
|
},
|
|
25
39
|
"browser": {
|
|
26
|
-
"./src/transport/tcp-transport.ts": "./src/transport/tcp-transport.browser.ts"
|
|
27
|
-
"./src/transport/datachannel/index.ts": "./src/transport/datachannel/index.browser.ts"
|
|
40
|
+
"./src/transport/tcp-transport.ts": "./src/transport/tcp-transport.browser.ts"
|
|
28
41
|
},
|
|
29
42
|
"types": "dist/types/src/index.d.ts",
|
|
30
43
|
"typesVersions": {
|
|
@@ -42,42 +55,28 @@
|
|
|
42
55
|
],
|
|
43
56
|
"dependencies": {
|
|
44
57
|
"@koush/wrtc": "^0.5.3",
|
|
45
|
-
"isomorphic-ws": "^5.0.0",
|
|
46
|
-
"nanomessage-rpc": "^3.0.0",
|
|
47
58
|
"node-datachannel": "^0.5.5",
|
|
48
|
-
"p-defer": "^3.0.0",
|
|
49
59
|
"simple-peer": "9.11.1",
|
|
50
|
-
"stream": "^0.0.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/log": "0.6.11",
|
|
65
|
-
"@dxos/messaging": "0.6.11",
|
|
66
|
-
"@dxos/protocols": "0.6.11",
|
|
67
|
-
"@dxos/node-std": "0.6.11",
|
|
68
|
-
"@dxos/rpc": "0.6.11",
|
|
69
|
-
"@dxos/teleport": "0.6.11",
|
|
70
|
-
"@dxos/util": "0.6.11"
|
|
60
|
+
"stream": "^0.0.3",
|
|
61
|
+
"@dxos/async": "0.6.12-main.5cc132e",
|
|
62
|
+
"@dxos/codec-protobuf": "0.6.12-main.5cc132e",
|
|
63
|
+
"@dxos/context": "0.6.12-main.5cc132e",
|
|
64
|
+
"@dxos/debug": "0.6.12-main.5cc132e",
|
|
65
|
+
"@dxos/invariant": "0.6.12-main.5cc132e",
|
|
66
|
+
"@dxos/keys": "0.6.12-main.5cc132e",
|
|
67
|
+
"@dxos/messaging": "0.6.12-main.5cc132e",
|
|
68
|
+
"@dxos/node-std": "0.6.12-main.5cc132e",
|
|
69
|
+
"@dxos/log": "0.6.12-main.5cc132e",
|
|
70
|
+
"@dxos/protocols": "0.6.12-main.5cc132e",
|
|
71
|
+
"@dxos/rpc": "0.6.12-main.5cc132e",
|
|
72
|
+
"@dxos/teleport": "0.6.12-main.5cc132e",
|
|
73
|
+
"@dxos/util": "0.6.12-main.5cc132e"
|
|
71
74
|
},
|
|
72
75
|
"devDependencies": {
|
|
73
|
-
"@swc-node/register": "1.9.1",
|
|
74
76
|
"@types/simple-peer": "9.11.3",
|
|
75
|
-
"@types/ws": "^7.4.0",
|
|
76
|
-
"earljs": "~0.1.10",
|
|
77
77
|
"fast-check": "^3.19.0",
|
|
78
78
|
"fetch-mock": "^11.0.0",
|
|
79
|
-
"
|
|
80
|
-
"@dxos/signal": "0.6.11"
|
|
79
|
+
"@dxos/signal": "0.6.12-main.5cc132e"
|
|
81
80
|
},
|
|
82
81
|
"publishConfig": {
|
|
83
82
|
"access": "public"
|
package/src/signal/ice.test.ts
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { expect } from 'chai';
|
|
6
5
|
import fetchMock from 'fetch-mock';
|
|
7
|
-
|
|
8
|
-
import { test, describe } from '@dxos/test';
|
|
6
|
+
import { afterEach, test, expect, describe } from 'vitest';
|
|
9
7
|
|
|
10
8
|
import { createIceProvider } from './ice';
|
|
11
9
|
|
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { expect } from 'earljs';
|
|
8
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { afterAll, onTestFinished, beforeAll, describe, expect, test } from 'vitest';
|
|
9
6
|
|
|
10
7
|
import { PublicKey } from '@dxos/keys';
|
|
11
8
|
import { Messenger, type PeerInfo, WebsocketSignalManager } from '@dxos/messaging';
|
|
12
9
|
import { runTestSignalServer, type SignalServerRunner } from '@dxos/signal';
|
|
13
|
-
import { afterAll, afterTest, beforeAll, describe, test } from '@dxos/test';
|
|
14
10
|
|
|
15
11
|
import { type SignalMessage } from './signal-messenger';
|
|
16
12
|
import { SwarmMessenger } from './swarm-messenger';
|
|
@@ -35,13 +31,15 @@ describe('Signal Integration Test', () => {
|
|
|
35
31
|
}) => {
|
|
36
32
|
const signalManager = new WebsocketSignalManager([{ server: broker.url() }]);
|
|
37
33
|
await signalManager.open();
|
|
38
|
-
|
|
34
|
+
onTestFinished(async () => {
|
|
35
|
+
await signalManager.close();
|
|
36
|
+
});
|
|
39
37
|
|
|
40
38
|
const messenger = new Messenger({
|
|
41
39
|
signalManager,
|
|
42
40
|
});
|
|
43
41
|
messenger.open();
|
|
44
|
-
|
|
42
|
+
onTestFinished(() => messenger.close());
|
|
45
43
|
await messenger.listen({
|
|
46
44
|
peer,
|
|
47
45
|
onMessage: async (message) => await messageRouter.receiveMessage(message),
|
|
@@ -96,7 +94,7 @@ describe('Signal Integration Test', () => {
|
|
|
96
94
|
offer: {},
|
|
97
95
|
},
|
|
98
96
|
}),
|
|
99
|
-
).
|
|
97
|
+
).toEqual(expect.objectContaining({ accept: true }));
|
|
100
98
|
|
|
101
99
|
expect(
|
|
102
100
|
await peerNetworking2.messageRouter.offer({
|
|
@@ -108,7 +106,7 @@ describe('Signal Integration Test', () => {
|
|
|
108
106
|
offer: {},
|
|
109
107
|
},
|
|
110
108
|
}),
|
|
111
|
-
).
|
|
109
|
+
).toEqual(expect.objectContaining({ accept: true }));
|
|
112
110
|
|
|
113
111
|
{
|
|
114
112
|
const message: SignalMessage = {
|
|
@@ -123,9 +121,7 @@ describe('Signal Integration Test', () => {
|
|
|
123
121
|
};
|
|
124
122
|
await peerNetworking1.messageRouter.signal(message);
|
|
125
123
|
|
|
126
|
-
await
|
|
127
|
-
expect(peerNetworking2.receivedSignals[0]).toBeAnObjectWith(message);
|
|
128
|
-
});
|
|
124
|
+
await expect.poll(() => peerNetworking2.receivedSignals[0]).toEqual(expect.objectContaining(message));
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
{
|
|
@@ -141,9 +137,7 @@ describe('Signal Integration Test', () => {
|
|
|
141
137
|
};
|
|
142
138
|
await peerNetworking2.messageRouter.signal(message);
|
|
143
139
|
|
|
144
|
-
await
|
|
145
|
-
expect(peerNetworking1.receivedSignals[0]).toBeAnObjectWith(message);
|
|
146
|
-
});
|
|
140
|
+
await expect.poll(() => peerNetworking1.receivedSignals[0]).toEqual(expect.objectContaining(message));
|
|
147
141
|
}
|
|
148
142
|
});
|
|
149
143
|
});
|
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { expect } from 'earljs';
|
|
8
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test, onTestFinished } from 'vitest';
|
|
9
6
|
|
|
10
7
|
import { type Awaited } from '@dxos/async';
|
|
11
8
|
import { PublicKey } from '@dxos/keys';
|
|
12
9
|
import { Messenger, WebsocketSignalManager } from '@dxos/messaging';
|
|
13
10
|
import { type Answer } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
14
11
|
import { runTestSignalServer } from '@dxos/signal';
|
|
15
|
-
import { afterAll, beforeAll, describe, test, afterTest } from '@dxos/test';
|
|
16
12
|
|
|
17
13
|
import { type OfferMessage, type SignalMessage } from './signal-messenger';
|
|
18
14
|
import { SwarmMessenger } from './swarm-messenger';
|
|
@@ -48,7 +44,9 @@ describe('SwarmMessenger', () => {
|
|
|
48
44
|
const peer = { peerKey: PublicKey.random().toHex() };
|
|
49
45
|
const signalManager = new WebsocketSignalManager([{ server: signalApiUrl }]);
|
|
50
46
|
await signalManager.open();
|
|
51
|
-
|
|
47
|
+
onTestFinished(async () => {
|
|
48
|
+
await signalManager.close();
|
|
49
|
+
});
|
|
52
50
|
|
|
53
51
|
const messenger = new Messenger({ signalManager });
|
|
54
52
|
await messenger.listen({
|
|
@@ -106,10 +104,8 @@ describe('SwarmMessenger', () => {
|
|
|
106
104
|
};
|
|
107
105
|
await router2.signal(msg);
|
|
108
106
|
|
|
109
|
-
await
|
|
110
|
-
|
|
111
|
-
}, 4_000);
|
|
112
|
-
}).timeout(5_000);
|
|
107
|
+
await expect.poll(() => received[0]).toEqual(expect.objectContaining(msg));
|
|
108
|
+
});
|
|
113
109
|
|
|
114
110
|
test('offer/answer', async () => {
|
|
115
111
|
const {
|
|
@@ -139,7 +135,7 @@ describe('SwarmMessenger', () => {
|
|
|
139
135
|
data: { offer: {} },
|
|
140
136
|
});
|
|
141
137
|
expect(answer.accept).toEqual(true);
|
|
142
|
-
})
|
|
138
|
+
});
|
|
143
139
|
|
|
144
140
|
test('signaling between 3 clients', async () => {
|
|
145
141
|
const received1: SignalMessage[] = [];
|
|
@@ -198,9 +194,7 @@ describe('SwarmMessenger', () => {
|
|
|
198
194
|
data: { signal: { payload: { msg: '1to3' } }, signalBatch: undefined },
|
|
199
195
|
};
|
|
200
196
|
await router1.signal(msg1to3);
|
|
201
|
-
await
|
|
202
|
-
expect(received3[0]).toBeAnObjectWith(msg1to3);
|
|
203
|
-
}, 4_000);
|
|
197
|
+
await expect.poll(() => received3[0]).toEqual(expect.objectContaining(msg1to3));
|
|
204
198
|
|
|
205
199
|
// sending signal from peer2 to peer3.
|
|
206
200
|
const msg2to3: SignalMessage = {
|
|
@@ -211,9 +205,7 @@ describe('SwarmMessenger', () => {
|
|
|
211
205
|
data: { signal: { payload: { msg: '2to3' } }, signalBatch: undefined },
|
|
212
206
|
};
|
|
213
207
|
await router2.signal(msg2to3);
|
|
214
|
-
await
|
|
215
|
-
expect(received3[1]).toBeAnObjectWith(msg2to3);
|
|
216
|
-
}, 4_000);
|
|
208
|
+
await expect.poll(() => received3[1]).toEqual(expect.objectContaining(msg2to3));
|
|
217
209
|
|
|
218
210
|
// sending signal from peer3 to peer1.
|
|
219
211
|
const msg3to1: SignalMessage = {
|
|
@@ -224,10 +216,8 @@ describe('SwarmMessenger', () => {
|
|
|
224
216
|
data: { signal: { payload: { msg: '3to1' } }, signalBatch: undefined },
|
|
225
217
|
};
|
|
226
218
|
await router3.signal(msg3to1);
|
|
227
|
-
await
|
|
228
|
-
|
|
229
|
-
}, 4_000);
|
|
230
|
-
}).timeout(5_000);
|
|
219
|
+
await expect.poll(() => received1[0]).toEqual(expect.objectContaining(msg3to1));
|
|
220
|
+
});
|
|
231
221
|
|
|
232
222
|
test('two offers', async () => {
|
|
233
223
|
const {
|
|
@@ -273,5 +263,5 @@ describe('SwarmMessenger', () => {
|
|
|
273
263
|
data: { offer: {} },
|
|
274
264
|
});
|
|
275
265
|
expect(answer2.accept).toEqual(true);
|
|
276
|
-
})
|
|
266
|
+
});
|
|
277
267
|
});
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
|
-
|
|
5
|
-
import
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout } from '@dxos/async';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
|
-
import { describe, test } from '@dxos/test';
|
|
10
9
|
|
|
11
10
|
import { ConnectionLimiter } from './connection-limiter';
|
|
12
11
|
|
|
13
|
-
chai.use(chaiAsPromised);
|
|
14
|
-
|
|
15
12
|
describe('ConnectionLimiter', () => {
|
|
16
13
|
function* setupPeers(
|
|
17
14
|
limiter: ConnectionLimiter,
|
|
@@ -37,7 +34,7 @@ describe('ConnectionLimiter', () => {
|
|
|
37
34
|
test('rejects if done is called', async () => {
|
|
38
35
|
const limiter = new ConnectionLimiter({ maxConcurrentInitConnections: 1 });
|
|
39
36
|
const [first] = setupPeers(limiter);
|
|
40
|
-
const testPromise = expect(first.connecting()).
|
|
37
|
+
const testPromise = expect(first.connecting()).rejects.toBeInstanceOf(Error);
|
|
41
38
|
first.doneConnecting();
|
|
42
39
|
await testPromise;
|
|
43
40
|
});
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { describe, test } from 'vitest';
|
|
6
|
+
|
|
5
7
|
import { sleep } from '@dxos/async';
|
|
6
8
|
import { PublicKey } from '@dxos/keys';
|
|
7
|
-
import { describe, test } from '@dxos/test';
|
|
8
9
|
|
|
9
10
|
import { Connection } from './connection';
|
|
10
11
|
import { TestWireProtocol } from '../testing/test-wire-protocol';
|
package/src/swarm/swarm.test.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { expect } from '
|
|
5
|
+
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, sleep } from '@dxos/async';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
type PeerInfo,
|
|
14
14
|
type SignalManager,
|
|
15
15
|
} from '@dxos/messaging';
|
|
16
|
-
import { afterTest, describe, test } from '@dxos/test';
|
|
17
16
|
import { ComplexSet } from '@dxos/util';
|
|
18
17
|
|
|
19
18
|
import { ConnectionState } from './connection';
|
|
@@ -61,7 +60,7 @@ describe('Swarm', () => {
|
|
|
61
60
|
initiationDelay,
|
|
62
61
|
);
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
onTestFinished(async () => {
|
|
65
64
|
await swarm.destroy();
|
|
66
65
|
await signalManager.close();
|
|
67
66
|
});
|
|
@@ -81,7 +80,7 @@ describe('Swarm', () => {
|
|
|
81
80
|
expect(peer2.swarm.connections.length).to.equal(0);
|
|
82
81
|
|
|
83
82
|
await connectSwarms(peer1, peer2);
|
|
84
|
-
})
|
|
83
|
+
});
|
|
85
84
|
|
|
86
85
|
test('two peers try to originate connections to each other simultaneously', async () => {
|
|
87
86
|
const topic = PublicKey.random();
|
|
@@ -93,7 +92,7 @@ describe('Swarm', () => {
|
|
|
93
92
|
expect(peer2.swarm.connections.length).to.equal(0);
|
|
94
93
|
|
|
95
94
|
await connectSwarms(peer1, peer2);
|
|
96
|
-
})
|
|
95
|
+
});
|
|
97
96
|
|
|
98
97
|
test('with simultaneous connections one of the peers drops initiated connection', async () => {
|
|
99
98
|
const topic = PublicKey.random();
|
|
@@ -111,9 +110,9 @@ describe('Swarm', () => {
|
|
|
111
110
|
|
|
112
111
|
await connectSwarms(peer1, peer2);
|
|
113
112
|
await asyncTimeout(connectionDisplaced!, 1000);
|
|
114
|
-
})
|
|
113
|
+
});
|
|
115
114
|
|
|
116
|
-
test('second peer discovered after delay', async () => {
|
|
115
|
+
test('second peer discovered after delay', { timeout: 10_000 }, async () => {
|
|
117
116
|
const topic = PublicKey.random();
|
|
118
117
|
|
|
119
118
|
const peer1 = await setupSwarm({ topic });
|
|
@@ -126,7 +125,7 @@ describe('Swarm', () => {
|
|
|
126
125
|
expect(peer2.swarm.connections.length).to.equal(0);
|
|
127
126
|
|
|
128
127
|
await connectSwarms(peer1, peer2, () => sleep(15));
|
|
129
|
-
})
|
|
128
|
+
});
|
|
130
129
|
|
|
131
130
|
test('connection limiter', async () => {
|
|
132
131
|
// remotePeer1 <--> peer (connectionLimiter: max = 1) <--> remotePeer2
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { expect } from '
|
|
6
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { onTestFinished, expect, test } from 'vitest';
|
|
7
6
|
|
|
8
7
|
import { asyncTimeout } from '@dxos/async';
|
|
9
8
|
import { PublicKey } from '@dxos/keys';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
|
-
import { afterTest, test } from '@dxos/test';
|
|
12
10
|
import { range } from '@dxos/util';
|
|
13
11
|
|
|
14
12
|
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
@@ -25,7 +23,7 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
25
23
|
return;
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
test('joins swarm, sends messages, and cleanly exits', async () => {
|
|
26
|
+
test.skip('joins swarm, sends messages, and cleanly exits', async () => {
|
|
29
27
|
const peer1 = testBuilder.createPeer();
|
|
30
28
|
const peer2 = testBuilder.createPeer();
|
|
31
29
|
await openAndCloseAfterTest([peer1, peer2]);
|
|
@@ -34,24 +32,24 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
34
32
|
const [swarm1, swarm2] = await joinSwarm([peer1, peer2], topic, () => new FullyConnectedTopology());
|
|
35
33
|
await exchangeMessages(swarm1, swarm2);
|
|
36
34
|
await leaveSwarm([peer1, peer2], topic);
|
|
37
|
-
})
|
|
35
|
+
});
|
|
38
36
|
|
|
39
37
|
// TODO(burdon): Test with more peers (configure and test messaging).
|
|
40
|
-
test('joins swarm with star topology', async () => {
|
|
38
|
+
test.skip('joins swarm with star topology', async () => {
|
|
41
39
|
const peer1 = testBuilder.createPeer();
|
|
42
|
-
|
|
40
|
+
onTestFinished(() => peer1.close());
|
|
43
41
|
const peer2 = testBuilder.createPeer();
|
|
44
|
-
|
|
42
|
+
onTestFinished(() => peer2.close());
|
|
45
43
|
await openAndCloseAfterTest([peer1, peer2]);
|
|
46
44
|
|
|
47
45
|
const topic = PublicKey.random();
|
|
48
46
|
const [swarm1, swarm2] = await joinSwarm([peer1, peer2], topic, () => new StarTopology(peer1.peerId)); // NOTE: Same peer.
|
|
49
47
|
await exchangeMessages(swarm1, swarm2);
|
|
50
48
|
await leaveSwarm([peer1, peer2], topic);
|
|
51
|
-
})
|
|
49
|
+
});
|
|
52
50
|
|
|
53
51
|
// TODO(burdon): Fails when trying to reconnect to same topic.
|
|
54
|
-
test('joins swarm multiple times', async () => {
|
|
52
|
+
test.skip('joins swarm multiple times', async () => {
|
|
55
53
|
const peer1 = testBuilder.createPeer();
|
|
56
54
|
const peer2 = testBuilder.createPeer();
|
|
57
55
|
await openAndCloseAfterTest([peer1, peer2]);
|
|
@@ -75,9 +73,9 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
75
73
|
await exchangeMessages(swarm1, swarm2);
|
|
76
74
|
await leaveSwarm([peer1, peer2], topic2);
|
|
77
75
|
}
|
|
78
|
-
})
|
|
76
|
+
});
|
|
79
77
|
|
|
80
|
-
test('joins multiple swarms', async () => {
|
|
78
|
+
test.skip('joins multiple swarms', async () => {
|
|
81
79
|
// TODO(burdon): N peers.
|
|
82
80
|
// TODO(burdon): Merge with test below.
|
|
83
81
|
const peer1 = testBuilder.createPeer();
|
|
@@ -87,9 +85,9 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
87
85
|
const numSwarms = 5;
|
|
88
86
|
const topics = Array.from(Array(numSwarms)).map(() => PublicKey.random());
|
|
89
87
|
expect(topics).to.have.length(numSwarms);
|
|
90
|
-
})
|
|
88
|
+
});
|
|
91
89
|
|
|
92
|
-
test('joins multiple swarms concurrently', async () => {
|
|
90
|
+
test.skip('joins multiple swarms concurrently', async () => {
|
|
93
91
|
const createSwarm = async () => {
|
|
94
92
|
const topicA = PublicKey.random();
|
|
95
93
|
const peer1a = testBuilder.createPeer();
|
|
@@ -109,9 +107,9 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
109
107
|
test1.swarm1a.protocol.testConnection(test1.peer2a.peerId),
|
|
110
108
|
test2.swarm1a.protocol.testConnection(test2.peer2a.peerId),
|
|
111
109
|
]);
|
|
112
|
-
})
|
|
110
|
+
});
|
|
113
111
|
|
|
114
|
-
test('peers reconnect after and error in connection', async () => {
|
|
112
|
+
test.skip('peers reconnect after and error in connection', async () => {
|
|
115
113
|
const peer1 = testBuilder.createPeer();
|
|
116
114
|
const peer2 = testBuilder.createPeer();
|
|
117
115
|
await openAndCloseAfterTest([peer1, peer2]);
|
|
@@ -131,9 +129,9 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
131
129
|
await exchangeMessages(swarm1, swarm2);
|
|
132
130
|
|
|
133
131
|
await leaveSwarm([peer1, peer2], topic);
|
|
134
|
-
})
|
|
132
|
+
});
|
|
135
133
|
|
|
136
|
-
test('going offline and back online', async () => {
|
|
134
|
+
test.skip('going offline and back online', { timeout: 2_000 }, async () => {
|
|
137
135
|
const peer1 = testBuilder.createPeer();
|
|
138
136
|
const peer2 = testBuilder.createPeer();
|
|
139
137
|
await openAndCloseAfterTest([peer1, peer2]);
|
|
@@ -158,28 +156,31 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
158
156
|
await peerLeft;
|
|
159
157
|
|
|
160
158
|
// Wait for peer to be removed from the swarm.
|
|
161
|
-
await
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
await expect
|
|
160
|
+
.poll(() => !!peer2._networkManager.getSwarm(topic)!._peers.get({ peerKey: peer1.peerId.toHex() })?.advertizing, {
|
|
161
|
+
timeout: 1_000,
|
|
162
|
+
})
|
|
163
|
+
.toBe(false);
|
|
165
164
|
|
|
166
165
|
await peer1.goOnline();
|
|
167
166
|
|
|
168
|
-
await
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
await expect
|
|
168
|
+
.poll(() => peer1._networkManager.getSwarm(topic)?._peers.get({ peerKey: peer2.peerId.toHex() })?.advertizing, {
|
|
169
|
+
timeout: 2_000,
|
|
170
|
+
})
|
|
171
|
+
.toBe(true);
|
|
172
|
+
await expect
|
|
173
|
+
.poll(() => peer2._networkManager.getSwarm(topic)?._peers.get({ peerKey: peer1.peerId.toHex() })?.advertizing, {
|
|
174
|
+
timeout: 2_000,
|
|
175
|
+
})
|
|
176
|
+
.toBe(true);
|
|
174
177
|
|
|
175
178
|
await exchangeMessages(swarm1, swarm2);
|
|
176
179
|
await leaveSwarm([peer1, peer2], topic);
|
|
177
|
-
})
|
|
178
|
-
.tag('flaky')
|
|
179
|
-
.timeout(2_000);
|
|
180
|
+
});
|
|
180
181
|
|
|
181
182
|
// TODO(mykola): Fails with large amount of peers ~10.
|
|
182
|
-
test('many peers and connections', async () => {
|
|
183
|
+
test.skip('many peers and connections', async () => {
|
|
183
184
|
const numTopics = 2;
|
|
184
185
|
const peersPerTopic = 3;
|
|
185
186
|
const swarmsAllPeersConnected: Promise<any>[] = [];
|
|
@@ -207,5 +208,5 @@ export const basicTestSuite = (testBuilder: TestBuilder, runTests = true) => {
|
|
|
207
208
|
);
|
|
208
209
|
|
|
209
210
|
await asyncTimeout(Promise.all(swarmsAllPeersConnected), 2_000);
|
|
210
|
-
})
|
|
211
|
+
});
|
|
211
212
|
};
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { randomBytes } from 'crypto';
|
|
5
|
+
import { randomBytes } from 'node:crypto';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
6
7
|
|
|
7
8
|
import { PublicKey } from '@dxos/keys';
|
|
8
|
-
import { test } from '@dxos/test';
|
|
9
9
|
import { range } from '@dxos/util';
|
|
10
10
|
|
|
11
11
|
import { basicTestSuite } from './basic-test-suite';
|
|
@@ -17,47 +17,45 @@ describe('Memory transport', () => {
|
|
|
17
17
|
const testBuilder = new TestBuilder();
|
|
18
18
|
basicTestSuite(testBuilder);
|
|
19
19
|
|
|
20
|
-
test
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// console.log(`Round ${i}/${NUM_ROUNDS}`);
|
|
49
|
-
await Promise.all(
|
|
50
|
-
pairs.map(async ({ swarm1, swarm2 }) => {
|
|
51
|
-
await exchangeMessages(swarm1, swarm2, message);
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
20
|
+
test.skip('load', { timeout: 1_000_000 }, async () => {
|
|
21
|
+
const NUM_PAIRS = 100;
|
|
22
|
+
const NUM_ROUNDS = 10_000;
|
|
23
|
+
const PACKET_SIZE = 1_000;
|
|
24
|
+
|
|
25
|
+
const pairs = await Promise.all(
|
|
26
|
+
range(NUM_PAIRS).map(async () => {
|
|
27
|
+
const peer1 = testBuilder.createPeer();
|
|
28
|
+
const peer2 = testBuilder.createPeer();
|
|
29
|
+
await openAndCloseAfterTest([peer1, peer2]);
|
|
30
|
+
|
|
31
|
+
const topic = PublicKey.random();
|
|
32
|
+
const [swarm1, swarm2] = await joinSwarm([peer1, peer2], topic, () => new FullyConnectedTopology());
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
peer1,
|
|
36
|
+
peer2,
|
|
37
|
+
topic,
|
|
38
|
+
swarm1,
|
|
39
|
+
swarm2,
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const message = randomBytes(PACKET_SIZE / 2).toString('hex');
|
|
45
|
+
|
|
46
|
+
for (let i = 0; i < NUM_ROUNDS; i++) {
|
|
47
|
+
// console.log(`Round ${i}/${NUM_ROUNDS}`);
|
|
56
48
|
await Promise.all(
|
|
57
|
-
pairs.map(async ({
|
|
58
|
-
await
|
|
49
|
+
pairs.map(async ({ swarm1, swarm2 }) => {
|
|
50
|
+
await exchangeMessages(swarm1, swarm2, message);
|
|
59
51
|
}),
|
|
60
52
|
);
|
|
61
|
-
}
|
|
62
|
-
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await Promise.all(
|
|
56
|
+
pairs.map(async ({ peer1, peer2, topic }) => {
|
|
57
|
+
await leaveSwarm([peer1, peer2], topic);
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
});
|
|
63
61
|
});
|