make large torrent test not depend on the network

for #18
This commit is contained in:
Feross Aboukhadijeh 2014-05-23 20:35:29 -07:00
parent b3d4acbb46
commit 954b3af78e

View File

@ -1,6 +1,8 @@
var Client = require('../').Client var Client = require('../').Client
var fs = require('fs') var fs = require('fs')
var parseTorrent = require('parse-torrent') var parseTorrent = require('parse-torrent')
var portfinder = require('portfinder')
var Server = require('../').Server
var test = require('tape') var test = require('tape')
var torrent = fs.readFileSync(__dirname + '/torrents/sintel-5gb.torrent') var torrent = fs.readFileSync(__dirname + '/torrents/sintel-5gb.torrent')
@ -8,11 +10,25 @@ var parsedTorrent = parseTorrent(torrent)
var peerId = new Buffer('01234567890123456789') var peerId = new Buffer('01234567890123456789')
var port = 6881 var port = 6881
// remove all tracker servers except a single UDP one, for now
parsedTorrent.announce = [ 'udp://tracker.publicbt.com:80/announce' ]
test('large torrent: client.start()', function (t) { test('large torrent: client.start()', function (t) {
t.plan(4) t.plan(5)
var server = new Server({ http: false })
server.on('error', function (err) {
t.fail(err.message)
})
server.on('warning', function (err) {
t.fail(err.message)
})
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 + '/announce' ]
var client = new Client(peerId, port, parsedTorrent) var client = new Client(peerId, port, parsedTorrent)
@ -21,7 +37,7 @@ test('large torrent: client.start()', function (t) {
}) })
client.once('update', function (data) { client.once('update', function (data) {
t.equal(data.announce, 'udp://tracker.publicbt.com:80/announce') t.equal(data.announce, 'udp://127.0.0.1:' + port + '/announce')
t.equal(typeof data.complete, 'number') t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number') t.equal(typeof data.incomplete, 'number')
}) })
@ -29,7 +45,9 @@ test('large torrent: client.start()', function (t) {
client.once('peer', function (addr) { client.once('peer', function (addr) {
t.pass('there is at least one peer') // TODO: this shouldn't rely on an external server! t.pass('there is at least one peer') // TODO: this shouldn't rely on an external server!
client.stop() client.stop()
server.close()
}) })
client.start() client.start()
}) })
})