Skip to content

Commit ec7d076

Browse files
committed
test: add pull-mplex to test suite
1 parent 59fe973 commit ec7d076

File tree

5 files changed

+123
-5
lines changed

5 files changed

+123
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"lodash.times": "^4.3.2",
8383
"nock": "^10.0.2",
8484
"pull-goodbye": "0.0.2",
85+
"pull-mplex": "~0.1.0",
8586
"pull-serializer": "~0.3.2",
8687
"pull-stream": "^3.6.9",
8788
"sinon": "^7.1.1",

test/stream-muxing.node.js

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ chai.use(require('dirty-chai'))
66
const expect = chai.expect
77
const parallel = require('async/parallel')
88
const series = require('async/series')
9+
const pMplex = require('pull-mplex')
910
const Mplex = require('libp2p-mplex')
1011
const SPDY = require('libp2p-spdy')
1112
const createNode = require('./utils/create-node')
@@ -99,6 +100,42 @@ describe('stream muxing', () => {
99100
], done)
100101
})
101102

103+
it('pMplex only', (done) => {
104+
let nodeA
105+
let nodeB
106+
107+
function setup (callback) {
108+
parallel([
109+
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
110+
modules: {
111+
streamMuxer: [ pMplex ]
112+
}
113+
}, (err, node) => {
114+
expect(err).to.not.exist()
115+
nodeA = node
116+
node.handle('/echo/1.0.0', echo)
117+
node.start(cb)
118+
}),
119+
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
120+
modules: {
121+
streamMuxer: [ pMplex ]
122+
}
123+
}, (err, node) => {
124+
expect(err).to.not.exist()
125+
nodeB = node
126+
node.handle('/echo/1.0.0', echo)
127+
node.start(cb)
128+
})
129+
], callback)
130+
}
131+
132+
series([
133+
(cb) => setup(cb),
134+
(cb) => test(nodeA, nodeB, cb),
135+
(cb) => teardown(nodeA, nodeB, cb)
136+
], done)
137+
})
138+
102139
it('spdy + mplex', function (done) {
103140
this.timeout(5000)
104141

@@ -137,7 +174,45 @@ describe('stream muxing', () => {
137174
], done)
138175
})
139176

140-
it('spdy + mplex switched order', function (done) {
177+
it('mplex + pull-mplex', function (done) {
178+
this.timeout(5000)
179+
180+
let nodeA
181+
let nodeB
182+
183+
function setup (callback) {
184+
parallel([
185+
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
186+
modules: {
187+
streamMuxer: [ Mplex ]
188+
}
189+
}, (err, node) => {
190+
expect(err).to.not.exist()
191+
nodeA = node
192+
node.handle('/echo/1.0.0', echo)
193+
node.start(cb)
194+
}),
195+
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
196+
modules: {
197+
streamMuxer: [ pMplex ]
198+
}
199+
}, (err, node) => {
200+
expect(err).to.not.exist()
201+
nodeB = node
202+
node.handle('/echo/1.0.0', echo)
203+
node.start(cb)
204+
})
205+
], callback)
206+
}
207+
208+
series([
209+
(cb) => setup(cb),
210+
(cb) => test(nodeA, nodeB, cb),
211+
(cb) => teardown(nodeA, nodeB, cb)
212+
], done)
213+
})
214+
215+
it('spdy + mplex in reverse muxer order', function (done) {
141216
this.timeout(5 * 1000)
142217

143218
let nodeA
@@ -175,6 +250,44 @@ describe('stream muxing', () => {
175250
], done)
176251
})
177252

