Skip to content

Commit

Permalink
~fixed linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed Nov 17, 2023
1 parent 0239548 commit 55b7bfa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/builders/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 159 in src/builders/sitemap.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `·})`
}));

Check failure on line 160 in src/builders/sitemap.ts

View workflow job for this annotation

GitHub Actions / Lint

Delete `})`

return (await Promise.all(entriesPromise)).flat().filter(truthy);
}
Expand Down
20 changes: 12 additions & 8 deletions src/utils/__tests__/rate-limiter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check failure on line 13 in src/utils/__tests__/rate-limiter.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎·····`
};

const tasks = Array(5)
.fill(null).map(async () => {

Check failure on line 17 in src/utils/__tests__/rate-limiter.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎······`
await limit.allocate();
Expand All @@ -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[] = [];

Check failure on line 34 in src/utils/__tests__/rate-limiter.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'taskOrder' is never reassigned. Use 'const' instead
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();
Expand All @@ -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)

Check failure on line 67 in src/utils/__tests__/rate-limiter.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎······`
.fill(0)

Check failure on line 68 in src/utils/__tests__/rate-limiter.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`
.map(_ => mockTask())

Check failure on line 69 in src/utils/__tests__/rate-limiter.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `··`

Check warning on line 69 in src/utils/__tests__/rate-limiter.test.ts

View workflow job for this annotation

GitHub Actions / Lint

'_' is defined but never used
);

expect(limit.getProcessing()).toEqual(0);
expect(limit.getWaiting()).toEqual(0);
Expand Down

0 comments on commit 55b7bfa

Please sign in to comment.