@@ -19,8 +19,8 @@ internal sealed class MongoTestStore : TestStore
1919
2020 private MongoDbContainer ? _container ;
2121
22- private MongoClient ? _client ;
23- private IMongoDatabase ? _database ;
22+ public MongoClient ? _client { get ; private set ; }
23+ public IMongoDatabase ? _database { get ; private set ; }
2424
2525 public MongoClient Client => this . _client ?? throw new InvalidOperationException ( "Not initialized" ) ;
2626 public IMongoDatabase Database => this . _database ?? throw new InvalidOperationException ( "Not initialized" ) ;
@@ -46,8 +46,8 @@ protected override async Task StartAsync()
4646 private async Task < MongoClientSettings > StartMongoDbContainerAsync ( )
4747 {
4848 this . _container = new MongoDbBuilder ( )
49- . WithImage ( "mongodb/mongodb-atlas-local:latest " )
50- . WithWaitStrategy ( Wait . ForUnixContainer ( ) . AddCustomWaitStrategy ( new WaitForVectorIndexService ( ) ) )
49+ . WithImage ( "mongodb/mongodb-atlas-local:7.0.6 " )
50+ . WithWaitStrategy ( Wait . ForUnixContainer ( ) . AddCustomWaitStrategy ( new MongoDbWaitUntil ( ) ) )
5151 . Build ( ) ;
5252
5353 using CancellationTokenSource cts = new ( ) ;
@@ -84,56 +84,15 @@ protected override async Task StopAsync()
8484 }
8585 }
8686
87- private sealed class WaitForVectorIndexService : IWaitUntil
87+ private sealed class MongoDbWaitUntil : IWaitUntil
8888 {
89+ /// <inheritdoc />
8990 public async Task < bool > UntilAsync ( IContainer container )
9091 {
91- var connectionString = $ "mongodb://{ container . Hostname } :{ container . GetMappedPublicPort ( 27017 ) . ToString ( ) } ?directConnection=true";
92- using var client = new MongoClient ( connectionString ) ;
93- var databaseName = Guid . NewGuid ( ) . ToString ( ) ;
94- var weGood = false ;
95-
96- try
97- {
98- var database = client . GetDatabase ( databaseName ) ;
99- var collectionName = Guid . NewGuid ( ) . ToString ( ) ;
100- await database . CreateCollectionAsync ( collectionName ) ;
101-
102- var model = new CreateSearchIndexModel (
103- Guid . NewGuid ( ) . ToString ( ) ,
104- SearchIndexType . VectorSearch ,
105- BsonDocument . Parse (
106- """
107- {
108- "fields": [
109- {
110- "type": "vector",
111- "path": "Dummy",
112- "numDimensions": 8,
113- "similarity": "cosine"
114- }
115- ]
116- }
117- """ ) ) ;
118-
119- await database . GetCollection < BsonDocument > ( collectionName ) . SearchIndexes . CreateOneAsync ( model ) ;
120- weGood = true ;
121- }
122- catch
123- {
124- // Intentionally ignored.
125- }
126-
127- try
128- {
129- await client . DropDatabaseAsync ( databaseName ) ;
130- }
131- catch
132- {
133- // Intentionally ignored.
134- }
135-
136- return weGood ;
92+ var ( stdout , _) = await container . GetLogsAsync ( timestampsEnabled : false )
93+ . ConfigureAwait ( false ) ;
94+
95+ return stdout . Contains ( "\" msg\" :\" Waiting for connections\" " ) ;
13796 }
13897 }
13998}
0 commit comments