@@ -62,8 +62,6 @@ export function jestTestMCPClient(): () => Client {
6262export function jestTestCluster ( ) : ( ) => runner . MongoCluster {
6363 let cluster : runner . MongoCluster | undefined ;
6464
65- function runMongodb ( ) { }
66-
6765 beforeAll ( async function ( ) {
6866 // Downloading Windows executables in CI takes a long time because
6967 // they include debug symbols...
@@ -72,7 +70,7 @@ export function jestTestCluster(): () => runner.MongoCluster {
7270
7371 // On Windows, we may have a situation where mongod.exe is not fully released by the OS
7472 // before we attempt to run it again, so we add a retry.
75- const dbsDir = path . join ( tmpDir , "mongodb-runner" , ` dbs` ) ;
73+ let dbsDir = path . join ( tmpDir , "mongodb-runner" , " dbs" ) ;
7674 for ( let i = 0 ; i < 10 ; i ++ ) {
7775 try {
7876 cluster = await MongoCluster . start ( {
@@ -83,10 +81,21 @@ export function jestTestCluster(): () => runner.MongoCluster {
8381
8482 return ;
8583 } catch ( err ) {
86- console . error ( `Failed to start cluster in ${ dbsDir } , attempt ${ i } : ${ err } ` ) ;
87- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
84+ if ( i < 5 ) {
85+ // Just wait a little bit and retry
86+ console . error ( `Failed to start cluster in ${ dbsDir } , attempt ${ i } : ${ err } ` ) ;
87+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
88+ } else {
89+ // If we still fail after 5 seconds, try another db dir
90+ console . error (
91+ `Failed to start cluster in ${ dbsDir } , attempt ${ i } : ${ err } . Retrying with a new db dir.`
92+ ) ;
93+ dbsDir = path . join ( tmpDir , "mongodb-runner" , `dbs${ i - 5 } ` ) ;
94+ }
8895 }
8996 }
97+
98+ throw new Error ( "Failed to start cluster after 10 attempts" ) ;
9099 } , 120_000 ) ;
91100
92101 afterAll ( async function ( ) {
0 commit comments