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

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Feb 7, 2018
1 parent 9121dca commit 5573289
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const multistream = require('multistream-select')
const waterfall = require('async/waterfall')
const debug = require('debug')
const log = debug('libp2p:swarm:connection')
const once = require('once')
const setImmediate = require('async/setImmediate')

const Circuit = require('libp2p-circuit')
Expand Down Expand Up @@ -37,6 +38,7 @@ module.exports = function connection (swarm) {
conn.getPeerInfo = (cb) => {
const conn = muxedConn.newStream()
const ms = new multistream.Dialer()
cb = once(cb)

waterfall([
(cb) => ms.handle(conn, cb),
Expand Down
9 changes: 5 additions & 4 deletions test/swarm-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('Switch (everything all together)', () => {

function check (err) {
expect(err).to.not.exist()
if (i++ === 2) { done() }
if (++i === 3) { done() }
}

switchC.handle('/mamao/1.0.0', (protocol, conn) => {
Expand All @@ -205,7 +205,7 @@ describe('Switch (everything all together)', () => {
expect(switchC._peerInfo.isConnected).to.exist()
expect(switchA._peerInfo.isConnected).to.exist()

tryEcho(conn, done)
tryEcho(conn, check)
})
})

Expand Down Expand Up @@ -233,9 +233,10 @@ describe('Switch (everything all together)', () => {

it('close a muxer emits event', function (done) {
this.timeout(3 * 1000)

parallel([
(cb) => switchC.stop(cb),
(cb) => switchA.once('peer-mux-closed', (peerInfo) => cb())
(cb) => switchA.once('peer-mux-closed', (peerInfo) => cb()),
(cb) => switchC.stop(cb)
], done)
})
})

0 comments on commit 5573289

Please sign in to comment.