Skip to content

Commit

Permalink
test: add pull-mplex to test suite (libp2p#305)
Browse files Browse the repository at this point in the history
* chore: use travis
* chore: update dependencies
  • Loading branch information
jacobheun authored Feb 15, 2019
1 parent 86e0a7a commit d504040
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 242 deletions.
2 changes: 2 additions & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const pull = require('pull-stream')
const PeerBook = require('peer-book')

const Switch = require('./src')
const mplex = require('pull-mplex')
const spdy = require('libp2p-spdy')
const fs = require('fs')
const path = require('path')
Expand Down Expand Up @@ -54,6 +55,7 @@ function pre (done) {
switchB = new Switch(peerB, new PeerBook())

switchB.transport.add('ws', new WebSockets())
switchB.connection.addStreamMuxer(mplex)
switchB.connection.addStreamMuxer(spdy)
switchB.connection.reuse()
switchB.handle('/echo/1.0.0', echo)
Expand Down
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
language: node_js
cache: npm
stages:
- check
- test
- cov

node_js:
- '10'

os:
- linux
- osx
- windows

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
- npm run lint

- stage: test
name: chrome
addons:
chrome: stable
script: npx aegir test -t browser

- stage: test
name: firefox
addons:
firefox: latest
script: npx aegir test -t browser -- --browsers FirefoxHeadless

notifications:
email: false

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ libp2p-switch JavaScript implementation
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Build Status](https://img.shields.io/travis/libp2p/js-libp2p-switch/master.svg?style=flat-square)](https://travis-ci.org/libp2p/js-libp2p-switch)
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-switch.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-switch)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-switch/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-switch?branch=master)
[![Travis CI](https://flat.badgen.net/travis/libp2p/js-libp2p-switch)](https://travis-ci.com/libp2p/js-libp2p-switch)
[![codecov](https://codecov.io/gh/libp2p/js-libp2p-switch/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-switch)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-switch.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-switch)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
Expand Down
2 changes: 0 additions & 2 deletions ci/Jenkinsfile

This file was deleted.

17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,28 @@
"npm": ">=3.0.0"
},
"devDependencies": {
"aegir": "^18.0.3",
"aegir": "^18.1.0",
"chai": "^4.2.0",
"chai-checkmark": "^1.0.1",
"dirty-chai": "^2.0.1",
"libp2p-mplex": "~0.8.4",
"libp2p-pnet": "~0.1.0",
"libp2p-secio": "~0.11.0",
"libp2p-secio": "~0.11.1",
"libp2p-spdy": "~0.13.1",
"libp2p-tcp": "~0.13.0",
"libp2p-webrtc-star": "~0.15.8",
"libp2p-websockets": "~0.12.1",
"libp2p-websockets": "~0.12.2",
"peer-book": "~0.9.1",
"portfinder": "^1.0.20",
"sinon": "^7.2.0",
"pull-length-prefixed": "^1.3.1",
"pull-mplex": "~0.1.0",
"pull-pair": "^1.1.0",
"sinon": "^7.2.3",
"webrtcsupport": "^2.2.0"
},
"dependencies": {
"async": "^2.6.1",
"bignumber.js": "^8.0.1",
"async": "^2.6.2",
"bignumber.js": "^8.0.2",
"class-is": "^1.1.0",
"debug": "^4.1.1",
"err-code": "^1.1.2",
Expand All @@ -68,7 +71,7 @@
"libp2p-circuit": "~0.3.4",
"libp2p-identify": "~0.7.5",
"moving-average": "^1.0.0",
"multiaddr": "^6.0.3",
"multiaddr": "^6.0.4",
"multistream-select": "~0.14.4",
"once": "^1.4.0",
"peer-id": "~0.12.2",
Expand Down
1 change: 1 addition & 0 deletions src/connection/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class BaseConnection extends EventEmitter {
* @returns {void}
*/
close (err) {
if (this._state._state === 'DISCONNECTING') return
this.log(`closing connection to ${this.theirB58Id}`)
if (err && this._events.error) {
this.emit('error', err)
Expand Down
2 changes: 1 addition & 1 deletion test/circuit-relay.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const parallel = require('async/parallel')
const series = require('async/series')
const TCP = require('libp2p-tcp')
const WS = require('libp2p-websockets')
const multiplex = require('libp2p-mplex')
const multiplex = require('pull-mplex')
const PeerBook = require('peer-book')
const getPorts = require('portfinder').getPorts

Expand Down
2 changes: 1 addition & 1 deletion test/connection.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const WS = require('libp2p-websockets')
const parallel = require('async/parallel')
const secio = require('libp2p-secio')
const pull = require('pull-stream')
const multiplex = require('libp2p-mplex')
const multiplex = require('pull-mplex')
const spdy = require('libp2p-spdy')
const Connection = require('interface-connection').Connection
const Protector = require('libp2p-pnet')
Expand Down
2 changes: 1 addition & 1 deletion test/dial-fsm.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const parallel = require('async/parallel')
const WS = require('libp2p-websockets')
const TCP = require('libp2p-tcp')
const secio = require('libp2p-secio')
const multiplex = require('libp2p-mplex')
const multiplex = require('pull-mplex')
const pull = require('pull-stream')

const utils = require('./utils')
Expand Down
2 changes: 1 addition & 1 deletion test/pnet.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const expect = chai.expect
chai.use(dirtyChai)
const parallel = require('async/parallel')
const TCP = require('libp2p-tcp')
const multiplex = require('libp2p-mplex')
const multiplex = require('pull-mplex')
const pull = require('pull-stream')
const PeerBook = require('peer-book')
const secio = require('libp2p-secio')
Expand Down
2 changes: 1 addition & 1 deletion test/secio.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const expect = chai.expect
chai.use(dirtyChai)
const parallel = require('async/parallel')
const TCP = require('libp2p-tcp')
const multiplex = require('libp2p-mplex')
const multiplex = require('pull-mplex')
const pull = require('pull-stream')
const secio = require('libp2p-secio')
const PeerBook = require('peer-book')
Expand Down
2 changes: 2 additions & 0 deletions test/stream-muxers.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ chai.use(dirtyChai)
const parallel = require('async/parallel')
const TCP = require('libp2p-tcp')
const multiplex = require('libp2p-mplex')
const pullMplex = require('pull-mplex')
const spdy = require('libp2p-spdy')
const pull = require('pull-stream')
const PeerBook = require('peer-book')
Expand All @@ -22,6 +23,7 @@ const Switch = require('../src')
describe('Stream Multiplexing', () => {
[
multiplex,
pullMplex,
spdy
].forEach((sm) => describe(sm.multicodec, () => {
let switchA
Expand Down
84 changes: 46 additions & 38 deletions test/swarm-muxing+websockets.browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 5] */
'use strict'

const chai = require('chai')
Expand All @@ -9,58 +10,65 @@ chai.use(dirtyChai)
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const WebSockets = require('libp2p-websockets')
const mplex = require('pull-mplex')
const spdy = require('libp2p-spdy')
const PeerBook = require('peer-book')
const tryEcho = require('./utils').tryEcho

const Switch = require('../src')

describe('Switch (WebSockets)', () => {
let sw
let peerDst
[
mplex,
spdy
].forEach((muxer) => {
describe(muxer.multicodec, () => {
let sw
let peerDst

before((done) => {
PeerInfo.create((err, peerSrc) => {
expect(err).to.not.exist()
sw = new Switch(peerSrc, new PeerBook())
done()
})
})
before((done) => {
PeerInfo.create((err, peerSrc) => {
expect(err).to.not.exist()
sw = new Switch(peerSrc, new PeerBook())
done()
})
})

it('add spdy', () => {
sw.connection.addStreamMuxer(spdy)
sw.connection.reuse()
})
after(done => {
sw.stop(done)
})

it('add ws', () => {
sw.transport.add('ws', new WebSockets())
expect(Object.keys(sw.transports).length).to.equal(1)
})
it(`add muxer (${muxer.multicodec})`, () => {
sw.connection.addStreamMuxer(muxer)
sw.connection.reuse()
})

it('create Dst peer info', (done) => {
PeerId.createFromJSON(require('./test-data/id-2.json'), (err, id) => {
expect(err).to.not.exist()
it('add ws', () => {
sw.transport.add('ws', new WebSockets())
expect(Object.keys(sw.transports).length).to.equal(1)
})

peerDst = new PeerInfo(id)
const ma = '/ip4/127.0.0.1/tcp/15347/ws'
peerDst.multiaddrs.add(ma)
done()
})
})
it('create Dst peer info', (done) => {
PeerId.createFromJSON(require('./test-data/id-2.json'), (err, id) => {
expect(err).to.not.exist()

it('dial to warm a conn', (done) => {
sw.dial(peerDst, done)
})
peerDst = new PeerInfo(id)
const ma = '/ip4/127.0.0.1/tcp/15347/ws'
peerDst.multiaddrs.add(ma)
done()
})
})

it('dial on protocol, use warmed conn', (done) => {
sw.dial(peerDst, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()
tryEcho(conn, done)
})
})
it('dial to warm a conn', (done) => {
sw.dial(peerDst, done)
})

it('close', (done) => {
// cause CI is slow
setTimeout(() => sw.stop(done), 1000)
it('dial on protocol, use warmed conn', (done) => {
sw.dial(peerDst, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()
tryEcho(conn, done)
})
})
})
})
})
Loading

0 comments on commit d504040

Please sign in to comment.