From 59fe9732d7dfe08a2ab9681ffa9b902429e16d48 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 14 Feb 2019 17:07:13 +0000 Subject: [PATCH 1/2] chore: move to travis (#322) * chore: move to travis * chore: move to travis 2 * chore: remove unused test file * chore: remove travis webworker * chore: fix webworker * chore: remove webrtcsupport module * chore: test windows * chore: make windows-build-tools silent * chore: test dllss * chore: test dllss 2 * chore: test dllss 3 * chore: remove before_install stuff * chore: remove windows from CI --- .gitignore | 1 + .travis.yml | 42 +++++++++++++++++++ ci/Jenkinsfile | 2 - package.json | 7 +--- test/transports.browser.js | 4 +- test/turbolence.node.js | 84 -------------------------------------- 6 files changed, 47 insertions(+), 93 deletions(-) create mode 100644 .travis.yml delete mode 100644 ci/Jenkinsfile delete mode 100644 test/turbolence.node.js diff --git a/.gitignore b/.gitignore index 1c73b3783a..4db4e02677 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ test/test-data/go-ipfs-repo/LOG.old # while testing npm5 package-lock.json +yarn.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..461d2aefc7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,42 @@ +language: node_js +cache: npm +stages: + - check + - test + - cov + +node_js: + - '10' + +os: + - linux + - osx +script: npx nyc -s npm run test:node -- --bail +after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov + +jobs: + include: + - stage: check + script: + - npx aegir commitlint --travis + - npx aegir dep-check -- -i wrtc -i electron-webrtc + - npm run lint + + - stage: test + name: chrome + addons: + chrome: stable + script: + - npx aegir test -t browser + - npx aegir test -t webworker + + - stage: test + name: firefox + addons: + firefox: latest + script: + - npx aegir test -t browser -- --browsers FirefoxHeadless + - npx aegir test -t webworker -- --browsers FirefoxHeadless + +notifications: + email: false \ No newline at end of file diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile deleted file mode 100644 index a7da2e54f3..0000000000 --- a/ci/Jenkinsfile +++ /dev/null @@ -1,2 +0,0 @@ -// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. -javascript() diff --git a/package.json b/package.json index d273d0c419..59904082dd 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,7 @@ "test:browser": "aegir test -t browser", "release": "aegir release -t node -t browser", "release-minor": "aegir release --type minor -t node -t browser", - "release-major": "aegir release --type major -t node -t browser", - "coverage": "aegir coverage", - "coverage-publish": "aegir coverage --provider coveralls" + "release-major": "aegir release --type major -t node -t browser" }, "repository": { "type": "git", @@ -61,7 +59,7 @@ }, "devDependencies": { "@nodeutils/defaults-deep": "^1.1.0", - "aegir": "^18.0.2", + "aegir": "^18.1.0", "chai": "^4.2.0", "chai-checkmark": "^1.0.1", "cids": "~0.5.5", @@ -87,7 +85,6 @@ "pull-serializer": "~0.3.2", "pull-stream": "^3.6.9", "sinon": "^7.1.1", - "webrtcsupport": "^2.2.0", "wrtc": "~0.3.2" }, "contributors": [ diff --git a/test/transports.browser.js b/test/transports.browser.js index f4338fd164..f96bcfd20c 100644 --- a/test/transports.browser.js +++ b/test/transports.browser.js @@ -12,7 +12,7 @@ const pull = require('pull-stream') const parallel = require('async/parallel') const goodbye = require('pull-goodbye') const serializer = require('pull-serializer') -const w = require('webrtcsupport') +const wrtcSupport = self.RTCPeerConnection && ('createDataChannel' in self.RTCPeerConnection.prototype) const tryEcho = require('./utils/try-echo') const Node = require('./utils/bundle-browser') @@ -232,7 +232,7 @@ describe('transports', () => { describe('webrtc-star', () => { /* eslint-disable-next-line no-console */ - if (!w.support) { return console.log('NO WEBRTC SUPPORT') } + if (!wrtcSupport) { return console.log('NO WEBRTC SUPPORT') } let peer1 let peer2 diff --git a/test/turbolence.node.js b/test/turbolence.node.js deleted file mode 100644 index d12c35edf9..0000000000 --- a/test/turbolence.node.js +++ /dev/null @@ -1,84 +0,0 @@ -/* eslint-env mocha */ -'use strict' - -const chai = require('chai') -chai.use(require('dirty-chai')) -const expect = chai.expect -const multiaddr = require('multiaddr') -const spawn = require('child_process').spawn -const path = require('path') -const pull = require('pull-stream') -const utils = require('./utils/node') -const createNode = utils.createNode -const echo = utils.echo - -describe('Turbolence tests', () => { - let nodeA - let nodeSpawn - - before((done) => { - createNode('/ip4/0.0.0.0/tcp/0', (err, node) => { - expect(err).to.not.exist() - nodeA = node - node.handle('/echo/1.0.0', echo) - node.start(done) - }) - }) - - after((done) => nodeA.stop(done)) - - it('spawn a node in a different process', (done) => { - const filePath = path.join(__dirname, './spawn-libp2p-node.js') - - nodeSpawn = spawn(filePath, { env: process.env }) - - let spawned = false - - nodeSpawn.stdout.on('data', (data) => { - // console.log(data.toString()) - if (!spawned) { - spawned = true - done() - } - }) - - /* eslint-disable-next-line no-console */ - nodeSpawn.stderr.on('data', (data) => console.log(data.toString())) - }) - - it('connect nodeA to that node', (done) => { - const spawnedId = require('./test-data/test-id.json') - const maddr = multiaddr('/ip4/127.0.0.1/tcp/12345/p2p/' + spawnedId.id) - - nodeA.dial(maddr, '/echo/1.0.0', (err, conn) => { - expect(err).to.not.exist() - const peers = nodeA.peerBook.getAll() - - expect(Object.keys(peers)).to.have.length(1) - - pull( - pull.values([Buffer.from('hey')]), - conn, - pull.collect((err, data) => { - expect(err).to.not.exist() - expect(data).to.eql([Buffer.from('hey')]) - done() - }) - ) - }) - }) - - it('crash that node, ensure nodeA continues going steady', (done) => { - // TODO investigate why CI crashes - setTimeout(() => nodeSpawn.kill('SIGKILL'), 1000) - // nodeSpawn.kill('SIGKILL') - setTimeout(check, 5000) - - function check () { - const peers = nodeA.peerBook.getAll() - expect(Object.keys(peers)).to.have.length(1) - expect(nodeA._switch.connection.getAll()).to.have.length(0) - done() - } - }) -}) From ec7d0761deb54412a76f44dfd5c3dc44f62a8730 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Fri, 15 Feb 2019 13:26:40 +0100 Subject: [PATCH 2/2] 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] } }