test: add failing test for the second part of #190

This commit is contained in:
Feross Aboukhadijeh 2017-01-20 18:34:05 -08:00
parent 63d24611ec
commit c3bf7f87f6

View File

@ -103,6 +103,60 @@ test('ws: client.stop()', function (t) {
testClientStop(t, 'ws')
})
function testClientStopDestroy (t, serverType) {
t.plan(2)
common.createServer(t, serverType, function (server, announceUrl) {
var client = new Client({
infoHash: fixtures.leaves.parsedTorrent.infoHash,
announce: announceUrl,
peerId: peerId1,
port: 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.start()
client.once('update', function () {
t.pass('client received response to "start" message')
client.stop()
client.on('update', function () { t.fail('client should not receive update after destroy is called') })
// Call destroy() in the same tick as stop(), but the message should still
// be received by the server, though obviously the client won't receive the
// response.
client.destroy()
server.once('stop', function (peer, params) {
t.pass('server received "stop" message')
setTimeout(function () {
// give the websocket server time to finish in progress (stream) messages
// to peers
server.close()
}, 100)
})
})
})
}
test('http: client.stop(); client.destroy()', function (t) {
testClientStopDestroy(t, 'http')
})
test('udp: client.stop(); client.destroy()', function (t) {
testClientStopDestroy(t, 'udp')
})
test('ws: client.stop(); client.destroy()', function (t) {
testClientStopDestroy(t, 'ws')
})
function testClientUpdate (t, serverType) {
t.plan(4)