Fix swarm.closeConns

This commit is contained in:
dignifiedquire 2015-07-31 23:13:05 +02:00
parent a73066b10b
commit f1d796f47b
3 changed files with 17 additions and 2 deletions

View File

@ -31,6 +31,7 @@
"code": "^1.4.1",
"lab": "^5.13.0",
"precommit-hook": "^3.0.0",
"sinon": "^1.15.4",
"standard": "^4.5.2",
"stream-pair": "^1.0.3"
},

View File

@ -150,9 +150,9 @@ function Swarm () {
if (number === 0) { cb() }
var c = new Counter(number, cb)
keys.map(function (key) {
c.hit()
keys.forEach(function (key) {
self.connections[key].conn.end()
c.hit()
})
}

View File

@ -1,5 +1,6 @@
var Lab = require('lab')
var Code = require('code')
var sinon = require('sinon')
var lab = exports.lab = Lab.script()
var experiment = lab.experiment
@ -85,6 +86,19 @@ experiment('BASICS', function () {
})
})
})
experiment('Swarm.closeConns', function () {
test('calls end on all connections', function (done) {
swarmA.openConnection(peerB, function () {
var key = Object.keys(swarmA.connections)[0]
sinon.spy(swarmA.connections[key].conn, 'end')
swarmA.closeConns(function () {
expect(swarmA.connections[key].conn.end.called).to.be.equal(true)
done()
})
})
})
})
})
experiment('BASE', function () {