mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-13 19:06:27 +00:00
client.stop() no longer calls client.destroy()
You must call client.destroy() manually to clean up resources
This commit is contained in:
parent
ee91dff19d
commit
f285c9dd3c
@ -153,8 +153,6 @@ Client.prototype.stop = function (opts) {
|
||||
opts = self._defaultAnnounceOpts(opts)
|
||||
opts.event = 'stopped'
|
||||
self._announce(opts)
|
||||
|
||||
self.destroy()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,9 +47,9 @@ test('large torrent: client.start()', function (t) {
|
||||
client.stop()
|
||||
|
||||
client.once('update', function () {
|
||||
server.close(function () {
|
||||
t.pass('server close')
|
||||
})
|
||||
t.pass('got response to stop')
|
||||
server.close()
|
||||
client.destroy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -8,7 +8,7 @@ var parsedTorrent = magnet(uri)
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
|
||||
test('magnet + udp: client.start/update/stop()', function (t) {
|
||||
t.plan(11)
|
||||
t.plan(10)
|
||||
|
||||
var server = new Server({ http: false })
|
||||
|
||||
@ -60,9 +60,8 @@ test('magnet + udp: client.start/update/stop()', function (t) {
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
|
||||
server.close(function () {
|
||||
t.pass('server closed')
|
||||
})
|
||||
server.close()
|
||||
client.destroy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -36,9 +36,9 @@ function testClientStart (t, serverType) {
|
||||
client.stop()
|
||||
|
||||
client.once('update', function () {
|
||||
server.close(function () {
|
||||
t.pass('server close')
|
||||
})
|
||||
t.pass('got response to stop')
|
||||
server.close()
|
||||
client.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
@ -55,7 +55,7 @@ test('udp: client.start()', function (t) {
|
||||
})
|
||||
|
||||
function testClientStop (t, serverType) {
|
||||
t.plan(4)
|
||||
t.plan(3)
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId1, port, parsedTorrent)
|
||||
@ -79,9 +79,8 @@ function testClientStop (t, serverType) {
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
|
||||
server.close(function () {
|
||||
t.pass('server close')
|
||||
})
|
||||
server.close()
|
||||
client.destroy()
|
||||
})
|
||||
}, 1000)
|
||||
})
|
||||
@ -121,9 +120,9 @@ function testClientUpdate (t, serverType) {
|
||||
client.stop()
|
||||
|
||||
client.once('update', function () {
|
||||
server.close(function () {
|
||||
t.pass('server close')
|
||||
})
|
||||
t.pass('got response to stop')
|
||||
server.close()
|
||||
client.destroy()
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -139,7 +138,7 @@ test('udp: client.update()', function (t) {
|
||||
})
|
||||
|
||||
function testClientScrape (t, serverType) {
|
||||
t.plan(5)
|
||||
t.plan(4)
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client = new Client(peerId1, port, parsedTorrent)
|
||||
@ -158,9 +157,8 @@ function testClientScrape (t, serverType) {
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
t.equal(typeof data.downloaded, 'number')
|
||||
|
||||
server.close(function () {
|
||||
t.pass('server close')
|
||||
})
|
||||
server.close()
|
||||
client.destroy()
|
||||
})
|
||||
|
||||
client.scrape()
|
||||
@ -176,7 +174,7 @@ test('udp: client.scrape()', function (t) {
|
||||
})
|
||||
|
||||
function testClientAnnounceWithNumWant (t, serverType) {
|
||||
t.plan(1)
|
||||
t.plan(4)
|
||||
common.createServer(t, serverType, function (server, announceUrl) {
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
var client1 = new Client(peerId1, port, parsedTorrent)
|
||||
@ -200,10 +198,30 @@ function testClientAnnounceWithNumWant (t, serverType) {
|
||||
client3.on('peer', function () {
|
||||
t.pass('got one peer (this should only fire once)')
|
||||
|
||||
var num = 3
|
||||
function tryCloseServer () {
|
||||
num -= 1
|
||||
if (num === 0) server.close()
|
||||
}
|
||||
|
||||
client1.stop()
|
||||
client1.once('update', function () {
|
||||
t.pass('got response to stop (client1)')
|
||||
client1.destroy()
|
||||
tryCloseServer()
|
||||
})
|
||||
client2.stop()
|
||||
client2.once('update', function () {
|
||||
t.pass('got response to stop (client2)')
|
||||
client2.destroy()
|
||||
tryCloseServer()
|
||||
})
|
||||
client3.stop()
|
||||
server.close()
|
||||
client3.once('update', function () {
|
||||
t.pass('got response to stop (client3)')
|
||||
client3.destroy()
|
||||
tryCloseServer()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -39,6 +39,7 @@ function testSingle (t, serverType) {
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
t.equal(typeof data.downloaded, 'number')
|
||||
client.destroy()
|
||||
server.close(function () {
|
||||
t.end()
|
||||
})
|
||||
@ -147,7 +148,7 @@ test('server: multiple info_hash scrape (manual http request)', function (t) {
|
||||
})
|
||||
})
|
||||
|
||||
test('server: all info_hash scrape', function (t) {
|
||||
test('server: all info_hash scrape (manual http request)', function (t) {
|
||||
var server = new Server({ udp: false })
|
||||
server.on('error', function (err) {
|
||||
t.error(err)
|
||||
@ -185,7 +186,7 @@ test('server: all info_hash scrape', function (t) {
|
||||
t.equal(typeof data.files[binaryBitlove].incomplete, 'number')
|
||||
t.equal(typeof data.files[binaryBitlove].downloaded, 'number')
|
||||
|
||||
client.stop()
|
||||
client.destroy()
|
||||
server.close(function () {
|
||||
t.end()
|
||||
})
|
||||
|
@ -8,7 +8,7 @@ var peerId2 = new Buffer('12345678901234567890')
|
||||
var torrentLength = 50000
|
||||
|
||||
function serverTest (t, serverType, serverFamily) {
|
||||
t.plan(26)
|
||||
t.plan(25)
|
||||
|
||||
var opts = serverType === 'http' ? { udp: false } : { http: false }
|
||||
var server = new Server(opts)
|
||||
@ -32,19 +32,19 @@ function serverTest (t, serverType, serverFamily) {
|
||||
var port = server[serverType].address().port
|
||||
var announceUrl = serverType + '://' + serverAddr + ':' + port + '/announce'
|
||||
|
||||
var client = new Client(peerId, 6881, {
|
||||
var client1 = new Client(peerId, 6881, {
|
||||
infoHash: infoHash,
|
||||
length: torrentLength,
|
||||
announce: [ announceUrl ]
|
||||
})
|
||||
|
||||
client.start()
|
||||
client1.start()
|
||||
|
||||
server.once('start', function () {
|
||||
t.pass('got start message from client1')
|
||||
})
|
||||
|
||||
client.once('update', function (data) {
|
||||
client1.once('update', function (data) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(data.complete, 0)
|
||||
t.equal(data.incomplete, 1)
|
||||
@ -61,16 +61,16 @@ function serverTest (t, serverType, serverFamily) {
|
||||
socket: undefined
|
||||
})
|
||||
|
||||
client.complete()
|
||||
client1.complete()
|
||||
|
||||
client.once('update', function (data) {
|
||||
client1.once('update', function (data) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(data.complete, 1)
|
||||
t.equal(data.incomplete, 0)
|
||||
|
||||
client.scrape()
|
||||
client1.scrape()
|
||||
|
||||
client.once('scrape', function (data) {
|
||||
client1.once('scrape', function (data) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
@ -96,16 +96,16 @@ function serverTest (t, serverType, serverFamily) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(data.complete, 1)
|
||||
t.equal(data.incomplete, 0)
|
||||
client2.destroy()
|
||||
|
||||
client.stop()
|
||||
client.once('update', function (data) {
|
||||
client1.stop()
|
||||
client1.once('update', function (data) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(data.complete, 0)
|
||||
t.equal(data.incomplete, 0)
|
||||
|
||||
server.close(function () {
|
||||
t.pass('server closed')
|
||||
})
|
||||
client1.destroy()
|
||||
server.close()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user