forked from webtorrent/bittorrent-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdestroy.js
More file actions
50 lines (40 loc) · 1.29 KB
/
destroy.js
File metadata and controls
50 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var Client = require('../')
var common = require('./common')
var fixtures = require('webtorrent-fixtures')
var test = require('tape')
var peerId = Buffer.from('01234567890123456789')
var port = 6881
function testNoEventsAfterDestroy (t, serverType) {
t.plan(1)
common.createServer(t, serverType, function (server, announceUrl) {
var client = new Client({
infoHash: fixtures.leaves.parsedTorrent.infoHash,
announce: announceUrl,
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')
})