253+
it('spdy + pull-mplex in reverse muxer order', function (done) {
254+
this.timeout(5 * 1000)
255+
256+
let nodeA
257+
let nodeB
258+
259+
function setup (callback) {
260+
parallel([
261+
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
262+
modules: {
263+
streamMuxer: [ SPDY, pMplex ]
264+
}
265+
}, (err, node) => {
266+
expect(err).to.not.exist()
267+
nodeA = node
268+
node.handle('/echo/1.0.0', echo)
269+
node.start(cb)
270+
}),
271+
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
272+
modules: {
273+
streamMuxer: [ pMplex, SPDY ]
274+
}
275+
}, (err, node) => {
276+
expect(err).to.not.exist()
277+
nodeB = node
278+
node.handle('/echo/1.0.0', echo)
279+
node.start(cb)
280+
})
281+
], callback)
282+
}
283+
284+
series([
285+
(cb) => setup(cb),
286+
(cb) => test(nodeA, nodeB, cb),
287+
(cb) => teardown(nodeA, nodeB, cb)
288+
], done)
289+
})
290+
178291
it('one without the other fails to establish a muxedConn', function (done) {
179292
this.timeout(5 * 1000)
180293

test/transports.browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ chai.use(require('dirty-chai'))
77
const expect = chai.expect
88
const PeerInfo = require('peer-info')
99
const PeerId = require('peer-id')
10-
const Mplex = require('libp2p-mplex')
10+
const Mplex = require('pull-mplex')
1111
const pull = require('pull-stream')
1212
const parallel = require('async/parallel')
1313
const goodbye = require('pull-goodbye')
@@ -57,7 +57,7 @@ describe('transports', () => {
5757
streamMuxer: [ Mplex ]
5858
}
5959
})
60-
expect(b._modules.streamMuxer).to.eql([require('libp2p-mplex')])
60+
expect(b._modules.streamMuxer).to.eql([require('pull-mplex')])
6161
done()
6262
})
6363
})

test/utils/bundle-browser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const WebSocketStar = require('libp2p-websocket-star')
66
const Bootstrap = require('libp2p-bootstrap')
77
const SPDY = require('libp2p-spdy')
88
const MPLEX = require('libp2p-mplex')
9+
const PULLMPLEX = require('pull-mplex')
910
const KadDHT = require('libp2p-kad-dht')
1011
const SECIO = require('libp2p-secio')
1112
const defaultsDeep = require('@nodeutils/defaults-deep')
@@ -17,6 +18,7 @@ function mapMuxers (list) {
1718
switch (pref.trim().toLowerCase()) {
1819
case 'spdy': return SPDY
1920
case 'mplex': return MPLEX
21+
case 'pullmplex': return PULLMPLEX
2022
default:
2123
throw new Error(pref + ' muxer not available')
2224
}
@@ -27,7 +29,7 @@ function getMuxers (options) {
2729
if (options) {
2830
return mapMuxers(options)
2931
} else {
30-
return [MPLEX, SPDY]
32+
return [PULLMPLEX, MPLEX, SPDY]
3133
}
3234
}
3335

test/utils/bundle-nodejs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Bootstrap = require('libp2p-bootstrap')
77
const SPDY = require('libp2p-spdy')
88
const KadDHT = require('libp2p-kad-dht')
99
const MPLEX = require('libp2p-mplex')
10+
const PULLMPLEX = require('pull-mplex')
1011
const SECIO = require('libp2p-secio')
1112
const defaultsDeep = require('@nodeutils/defaults-deep')
1213
const libp2p = require('../..')
@@ -17,6 +18,7 @@ function mapMuxers (list) {
1718
switch (pref.trim().toLowerCase()) {
1819
case 'spdy': return SPDY
1920
case 'mplex': return MPLEX
21+
case 'pullmplex': return PULLMPLEX
2022
default:
2123
throw new Error(pref + ' muxer not available')
2224
}
@@ -30,7 +32,7 @@ function getMuxers (muxers) {
3032
} else if (muxers) {
3133
return mapMuxers(muxers)
3234
} else {
33-
return [MPLEX, SPDY]
35+
return [PULLMPLEX, MPLEX, SPDY]
3436
}
3537
}
3638

0 commit comments

Comments
 (0)