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

57 lines
1.3 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 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) {
t.plan(5)
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
})
server.listen(0, function () {
var port = server.udp.address().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 () {
t.pass('got response to stop')
server.close()
client.destroy()
2014-05-24 03:43:45 +00:00
})
2014-05-24 04:02:53 +00:00
})
})
2014-04-19 06:08:17 +00:00
})