X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Ftracker.ts;h=5b56a83bb73ee4eb46c45cc86184e3b0f5b63073;hb=d4bf24df8ed7032d6db1b04a716e3881679bbf46;hp=25ca00029bc9fc8d94731b27be1b9daf257f2257;hpb=b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 25ca00029..5b56a83bb 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -1,9 +1,17 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await,@typescript-eslint/no-floating-promises */ import * as magnetUtil from 'magnet-uri' import 'mocha' -import { getVideo, killallServers, runServer, ServerInfo, uploadVideo } from '../../../../shared/utils' -import { flushTests, setAccessTokensToServers } from '../../../../shared/utils/index' +import { + cleanupTests, + flushAndRunServer, + getVideo, + killallServers, + reRunServer, + ServerInfo, + uploadVideo +} from '../../../../shared/extra-utils' +import { setAccessTokensToServers } from '../../../../shared/extra-utils/index' import { VideoDetails } from '../../../../shared/models/videos' import * as WebTorrent from 'webtorrent' @@ -14,9 +22,7 @@ describe('Test tracker', function () { before(async function () { this.timeout(60000) - - await flushTests() - server = await runServer(1) + server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) { @@ -34,7 +40,7 @@ describe('Test tracker', function () { } }) - it('Should return an error when adding an incorrect infohash', done => { + it('Should return an error when adding an incorrect infohash', function (done) { this.timeout(10000) const webtorrent = new WebTorrent() @@ -43,13 +49,13 @@ describe('Test tracker', function () { torrent.on('error', done) torrent.on('warning', warn => { const message = typeof warn === 'string' ? warn : warn.message - if (message.indexOf('Unknown infoHash ') !== -1) return done() + if (message.includes('Unknown infoHash ')) return done() }) torrent.on('done', () => done(new Error('No error on infohash'))) }) - it('Should succeed with the correct infohash', done => { + it('Should succeed with the correct infohash', function (done) { this.timeout(10000) const webtorrent = new WebTorrent() @@ -58,13 +64,39 @@ describe('Test tracker', function () { torrent.on('error', done) torrent.on('warning', warn => { const message = typeof warn === 'string' ? warn : warn.message - if (message.indexOf('Unknown infoHash ') !== -1) return done(new Error('Error on infohash')) + if (message.includes('Unknown infoHash ')) return done(new Error('Error on infohash')) }) torrent.on('done', done) }) - after(async function () { + it('Should disable the tracker', function (done) { + this.timeout(20000) + + const errCb = () => done(new Error('Tracker is enabled')) + killallServers([ server ]) + reRunServer(server, { tracker: { enabled: false } }) + .then(() => { + const webtorrent = new WebTorrent() + + const torrent = webtorrent.add(goodMagnet) + + torrent.on('error', done) + torrent.on('warning', warn => { + const message = typeof warn === 'string' ? warn : warn.message + if (message.includes('disabled ')) { + torrent.off('done', errCb) + + return done() + } + }) + + torrent.on('done', errCb) + }) + }) + + after(async function () { + await cleanupTests([ server ]) }) })