From 9a48e1c10a1660ac498d7a1856de36ece115622c Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Thu, 31 Mar 2016 21:48:21 -0700 Subject: [PATCH] Add failing test for #141 --- test/client-ws-socket-pool.js | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/client-ws-socket-pool.js diff --git a/test/client-ws-socket-pool.js b/test/client-ws-socket-pool.js new file mode 100644 index 0000000..11dc52b --- /dev/null +++ b/test/client-ws-socket-pool.js @@ -0,0 +1,56 @@ +var Client = require('../') +var common = require('./common') +var fixtures = require('webtorrent-fixtures') +var test = require('tape') + +var peerId = new Buffer('01234567890123456789') +var port = 6681 + +test('ensure client.destroy() callback is called with re-used websockets in socketPool', function (t) { + t.plan(4) + + common.createServer(t, 'ws', function (server, announceUrl) { + var client1 = new Client({ + infoHash: fixtures.leaves.parsedTorrent.infoHash, + announce: announceUrl, + peerId: peerId, + port: port, + wrtc: {} + }) + + common.mockWebsocketTracker(client1) + client1.on('error', function (err) { t.error(err) }) + client1.on('warning', function (err) { t.error(err) }) + + client1.start() + + client1.once('update', function () { + t.pass('got client1 update') + // second ws client using same announce url will re-use the same websocket + var client2 = new Client({ + infoHash: fixtures.alice.parsedTorrent.infoHash, // different info hash + announce: announceUrl, + peerId: peerId, + port: port, + wrtc: {} + }) + + common.mockWebsocketTracker(client2) + client2.on('error', function (err) { t.error(err) }) + client2.on('warning', function (err) { t.error(err) }) + + client2.start() + + client2.once('update', function () { + t.pass('got client2 update') + client1.destroy(function (err) { + t.error(err, 'got client1 destroy callback') + client2.destroy(function (err) { + t.error(err, 'got client2 destroy callback') + server.close() + }) + }) + }) + }) + }) +})