bittorrent-tracker/test/client-large-torrent.js

63 lines
1.7 KiB
JavaScript
Raw Normal View History

var Client = require('../')
var common = require('./common')
2014-04-19 06:08:17 +00:00
var fs = require('fs')
var parseTorrent = require('parse-torrent')
2016-02-05 22:08:46 +00:00
var path = require('path')
2014-04-19 06:08:17 +00:00
var test = require('tape')
2016-02-05 22:08:46 +00:00
var torrent = fs.readFileSync(path.join(__dirname, 'torrents/sintel-5gb.torrent'))
2014-04-19 06:08:17 +00:00
var parsedTorrent = parseTorrent(torrent)
var peerId = new Buffer('01234567890123456789')
function testLargeTorrent (t, serverType) {
t.plan(9)
2014-04-19 06:08:17 +00:00
common.createServer(t, serverType, function (server, announceUrl) {
parsedTorrent.announce = [ announceUrl ]
var client = new Client(peerId, 6881, parsedTorrent, { wrtc: {} })
2014-04-19 06:08:17 +00:00
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 (data) {
t.equal(data.announce, announceUrl)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
2014-05-24 04:02:53 +00:00
client.update()
client.once('update', function (data) {
t.equal(data.announce, announceUrl)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
client.stop()
client.once('update', function (data) {
t.equal(data.announce, announceUrl)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
2014-05-24 04:02:53 +00:00
server.close()
client.destroy()
})
2014-05-24 03:43:45 +00:00
})
2014-05-24 04:02:53 +00:00
})
client.start()
})
}
test('http: large torrent: client.start()', function (t) {
testLargeTorrent(t, 'http')
})
test('udp: large torrent: client.start()', function (t) {
testLargeTorrent(t, 'udp')
})
test('ws: large torrent: client.start()', function (t) {
testLargeTorrent(t, 'ws')
2014-04-19 06:08:17 +00:00
})