Skip to content

Commit c823e36

Browse files
committed
test(async): use FakeTime in pooledMap testing
1 parent 1dee498 commit c823e36

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

async/pool_test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ import {
88
assertRejects,
99
assertStringIncludes,
1010
} from "@std/assert";
11+
import { FakeTime } from "@std/testing/time";
1112

1213
Deno.test("pooledMap()", async () => {
13-
const start = performance.now();
14+
using time = new FakeTime();
15+
16+
const start = Date.now();
1417
const results = pooledMap(
1518
2,
1619
[1, 2, 3],
1720
(i) => new Promise<number>((r) => setTimeout(() => r(i), 300)),
1821
);
19-
const array = await Array.fromAsync(results);
22+
const promise = Array.fromAsync(results);
23+
for (const _ of Array(7)) {
24+
time.tick(100);
25+
await time.runMicrotasks();
26+
}
27+
const array = await promise;
2028
assertEquals(array, [1, 2, 3]);
21-
const diff = performance.now() - start;
29+
const diff = Date.now() - start;
2230

2331
assertGreaterOrEqual(diff, 600);
2432
assertLess(diff, 900);

0 commit comments

Comments
 (0)