2022-12-05 22:06:54 +00:00
|
|
|
import Client from '../index.js'
|
|
|
|
import common from './common.js'
|
|
|
|
import fixtures from 'webtorrent-fixtures'
|
|
|
|
import test from 'tape'
|
2016-09-16 14:49:49 +00:00
|
|
|
|
2020-10-29 04:57:47 +00:00
|
|
|
const peerId = Buffer.from('01234567890123456789')
|
|
|
|
const port = 6881
|
2016-09-16 14:49:49 +00:00
|
|
|
|
|
|
|
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({
|
2016-09-16 14:49:49 +00:00
|
|
|
infoHash: fixtures.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
2020-04-25 09:34:40 +00:00
|
|
|
peerId,
|
|
|
|
port,
|
2016-09-16 14:49:49 +00:00
|
|
|
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) })
|
2016-09-16 14:49:49 +00:00
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
client.once('update', () => {
|
2016-09-16 14:49:49 +00:00
|
|
|
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(() => {
|
2016-09-16 14:49:49 +00:00
|
|
|
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 => {
|
2016-09-16 14:49:49 +00:00
|
|
|
testNoEventsAfterDestroy(t, 'http')
|
|
|
|
})
|
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
test('udp: no "update" events after destroy()', t => {
|
2016-09-16 14:49:49 +00:00
|
|
|
testNoEventsAfterDestroy(t, 'udp')
|
|
|
|
})
|
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
test('ws: no "update" events after destroy()', t => {
|
2016-09-16 14:49:49 +00:00
|
|
|
testNoEventsAfterDestroy(t, 'ws')
|
|
|
|
})
|