test: add pull-mplex to test suite

This commit is contained in:
Jacob Heun 2019-02-15 13:26:40 +01:00
parent 59fe9732d7
commit ec7d0761de
5 changed files with 123 additions and 5 deletions

View File

@ -82,6 +82,7 @@
"lodash.times": "^4.3.2",
"nock": "^10.0.2",
"pull-goodbye": "0.0.2",
"pull-mplex": "~0.1.0",
"pull-serializer": "~0.3.2",
"pull-stream": "^3.6.9",
"sinon": "^7.1.1",

View File

@ -6,6 +6,7 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const parallel = require('async/parallel')
const series = require('async/series')
const pMplex = require('pull-mplex')
const Mplex = require('libp2p-mplex')
const SPDY = require('libp2p-spdy')
const createNode = require('./utils/create-node')
@ -99,6 +100,42 @@ describe('stream muxing', () => {
], done)
})
it('pMplex only', (done) => {
let nodeA
let nodeB
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
], callback)
}
series([
(cb) => setup(cb),
(cb) => test(nodeA, nodeB, cb),
(cb) => teardown(nodeA, nodeB, cb)
], done)
})
it('spdy + mplex', function (done) {
this.timeout(5000)
@ -137,7 +174,45 @@ describe('stream muxing', () => {
], done)
})
it('spdy + mplex switched order', function (done) {
it('mplex + pull-mplex', function (done) {
this.timeout(5000)
let nodeA
let nodeB
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ Mplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
], callback)
}
series([
(cb) => setup(cb),
(cb) => test(nodeA, nodeB, cb),
(cb) => teardown(nodeA, nodeB, cb)
], done)
})
it('spdy + mplex in reverse muxer order', function (done) {
this.timeout(5 * 1000)
let nodeA
@ -175,6 +250,44 @@ describe('stream muxing', () => {
], done)
})
it('spdy + pull-mplex in reverse muxer order', function (done) {
this.timeout(5 * 1000)
let nodeA
let nodeB
function setup (callback) {
parallel([
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ SPDY, pMplex ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeA = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
}),
(cb) => createNode('/ip4/0.0.0.0/tcp/0', {
modules: {
streamMuxer: [ pMplex, SPDY ]
}
}, (err, node) => {
expect(err).to.not.exist()
nodeB = node
node.handle('/echo/1.0.0', echo)
node.start(cb)
})
], callback)
}
series([
(cb) => setup(cb),
(cb) => test(nodeA, nodeB, cb),
(cb) => teardown(nodeA, nodeB, cb)
], done)
})
it('one without the other fails to establish a muxedConn', function (done) {
this.timeout(5 * 1000)

View File

@ -7,7 +7,7 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const Mplex = require('libp2p-mplex')
const Mplex = require('pull-mplex')
const pull = require('pull-stream')
const parallel = require('async/parallel')
const goodbye = require('pull-goodbye')
@ -57,7 +57,7 @@ describe('transports', () => {
streamMuxer: [ Mplex ]
}
})
expect(b._modules.streamMuxer).to.eql([require('libp2p-mplex')])
expect(b._modules.streamMuxer).to.eql([require('pull-mplex')])
done()
})
})

View File

@ -6,6 +6,7 @@ const WebSocketStar = require('libp2p-websocket-star')
const Bootstrap = require('libp2p-bootstrap')
const SPDY = require('libp2p-spdy')
const MPLEX = require('libp2p-mplex')
const PULLMPLEX = require('pull-mplex')
const KadDHT = require('libp2p-kad-dht')
const SECIO = require('libp2p-secio')
const defaultsDeep = require('@nodeutils/defaults-deep')
@ -17,6 +18,7 @@ function mapMuxers (list) {
switch (pref.trim().toLowerCase()) {
case 'spdy': return SPDY
case 'mplex': return MPLEX
case 'pullmplex': return PULLMPLEX
default:
throw new Error(pref + ' muxer not available')
}
@ -27,7 +29,7 @@ function getMuxers (options) {
if (options) {
return mapMuxers(options)
} else {
return [MPLEX, SPDY]
return [PULLMPLEX, MPLEX, SPDY]
}
}

View File

@ -7,6 +7,7 @@ const Bootstrap = require('libp2p-bootstrap')
const SPDY = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht')
const MPLEX = require('libp2p-mplex')
const PULLMPLEX = require('pull-mplex')
const SECIO = require('libp2p-secio')
const defaultsDeep = require('@nodeutils/defaults-deep')
const libp2p = require('../..')
@ -17,6 +18,7 @@ function mapMuxers (list) {
switch (pref.trim().toLowerCase()) {
case 'spdy': return SPDY
case 'mplex': return MPLEX
case 'pullmplex': return PULLMPLEX
default:
throw new Error(pref + ' muxer not available')
}
@ -30,7 +32,7 @@ function getMuxers (muxers) {
} else if (muxers) {
return mapMuxers(muxers)
} else {
return [MPLEX, SPDY]
return [PULLMPLEX, MPLEX, SPDY]
}
}