X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fhelpers%2Frequest.ts;h=a85d80b88cf18acc6f5b8404e17f37286ed7748c;hb=77239b425a8e00822a53c9907415832a473c3eb6;hp=f8b2d599b8f1e606af4cabde456ae4ad136ee348;hpb=7cd1b12c19d0589d1d692ed0571ca0800f028aea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/helpers/request.ts b/server/tests/helpers/request.ts index f8b2d599b..a85d80b88 100644 --- a/server/tests/helpers/request.ts +++ b/server/tests/helpers/request.ts @@ -1,11 +1,11 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' -import { get4KFileUrl, root, wait } from '../../../shared/extra-utils' -import { join } from 'path' -import { pathExists, remove } from 'fs-extra' import { expect } from 'chai' +import { pathExists, remove } from 'fs-extra' +import { join } from 'path' +import { root, wait } from '@shared/core-utils' +import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' +import { FIXTURE_URLS, Mock429 } from '../shared' describe('Request helpers', function () { const destPath1 = join(root(), 'test-output-1.txt') @@ -13,7 +13,7 @@ describe('Request helpers', function () { it('Should throw an error when the bytes limit is exceeded for request', async function () { try { - await doRequest({ uri: get4KFileUrl() }, 3) + await doRequest(FIXTURE_URLS.file4K, { bodyKBLimit: 3 }) } catch { return } @@ -23,7 +23,7 @@ describe('Request helpers', function () { it('Should throw an error when the bytes limit is exceeded for request and save file', async function () { try { - await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath1, 3) + await doRequestAndSaveToFile(FIXTURE_URLS.file4K, destPath1, { bodyKBLimit: 3 }) } catch { await wait(500) @@ -34,9 +34,23 @@ describe('Request helpers', function () { throw new Error('No error thrown by do request and save to file') }) + it('Should correctly retry on 429 error', async function () { + this.timeout(25000) + + const mock = new Mock429() + const port = await mock.initialize() + + const before = new Date().getTime() + await doRequest('http://localhost:' + port) + + expect(new Date().getTime() - before).to.be.greaterThan(2000) + + await mock.terminate() + }) + it('Should succeed if the file is below the limit', async function () { - await doRequest({ uri: get4KFileUrl() }, 5) - await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath2, 5) + await doRequest(FIXTURE_URLS.file4K, { bodyKBLimit: 5 }) + await doRequestAndSaveToFile(FIXTURE_URLS.file4K, destPath2, { bodyKBLimit: 5 }) expect(await pathExists(destPath2)).to.be.true })