Skip to content

Commit f31f4e5

Browse files
committed
chore: comments
1 parent 83360ec commit f31f4e5

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

test/tools/unified-spec-runner/entities.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AssertionError, expect } from 'chai';
22
import { EventEmitter } from 'events';
3+
import { setImmediate } from 'timers';
34

45
import {
56
AbstractCursor,
@@ -628,20 +629,20 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
628629
if (entity.client.awaitMinPoolSizeMS) {
629630
if (client.topology?.s?.servers) {
630631
const timeout = Timeout.expires(entity.client.awaitMinPoolSizeMS);
631-
for (const server of client.topology.s.servers.values()) {
632-
const pool = server.pool;
633-
try {
634-
await Promise.race([checkMinPoolSize(pool), timeout]);
635-
} catch (error) {
636-
if (TimeoutError.is(error)) {
637-
throw new AssertionError(
638-
`Timed out waiting for min pool size to be populated within ${entity.client.awaitMinPoolSizeMS}ms`
639-
);
640-
}
641-
throw error;
642-
} finally {
643-
timeout.clear();
632+
const poolSizeChecks = client.topology.s.servers
633+
.values()
634+
.map(server => checkMinPoolSize(server.pool));
635+
try {
636+
await Promise.race([Promise.allSettled(poolSizeChecks), timeout]);
637+
} catch (error) {
638+
if (TimeoutError.is(error)) {
639+
throw new AssertionError(
640+
`Timed out waiting for min pool size to be populated within ${entity.client.awaitMinPoolSizeMS}ms`
641+
);
644642
}
643+
throw error;
644+
} finally {
645+
timeout.clear();
645646
}
646647
}
647648
}
@@ -747,9 +748,13 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
747748

748749
function checkMinPoolSize(pool: ConnectionPool): Promise<boolean> {
749750
return new Promise(resolve => {
750-
while (pool.options.minPoolSize < pool.totalConnectionCount) {
751-
// Just looping until the min pool size is reached.
752-
}
753-
resolve(true);
751+
const checkSize = () => {
752+
if (pool.totalConnectionCount >= pool.options.minPoolSize) {
753+
resolve(true);
754+
} else {
755+
setImmediate(checkSize);
756+
}
757+
};
758+
checkSize();
754759
});
755760
}

0 commit comments

Comments
 (0)