bittorrent-tracker/test/destroy.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

import Client from '../index.js'
import common from './common.js'
import fixtures from 'webtorrent-fixtures'
import test from 'tape'
2020-10-29 04:57:47 +00:00
const peerId = Buffer.from('01234567890123456789')
const port = 6881
function testNoEventsAfterDestroy (t, serverType) {
t.plan(1)
2021-06-15 01:54:41 +00:00
common.createServer(t, serverType, (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)
2021-06-15 01:54:41 +00:00
client.on('error', err => { t.error(err) })
client.on('warning', err => { t.error(err) })
2021-06-15 01:54:41 +00:00
client.once('update', () => {
t.fail('no "update" event should fire, since client is destroyed')
})
// announce, then immediately destroy
client.update()
client.destroy()
2021-06-15 01:54:41 +00:00
setTimeout(() => {
t.pass('wait to see if any events are fired')
server.close()
}, 1000)
})
}
2021-06-15 01:54:41 +00:00
test('http: no "update" events after destroy()', t => {
testNoEventsAfterDestroy(t, 'http')
})
2021-06-15 01:54:41 +00:00
test('udp: no "update" events after destroy()', t => {
testNoEventsAfterDestroy(t, 'udp')
})
2021-06-15 01:54:41 +00:00
test('ws: no "update" events after destroy()', t => {
testNoEventsAfterDestroy(t, 'ws')
})