fix tests: wait for socket to send final responses

This commit is contained in:
Feross Aboukhadijeh 2017-02-02 18:20:26 -08:00
parent 7075088848
commit 1b22b53fe8

View File

@ -14,15 +14,18 @@ function Swarm (infoHash, server) {
maxAge: server.peersCacheTtl || 20 * 60 * 1000 // 20 minutes
})
// When a peer is evicted from the LRU cache, if it's a websocket peer,
// close the websocket.
// When a websocket peer is evicted from the LRU cache, close the websocket
// after a short timeout period. We wait 1s so the server has a chance to send
// a response to 'stopped' events, which remove the peer and cause an eviction.
this.peers.on('evict', function (data) {
var peer = data.value
if (peer.socket) {
try {
peer.socket.close()
peer.socket = null
} catch (err) {}
setTimeout(function () {
try {
peer.socket.close()
peer.socket = null
} catch (err) {}
}, 1000)
}
})
}