X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Ftests%2Fhelpers%2Frequest.ts;h=db0cca39059eb1773e44fa9b932b74e77d19168e;hb=bf54587a3e2ad9c2c186828f2a5682b91ee2cc00;hp=5e77f129ea5b24bd7ed38c9375612a97ca773ac7;hpb=903353d67a8d0fdda8465ed6c57b77a9a5afbe92;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/helpers/request.ts b/server/tests/helpers/request.ts index 5e77f129e..db0cca390 100644 --- a/server/tests/helpers/request.ts +++ b/server/tests/helpers/request.ts @@ -4,7 +4,8 @@ import 'mocha' import { expect } from 'chai' import { pathExists, remove } from 'fs-extra' import { join } from 'path' -import { get4KFileUrl, root, wait } from '../../../shared/extra-utils' +import { Mock429 } from '@shared/server-commands/mock-servers/mock-429' +import { FIXTURE_URLS, root, wait } from '../../../shared/server-commands' import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' describe('Request helpers', function () { @@ -13,7 +14,7 @@ describe('Request helpers', function () { it('Should throw an error when the bytes limit is exceeded for request', async function () { try { - await doRequest(get4KFileUrl(), { bodyKBLimit: 3 }) + await doRequest(FIXTURE_URLS.file4K, { bodyKBLimit: 3 }) } catch { return } @@ -23,7 +24,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(get4KFileUrl(), destPath1, { bodyKBLimit: 3 }) + await doRequestAndSaveToFile(FIXTURE_URLS.file4K, destPath1, { bodyKBLimit: 3 }) } catch { await wait(500) @@ -34,9 +35,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(get4KFileUrl(), { bodyKBLimit: 5 }) - await doRequestAndSaveToFile(get4KFileUrl(), destPath2, { bodyKBLimit: 5 }) + await doRequest(FIXTURE_URLS.file4K, { bodyKBLimit: 5 }) + await doRequestAndSaveToFile(FIXTURE_URLS.file4K, destPath2, { bodyKBLimit: 5 }) expect(await pathExists(destPath2)).to.be.true })