@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
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import * as fc from 'fast-check';
|
|
6
6
|
import { type ModelRunSetup } from 'fast-check';
|
|
7
|
-
import
|
|
7
|
+
import { test } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { todo } from '@dxos/debug';
|
|
10
10
|
import { PublicKey } from '@dxos/keys';
|
|
11
|
-
import { test } from '@dxos/test';
|
|
12
11
|
import { ComplexMap, ComplexSet, range } from '@dxos/util';
|
|
13
12
|
|
|
14
13
|
import { type SwarmNetworkManager } from '../network-manager';
|
|
@@ -37,29 +36,29 @@ export const propertyTestSuite = () => {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
const assertState = async (model: Model, real: Real) => {
|
|
40
|
-
await waitForExpect(() => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
39
|
+
// await waitForExpect(() => {
|
|
40
|
+
for (const peer of real.peers.values()) {
|
|
41
|
+
if (peer.presence) {
|
|
42
|
+
for (const expectedPeerId of model.joinedPeers) {
|
|
43
|
+
if (expectedPeerId.equals(peer.presence.peerId)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const actuallyConnectedPeers = peer.presence!.peers;
|
|
48
|
+
if (!actuallyConnectedPeers.some((peer: any) => PublicKey.equals(expectedPeerId, peer))) {
|
|
49
|
+
// TODO(burdon): More concise error.
|
|
50
|
+
const context = {
|
|
51
|
+
peerId: peer.presence.peerId,
|
|
52
|
+
expectedPeerId: expectedPeerId.truncate(),
|
|
53
|
+
connectedPeerIds: actuallyConnectedPeers.map((key: any) => key.toString('hex')),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
throw new Error(`Expected peer to be in the list of joined peers: ${context}`);
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
|
-
}
|
|
60
|
+
}
|
|
61
|
+
// }, 5_000);
|
|
63
62
|
|
|
64
63
|
real.peers.forEach((peer) =>
|
|
65
64
|
peer.networkManager.topics.forEach((topic) => {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2021 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { randomBytes } from 'node:crypto';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { PublicKey } from '@dxos/keys';
|
|
9
|
+
import { range } from '@dxos/util';
|
|
10
|
+
|
|
11
|
+
import { basicTestSuite } from './basic-test-suite';
|
|
12
|
+
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
13
|
+
import { TestBuilder } from '../testing';
|
|
14
|
+
import { FullyConnectedTopology } from '../topology';
|
|
15
|
+
import { TransportKind } from '../transport';
|
|
16
|
+
|
|
17
|
+
describe('Tcp transport', () => {
|
|
18
|
+
const testBuilder = new TestBuilder({
|
|
19
|
+
transport: TransportKind.TCP,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
basicTestSuite(testBuilder);
|
|
23
|
+
|
|
24
|
+
test.skip('load', { timeout: 1_000_000 }, async () => {
|
|
25
|
+
const NUM_PAIRS = 100;
|
|
26
|
+
const NUM_ROUNDS = 10_000;
|
|
27
|
+
const PACKET_SIZE = 1_000;
|
|
28
|
+
|
|
29
|
+
const pairs = await Promise.all(
|
|
30
|
+
range(NUM_PAIRS).map(async () => {
|
|
31
|
+
const peer1 = testBuilder.createPeer();
|
|
32
|
+
const peer2 = testBuilder.createPeer();
|
|
33
|
+
await openAndCloseAfterTest([peer1, peer2]);
|
|
34
|
+
|
|
35
|
+
const topic = PublicKey.random();
|
|
36
|
+
const [swarm1, swarm2] = await joinSwarm([peer1, peer2], topic, () => new FullyConnectedTopology());
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
peer1,
|
|
40
|
+
peer2,
|
|
41
|
+
topic,
|
|
42
|
+
swarm1,
|
|
43
|
+
swarm2,
|
|
44
|
+
};
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const message = randomBytes(PACKET_SIZE / 2).toString('hex');
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < NUM_ROUNDS; i++) {
|
|
51
|
+
// console.log(`Round ${i}/${NUM_ROUNDS}`);
|
|
52
|
+
await Promise.all(
|
|
53
|
+
pairs.map(async ({ swarm1, swarm2 }) => {
|
|
54
|
+
await exchangeMessages(swarm1, swarm2, message);
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await Promise.all(
|
|
60
|
+
pairs.map(async ({ peer1, peer2, topic }) => {
|
|
61
|
+
await leaveSwarm([peer1, peer2], topic);
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
});
|
package/src/tests/utils.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { onTestFinished } from 'vitest';
|
|
6
|
+
|
|
5
7
|
import { asyncTimeout } from '@dxos/async';
|
|
6
8
|
import { type PublicKey } from '@dxos/keys';
|
|
7
|
-
import { afterTest } from '@dxos/test';
|
|
8
9
|
import { type Provider } from '@dxos/util';
|
|
9
10
|
|
|
10
11
|
import { type TestPeer, type TestSwarmConnection } from '../testing';
|
|
@@ -19,7 +20,7 @@ import { type Topology } from '../topology';
|
|
|
19
20
|
*/
|
|
20
21
|
export const openAndCloseAfterTest = async (peers: TestPeer[]) => {
|
|
21
22
|
await Promise.all(peers.map((peer) => peer.open()));
|
|
22
|
-
|
|
23
|
+
onTestFinished(async () => {
|
|
23
24
|
await asyncTimeout(Promise.all(peers.map((peer) => peer.close())), 1_000);
|
|
24
25
|
});
|
|
25
26
|
};
|
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe } from '
|
|
5
|
+
import { describe } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { basicTestSuite } from './basic-test-suite';
|
|
8
8
|
import { TEST_SIGNAL_HOSTS, TestBuilder } from '../testing';
|
|
9
9
|
|
|
10
|
-
describe('WebRTC transport', () => {
|
|
10
|
+
describe('WebRTC transport', { timeout: 10_000 }, () => {
|
|
11
11
|
const testBuilder = new TestBuilder();
|
|
12
12
|
basicTestSuite(testBuilder);
|
|
13
|
-
})
|
|
13
|
+
});
|
|
14
14
|
|
|
15
|
-
describe('WebRTC transport proxy', () => {
|
|
15
|
+
describe('WebRTC transport proxy', { timeout: 10_000 }, () => {
|
|
16
16
|
const testBuilder = new TestBuilder({ bridge: true });
|
|
17
17
|
basicTestSuite(testBuilder);
|
|
18
|
-
})
|
|
18
|
+
});
|
|
19
19
|
|
|
20
20
|
describe('test with signal server', () => {
|
|
21
|
-
describe('WebRTC transport', () => {
|
|
21
|
+
describe('WebRTC transport', { timeout: 10_000 }, () => {
|
|
22
22
|
const testBuilder = new TestBuilder({ signalHosts: TEST_SIGNAL_HOSTS });
|
|
23
23
|
basicTestSuite(testBuilder);
|
|
24
|
-
})
|
|
24
|
+
});
|
|
25
25
|
|
|
26
|
-
describe('WebRTC transport proxy', () => {
|
|
26
|
+
describe('WebRTC transport proxy', { timeout: 10_000 }, () => {
|
|
27
27
|
const testBuilder = new TestBuilder({ signalHosts: TEST_SIGNAL_HOSTS, bridge: true });
|
|
28
28
|
basicTestSuite(testBuilder);
|
|
29
|
-
})
|
|
29
|
+
});
|
|
30
30
|
});
|
package/src/transport/{libdatachannel-transport.test.ts → libdatachannel-transport.node.test.ts}
RENAMED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Duplex } from 'stream';
|
|
5
|
+
import { Duplex } from 'node:stream';
|
|
6
|
+
import { onTestFinished, describe, test } from 'vitest';
|
|
6
7
|
|
|
7
8
|
import { sleep, TestStream } from '@dxos/async';
|
|
8
9
|
import { log } from '@dxos/log';
|
|
9
|
-
import { afterTest, describe, test } from '@dxos/test';
|
|
10
10
|
|
|
11
11
|
import { LibDataChannelTransport } from './libdatachannel-transport';
|
|
12
12
|
import { SimplePeerTransport } from './simplepeer-transport';
|
|
13
13
|
|
|
14
14
|
describe('LibDataChannelTransport', () => {
|
|
15
|
-
test('open and close', async () => {
|
|
15
|
+
test('open and close', { timeout: 1_000 }, async () => {
|
|
16
16
|
const connection = new LibDataChannelTransport({
|
|
17
17
|
initiator: true,
|
|
18
18
|
stream: new Duplex(),
|
|
@@ -23,12 +23,9 @@ describe('LibDataChannelTransport', () => {
|
|
|
23
23
|
const wait = connection.closed.waitForCount(1);
|
|
24
24
|
await connection.close();
|
|
25
25
|
await wait;
|
|
26
|
-
})
|
|
27
|
-
.onlyEnvironments('nodejs')
|
|
28
|
-
.timeout(1_000)
|
|
29
|
-
.retries(3);
|
|
26
|
+
});
|
|
30
27
|
|
|
31
|
-
test('establish connection and send data through with protocol', async () => {
|
|
28
|
+
test('establish connection and send data through with protocol', { timeout: 2_000 }, async () => {
|
|
32
29
|
const stream1 = new TestStream();
|
|
33
30
|
const connection1 = new LibDataChannelTransport({
|
|
34
31
|
initiator: true,
|
|
@@ -39,8 +36,8 @@ describe('LibDataChannelTransport', () => {
|
|
|
39
36
|
},
|
|
40
37
|
});
|
|
41
38
|
await connection1.open();
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
onTestFinished(() => connection1.close());
|
|
40
|
+
onTestFinished(() => connection1.errors.assertNoUnhandledErrors());
|
|
44
41
|
|
|
45
42
|
const stream2 = new TestStream();
|
|
46
43
|
const connection2 = new LibDataChannelTransport({
|
|
@@ -52,16 +49,13 @@ describe('LibDataChannelTransport', () => {
|
|
|
52
49
|
},
|
|
53
50
|
});
|
|
54
51
|
await connection2.open();
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
onTestFinished(() => connection2.close());
|
|
53
|
+
onTestFinished(() => connection2.errors.assertNoUnhandledErrors());
|
|
57
54
|
|
|
58
55
|
await TestStream.assertConnectivity(stream1, stream2, { timeout: 2_000 });
|
|
59
|
-
})
|
|
60
|
-
.onlyEnvironments('nodejs')
|
|
61
|
-
.timeout(2_000)
|
|
62
|
-
.retries(3);
|
|
56
|
+
});
|
|
63
57
|
|
|
64
|
-
test('establish connection between LibDataChannel and SimplePeer', async () => {
|
|
58
|
+
test('establish connection between LibDataChannel and SimplePeer', { timeout: 2_000 }, async () => {
|
|
65
59
|
const stream1 = new TestStream();
|
|
66
60
|
const connection1 = new LibDataChannelTransport({
|
|
67
61
|
initiator: true,
|
|
@@ -74,8 +68,8 @@ describe('LibDataChannelTransport', () => {
|
|
|
74
68
|
},
|
|
75
69
|
});
|
|
76
70
|
await connection1.open();
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
onTestFinished(() => connection1.close());
|
|
72
|
+
onTestFinished(() => connection1.errors.assertNoUnhandledErrors());
|
|
79
73
|
|
|
80
74
|
const stream2 = new TestStream();
|
|
81
75
|
const connection2 = new SimplePeerTransport({
|
|
@@ -89,12 +83,9 @@ describe('LibDataChannelTransport', () => {
|
|
|
89
83
|
},
|
|
90
84
|
});
|
|
91
85
|
await connection2.open();
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
onTestFinished(() => connection2.close());
|
|
87
|
+
onTestFinished(() => connection2.errors.assertNoUnhandledErrors());
|
|
94
88
|
|
|
95
89
|
await TestStream.assertConnectivity(stream1, stream2, { timeout: 2_000 });
|
|
96
|
-
})
|
|
97
|
-
.onlyEnvironments('nodejs')
|
|
98
|
-
.timeout(2_000)
|
|
99
|
-
.retries(3);
|
|
90
|
+
});
|
|
100
91
|
});
|
|
@@ -73,8 +73,7 @@ export class LibDataChannelTransport implements Transport {
|
|
|
73
73
|
|
|
74
74
|
// TODO(burdon): Move to factory?
|
|
75
75
|
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
76
|
-
const { RTCPeerConnection } =
|
|
77
|
-
.default as typeof import('node-datachannel/polyfill');
|
|
76
|
+
const { RTCPeerConnection } = await import('#node-datachannel/polyfill');
|
|
78
77
|
|
|
79
78
|
const providedIceServers = await this._options.iceProvider?.getIceServers();
|
|
80
79
|
|
|
@@ -174,7 +173,7 @@ export class LibDataChannelTransport implements Transport {
|
|
|
174
173
|
async close() {
|
|
175
174
|
await this._close();
|
|
176
175
|
if (--LibDataChannelTransport._instanceCount === 0) {
|
|
177
|
-
(await
|
|
176
|
+
(await import('#node-datachannel')).cleanup();
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
179
|
|
|
@@ -371,6 +370,3 @@ export class LibDataChannelTransport implements Transport {
|
|
|
371
370
|
this._options.stream.unpipe?.(this._stream)?.unpipe?.(this._options.stream);
|
|
372
371
|
}
|
|
373
372
|
}
|
|
374
|
-
|
|
375
|
-
// eslint-disable-next-line no-new-func
|
|
376
|
-
const importESM = Function('path', 'return import(path)');
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { onTestFinished, describe, test } from 'vitest';
|
|
6
|
+
|
|
5
7
|
import { TestStream } from '@dxos/async';
|
|
6
8
|
import { PublicKey } from '@dxos/keys';
|
|
7
|
-
import { afterTest, describe, test } from '@dxos/test';
|
|
8
9
|
import { range } from '@dxos/util';
|
|
9
10
|
|
|
10
11
|
import { MemoryTransport } from './memory-transport';
|
|
@@ -28,8 +29,8 @@ const createPair = async () => {
|
|
|
28
29
|
initiator: true,
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
onTestFinished(() => connection1.close());
|
|
33
|
+
onTestFinished(() => connection1.errors.assertNoUnhandledErrors());
|
|
33
34
|
|
|
34
35
|
const stream2 = new TestStream();
|
|
35
36
|
const connection2 = new MemoryTransport({
|
|
@@ -40,8 +41,8 @@ const createPair = async () => {
|
|
|
40
41
|
initiator: false,
|
|
41
42
|
});
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
onTestFinished(() => connection2.close());
|
|
45
|
+
onTestFinished(() => connection2.errors.assertNoUnhandledErrors());
|
|
45
46
|
|
|
46
47
|
await connection1.open();
|
|
47
48
|
await connection2.open();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import wrtc from '@koush/wrtc';
|
|
6
|
+
import SimplePeerConstructor from 'simple-peer';
|
|
7
|
+
import { describe, test } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { sleep } from '@dxos/async';
|
|
10
|
+
|
|
11
|
+
describe('Node WebRTC and simple-peer', () => {
|
|
12
|
+
// Simplest test that reproduces SIGABRT (mac) and SIGSEGV (linux) in wrtc.
|
|
13
|
+
test.skip('open and close', { timeout: 3_000 }, async () => {
|
|
14
|
+
const peer = new SimplePeerConstructor({
|
|
15
|
+
initiator: true,
|
|
16
|
+
wrtc,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await sleep(1);
|
|
20
|
+
await peer.destroy();
|
|
21
|
+
});
|
|
22
|
+
});
|
package/src/transport/{simplepeer-transport-proxy-test.ts → simplepeer-transport-proxy.node.test.ts}
RENAMED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { afterAll, onTestFinished, beforeAll, describe, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { TestStream } from '@dxos/async';
|
|
8
8
|
import { schema } from '@dxos/protocols/proto';
|
|
9
9
|
import { type BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
10
10
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
11
11
|
import { createLinkedPorts, createProtoRpcPeer, type ProtoRpcPeer } from '@dxos/rpc';
|
|
12
|
-
import { afterAll, afterTest, beforeAll, describe, test } from '@dxos/test';
|
|
13
12
|
|
|
14
13
|
import { SimplePeerTransportProxy } from './simplepeer-transport-proxy';
|
|
15
14
|
import { SimplePeerTransportService } from './simplepeer-transport-service';
|
|
@@ -43,7 +42,7 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
43
42
|
},
|
|
44
43
|
});
|
|
45
44
|
await rpcService.open();
|
|
46
|
-
|
|
45
|
+
onTestFinished(() => rpcService.close());
|
|
47
46
|
|
|
48
47
|
// Starting RPC client
|
|
49
48
|
const rpcClient = createProtoRpcPeer({
|
|
@@ -57,7 +56,7 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
57
56
|
},
|
|
58
57
|
});
|
|
59
58
|
await rpcClient.open();
|
|
60
|
-
|
|
59
|
+
onTestFinished(() => rpcClient.close());
|
|
61
60
|
|
|
62
61
|
const simplePeerTransportProxy = new SimplePeerTransportProxy({
|
|
63
62
|
initiator,
|
|
@@ -66,21 +65,21 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
66
65
|
bridgeService: rpcClient.rpc.BridgeService,
|
|
67
66
|
});
|
|
68
67
|
await simplePeerTransportProxy.open();
|
|
69
|
-
|
|
68
|
+
onTestFinished(async () => await simplePeerTransportProxy.close());
|
|
70
69
|
|
|
71
70
|
return { simplePeerService: rpcService, SimplePeerTransportProxy: simplePeerTransportProxy };
|
|
72
71
|
};
|
|
73
72
|
|
|
74
73
|
// This doesn't clean up correctly and crashes with SIGSEGV / SIGABRT at the end. Probably an issue with wrtc package.
|
|
75
|
-
test('open and close', async () => {
|
|
74
|
+
test('open and close', { timeout: 1_000 }, async () => {
|
|
76
75
|
const { SimplePeerTransportProxy: connection } = await setupProxy();
|
|
77
76
|
|
|
78
77
|
const wait = connection.closed.waitForCount(1);
|
|
79
78
|
await connection.close();
|
|
80
79
|
await wait;
|
|
81
|
-
})
|
|
80
|
+
});
|
|
82
81
|
|
|
83
|
-
test('establish connection and send data through with protocol', async () => {
|
|
82
|
+
test('establish connection and send data through with protocol', { timeout: 2_000 }, async () => {
|
|
84
83
|
const stream1 = new TestStream();
|
|
85
84
|
const { SimplePeerTransportProxy: connection1 } = await setupProxy({
|
|
86
85
|
initiator: true,
|
|
@@ -89,7 +88,7 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
89
88
|
await connection2.onSignal(signal);
|
|
90
89
|
},
|
|
91
90
|
});
|
|
92
|
-
|
|
91
|
+
onTestFinished(() => connection1.errors.assertNoUnhandledErrors());
|
|
93
92
|
|
|
94
93
|
const stream2 = new TestStream();
|
|
95
94
|
const { SimplePeerTransportProxy: connection2 } = await setupProxy({
|
|
@@ -99,10 +98,10 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
99
98
|
await connection1.onSignal(signal);
|
|
100
99
|
},
|
|
101
100
|
});
|
|
102
|
-
|
|
101
|
+
onTestFinished(() => connection2.errors.assertNoUnhandledErrors());
|
|
103
102
|
|
|
104
103
|
await TestStream.assertConnectivity(stream1, stream2);
|
|
105
|
-
})
|
|
104
|
+
});
|
|
106
105
|
|
|
107
106
|
describe('Multiplexing', () => {
|
|
108
107
|
let service: any;
|
|
@@ -143,7 +142,7 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
143
142
|
await rpcClient?.close();
|
|
144
143
|
});
|
|
145
144
|
|
|
146
|
-
test('establish connection and send data through with protocol', async () => {
|
|
145
|
+
test('establish connection and send data through with protocol', { timeout: 3_000 }, async () => {
|
|
147
146
|
const stream1 = new TestStream();
|
|
148
147
|
const proxy1 = new SimplePeerTransportProxy({
|
|
149
148
|
initiator: true,
|
|
@@ -153,7 +152,7 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
153
152
|
},
|
|
154
153
|
bridgeService: rpcClient.rpc.BridgeService,
|
|
155
154
|
});
|
|
156
|
-
|
|
155
|
+
onTestFinished(async () => {
|
|
157
156
|
proxy1.errors.assertNoUnhandledErrors();
|
|
158
157
|
await proxy1.close();
|
|
159
158
|
});
|
|
@@ -167,7 +166,7 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
167
166
|
},
|
|
168
167
|
bridgeService: rpcClient.rpc.BridgeService,
|
|
169
168
|
});
|
|
170
|
-
|
|
169
|
+
onTestFinished(async () => {
|
|
171
170
|
proxy2.errors.assertNoUnhandledErrors();
|
|
172
171
|
await proxy2.close();
|
|
173
172
|
});
|
|
@@ -176,6 +175,6 @@ describe('SimplePeerTransportProxy', () => {
|
|
|
176
175
|
await proxy2.open();
|
|
177
176
|
|
|
178
177
|
await TestStream.assertConnectivity(stream1, stream2);
|
|
179
|
-
})
|
|
178
|
+
});
|
|
180
179
|
});
|
|
181
180
|
});
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Duplex } from 'stream';
|
|
5
|
+
import { Duplex } from 'node:stream';
|
|
6
|
+
import { onTestFinished, describe, test } from 'vitest';
|
|
6
7
|
|
|
7
8
|
import { sleep, TestStream } from '@dxos/async';
|
|
8
|
-
import { afterTest, describe, test } from '@dxos/test';
|
|
9
9
|
|
|
10
10
|
import { SimplePeerTransport } from './simplepeer-transport';
|
|
11
11
|
|
|
12
12
|
describe('SimplePeerTransport', () => {
|
|
13
13
|
// This doesn't clean up correctly and crashes with SIGSEGV / SIGABRT at the end. Probably an issue with wrtc package.
|
|
14
|
-
test('open and close', async () => {
|
|
14
|
+
test('open and close', { timeout: 1_000 }, async () => {
|
|
15
15
|
const connection = new SimplePeerTransport({
|
|
16
16
|
initiator: true,
|
|
17
17
|
stream: new Duplex(),
|
|
@@ -22,11 +22,9 @@ describe('SimplePeerTransport', () => {
|
|
|
22
22
|
const wait = connection.closed.waitForCount(1);
|
|
23
23
|
await connection.close();
|
|
24
24
|
await wait;
|
|
25
|
-
})
|
|
26
|
-
.timeout(1_000)
|
|
27
|
-
.retries(3);
|
|
25
|
+
});
|
|
28
26
|
|
|
29
|
-
test('establish connection and send data through with protocol', async () => {
|
|
27
|
+
test('establish connection and send data through with protocol', { timeout: 2_000 }, async () => {
|
|
30
28
|
const stream1 = new TestStream();
|
|
31
29
|
const connection1 = new SimplePeerTransport({
|
|
32
30
|
initiator: true,
|
|
@@ -36,8 +34,8 @@ describe('SimplePeerTransport', () => {
|
|
|
36
34
|
await connection2.onSignal(signal);
|
|
37
35
|
},
|
|
38
36
|
});
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
onTestFinished(() => connection1.close());
|
|
38
|
+
onTestFinished(() => connection1.errors.assertNoUnhandledErrors());
|
|
41
39
|
|
|
42
40
|
const stream2 = new TestStream();
|
|
43
41
|
const connection2 = new SimplePeerTransport({
|
|
@@ -48,14 +46,12 @@ describe('SimplePeerTransport', () => {
|
|
|
48
46
|
await connection1.onSignal(signal);
|
|
49
47
|
},
|
|
50
48
|
});
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
onTestFinished(() => connection2.close());
|
|
50
|
+
onTestFinished(() => connection2.errors.assertNoUnhandledErrors());
|
|
53
51
|
|
|
54
52
|
await connection1.open();
|
|
55
53
|
await connection2.open();
|
|
56
54
|
|
|
57
55
|
await TestStream.assertConnectivity(stream1, stream2);
|
|
58
|
-
})
|
|
59
|
-
.timeout(2_000)
|
|
60
|
-
.retries(3);
|
|
56
|
+
});
|
|
61
57
|
});
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
//
|
|
5
5
|
|
|
6
6
|
import SimplePeerConstructor, { type Instance as SimplePeer } from 'simple-peer';
|
|
7
|
-
import invariant from 'tiny-invariant';
|
|
8
7
|
|
|
9
8
|
import { Event, synchronized } from '@dxos/async';
|
|
10
9
|
import { ErrorStream, raise } from '@dxos/debug';
|
|
10
|
+
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { ConnectionResetError, ConnectivityError, ProtocolError, UnknownProtocolError, trace } from '@dxos/protocols';
|
package/src/typings.d.ts
CHANGED
|
@@ -3,5 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
declare module '@koush/wrtc';
|
|
6
|
-
|
|
7
|
-
declare module '
|
|
6
|
+
|
|
7
|
+
declare module '#node-datachannel' {
|
|
8
|
+
export * from 'node-datachannel';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module '#node-datachannel/polyfill' {
|
|
12
|
+
export * from 'node-datachannel/polyfill';
|
|
13
|
+
}
|