From c223bdd3e95aaaafb64fc9a3f673aab653eccce0 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Fri, 15 Feb 2019 13:26:40 +0100 Subject: [PATCH] test: add pull-mplex to test suite --- package.json | 1 + test/stream-muxing.node.js | 115 ++++++++++++++++++++++++++++++++++- test/transports.browser.js | 4 +- test/utils/bundle-browser.js | 4 +- test/utils/bundle-nodejs.js | 4 +- 5 files changed, 123 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 59904082dd..d538271d75 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/stream-muxing.node.js b/test/stream-muxing.node.js index cd8da66689..2e200d3d4b 100644 --- a/test/stream-muxing.node.js +++ b/test/stream-muxing.node.js @@ -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) diff --git a/test/transports.browser.js b/test/transports.browser.js index f96bcfd20c..a3c5e7b17f 100644 --- a/test/transports.browser.js +++ b/test/transports.browser.js @@ -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() }) }) diff --git a/test/utils/bundle-browser.js b/test/utils/bundle-browser.js index 831821f6e1..e066031404 100644 --- a/test/utils/bundle-browser.js +++ b/test/utils/bundle-browser.js @@ -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] } } diff --git a/test/utils/bundle-nodejs.js b/test/utils/bundle-nodejs.js index 55faa6c25f..cbebd2d58a 100644 --- a/test/utils/bundle-nodejs.js +++ b/test/utils/bundle-nodejs.js @@ -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] } }