Skip to content

Commit

Permalink
test(async): improve test speed of async/pool_test.ts (#5611)
Browse files Browse the repository at this point in the history
* test(async): improve test speed of `async/pool_test.ts`

* fix
  • Loading branch information
iuioiua authored Aug 2, 2024
1 parent 69a579e commit cd0bc9f
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions async/pool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Deno.test("pooledMap()", async () => {
const results = pooledMap(
2,
[1, 2, 3],
(i) => new Promise<number>((r) => setTimeout(() => r(i), 1000)),
(i) => new Promise<number>((r) => setTimeout(() => r(i), 100)),
);
const array = await Array.fromAsync(results);
assertEquals(array, [1, 2, 3]);
const diff = new Date().getTime() - start.getTime();
assert(diff >= 2000);
assert(diff < 3000);
assert(diff >= 200);
assert(diff < 300);
});

Deno.test("pooledMap() handles errors", async () => {
Expand Down Expand Up @@ -47,19 +47,10 @@ Deno.test("pooledMap() handles errors", async () => {
});

Deno.test("pooledMap() returns ordered items", async () => {
function getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}

const results = pooledMap(
2,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
(i) =>
new Promise<number>((r) =>
setTimeout(() => r(i), getRandomInt(5, 20) * 100)
),
(i) => new Promise<number>((r) => setTimeout(() => r(i), 100 / i)),
);

const returned = await Array.fromAsync(results);
Expand Down

0 comments on commit cd0bc9f

Please sign in to comment.