66 validateToolMetadata ,
77 validateThrowsForInvalidArguments ,
88 databaseCollectionInvalidArgs ,
9+ sleep ,
910} from "../../../helpers.js" ;
1011import type { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver" ;
1112import type { SearchIndexStatus } from "../../../../../src/tools/mongodb/search/listSearchIndexes.js" ;
@@ -102,16 +103,18 @@ describeWithMongoDB(
102103 { search : true } // use a search cluster
103104) ;
104105
106+ const SEARCH_RETRIES = 10_000 ;
105107async function waitUntilSearchIsReady ( provider : NodeDriverServiceProvider , abortSignal : AbortSignal ) : Promise < void > {
106108 let success = true ;
107- for ( let i = 0 ; i < 1000 && ! abortSignal . aborted ; i ++ ) {
109+ for ( let i = 0 ; i < SEARCH_RETRIES && ! abortSignal . aborted ; i ++ ) {
108110 try {
109111 await provider . insertOne ( "tmp" , "test" , { field1 : "yay" } ) ;
110112 await provider . createSearchIndexes ( "tmp" , "test" , [ { definition : { mappings : { dynamic : true } } } ] ) ;
111113 success = true ;
112114 break ;
113115 } catch ( err ) {
114116 void err ;
117+ await sleep ( 100 ) ;
115118 }
116119 }
117120
@@ -128,7 +131,7 @@ async function waitUntilIndexIsQueryable(
128131 abortSignal : AbortSignal
129132) : Promise < void > {
130133 let success = false ;
131- for ( let i = 0 ; i < 1000 && ! abortSignal . aborted ; i ++ ) {
134+ for ( let i = 0 ; i < SEARCH_RETRIES && ! abortSignal . aborted ; i ++ ) {
132135 try {
133136 const [ indexStatus ] = await provider . getSearchIndexes ( database , collection , indexName ) ;
134137 if ( indexStatus ?. queryable === true ) {
@@ -137,6 +140,7 @@ async function waitUntilIndexIsQueryable(
137140 }
138141 } catch ( err ) {
139142 void err ;
143+ await sleep ( 100 ) ;
140144 }
141145 }
142146
0 commit comments