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

60 lines
1.4 KiB
JavaScript
Raw Normal View History

var Client = require('../')
2014-04-19 06:08:17 +00:00
var fs = require('fs')
var parseTorrent = require('parse-torrent')
var portfinder = require('portfinder')
var Server = require('../').Server
2014-04-19 06:08:17 +00:00
var test = require('tape')
var torrent = fs.readFileSync(__dirname + '/torrents/sintel-5gb.torrent')
var parsedTorrent = parseTorrent(torrent)
var peerId = new Buffer('01234567890123456789')
test('large torrent: client.start()', function (t) {
2014-05-24 03:43:45 +00:00
t.plan(6)
2014-04-19 06:08:17 +00:00
var server = new Server({ http: false })
2014-04-19 06:08:17 +00:00
server.on('error', function (err) {
t.fail(err.message)
2014-04-19 06:08:17 +00:00
})
server.on('warning', function (err) {
t.fail(err.message)
2014-04-19 06:08:17 +00:00
})
portfinder.getPort(function (err, port) {
t.error(err, 'found free port')
server.listen(port)
// remove all tracker servers except a single UDP one, for now
parsedTorrent.announce = [ 'udp://127.0.0.1:' + port ]
2014-05-24 03:43:45 +00:00
var client = new Client(peerId, 6881, parsedTorrent)
2014-04-19 06:08:17 +00:00
client.on('error', function (err) {
t.error(err)
})
client.once('update', function (data) {
t.equal(data.announce, 'udp://127.0.0.1:' + port)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
})
2014-05-24 04:02:53 +00:00
client.start()
2014-11-26 12:11:49 +00:00
client.once('peer', function () {
t.pass('there is at least one peer')
2014-05-24 04:02:53 +00:00
client.stop()
2014-05-24 04:02:53 +00:00
client.once('update', function () {
server.close(function () {
t.pass('server close')
})
2014-05-24 03:43:45 +00:00
})
2014-05-24 04:02:53 +00:00
})
})
2014-04-19 06:08:17 +00:00
})