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

Commit

Permalink
test: cleanup and fix hanging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 9, 2016
1 parent 5c76907 commit 1210a9f
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 112 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
"bl": "^1.1.2",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"aegir": "^3.0.0",
"aegir": "^3.0.1",
"gulp": "^3.9.1",
"istanbul": "^0.4.3",
"libp2p-multiplex": "^0.2.1",
"libp2p-spdy": "^0.3.1",
"libp2p-tcp": "^0.5.1",
"libp2p-websockets": "^0.4.3",
"libp2p-websockets": "^0.4.4",
"pre-commit": "^1.1.2",
"stream-pair": "^1.0.3"
},
Expand All @@ -55,7 +55,7 @@
"duplex-passthrough": "github:diasdavid/duplex-passthrough",
"ip-address": "^5.8.0",
"lodash.contains": "^2.4.3",
"multiaddr": "^1.4.0",
"multiaddr": "^1.4.1",
"multistream-select": "^0.6.5",
"peer-id": "^0.6.6",
"peer-info": "^0.6.2",
Expand Down
5 changes: 2 additions & 3 deletions test/00-basic.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const expect = require('chai').expect
const Swarm = require('../src')

describe('basics', () => {
it('throws on missing peerInfo', (done) => {
expect(Swarm).to.throw(Error)
done()
it('throws on missing peerInfo', () => {
expect(() => Swarm()).to.throw(Error)
})
})
50 changes: 23 additions & 27 deletions test/03-transport-websockets.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ describe('transport - websockets', function () {
var peerA = new Peer()
var peerB = new Peer()

before((done) => {
before(() => {
peerA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets'))
peerB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets'))
swarmA = new Swarm(peerA)
swarmB = new Swarm(peerB)
done()
})

it('add', (done) => {
Expand All @@ -36,31 +35,28 @@ describe('transport - websockets', function () {
})

it('listen', (done) => {
var count = 0
swarmA.transport.listen('ws', {}, (conn) => {
conn.pipe(conn)
}, ready)
swarmB.transport.listen('ws', {}, (conn) => {
conn.pipe(conn)
}, ready)

function ready () {
if (++count === 2) {
expect(peerA.multiaddrs.length).to.equal(1)
expect(
peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets'))
).to.be.equal(
true
)
expect(peerB.multiaddrs.length).to.equal(1)
expect(
peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets'))
).to.equal(
true
)
done()
}
}
parallel([
(cb) => swarmA.transport.listen('ws', {}, (conn) => {
conn.pipe(conn)
}, cb),
(cb) => swarmB.transport.listen('ws', {}, (conn) => {
conn.pipe(conn)
}, cb)
], () => {
expect(peerA.multiaddrs.length).to.equal(1)
expect(
peerA.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9888/websockets'))
).to.be.equal(
true
)
expect(peerB.multiaddrs.length).to.equal(1)
expect(
peerB.multiaddrs[0].equals(multiaddr('/ip4/127.0.0.1/tcp/9999/websockets'))
).to.equal(
true
)
done()
})
})

it('dial', (done) => {
Expand Down
7 changes: 3 additions & 4 deletions test/05-muxing-spdy.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ describe('stream muxing with spdy (on TCP)', function () {
after((done) => {
parallel([
(cb) => swarmA.close(cb),
(cb) => swarmB.close(cb),
(cb) => swarmC.close(cb)
(cb) => swarmB.close(cb)
// (cb) => swarmC.close(cb)
], done)
})

it('add', (done) => {
it('add', () => {
swarmA.connection.addStreamMuxer(spdy)
swarmB.connection.addStreamMuxer(spdy)
swarmC.connection.addStreamMuxer(spdy)
done()
})

it('handle + dial on protocol', (done) => {
Expand Down
3 changes: 0 additions & 3 deletions test/06-conn-upgrade-secio.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
describe('secio conn upgrade (on TCP)', function () {
this.timeout(20000)

before((done) => { done() })
after((done) => { done() })

it.skip('add', (done) => {})
it.skip('dial', (done) => {})
it.skip('tls on a muxed stream (not the full conn)', (done) => {})
Expand Down
3 changes: 0 additions & 3 deletions test/07-conn-upgrade-tls.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
'use strict'

describe('tls conn upgrade (on TCP)', function () {
before((done) => { done() })
after((done) => { done() })

it.skip('add', (done) => {})
it.skip('dial', (done) => {})
it.skip('tls on a muxed stream (not the full conn)', (done) => {})
Expand Down
14 changes: 4 additions & 10 deletions test/08-swarm-without-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
swarmB = new Swarm(peerB)

swarmA.transport.add('tcp', new TCP())
swarmA.transport.listen('tcp', {}, null, ready)

swarmB.transport.add('tcp', new TCP())
swarmB.transport.listen('tcp', {}, null, ready)

var counter = 0

function ready () {
if (++counter === 2) {
done()
}
}
parallel([
(cb) => swarmA.transport.listen('tcp', {}, null, cb),
(cb) => swarmB.transport.listen('tcp', {}, null, cb)
], done)
})

after((done) => {
Expand Down
81 changes: 32 additions & 49 deletions test/09-swarm-with-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,14 @@ describe('high level API - with everything mixed all together!', function () {
peerC.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/0'))

swarmA.transport.add('tcp', new TCP())
swarmA.transport.listen('tcp', {}, null, ready)

swarmB.transport.add('tcp', new TCP())
swarmB.transport.listen('tcp', {}, null, ready)

swarmC.transport.add('tcp', new TCP())
swarmC.transport.listen('tcp', {}, null, ready)

var counter = 0

function ready () {
if (++counter === 3) {
done()
}
}
parallel([
(cb) => swarmA.transport.listen('tcp', {}, null, cb),
(cb) => swarmB.transport.listen('tcp', {}, null, cb),
(cb) => swarmC.transport.listen('tcp', {}, null, cb)
], done)
})

it.skip('add utp', (done) => {})
Expand All @@ -87,27 +80,19 @@ describe('high level API - with everything mixed all together!', function () {
peerE.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/9042/websockets'))

swarmB.transport.add('ws', new WebSockets())
swarmB.transport.listen('ws', {}, null, ready)

swarmC.transport.add('ws', new WebSockets())
swarmC.transport.listen('ws', {}, null, ready)

swarmD.transport.add('ws', new WebSockets())
swarmD.transport.listen('ws', {}, null, ready)

swarmE.transport.add('ws', new WebSockets())
swarmE.transport.listen('ws', {}, null, ready)

var counter = 0

function ready () {
if (++counter === 4) {
done()
}
}
parallel([
(cb) => swarmB.transport.listen('ws', {}, null, cb),
(cb) => swarmC.transport.listen('ws', {}, null, cb),
(cb) => swarmD.transport.listen('ws', {}, null, cb),
(cb) => swarmE.transport.listen('ws', {}, null, cb)
], done)
})

it('add spdy', (done) => {
it('add spdy', () => {
swarmA.connection.addStreamMuxer(spdy)
swarmB.connection.addStreamMuxer(spdy)
swarmC.connection.addStreamMuxer(spdy)
Expand All @@ -119,26 +104,26 @@ describe('high level API - with everything mixed all together!', function () {
swarmC.connection.reuse()
swarmD.connection.reuse()
swarmE.connection.reuse()

done()
})

it.skip('add multiplex', (done) => {})
it.skip('add multiplex', () => {})

it('warm up from A to B on tcp to tcp+ws', (done) => {
swarmB.once('peer-mux-established', (peerInfo) => {
expect(peerInfo.id.toB58String()).to.equal(peerA.id.toB58String())
})

swarmA.once('peer-mux-established', (peerInfo) => {
expect(peerInfo.id.toB58String()).to.equal(peerB.id.toB58String())
})

swarmA.dial(peerB, (err) => {
expect(err).to.not.exist
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
done()
})
parallel([
(cb) => swarmB.once('peer-mux-established', (peerInfo) => {
expect(peerInfo.id.toB58String()).to.equal(peerA.id.toB58String())
cb()
}),
(cb) => swarmA.once('peer-mux-established', (peerInfo) => {
expect(peerInfo.id.toB58String()).to.equal(peerB.id.toB58String())
cb()
}),
(cb) => swarmA.dial(peerB, (err) => {
expect(err).to.not.exist
expect(Object.keys(swarmA.muxedConns).length).to.equal(1)
cb()
})
], done)
})

it('warm up a warmed up, from B to A', (done) => {
Expand Down Expand Up @@ -225,11 +210,9 @@ describe('high level API - with everything mixed all together!', function () {
})

it('close a muxer emits event', (done) => {
swarmC.close((err) => {
if (err) throw err
})
swarmA.once('peer-mux-closed', (peerInfo) => {
done()
})
parallel([
(cb) => swarmC.close(cb),
(cb) => swarmA.once('peer-mux-closed', () => cb())
], done)
})
})
14 changes: 4 additions & 10 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ describe('transport - websockets', function () {

var swarm

before((done) => {
before(() => {
const b58IdSrc = 'QmYzgdesgjdvD3okTPGZT9NPmh1BuH5FfTVNKjsvaAprhb'
// use a pre generated Id to save time
const idSrc = Id.createFromB58String(b58IdSrc)
const peerSrc = new Peer(idSrc)
swarm = new Swarm(peerSrc)

done()
})

it('add', (done) => {
Expand Down Expand Up @@ -62,35 +60,31 @@ describe('high level API - 1st without stream multiplexing (on websockets)', fun
var swarm
var peerDst

before((done) => {
before(() => {
const b58IdSrc = 'QmYzgdesgjdvD3okTPGZT9NPmh1BuH5FfTVNKjsvaAprhb'
// use a pre generated Id to save time
const idSrc = Id.createFromB58String(b58IdSrc)
const peerSrc = new Peer(idSrc)
swarm = new Swarm(peerSrc)

done()
})

after((done) => {
swarm.close(done)
})

it('add ws', (done) => {
it('add ws', () => {
swarm.transport.add('ws', new WebSockets())
expect(Object.keys(swarm.transports).length).to.equal(1)
done()
})

it('create Dst peer info', (done) => {
it('create Dst peer info', () => {
const b58IdDst = 'QmYzgdesgjdvD3okTPGZT9NPmh1BuH5FfTVNKjsvaAprhb'
// use a pre generated Id to save time
const idDst = Id.createFromB58String(b58IdDst)
peerDst = new Peer(idDst)

const ma = multiaddr('/ip4/127.0.0.1/tcp/9200/websockets')
peerDst.multiaddr.add(ma)
done()
})

it('dial on protocol', (done) => {
Expand Down

0 comments on commit 1210a9f

Please sign in to comment.