@@ -132,14 +132,10 @@ public void Run(
132132 KillOpenTransactions ( DriverTestConfiguration . Client ) ;
133133 }
134134
135- _entityMap = UnifiedEntityMap . Create ( _eventFormatters , _loggingService . LoggingSettings , async) ;
135+ BsonDocument lastKnownClusterTime = AddInitialData ( DriverTestConfiguration . Client , initialData ) ;
136+ _entityMap = UnifiedEntityMap . Create ( _eventFormatters , _loggingService . LoggingSettings , async, lastKnownClusterTime ) ;
136137 _entityMap . AddRange ( entities ) ;
137138
138- if ( initialData != null )
139- {
140- AddInitialData ( DriverTestConfiguration . Client , initialData , _entityMap ) ;
141- }
142-
143139 foreach ( var operation in operations )
144140 {
145141 var cancellationToken = CancellationToken . None ;
@@ -181,45 +177,36 @@ public void Dispose()
181177 }
182178
183179 // private methods
184- private void AddInitialData ( IMongoClient client , BsonArray initialData , UnifiedEntityMap entityMap )
180+ private BsonDocument AddInitialData ( IMongoClient client , BsonArray initialData )
185181 {
186- var mongoCollectionSettings = new MongoCollectionSettings ( ) ;
187-
188- var writeConcern = WriteConcern . WMajority ;
189- if ( DriverTestConfiguration . IsReplicaSet ( client ) )
182+ if ( initialData == null )
190183 {
191- // Makes server to wait for ack from all data nodes to make sure the test data availability before running the test itself.
192- // It's limited to replica set only because there is no simple way to calculate proper w for sharded cluster.
193- var dataBearingServersCount = DriverTestConfiguration . GetReplicaSetNumberOfDataBearingMembers ( client ) ;
194- writeConcern = WriteConcern . Acknowledged . With ( w : dataBearingServersCount , journal : true ) ;
184+ return null ;
195185 }
196186
197- BsonDocument serverTime = null ;
187+ BsonDocument lastKnownClusterTime = null ;
198188 foreach ( var dataItem in initialData )
199189 {
200190 var collectionName = dataItem [ "collectionName" ] . AsString ;
201191 var databaseName = dataItem [ "databaseName" ] . AsString ;
202192 var documents = dataItem [ "documents" ] . AsBsonArray . Cast < BsonDocument > ( ) . ToList ( ) ;
203193
204- var database = client . GetDatabase ( databaseName ) . WithWriteConcern ( writeConcern ) ;
205- var collection = database . GetCollection < BsonDocument > ( collectionName , mongoCollectionSettings ) ;
194+ var database = client . GetDatabase ( databaseName ) . WithWriteConcern ( WriteConcern . WMajority ) ;
206195
207196 _logger . LogDebug ( "Dropping {0}" , collectionName ) ;
208- var session = client . StartSession ( ) ;
197+ using var session = client . StartSession ( ) ;
209198 database . DropCollection ( session , collectionName ) ;
199+ database . CreateCollection ( session , collectionName ) ;
210200 if ( documents . Any ( ) )
211201 {
202+ var collection = database . GetCollection < BsonDocument > ( collectionName ) ;
212203 collection . InsertMany ( session , documents ) ;
213204 }
214- else
215- {
216- database . CreateCollection ( session , collectionName ) ;
217- }
218205
219- serverTime = session . ClusterTime ;
206+ lastKnownClusterTime = session . ClusterTime ;
220207 }
221208
222- entityMap . AdjustSessionsClusterTime ( serverTime ) ;
209+ return lastKnownClusterTime ;
223210 }
224211
225212 private void AssertEvents ( BsonArray eventItems , UnifiedEntityMap entityMap )
0 commit comments