bittorrent-tracker/test/destroy.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-10-29 04:57:47 +00:00
const Client = require('../')
const common = require('./common')
const fixtures = require('webtorrent-fixtures')
const test = require('tape')
2020-10-29 04:57:47 +00:00
const peerId = Buffer.from('01234567890123456789')
const port = 6881
function testNoEventsAfterDestroy (t, serverType) {
t.plan(1)
common.createServer(t, serverType, function (server, announceUrl) {
2020-10-29 04:57:47 +00:00
const client = new Client({
infoHash: fixtures.leaves.parsedTorrent.infoHash,
announce: announceUrl,
2020-04-25 09:34:40 +00:00
peerId,
port,
wrtc: {}
})
if (serverType === 'ws') common.mockWebsocketTracker(client)
client.on('error', function (err) { t.error(err) })
client.on('warning', function (err) { t.error(err) })
client.once('update', function () {
t.fail('no "update" event should fire, since client is destroyed')
})
// announce, then immediately destroy
client.update()
client.destroy()
setTimeout(function () {
t.pass('wait to see if any events are fired')
server.close()
}, 1000)
})
}
test('http: no "update" events after destroy()', function (t) {
testNoEventsAfterDestroy(t, 'http')
})
test('udp: no "update" events after destroy()', function (t) {
testNoEventsAfterDestroy(t, 'udp')
})
test('ws: no "update" events after destroy()', function (t) {
testNoEventsAfterDestroy(t, 'ws')
})