Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Aug 24, 2016
1 parent 56e558e commit ea9c93c
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 164 deletions.
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const gulp = require('gulp')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const WebSockets = require('libp2p-websockets')
const pull = require('pull-stream')

const Swarm = require('./src')
const spdy = require('libp2p-spdy')
Expand Down Expand Up @@ -60,7 +61,7 @@ gulp.task('test:browser:before', (done) => {
sigS = sigServer.start(15555, ready)

function echo (conn) {
conn.pipe(conn)
pull(conn, conn)
}
})

Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "libp2p-swarm",
"version": "0.22.3",
"description": "libp2p swarm implementation in JavaScript",
"main": "lib/index.js",
"main": "src/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"lint": "gulp lint",
Expand Down Expand Up @@ -37,35 +37,31 @@
"node": "^4.3.0"
},
"devDependencies": {
"aegir": "^4.0.0",
"aegir": "^7.0.1",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"gulp": "^3.9.1",
"istanbul": "^0.4.3",
"libp2p-multiplex": "^0.2.1",
"libp2p-spdy": "^0.8.1",
"libp2p-tcp": "^0.7.4",
"libp2p-webrtc-star": "^0.3.2",
"libp2p-websockets": "^0.7.1",
"pre-commit": "^1.1.3",
"pull-goodbye": "0.0.1",
"pull-stream": "^3.4.3",
"stream-pair": "^1.0.3",
"webrtcsupport": "^2.2.0"
},
"dependencies": {
"babel-runtime": "^6.9.0",
"bl": "^1.1.2",
"browserify-zlib": "github:ipfs/browserify-zlib",
"debug": "^2.2.0",
"duplexify": "^3.4.3",
"interface-connection": "^0.1.7",
"ip-address": "^5.8.0",
"length-prefixed-stream": "^1.5.0",
"libp2p-identify": "^0.1.3",
"libp2p-secio": "^0.3.0",
"lodash.contains": "^2.4.3",
"multiaddr": "^2.0.2",
"multistream-select": "^0.9.0",
"multistream-select": "^0.10.0",
"peer-id": "^0.7.0",
"peer-info": "^0.7.0",
"protocol-buffers": "^3.1.6",
Expand Down
2 changes: 0 additions & 2 deletions test/01-transport-tcp.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ const pull = require('pull-stream')
const Swarm = require('../src')

describe('transport - tcp', function () {
this.timeout(10000)

let swarmA
let swarmB
let peerA = new Peer()
Expand Down
43 changes: 25 additions & 18 deletions test/03-transport-websockets.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const expect = require('chai').expect
const parallel = require('run-parallel')
const multiaddr = require('multiaddr')
const Peer = require('peer-info')
const Swarm = require('../src')
const WebSockets = require('libp2p-websockets')
const bl = require('bl')
const pull = require('pull-stream')
const goodbye = require('pull-goodbye')

describe.skip('transport - websockets', function () {
this.timeout(10000)
const Swarm = require('../src')

describe('transport - websockets', function () {
var swarmA
var swarmB
var peerA = new Peer()
Expand All @@ -37,10 +37,10 @@ describe.skip('transport - websockets', function () {
it('listen', (done) => {
parallel([
(cb) => swarmA.transport.listen('ws', {}, (conn) => {
conn.pipe(conn)
pull(conn, conn)
}, cb),
(cb) => swarmB.transport.listen('ws', {}, (conn) => {
conn.pipe(conn)
pull(conn, conn)
}, cb)
], () => {
expect(peerA.multiaddrs.length).to.equal(1)
Expand All @@ -63,24 +63,31 @@ describe.skip('transport - websockets', function () {
const conn = swarmA.transport.dial('ws', multiaddr('/ip4/127.0.0.1/tcp/9999/ws'), (err, conn) => {
expect(err).to.not.exist
})
conn.pipe(bl((err, data) => {
expect(err).to.not.exist
done()
}))
conn.write('hey')
conn.end()

const s = goodbye({
source: pull.values([Buffer('hey')]),
sink: pull.collect((err, data) => {
expect(err).to.not.exist
expect(data).to.be.eql([Buffer('hey')])
done()
})
})
pull(s, conn, s)
})

it('dial (conn from callback)', (done) => {
swarmA.transport.dial('ws', multiaddr('/ip4/127.0.0.1/tcp/9999/ws'), (err, conn) => {
expect(err).to.not.exist

conn.pipe(bl((err, data) => {
expect(err).to.not.exist
done()
}))
conn.write('hey')
conn.end()
const s = goodbye({
source: pull.values([Buffer('hey')]),
sink: pull.collect((err, data) => {
expect(err).to.not.exist
expect(data).to.be.eql([Buffer('hey')])
done()
})
})
pull(s, conn, s)
})
})

Expand Down
44 changes: 24 additions & 20 deletions test/04-muxing-multiplex.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ const expect = require('chai').expect
const parallel = require('run-parallel')
const multiaddr = require('multiaddr')
const Peer = require('peer-info')
const Swarm = require('../src')
const TCP = require('libp2p-tcp')
const multiplex = require('libp2p-spdy')
const pull = require('pull-stream')

// TODO multiplex needs to be upgraded, like spdy, to work again
describe.skip('stream muxing with multiplex (on TCP)', function () {
this.timeout(60 * 1000)
const Swarm = require('../src')

var swarmA
var peerA
var swarmB
var peerB
var swarmC
var peerC
// Multiplex is not yet ported
// Reenable when https://github.com/libp2p/js-libp2p-multiplex/issues/14
// is done
describe.skip('stream muxing with multiplex (on TCP)', () => {
let swarmA
let peerA
let swarmB
let peerB
let swarmC
let peerC

before((done) => {
peerA = new Peer()
Expand Down Expand Up @@ -66,16 +68,17 @@ describe.skip('stream muxing with multiplex (on TCP)', function () {

it('handle + dial on protocol', (done) => {
swarmB.handle('/abacaxi/1.0.0', (conn) => {
conn.pipe(conn)
pull(conn, conn)
})

swarmA.dial(peerB, '/abacaxi/1.0.0', (err, conn) => {
expect(err).to.not.exist
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
conn.end()

conn.on('data', () => {}) // let it flow.. let it flooooow
conn.on('end', done)
pull(
pull.empty(),
conn,
pull.onEnd(done)
)
})
})

Expand All @@ -90,17 +93,18 @@ describe.skip('stream muxing with multiplex (on TCP)', function () {

it('dial on protocol, reuse warmed conn', (done) => {
swarmA.handle('/papaia/1.0.0', (conn) => {
conn.pipe(conn)
pull(conn, conn)
})

swarmB.dial(peerA, '/papaia/1.0.0', (err, conn) => {
expect(err).to.not.exist
expect(Object.keys(swarmB.conns).length).to.equal(0)
expect(Object.keys(swarmB.muxedConns).length).to.equal(1)
conn.end()

conn.on('data', () => {}) // let it flow.. let it flooooow
conn.on('end', done)
pull(
pull.empty(),
conn,
pull.onEnd(done)
)
})
})

Expand Down
28 changes: 13 additions & 15 deletions test/05-muxing-spdy.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ const pull = require('pull-stream')

const spdy = require('libp2p-spdy')

describe('stream muxing with spdy (on TCP)', function () {
this.timeout(60 * 1000)

var swarmA
var peerA
var swarmB
var peerB
var swarmC
var peerC
var swarmD
var peerD
describe('stream muxing with spdy (on TCP)', () => {
let swarmA
let peerA
let swarmB
let peerB
let swarmC
let peerC
let swarmD
let peerD

before((done) => {
peerA = new Peer()
Expand Down Expand Up @@ -174,10 +172,10 @@ describe('stream muxing with spdy (on TCP)', function () {
// TODO: create a similar version, but that spawns a swarm in a
// different proc
it.skip('blow up a socket, with WebSockets', (done) => {
var swarmE
var peerE
var swarmF
var peerF
let swarmE
let peerE
let swarmF
let peerF

peerE = new Peer()
peerF = new Peer()
Expand Down
16 changes: 7 additions & 9 deletions test/06-conn-upgrade-secio.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ const pull = require('pull-stream')

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

describe('secio conn upgrade (on TCP)', function () {
this.timeout(60 * 1000)

var swarmA
var peerA
var swarmB
var peerB
var swarmC
var peerC
describe('secio conn upgrade (on TCP)', () => {
let swarmA
let peerA
let swarmB
let peerB
let swarmC
let peerC

before((done) => {
peerA = new Peer()
Expand Down
12 changes: 5 additions & 7 deletions test/08-swarm-without-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ const pull = require('pull-stream')

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

describe('high level API - 1st without stream multiplexing (on TCP)', function () {
this.timeout(20000)

var swarmA
var peerA
var swarmB
var peerB
describe('high level API - 1st without stream multiplexing (on TCP)', () => {
let swarmA
let peerA
let swarmB
let peerB

before((done) => {
peerA = new Peer()
Expand Down
Loading

0 comments on commit ea9c93c

Please sign in to comment.