Skip to content

Commit

Permalink
test: add pull-mplex to test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Feb 18, 2019
1 parent 59fe973 commit ec7d076
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
115 changes: 114 additions & 1 deletion test/stream-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/transports.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
})
})
Expand Down
4 changes: 3 additions & 1 deletion test/utils/bundle-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
}
Expand All @@ -27,7 +29,7 @@ function getMuxers (options) {
if (options) {
return mapMuxers(options)
} else {
return [MPLEX, SPDY]
return [PULLMPLEX, MPLEX, SPDY]
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/utils/bundle-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('../..')
Expand All @@ -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')
}
Expand All @@ -30,7 +32,7 @@ function getMuxers (muxers) {
} else if (muxers) {
return mapMuxers(muxers)
} else {
return [MPLEX, SPDY]
return [PULLMPLEX, MPLEX, SPDY]
}
}

Expand Down

0 comments on commit ec7d076

Please sign in to comment.