wait for server close before next test

This commit is contained in:
Feross Aboukhadijeh 2014-05-23 20:43:45 -07:00
parent 0ff2c1917b
commit 14034c2848
3 changed files with 13 additions and 8 deletions

View File

@ -8,10 +8,9 @@ var test = require('tape')
var torrent = fs.readFileSync(__dirname + '/torrents/sintel-5gb.torrent') var torrent = fs.readFileSync(__dirname + '/torrents/sintel-5gb.torrent')
var parsedTorrent = parseTorrent(torrent) var parsedTorrent = parseTorrent(torrent)
var peerId = new Buffer('01234567890123456789') var peerId = new Buffer('01234567890123456789')
var port = 6881
test('large torrent: client.start()', function (t) { test('large torrent: client.start()', function (t) {
t.plan(5) t.plan(6)
var server = new Server({ http: false }) var server = new Server({ http: false })
@ -30,7 +29,7 @@ test('large torrent: client.start()', function (t) {
// remove all tracker servers except a single UDP one, for now // remove all tracker servers except a single UDP one, for now
parsedTorrent.announce = [ 'udp://127.0.0.1:' + port + '/announce' ] parsedTorrent.announce = [ 'udp://127.0.0.1:' + port + '/announce' ]
var client = new Client(peerId, port, parsedTorrent) var client = new Client(peerId, 6881, parsedTorrent)
client.on('error', function (err) { client.on('error', function (err) {
t.error(err) t.error(err)
@ -45,7 +44,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() server.close(function () {
t.pass('server close')
})
}) })
client.start() client.start()

View File

@ -9,7 +9,7 @@ var peerId2 = '12345678901234567890'
var torrentLength = 50000 var torrentLength = 50000
test('server', function (t) { test('server', function (t) {
t.plan(26) t.plan(27)
var server = new Server({ udp: false }) // { interval: 50000, compactOnly: false } var server = new Server({ udp: false }) // { interval: 50000, compactOnly: false }
@ -100,7 +100,9 @@ test('server', function (t) {
t.equal(data.complete, 0) t.equal(data.complete, 0)
t.equal(data.incomplete, 0) t.equal(data.incomplete, 0)
server.close() server.close(function () {
t.pass('server closed')
})
}) })
}) })
}) })

View File

@ -9,7 +9,7 @@ var peerId2 = '12345678901234567890'
var torrentLength = 50000 var torrentLength = 50000
test('server', function (t) { test('server', function (t) {
t.plan(26) t.plan(27)
var server = new Server({ http: false }) var server = new Server({ http: false })
@ -100,7 +100,9 @@ test('server', function (t) {
t.equal(data.complete, 0) t.equal(data.complete, 0)
t.equal(data.incomplete, 0) t.equal(data.incomplete, 0)
server.close() server.close(function () {
t.pass('server close')
})
}) })
}) })
}) })