@@ -17,6 +17,7 @@ import {
1717 type ConnectionCheckOutStartedEvent ,
1818 type ConnectionClosedEvent ,
1919 type ConnectionCreatedEvent ,
20+ type ConnectionPool ,
2021 type ConnectionPoolClearedEvent ,
2122 type ConnectionPoolClosedEvent ,
2223 type ConnectionPoolCreatedEvent ,
@@ -39,6 +40,8 @@ import {
3940 type ServerHeartbeatStartedEvent ,
4041 type ServerHeartbeatSucceededEvent ,
4142 type ServerOpeningEvent ,
43+ Timeout ,
44+ TimeoutError ,
4245 type TopologyClosedEvent ,
4346 type TopologyDescription ,
4447 type TopologyDescriptionChangedEvent ,
@@ -622,6 +625,26 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
622625 try {
623626 new EntityEventRegistry ( client , entity . client , map ) . register ( ) ;
624627 await client . connect ( ) ;
628+ if ( entity . client . awaitMinPoolSizeMS ) {
629+ if ( client . topology ?. s ?. servers ) {
630+ for ( const server of client . topology . s . servers . values ( ) ) {
631+ const pool = server . pool ;
632+ const timeout = Timeout . expires ( entity . client . awaitMinPoolSizeMS ) ;
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 ( ) ;
644+ }
645+ }
646+ }
647+ }
625648 } catch ( error ) {
626649 console . error ( 'failed to connect entity' , entity ) ;
627650 // In the case where multiple clients are defined in the test and any one of them failed
@@ -721,3 +744,12 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
721744 return map ;
722745 }
723746}
747+
748+ function checkMinPoolSize ( pool : ConnectionPool ) : Promise < boolean > {
749+ 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 ) ;
754+ } ) ;
755+ }
0 commit comments