mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-13 10:56:25 +00:00
parent
2aea063b8c
commit
62be68979b
@ -1,20 +1,38 @@
|
||||
var Client = require('../').Client
|
||||
var fs = require('fs')
|
||||
var parseTorrent = require('parse-torrent')
|
||||
var portfinder = require('portfinder')
|
||||
var Server = require('../').Server
|
||||
var test = require('tape')
|
||||
|
||||
var torrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
|
||||
var parsedTorrent = parseTorrent(torrent)
|
||||
|
||||
// remove all tracker servers except a single UDP one, for now
|
||||
var announceUrl = 'udp://tracker.publicbt.com:80'
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
|
||||
var peerId = new Buffer('01234567890123456789')
|
||||
var port = 6881
|
||||
|
||||
test('udp: client.start/update/stop()', function (t) {
|
||||
t.plan(10)
|
||||
t.plan(12)
|
||||
|
||||
var server = new Server({ udp: false })
|
||||
|
||||
server.on('error', function (err) {
|
||||
t.fail(err.message)
|
||||
})
|
||||
|
||||
server.on('warning', function (err) {
|
||||
t.fail(err.message)
|
||||
})
|
||||
|
||||
var announceUrl
|
||||
portfinder.getPort(function (err, port) {
|
||||
t.error(err, 'found free port')
|
||||
|
||||
// remove all tracker servers except a single UDP one, for now
|
||||
announceUrl = 'http://127.0.0.1:' + port + '/announce'
|
||||
parsedTorrent.announce = [ announceUrl ]
|
||||
|
||||
server.listen(port)
|
||||
|
||||
var client = new Client(peerId, port, parsedTorrent)
|
||||
|
||||
@ -42,6 +60,10 @@ test('udp: client.start/update/stop()', function (t) {
|
||||
t.equal(data.announce, announceUrl)
|
||||
t.equal(typeof data.complete, 'number')
|
||||
t.equal(typeof data.incomplete, 'number')
|
||||
|
||||
server.close(function () {
|
||||
t.pass('server close')
|
||||
})
|
||||
})
|
||||
|
||||
client.stop()
|
||||
@ -52,3 +74,4 @@ test('udp: client.start/update/stop()', function (t) {
|
||||
|
||||
client.start()
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user