From 55b7bfaaebd34d9b88231f67af2ff07579363382 Mon Sep 17 00:00:00 2001 From: Ajani Bilby <11359344+AjaniBilby@users.noreply.github.com> Date: Sat, 18 Nov 2023 09:55:50 +1100 Subject: [PATCH] ~fixed linter issues --- src/builders/sitemap.ts | 4 +++- src/utils/__tests__/rate-limiter.test.ts | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/builders/sitemap.ts b/src/builders/sitemap.ts index c56949a..a41be2e 100644 --- a/src/builders/sitemap.ts +++ b/src/builders/sitemap.ts @@ -155,7 +155,9 @@ async function IngestRoutes(params: GetSitemapParams) { return (await Promise.all(entriesPromise)).flat().filter(truthy); } else { - const entriesPromise = routes.map(route => getEntry({ route, config, context, request })); + const entriesPromise = routes.map(route => + getEntry({ route, config, context, request + })); return (await Promise.all(entriesPromise)).flat().filter(truthy); } diff --git a/src/utils/__tests__/rate-limiter.test.ts b/src/utils/__tests__/rate-limiter.test.ts index d60d3db..be9841f 100644 --- a/src/utils/__tests__/rate-limiter.test.ts +++ b/src/utils/__tests__/rate-limiter.test.ts @@ -4,12 +4,15 @@ describe('RateLimiter', () => { it('should not allow more than the rate limit to run concurrently', async () => { const limit = new RateLimiter(3); let activeTasks = 0; + const increaseActive = () => { activeTasks++; }; + const decreaseActive = () => { activeTasks--; limit.free(); }; + const tasks = Array(5) .fill(null).map(async () => { await limit.allocate(); @@ -23,17 +26,17 @@ describe('RateLimiter', () => { ); decreaseActive(); }); - await Promise.all(tasks); + await Promise.all(tasks); }); it('should queue tasks and execute them in order', async () => { - const limit = new RateLimiter(2); + const limit = new RateLimiter(1); let taskOrder: number[] = []; - const mockTask = async (id) => { + const mockTask = async (id: number) => { await limit.allocate(); // Make each task successively longer to ensure execution completion order - await new Promise(resolve => setTimeout(resolve, 500 + 500*id)); + await new Promise(resolve => setTimeout(resolve, 100 + 500 * id)); taskOrder.push(id); limit.free(); @@ -55,15 +58,16 @@ describe('RateLimiter', () => { expect(limit.getProcessing()).toBeLessThanOrEqual(maxConcurrent); // Mock task duration (randomness to affect completion order) - await new Promise(resolve => setTimeout(resolve, 500*Math.random())); + await new Promise(resolve => setTimeout(resolve, 500 * Math.random())); expect(limit.getProcessing()).toBeLessThanOrEqual(maxConcurrent); limit.free(); }; - - const tasks = Array(100).fill().map(_ => mockTask); - await Promise.all(tasks); + await Promise.all(Array(100) + .fill(0) + .map(_ => mockTask()) + ); expect(limit.getProcessing()).toEqual(0); expect(limit.getWaiting()).toEqual(0);