From 26dcc3fb29e3d9fa4b94fe195aae7ba028684178 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 12 Aug 2019 14:06:27 +0200 Subject: Fix left parameter for asynchronous behaviour --- test/common.js | 13 +++++++++++++ test/node/blocklist-dht.js | 9 +++++++-- test/node/blocklist-tracker.js | 9 +++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 test/common.js (limited to 'test') diff --git a/test/common.js b/test/common.js new file mode 100644 index 0000000..9ac99a1 --- /dev/null +++ b/test/common.js @@ -0,0 +1,13 @@ +const os = require('os') +const fs = require('fs') +const path = require('path') + +exports.getTestPath = function (infix, infoHash) { + let testPath + try { + testPath = path.join(fs.statSync('/tmp') && '/tmp', 'webtorrent', 'test') + } catch (err) { + testPath = path.join(typeof os.tmpdir === 'function' ? os.tmpdir() : '/', 'webtorrent', 'test') + } + return path.join(testPath, infix, infoHash) +} diff --git a/test/node/blocklist-dht.js b/test/node/blocklist-dht.js index e956731..d2ce9bc 100644 --- a/test/node/blocklist-dht.js +++ b/test/node/blocklist-dht.js @@ -3,6 +3,7 @@ var fixtures = require('webtorrent-fixtures') var series = require('run-series') var test = require('tape') var WebTorrent = require('../../') +var common = require('../common') test('blocklist blocks peers discovered via DHT', function (t) { t.plan(8) @@ -25,7 +26,9 @@ test('blocklist blocks peers discovered via DHT', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var torrent1 = client1.add(fixtures.leaves.parsedTorrent) + var torrent1 = client1.add(fixtures.leaves.parsedTorrent, { + path: common.getTestPath('client_1', fixtures.leaves.parsedTorrent.infoHash) + }) torrent1.on('peer', function () { t.fail('client1 should not find any peers') @@ -63,7 +66,9 @@ test('blocklist blocks peers discovered via DHT', function (t) { client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) - var torrent2 = client2.add(fixtures.leaves.parsedTorrent) + var torrent2 = client2.add(fixtures.leaves.parsedTorrent, { + path: common.getTestPath('client_2', fixtures.leaves.parsedTorrent.infoHash) + }) torrent2.on('blockedPeer', function (addr) { t.pass('client2 blocked connection to client1: ' + addr) diff --git a/test/node/blocklist-tracker.js b/test/node/blocklist-tracker.js index 302bd8f..665ad48 100644 --- a/test/node/blocklist-tracker.js +++ b/test/node/blocklist-tracker.js @@ -3,6 +3,7 @@ var series = require('run-series') var test = require('tape') var TrackerServer = require('bittorrent-tracker/server') var WebTorrent = require('../../') +var common = require('../common') test('blocklist blocks peers discovered via tracker', function (t) { t.plan(9) @@ -38,7 +39,9 @@ test('blocklist blocks peers discovered via tracker', function (t) { client1.on('error', function (err) { t.fail(err) }) client1.on('warning', function (err) { t.fail(err) }) - var torrent1 = client1.add(parsedTorrent) + var torrent1 = client1.add(parsedTorrent, { + path: common.getTestPath('client_1', parsedTorrent.infoHash) + }) torrent1.on('invalidPeer', function () { t.pass('client1 found itself') @@ -58,7 +61,9 @@ test('blocklist blocks peers discovered via tracker', function (t) { client2.on('error', function (err) { t.fail(err) }) client2.on('warning', function (err) { t.fail(err) }) - var torrent2 = client2.add(parsedTorrent) + var torrent2 = client2.add(parsedTorrent, { + path: common.getTestPath('client_2', parsedTorrent.infoHash) + }) torrent2.once('blockedPeer', function () { t.pass('client2 blocked first peer') -- cgit v1.2.3