2014-06-07 15:15:00 -07:00
|
|
|
var Client = require('../')
|
2016-02-29 17:14:47 -08:00
|
|
|
var common = require('./common')
|
2014-04-18 23:08:17 -07:00
|
|
|
var fs = require('fs')
|
|
|
|
|
var parseTorrent = require('parse-torrent')
|
2016-02-05 14:08:46 -08:00
|
|
|
var path = require('path')
|
2014-04-18 23:08:17 -07:00
|
|
|
var test = require('tape')
|
|
|
|
|
|
2016-02-05 14:08:46 -08:00
|
|
|
var torrent = fs.readFileSync(path.join(__dirname, 'torrents/sintel-5gb.torrent'))
|
2014-04-18 23:08:17 -07:00
|
|
|
var parsedTorrent = parseTorrent(torrent)
|
|
|
|
|
var peerId = new Buffer('01234567890123456789')
|
|
|
|
|
|
2016-02-29 17:11:02 -08:00
|
|
|
function testLargeTorrent (t, serverType) {
|
2016-02-29 17:14:47 -08:00
|
|
|
t.plan(9)
|
2014-04-18 23:08:17 -07:00
|
|
|
|
2016-02-29 17:11:02 -08:00
|
|
|
common.createServer(t, serverType, function (server, announceUrl) {
|
|
|
|
|
parsedTorrent.announce = [ announceUrl ]
|
|
|
|
|
var client = new Client(peerId, 6881, parsedTorrent, { wrtc: {} })
|
2014-04-18 23:08:17 -07:00
|
|
|
|
2016-02-29 17:11:02 -08:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
|
|
|
|
client.on('error', function (err) { t.error(err) })
|
|
|
|
|
client.on('warning', function (err) { t.error(err) })
|
2014-05-23 20:35:29 -07:00
|
|
|
|
|
|
|
|
client.once('update', function (data) {
|
2016-02-29 17:11:02 -08:00
|
|
|
t.equal(data.announce, announceUrl)
|
2014-05-23 20:35:29 -07:00
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
2014-05-23 21:02:53 -07:00
|
|
|
|
2016-02-29 17:14:47 -08: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-23 21:02:53 -07:00
|
|
|
|
2016-02-29 17:14:47 -08:00
|
|
|
server.close()
|
|
|
|
|
client.destroy()
|
|
|
|
|
})
|
2014-05-23 20:43:45 -07:00
|
|
|
})
|
2014-05-23 21:02:53 -07:00
|
|
|
})
|
2016-02-29 17:11:02 -08:00
|
|
|
|
|
|
|
|
client.start()
|
2014-05-23 20:35:29 -07:00
|
|
|
})
|
2016-02-29 17:11:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-18 23:08:17 -07:00
|
|
|
})
|