Skip to content

Commit 9a48e1c

Browse files
committed
Add failing test for webtorrent#141
1 parent 2966165 commit 9a48e1c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/client-ws-socket-pool.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var Client = require('../')
2+
var common = require('./common')
3+
var fixtures = require('webtorrent-fixtures')
4+
var test = require('tape')
5+
6+
var peerId = new Buffer('01234567890123456789')
7+
var port = 6681
8+
9+
test('ensure client.destroy() callback is called with re-used websockets in socketPool', function (t) {
10+
t.plan(4)
11+
12+
common.createServer(t, 'ws', function (server, announceUrl) {
13+
var client1 = new Client({
14+
infoHash: fixtures.leaves.parsedTorrent.infoHash,
15+
announce: announceUrl,
16+
peerId: peerId,
17+
port: port,
18+
wrtc: {}
19+
})
20+
21+
common.mockWebsocketTracker(client1)
22+
client1.on('error', function (err) { t.error(err) })
23+
client1.on('warning', function (err) { t.error(err) })
24+
25+
client1.start()
26+
27+
client1.once('update', function () {
28+
t.pass('got client1 update')
29+
// second ws client using same announce url will re-use the same websocket
30+
var client2 = new Client({
31+
infoHash: fixtures.alice.parsedTorrent.infoHash, // different info hash
32+
announce: announceUrl,
33+
peerId: peerId,
34+
port: port,
35+
wrtc: {}
36+
})
37+
38+
common.mockWebsocketTracker(client2)
39+
client2.on('error', function (err) { t.error(err) })
40+
client2.on('warning', function (err) { t.error(err) })
41+
42+
client2.start()
43+
44+
client2.once('update', function () {
45+
t.pass('got client2 update')
46+
client1.destroy(function (err) {
47+
t.error(err, 'got client1 destroy callback')
48+
client2.destroy(function (err) {
49+
t.error(err, 'got client2 destroy callback')
50+
server.close()
51+
})
52+
})
53+
})
54+
})
55+
})
56+
})

0 commit comments

Comments
 (0)