@libp2p/interface-compliance-tests 6.5.0 → 7.0.0-55b7e5fea
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/src/connection-encryption/index.d.ts.map +1 -1
- package/dist/src/connection-encryption/index.js +24 -15
- package/dist/src/connection-encryption/index.js.map +1 -1
- package/dist/src/stream-muxer/base-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/base-test.js +62 -345
- package/dist/src/stream-muxer/base-test.js.map +1 -1
- package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/close-test.js +254 -320
- package/dist/src/stream-muxer/close-test.js.map +1 -1
- package/dist/src/stream-muxer/index.js +2 -2
- package/dist/src/stream-muxer/index.js.map +1 -1
- package/dist/src/stream-muxer/{mega-stress-test.d.ts → stream-test.d.ts} +2 -2
- package/dist/src/stream-muxer/stream-test.d.ts.map +1 -0
- package/dist/src/stream-muxer/stream-test.js +290 -0
- package/dist/src/stream-muxer/stream-test.js.map +1 -0
- package/dist/src/stream-muxer/stress-test.d.ts.map +1 -1
- package/dist/src/stream-muxer/stress-test.js +70 -16
- package/dist/src/stream-muxer/stress-test.js.map +1 -1
- package/dist/src/transport/index.d.ts.map +1 -1
- package/dist/src/transport/index.js +235 -205
- package/dist/src/transport/index.js.map +1 -1
- package/dist/src/transport/utils.d.ts.map +1 -1
- package/dist/src/transport/utils.js +3 -2
- package/dist/src/transport/utils.js.map +1 -1
- package/package.json +25 -53
- package/src/connection-encryption/index.ts +27 -20
- package/src/stream-muxer/base-test.ts +75 -413
- package/src/stream-muxer/close-test.ts +305 -343
- package/src/stream-muxer/index.ts +2 -2
- package/src/stream-muxer/stream-test.ts +381 -0
- package/src/stream-muxer/stress-test.ts +92 -18
- package/src/transport/index.ts +281 -241
- package/src/transport/utils.ts +3 -2
- package/dist/src/connection-encryption/utils/index.d.ts +0 -3
- package/dist/src/connection-encryption/utils/index.d.ts.map +0 -1
- package/dist/src/connection-encryption/utils/index.js +0 -21
- package/dist/src/connection-encryption/utils/index.js.map +0 -1
- package/dist/src/matchers.d.ts +0 -12
- package/dist/src/matchers.d.ts.map +0 -1
- package/dist/src/matchers.js +0 -14
- package/dist/src/matchers.js.map +0 -1
- package/dist/src/mocks/connection-manager.d.ts +0 -27
- package/dist/src/mocks/connection-manager.d.ts.map +0 -1
- package/dist/src/mocks/connection-manager.js +0 -147
- package/dist/src/mocks/connection-manager.js.map +0 -1
- package/dist/src/mocks/connection.d.ts +0 -41
- package/dist/src/mocks/connection.d.ts.map +0 -1
- package/dist/src/mocks/connection.js +0 -236
- package/dist/src/mocks/connection.js.map +0 -1
- package/dist/src/mocks/duplex.d.ts +0 -4
- package/dist/src/mocks/duplex.d.ts.map +0 -1
- package/dist/src/mocks/duplex.js +0 -9
- package/dist/src/mocks/duplex.js.map +0 -1
- package/dist/src/mocks/index.d.ts +0 -12
- package/dist/src/mocks/index.d.ts.map +0 -1
- package/dist/src/mocks/index.js +0 -8
- package/dist/src/mocks/index.js.map +0 -1
- package/dist/src/mocks/multiaddr-connection.d.ts +0 -17
- package/dist/src/mocks/multiaddr-connection.d.ts.map +0 -1
- package/dist/src/mocks/multiaddr-connection.js +0 -64
- package/dist/src/mocks/multiaddr-connection.js.map +0 -1
- package/dist/src/mocks/muxer.d.ts +0 -36
- package/dist/src/mocks/muxer.d.ts.map +0 -1
- package/dist/src/mocks/muxer.js +0 -234
- package/dist/src/mocks/muxer.js.map +0 -1
- package/dist/src/mocks/registrar.d.ts +0 -16
- package/dist/src/mocks/registrar.d.ts.map +0 -1
- package/dist/src/mocks/registrar.js +0 -66
- package/dist/src/mocks/registrar.js.map +0 -1
- package/dist/src/mocks/upgrader.d.ts +0 -9
- package/dist/src/mocks/upgrader.d.ts.map +0 -1
- package/dist/src/mocks/upgrader.js +0 -46
- package/dist/src/mocks/upgrader.js.map +0 -1
- package/dist/src/pubsub/api.d.ts +0 -6
- package/dist/src/pubsub/api.d.ts.map +0 -1
- package/dist/src/pubsub/api.js +0 -88
- package/dist/src/pubsub/api.js.map +0 -1
- package/dist/src/pubsub/connection-handlers.d.ts +0 -6
- package/dist/src/pubsub/connection-handlers.d.ts.map +0 -1
- package/dist/src/pubsub/connection-handlers.js +0 -329
- package/dist/src/pubsub/connection-handlers.js.map +0 -1
- package/dist/src/pubsub/emit-self.d.ts +0 -6
- package/dist/src/pubsub/emit-self.d.ts.map +0 -1
- package/dist/src/pubsub/emit-self.js +0 -80
- package/dist/src/pubsub/emit-self.js.map +0 -1
- package/dist/src/pubsub/index.d.ts +0 -18
- package/dist/src/pubsub/index.d.ts.map +0 -1
- package/dist/src/pubsub/index.js +0 -17
- package/dist/src/pubsub/index.js.map +0 -1
- package/dist/src/pubsub/messages.d.ts +0 -6
- package/dist/src/pubsub/messages.d.ts.map +0 -1
- package/dist/src/pubsub/messages.js +0 -48
- package/dist/src/pubsub/messages.js.map +0 -1
- package/dist/src/pubsub/multiple-nodes.d.ts +0 -6
- package/dist/src/pubsub/multiple-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/multiple-nodes.js +0 -350
- package/dist/src/pubsub/multiple-nodes.js.map +0 -1
- package/dist/src/pubsub/two-nodes.d.ts +0 -6
- package/dist/src/pubsub/two-nodes.d.ts.map +0 -1
- package/dist/src/pubsub/two-nodes.js +0 -216
- package/dist/src/pubsub/two-nodes.js.map +0 -1
- package/dist/src/pubsub/utils.d.ts +0 -5
- package/dist/src/pubsub/utils.d.ts.map +0 -1
- package/dist/src/pubsub/utils.js +0 -27
- package/dist/src/pubsub/utils.js.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.d.ts.map +0 -1
- package/dist/src/stream-muxer/mega-stress-test.js +0 -11
- package/dist/src/stream-muxer/mega-stress-test.js.map +0 -1
- package/dist/src/stream-muxer/spawner.d.ts +0 -4
- package/dist/src/stream-muxer/spawner.d.ts.map +0 -1
- package/dist/src/stream-muxer/spawner.js +0 -39
- package/dist/src/stream-muxer/spawner.js.map +0 -1
- package/dist/typedoc-urls.json +0 -44
- package/src/connection-encryption/utils/index.ts +0 -27
- package/src/matchers.ts +0 -18
- package/src/mocks/connection-manager.ts +0 -216
- package/src/mocks/connection.ts +0 -309
- package/src/mocks/duplex.ts +0 -11
- package/src/mocks/index.ts +0 -11
- package/src/mocks/multiaddr-connection.ts +0 -80
- package/src/mocks/muxer.ts +0 -331
- package/src/mocks/registrar.ts +0 -86
- package/src/mocks/upgrader.ts +0 -65
- package/src/pubsub/api.ts +0 -116
- package/src/pubsub/connection-handlers.ts +0 -413
- package/src/pubsub/emit-self.ts +0 -99
- package/src/pubsub/index.ts +0 -34
- package/src/pubsub/messages.ts +0 -59
- package/src/pubsub/multiple-nodes.ts +0 -440
- package/src/pubsub/two-nodes.ts +0 -272
- package/src/pubsub/utils.ts +0 -34
- package/src/stream-muxer/mega-stress-test.ts +0 -14
- package/src/stream-muxer/spawner.ts +0 -57
|
@@ -1,458 +1,120 @@
|
|
|
1
|
+
import { multiaddrConnectionPair, byteStream } from '@libp2p/utils'
|
|
1
2
|
import { expect } from 'aegir/chai'
|
|
2
|
-
import
|
|
3
|
-
import { byteStream } from 'it-byte-stream'
|
|
4
|
-
import map from 'it-map'
|
|
5
|
-
import { duplexPair } from 'it-pair/duplex'
|
|
6
|
-
import { pipe } from 'it-pipe'
|
|
7
|
-
import defer from 'p-defer'
|
|
8
|
-
import { Uint8ArrayList } from 'uint8arraylist'
|
|
3
|
+
import { pEvent } from 'p-event'
|
|
9
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
11
|
-
import { isValidTick } from '../is-valid-tick.js'
|
|
12
5
|
import type { TestSetup } from '../index.js'
|
|
13
|
-
import type { Stream, StreamMuxerFactory } from '@libp2p/interface'
|
|
14
|
-
import type { Source } from 'it-stream-types'
|
|
15
|
-
import type { DeferredPromise } from 'p-defer'
|
|
6
|
+
import type { Stream, StreamMuxer, StreamMuxerFactory } from '@libp2p/interface'
|
|
16
7
|
|
|
17
8
|
export default (common: TestSetup<StreamMuxerFactory>): void => {
|
|
18
9
|
describe('base', () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
let dialer: StreamMuxer
|
|
11
|
+
let listener: StreamMuxer
|
|
12
|
+
|
|
13
|
+
beforeEach(async () => {
|
|
14
|
+
const [outboundConnection, inboundConnection] = multiaddrConnectionPair()
|
|
23
15
|
|
|
24
16
|
const dialerFactory = await common.setup()
|
|
25
|
-
|
|
26
|
-
direction: 'outbound'
|
|
27
|
-
})
|
|
17
|
+
dialer = dialerFactory.createStreamMuxer(outboundConnection)
|
|
28
18
|
|
|
29
19
|
const listenerFactory = await common.setup()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
onIncomingStream: (stream) => {
|
|
33
|
-
onStreamPromise.resolve(stream)
|
|
34
|
-
},
|
|
35
|
-
onStreamEnd: (stream) => {
|
|
36
|
-
onStreamEndPromise.resolve(stream)
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
void pipe(p[0], dialer, p[0])
|
|
41
|
-
void pipe(p[1], listener, p[1])
|
|
42
|
-
|
|
43
|
-
const dialerStream = await dialer.newStream()
|
|
44
|
-
expect(dialer.streams).to.include(dialerStream)
|
|
45
|
-
expect(isValidTick(dialerStream.timeline.open)).to.equal(true)
|
|
46
|
-
|
|
47
|
-
const dialerBytes = byteStream(dialerStream)
|
|
48
|
-
void dialerBytes.write(uint8ArrayFromString('hello'))
|
|
20
|
+
listener = listenerFactory.createStreamMuxer(inboundConnection)
|
|
21
|
+
})
|
|
49
22
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
23
|
+
afterEach(async () => {
|
|
24
|
+
await dialer?.close()
|
|
25
|
+
await listener?.close()
|
|
26
|
+
})
|
|
54
27
|
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
it('should have a protocol', async () => {
|
|
29
|
+
expect(dialer.protocol).to.be.a('string')
|
|
30
|
+
})
|
|
57
31
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
32
|
+
it('should be open', async () => {
|
|
33
|
+
expect(dialer.status).to.equal('open')
|
|
34
|
+
})
|
|
61
35
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
it('should be closing during closing', async () => {
|
|
37
|
+
const closePromise = dialer.close()
|
|
38
|
+
expect(dialer.status).to.equal('closing')
|
|
65
39
|
|
|
66
|
-
|
|
67
|
-
|
|
40
|
+
await closePromise
|
|
41
|
+
})
|
|
68
42
|
|
|
43
|
+
it('should be closed after closing', async () => {
|
|
69
44
|
await dialer.close()
|
|
70
|
-
await listener.close()
|
|
71
45
|
|
|
72
|
-
|
|
73
|
-
expect(dialer.streams).to.have.length(0)
|
|
74
|
-
expect(listener.streams).to.have.length(0)
|
|
46
|
+
expect(dialer.status).to.equal('closed')
|
|
75
47
|
})
|
|
76
48
|
|
|
77
|
-
it('should open a stream
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
onStreamPromise.resolve(stream)
|
|
86
|
-
},
|
|
87
|
-
onStreamEnd: (stream) => {
|
|
88
|
-
onStreamEndPromise.resolve(stream)
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const listenerFactory = await common.setup()
|
|
93
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
94
|
-
direction: 'inbound'
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
void pipe(p[0], dialer, p[0])
|
|
98
|
-
void pipe(p[1], listener, p[1])
|
|
49
|
+
it('should open a stream', async () => {
|
|
50
|
+
const [
|
|
51
|
+
listenerStream,
|
|
52
|
+
dialerStream
|
|
53
|
+
] = await Promise.all([
|
|
54
|
+
pEvent<'stream', CustomEvent<Stream>>(listener, 'stream').then(evt => evt.detail),
|
|
55
|
+
dialer.createStream()
|
|
56
|
+
])
|
|
99
57
|
|
|
100
|
-
const
|
|
58
|
+
const dialerBytes = byteStream(dialerStream)
|
|
101
59
|
const listenerBytes = byteStream(listenerStream)
|
|
102
|
-
void listenerBytes.write(uint8ArrayFromString('hello'))
|
|
103
|
-
|
|
104
|
-
const dialerStream = await onStreamPromise.promise
|
|
105
60
|
|
|
106
|
-
|
|
107
|
-
expect(listener.streams).to.include(listenerStream)
|
|
108
|
-
expect(isValidTick(listenerStream.timeline.open)).to.equal(true)
|
|
61
|
+
const input = uint8ArrayFromString('hello')
|
|
109
62
|
|
|
110
|
-
await
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const endedStream = await onStreamEndPromise.promise
|
|
115
|
-
expect(dialer.streams).to.not.include(endedStream)
|
|
116
|
-
|
|
117
|
-
if (endedStream.timeline.close == null) {
|
|
118
|
-
throw new Error('timeline had no close time')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Make sure the stream is removed from tracking
|
|
122
|
-
expect(isValidTick(endedStream.timeline.close)).to.equal(true)
|
|
63
|
+
const [, output] = await Promise.all([
|
|
64
|
+
dialerBytes.write(input),
|
|
65
|
+
listenerBytes.read()
|
|
66
|
+
])
|
|
123
67
|
|
|
124
|
-
|
|
125
|
-
await listener.close()
|
|
68
|
+
expect(output?.subarray()).to.equalBytes(input.subarray())
|
|
126
69
|
})
|
|
127
70
|
|
|
128
71
|
it('should open a stream on both sides', async () => {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const dialerFactory = await common.setup()
|
|
133
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
134
|
-
direction: 'outbound',
|
|
135
|
-
onIncomingStream: (stream) => {
|
|
136
|
-
onDialerStreamPromise.resolve(stream)
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
const listenerFactory = await common.setup()
|
|
141
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
142
|
-
direction: 'inbound',
|
|
143
|
-
onIncomingStream: (stream) => {
|
|
144
|
-
onListenerStreamPromise.resolve(stream)
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
void pipe(p[0], dialer, p[0])
|
|
149
|
-
void pipe(p[1], listener, p[1])
|
|
72
|
+
const [
|
|
73
|
+
listenerInboundStream,
|
|
74
|
+
dialerOutboundStream,
|
|
150
75
|
|
|
151
|
-
|
|
152
|
-
|
|
76
|
+
dialerInboundStream,
|
|
77
|
+
listenerOutboundStream
|
|
78
|
+
] = await Promise.all([
|
|
79
|
+
pEvent<'stream', CustomEvent<Stream>>(listener, 'stream').then(evt => evt.detail),
|
|
80
|
+
dialer.createStream(),
|
|
153
81
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
listenerInitiatorStream.close(),
|
|
157
|
-
onDialerStreamPromise.promise.then(async stream => { await stream.close() }),
|
|
158
|
-
onListenerStreamPromise.promise.then(async stream => { await stream.close() })
|
|
82
|
+
pEvent<'stream', CustomEvent<Stream>>(dialer, 'stream').then(evt => evt.detail),
|
|
83
|
+
listener.createStream()
|
|
159
84
|
])
|
|
160
85
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
listener.close()
|
|
164
|
-
])
|
|
165
|
-
})
|
|
86
|
+
const dialerOutboundBytes = byteStream(dialerOutboundStream)
|
|
87
|
+
const listenerInboundBytes = byteStream(listenerInboundStream)
|
|
166
88
|
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
170
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
171
|
-
const onListenerStreamPromise: DeferredPromise<Stream> = defer()
|
|
172
|
-
const dialerFactory = await common.setup()
|
|
173
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
174
|
-
direction: 'outbound',
|
|
175
|
-
onIncomingStream: (stream) => {
|
|
176
|
-
onDialerStreamPromise.resolve(stream)
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
const listenerFactory = await common.setup()
|
|
180
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
181
|
-
direction: 'inbound',
|
|
182
|
-
onIncomingStream: (stream) => {
|
|
183
|
-
onListenerStreamPromise.resolve(stream)
|
|
184
|
-
}
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
void pipe(p[0], dialer, p[0])
|
|
188
|
-
void pipe(p[1], listener, p[1])
|
|
89
|
+
const listenerOutboundBytes = byteStream(listenerOutboundStream)
|
|
90
|
+
const dialerInboundBytes = byteStream(dialerInboundStream)
|
|
189
91
|
|
|
190
|
-
const
|
|
191
|
-
const
|
|
92
|
+
const inputA = uint8ArrayFromString('hello')
|
|
93
|
+
const inputB = uint8ArrayFromString('world')
|
|
192
94
|
|
|
193
|
-
|
|
194
|
-
|
|
95
|
+
const [, outputA] = await Promise.all([
|
|
96
|
+
dialerOutboundBytes.write(inputA),
|
|
97
|
+
listenerInboundBytes.read(),
|
|
195
98
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
listenerStream
|
|
199
|
-
] = await Promise.all([
|
|
200
|
-
onDialerStreamPromise.promise,
|
|
201
|
-
onListenerStreamPromise.promise
|
|
99
|
+
listenerOutboundBytes.write(inputB),
|
|
100
|
+
dialerInboundBytes.read()
|
|
202
101
|
])
|
|
203
102
|
|
|
103
|
+
expect(outputA?.subarray()).to.equalBytes(inputA.subarray())
|
|
104
|
+
expect(inputB?.subarray()).to.equalBytes(inputB.subarray())
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('should store a stream in the streams list', async () => {
|
|
204
108
|
const [
|
|
205
|
-
|
|
206
|
-
|
|
109
|
+
listenerStream,
|
|
110
|
+
dialerStream
|
|
207
111
|
] = await Promise.all([
|
|
208
|
-
|
|
209
|
-
|
|
112
|
+
pEvent<'stream', CustomEvent<Stream>>(listener, 'stream').then(evt => evt.detail),
|
|
113
|
+
dialer.createStream()
|
|
210
114
|
])
|
|
211
115
|
|
|
212
|
-
expect(
|
|
213
|
-
expect(
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
it('should echo a small value via a pipe', async () => {
|
|
217
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
218
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
219
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
220
|
-
const dialerFactory = await common.setup()
|
|
221
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
222
|
-
direction: 'outbound',
|
|
223
|
-
onIncomingStream: (stream) => {
|
|
224
|
-
onDialerStreamPromise.resolve(stream)
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
const listenerFactory = await common.setup()
|
|
228
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
229
|
-
direction: 'inbound',
|
|
230
|
-
onIncomingStream: (stream) => {
|
|
231
|
-
void Promise.resolve().then(async () => {
|
|
232
|
-
const output = new Uint8ArrayList()
|
|
233
|
-
|
|
234
|
-
for await (const buf of stream.source) {
|
|
235
|
-
output.append(buf)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
239
|
-
})
|
|
240
|
-
}
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
void pipe(p[0], dialer, p[0])
|
|
244
|
-
void pipe(p[1], listener, p[1])
|
|
245
|
-
|
|
246
|
-
const stream = await dialer.newStream()
|
|
247
|
-
const input = Uint8Array.from([0, 1, 2, 3, 4])
|
|
248
|
-
|
|
249
|
-
await pipe(
|
|
250
|
-
[input],
|
|
251
|
-
stream
|
|
252
|
-
)
|
|
253
|
-
await stream.close()
|
|
254
|
-
|
|
255
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
it('should echo a large value via a pipe', async () => {
|
|
259
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
260
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
261
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
262
|
-
const dialerFactory = await common.setup()
|
|
263
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
264
|
-
direction: 'outbound',
|
|
265
|
-
onIncomingStream: (stream) => {
|
|
266
|
-
onDialerStreamPromise.resolve(stream)
|
|
267
|
-
}
|
|
268
|
-
})
|
|
269
|
-
const listenerFactory = await common.setup()
|
|
270
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
271
|
-
direction: 'inbound',
|
|
272
|
-
onIncomingStream: (stream) => {
|
|
273
|
-
void Promise.resolve().then(async () => {
|
|
274
|
-
const output = new Uint8ArrayList()
|
|
275
|
-
|
|
276
|
-
for await (const buf of stream.source) {
|
|
277
|
-
output.append(buf)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
void pipe(p[0], dialer, p[0])
|
|
286
|
-
void pipe(p[1], listener, p[1])
|
|
287
|
-
|
|
288
|
-
const stream = await dialer.newStream()
|
|
289
|
-
const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0))
|
|
290
|
-
|
|
291
|
-
await pipe(
|
|
292
|
-
[input],
|
|
293
|
-
stream
|
|
294
|
-
)
|
|
295
|
-
await stream.close()
|
|
296
|
-
|
|
297
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
it('should echo a small value via sink', async () => {
|
|
301
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
302
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
303
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
304
|
-
const dialerFactory = await common.setup()
|
|
305
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
306
|
-
direction: 'outbound',
|
|
307
|
-
onIncomingStream: (stream) => {
|
|
308
|
-
onDialerStreamPromise.resolve(stream)
|
|
309
|
-
}
|
|
310
|
-
})
|
|
311
|
-
const listenerFactory = await common.setup()
|
|
312
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
313
|
-
direction: 'inbound',
|
|
314
|
-
onIncomingStream: (stream) => {
|
|
315
|
-
void Promise.resolve().then(async () => {
|
|
316
|
-
const output = new Uint8ArrayList()
|
|
317
|
-
|
|
318
|
-
for await (const buf of stream.source) {
|
|
319
|
-
output.append(buf)
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
323
|
-
})
|
|
324
|
-
}
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
void pipe(p[0], dialer, p[0])
|
|
328
|
-
void pipe(p[1], listener, p[1])
|
|
329
|
-
|
|
330
|
-
const stream = await dialer.newStream()
|
|
331
|
-
const input = Uint8Array.from([0, 1, 2, 3, 4])
|
|
332
|
-
|
|
333
|
-
await stream.sink([input])
|
|
334
|
-
await stream.close()
|
|
335
|
-
|
|
336
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
it('should echo a large value via sink', async () => {
|
|
340
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
341
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
342
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
343
|
-
const dialerFactory = await common.setup()
|
|
344
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
345
|
-
direction: 'outbound',
|
|
346
|
-
onIncomingStream: (stream) => {
|
|
347
|
-
onDialerStreamPromise.resolve(stream)
|
|
348
|
-
}
|
|
349
|
-
})
|
|
350
|
-
const listenerFactory = await common.setup()
|
|
351
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
352
|
-
direction: 'inbound',
|
|
353
|
-
onIncomingStream: (stream) => {
|
|
354
|
-
void Promise.resolve().then(async () => {
|
|
355
|
-
const output = new Uint8ArrayList()
|
|
356
|
-
|
|
357
|
-
for await (const buf of stream.source) {
|
|
358
|
-
output.append(buf)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
362
|
-
})
|
|
363
|
-
}
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
void pipe(p[0], dialer, p[0])
|
|
367
|
-
void pipe(p[1], listener, p[1])
|
|
368
|
-
|
|
369
|
-
const stream = await dialer.newStream()
|
|
370
|
-
const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0))
|
|
371
|
-
|
|
372
|
-
await stream.sink([input])
|
|
373
|
-
await stream.close()
|
|
374
|
-
|
|
375
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
it('should echo a small value via a pushable', async () => {
|
|
379
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
380
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
381
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
382
|
-
const dialerFactory = await common.setup()
|
|
383
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
384
|
-
direction: 'outbound',
|
|
385
|
-
onIncomingStream: (stream) => {
|
|
386
|
-
onDialerStreamPromise.resolve(stream)
|
|
387
|
-
}
|
|
388
|
-
})
|
|
389
|
-
const listenerFactory = await common.setup()
|
|
390
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
391
|
-
direction: 'inbound',
|
|
392
|
-
onIncomingStream: (stream) => {
|
|
393
|
-
void Promise.resolve().then(async () => {
|
|
394
|
-
const output = new Uint8ArrayList()
|
|
395
|
-
|
|
396
|
-
for await (const buf of stream.source) {
|
|
397
|
-
output.append(buf)
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
401
|
-
})
|
|
402
|
-
}
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
void pipe(p[0], dialer, p[0])
|
|
406
|
-
void pipe(p[1], listener, p[1])
|
|
407
|
-
|
|
408
|
-
const stream = await dialer.newStream()
|
|
409
|
-
const input = Uint8Array.from([0, 1, 2, 3, 4])
|
|
410
|
-
|
|
411
|
-
const pushable = byteStream(stream)
|
|
412
|
-
await pushable.write(input)
|
|
413
|
-
await pushable.unwrap().close()
|
|
414
|
-
|
|
415
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
it('should echo a large value via a pushable', async () => {
|
|
419
|
-
const p = duplexPair<Uint8Array | Uint8ArrayList>()
|
|
420
|
-
const onDialerStreamPromise: DeferredPromise<Stream> = defer()
|
|
421
|
-
const onDataReceivedPromise: DeferredPromise<Uint8Array> = defer()
|
|
422
|
-
const dialerFactory = await common.setup()
|
|
423
|
-
const dialer = dialerFactory.createStreamMuxer({
|
|
424
|
-
direction: 'outbound',
|
|
425
|
-
onIncomingStream: (stream) => {
|
|
426
|
-
onDialerStreamPromise.resolve(stream)
|
|
427
|
-
}
|
|
428
|
-
})
|
|
429
|
-
const listenerFactory = await common.setup()
|
|
430
|
-
const listener = listenerFactory.createStreamMuxer({
|
|
431
|
-
direction: 'inbound',
|
|
432
|
-
onIncomingStream: (stream) => {
|
|
433
|
-
void Promise.resolve().then(async () => {
|
|
434
|
-
const output = new Uint8ArrayList()
|
|
435
|
-
|
|
436
|
-
for await (const buf of stream.source) {
|
|
437
|
-
output.append(buf)
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
onDataReceivedPromise.resolve(output.subarray())
|
|
441
|
-
})
|
|
442
|
-
}
|
|
443
|
-
})
|
|
444
|
-
|
|
445
|
-
void pipe(p[0], dialer, p[0])
|
|
446
|
-
void pipe(p[1], listener, p[1])
|
|
447
|
-
|
|
448
|
-
const stream = await dialer.newStream()
|
|
449
|
-
const input = Uint8Array.from(new Array(1024 * 1024 * 10).fill(0))
|
|
450
|
-
|
|
451
|
-
const pushable = byteStream(stream)
|
|
452
|
-
await pushable.write(input)
|
|
453
|
-
await pushable.unwrap().close()
|
|
454
|
-
|
|
455
|
-
expect(await onDataReceivedPromise.promise).to.equalBytes(input)
|
|
116
|
+
expect(dialer.streams).to.include(dialerStream, 'dialer did not store outbound stream')
|
|
117
|
+
expect(listener.streams).to.include(listenerStream, 'listener did not store inbound stream')
|
|
456
118
|
})
|
|
457
119
|
})
|
|
458
120
|
}
|