diff options
Diffstat (limited to 'test/node/conn-pool.js')
-rw-r--r-- | test/node/conn-pool.js | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/test/node/conn-pool.js b/test/node/conn-pool.js index b77a917..1127501 100644 --- a/test/node/conn-pool.js +++ b/test/node/conn-pool.js @@ -4,17 +4,17 @@ const WebTorrent = require('../../') const MemoryChunkStore = require('memory-chunk-store') const dgram = require('dgram') -test('client.conn-pool: use TCP when uTP disabled', function (t) { +test('client.conn-pool: use TCP when uTP disabled', t => { t.plan(6) const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false }) const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false }) - client1.on('error', function (err) { t.fail(err) }) - client1.on('warning', function (err) { t.fail(err) }) + client1.on('error', err => { t.fail(err) }) + client1.on('warning', err => { t.fail(err) }) - client2.on('error', function (err) { t.fail(err) }) - client2.on('warning', function (err) { t.fail(err) }) + client2.on('error', err => { t.fail(err) }) + client2.on('warning', err => { t.fail(err) }) // Start seeding client2.seed(fixtures.leaves.content, { @@ -22,47 +22,47 @@ test('client.conn-pool: use TCP when uTP disabled', function (t) { announce: [] }) - client2.on('listening', function () { + client2.on('listening', () => { // Start downloading const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers - torrent.addPeer('127.0.0.1:' + client2.address().port) + torrent.addPeer(`127.0.0.1:${client2.address().port}`) let order = 0 - torrent.on('infoHash', function () { + torrent.on('infoHash', () => { t.equal(++order, 1) }) - torrent.on('metadata', function () { + torrent.on('metadata', () => { t.equal(++order, 2) }) - torrent.on('ready', function () { + torrent.on('ready', () => { t.equal(++order, 3) }) - torrent.on('done', function () { + torrent.on('done', () => { t.equal(++order, 4) - client1.destroy(function (err) { t.error(err, 'client 1 destroyed') }) - client2.destroy(function (err) { t.error(err, 'client 2 destroyed') }) + client1.destroy(err => { t.error(err, 'client 1 destroyed') }) + client2.destroy(err => { t.error(err, 'client 2 destroyed') }) }) }) }) -test('client.conn-pool: use uTP when uTP enabled', function (t) { +test('client.conn-pool: use uTP when uTP enabled', t => { t.plan(6) const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true }) const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true }) - client1.on('error', function (err) { t.fail(err) }) - client1.on('warning', function (err) { t.fail(err) }) + client1.on('error', err => { t.fail(err) }) + client1.on('warning', err => { t.fail(err) }) - client2.on('error', function (err) { t.fail(err) }) - client2.on('warning', function (err) { t.fail(err) }) + client2.on('error', err => { t.fail(err) }) + client2.on('warning', err => { t.fail(err) }) // Start seeding client2.seed(fixtures.leaves.content, { @@ -70,47 +70,47 @@ test('client.conn-pool: use uTP when uTP enabled', function (t) { announce: [] }) - client2.on('listening', function () { + client2.on('listening', () => { // Start downloading const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers - torrent.addPeer('127.0.0.1:' + client2.address().port) + torrent.addPeer(`127.0.0.1:${client2.address().port}`) let order = 0 - torrent.on('infoHash', function () { + torrent.on('infoHash', () => { t.equal(++order, 1) }) - torrent.on('metadata', function () { + torrent.on('metadata', () => { t.equal(++order, 2) }) - torrent.on('ready', function () { + torrent.on('ready', () => { t.equal(++order, 3) }) - torrent.on('done', function () { + torrent.on('done', () => { t.equal(++order, 4) - client1.destroy(function (err) { t.error(err, 'client 1 destroyed') }) - client2.destroy(function (err) { t.error(err, 'client 2 destroyed') }) + client1.destroy(err => { t.error(err, 'client 1 destroyed') }) + client2.destroy(err => { t.error(err, 'client 2 destroyed') }) }) }) }) -test('client.conn-pool: adding IPv6 peer when uTP enabled should fallback to TCP', function (t) { +test('client.conn-pool: adding IPv6 peer when uTP enabled should fallback to TCP', t => { t.plan(6) const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true }) const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true }) - client1.on('error', function (err) { t.fail(err) }) - client1.on('warning', function (err) { t.fail(err) }) + client1.on('error', err => { t.fail(err) }) + client1.on('warning', err => { t.fail(err) }) - client2.on('error', function (err) { t.fail(err) }) - client2.on('warning', function (err) { t.fail(err) }) + client2.on('error', err => { t.fail(err) }) + client2.on('warning', err => { t.fail(err) }) // Start seeding client2.seed(fixtures.leaves.content, { @@ -118,38 +118,38 @@ test('client.conn-pool: adding IPv6 peer when uTP enabled should fallback to TCP announce: [] }) - client2.on('listening', function () { + client2.on('listening', () => { // Start downloading const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers - torrent.addPeer('[::1]:' + client2.address().port) + torrent.addPeer(`[::1]:${client2.address().port}`) let order = 0 - torrent.on('infoHash', function () { + torrent.on('infoHash', () => { t.equal(++order, 1) }) - torrent.on('metadata', function () { + torrent.on('metadata', () => { t.equal(++order, 2) }) - torrent.on('ready', function () { + torrent.on('ready', () => { t.equal(++order, 3) }) - torrent.on('done', function () { + torrent.on('done', () => { t.equal(++order, 4) - client1.destroy(function (err) { t.error(err, 'client 1 destroyed') }) - client2.destroy(function (err) { t.error(err, 'client 2 destroyed') }) + client1.destroy(err => { t.error(err, 'client 1 destroyed') }) + client2.destroy(err => { t.error(err, 'client 2 destroyed') }) }) }) }) // Warning: slow test as we need to rely on connection timeouts -test('client.conn-pool: fallback to TCP when uTP server failed', function (t) { +test('client.conn-pool: fallback to TCP when uTP server failed', t => { t.plan(6) // force uTP server failure @@ -159,11 +159,11 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) { const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true, torrentPort: 63000 }) const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false }) - client1.on('error', function (err) { t.fail(err) }) - client1.on('warning', function (err) { t.fail(err) }) + client1.on('error', err => { t.fail(err) }) + client1.on('warning', err => { t.fail(err) }) - client2.on('error', function (err) { t.fail(err) }) - client2.on('warning', function (err) { t.fail(err) }) + client2.on('error', err => { t.fail(err) }) + client2.on('warning', err => { t.fail(err) }) // Start seeding client2.seed(fixtures.leaves.content, { @@ -171,32 +171,32 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) { announce: [] }) - client2.on('listening', function () { + client2.on('listening', () => { // Start downloading const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers - torrent.addPeer('127.0.0.1:' + client2.address().port) + torrent.addPeer(`127.0.0.1:${client2.address().port}`) let order = 0 - torrent.on('infoHash', function () { + torrent.on('infoHash', () => { t.equal(++order, 1) }) - torrent.on('metadata', function () { + torrent.on('metadata', () => { t.equal(++order, 2) }) - torrent.on('ready', function () { + torrent.on('ready', () => { t.equal(++order, 3) }) - torrent.on('done', function () { + torrent.on('done', () => { t.equal(++order, 4) - client1.destroy(function (err) { t.error(err, 'client 1 destroyed') }) - client2.destroy(function (err) { t.error(err, 'client 2 destroyed') }) + client1.destroy(err => { t.error(err, 'client 1 destroyed') }) + client2.destroy(err => { t.error(err, 'client 2 destroyed') }) server.close() }) @@ -204,17 +204,17 @@ test('client.conn-pool: fallback to TCP when uTP server failed', function (t) { }) // Warning: slow test as we need to rely on connection timeouts -test('client.conn-pool: fallback to TCP when remote client has uTP disabled', function (t) { +test('client.conn-pool: fallback to TCP when remote client has uTP disabled', t => { t.plan(6) const client1 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: true }) const client2 = new WebTorrent({ dht: false, tracker: false, lsd: false, utp: false }) - client1.on('error', function (err) { t.fail(err) }) - client1.on('warning', function (err) { t.fail(err) }) + client1.on('error', err => { t.fail(err) }) + client1.on('warning', err => { t.fail(err) }) - client2.on('error', function (err) { t.fail(err) }) - client2.on('warning', function (err) { t.fail(err) }) + client2.on('error', err => { t.fail(err) }) + client2.on('warning', err => { t.fail(err) }) // Start seeding client2.seed(fixtures.leaves.content, { @@ -222,32 +222,32 @@ test('client.conn-pool: fallback to TCP when remote client has uTP disabled', fu announce: [] }) - client2.on('listening', function () { + client2.on('listening', () => { // Start downloading const torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore }) // Manually connect peers - torrent.addPeer('127.0.0.1:' + client2.address().port) + torrent.addPeer(`127.0.0.1:${client2.address().port}`) let order = 0 - torrent.on('infoHash', function () { + torrent.on('infoHash', () => { t.equal(++order, 1) }) - torrent.on('metadata', function () { + torrent.on('metadata', () => { t.equal(++order, 2) }) - torrent.on('ready', function () { + torrent.on('ready', () => { t.equal(++order, 3) }) - torrent.on('done', function () { + torrent.on('done', () => { t.equal(++order, 4) - client1.destroy(function (err) { t.error(err, 'client 1 destroyed') }) - client2.destroy(function (err) { t.error(err, 'client 2 destroyed') }) + client1.destroy(err => { t.error(err, 'client 1 destroyed') }) + client2.destroy(err => { t.error(err, 'client 2 destroyed') }) }) }) }) |