@@ -51,7 +51,7 @@ public void Run(JsonDrivenTestCase testCase)
51
51
private void Run ( BsonDocument shared , BsonDocument test )
52
52
{
53
53
JsonDrivenHelper . EnsureAllFieldsAreValid ( shared , "_path" , "database_name" , "database2_name" , "collection_name" , "collection2_name" , "tests" ) ;
54
- JsonDrivenHelper . EnsureAllFieldsAreValid ( test , "description" , "minServerVersion" , "topology" , "target" , "changeStreamPipeline" , "changeStreamOptions" , "operations" , "expectations" , "result" ) ;
54
+ JsonDrivenHelper . EnsureAllFieldsAreValid ( test , "description" , "minServerVersion" , "topology" , "target" , "changeStreamPipeline" , "changeStreamOptions" , "operations" , "expectations" , "result" , "async" ) ;
55
55
56
56
if ( test . Contains ( "minServerVersion" ) )
57
57
{
@@ -81,12 +81,13 @@ private void Run(BsonDocument shared, BsonDocument test)
81
81
{
82
82
try
83
83
{
84
- using ( var cursor = Watch ( client , test ) )
84
+ var async = test [ "async" ] . AsBoolean ;
85
+ using ( var cursor = Watch ( client , test , async ) )
85
86
{
86
87
var globalClient = DriverTestConfiguration . Client ;
87
88
ExecuteOperations( globalClient , test [ "operations" ] . AsBsonArray ) ;
88
89
89
- actualResult = ReadChangeStreamDocuments ( cursor , test ) ;
90
+ actualResult = ReadChangeStreamDocuments ( cursor , test , async ) ;
90
91
actualEvents = GetEvents ( eventCapturer ) ;
91
92
}
92
93
}
@@ -173,7 +174,7 @@ private DisposableMongoClient CreateDisposableClient(EventCapturer eventCapturer
173
174
} ) ;
174
175
}
175
176
176
- private IAsyncCursor < ChangeStreamDocument < BsonDocument > > Watch ( IMongoClient client , BsonDocument test )
177
+ private IAsyncCursor< ChangeStreamDocument < BsonDocument > > Watch ( IMongoClient client , BsonDocument test , bool async )
177
178
{
178
179
var target = test[ "target" ] . AsString ;
179
180
var stages = test[ "changeStreamPipeline" ] . AsBsonArray . Cast < BsonDocument > ( ) ;
@@ -182,19 +183,40 @@ private IAsyncCursor<ChangeStreamDocument<BsonDocument>> Watch(IMongoClient clie
182
183
183
184
if ( target = = "client" )
184
185
{
185
- return client . Watch ( pipeline , options ) ;
186
+ if ( async )
187
+ {
188
+ return client . WatchAsync( pipeline , options ) . GetAwaiter ( ) . GetResult( ) ;
189
+ }
190
+ else
191
+ {
192
+ return client . Watch ( pipeline , options ) ;
193
+ }
186
194
}
187
195
188
196
var database = client . GetDatabase ( _databaseName ) ;
189
197
if ( target == "database" )
190
198
{
191
- return database . Watch ( pipeline , options ) ;
199
+ if ( async )
200
+ {
201
+ return database . WatchAsync( pipeline , options ) . GetAwaiter ( ) . GetResult( ) ;
202
+ }
203
+ else
204
+ {
205
+ return database . Watch ( pipeline , options ) ;
206
+ }
192
207
}
193
208
194
209
var collection = database . GetCollection < BsonDocument > ( _collectionName ) ;
195
210
if ( target == "collection" )
196
211
{
197
- return collection . Watch ( pipeline , options ) ;
212
+ if ( async )
213
+ {
214
+ return collection . WatchAsync( pipeline , options ) . GetAwaiter ( ) . GetResult( ) ;
215
+ }
216
+ else
217
+ {
218
+ return collection . Watch ( pipeline , options ) ;
219
+ }
198
220
}
199
221
200
222
throw new FormatException ( $"Invalid target: \" {target}\" ." ) ;
@@ -237,12 +259,12 @@ private List<CommandStartedEvent> GetEvents(EventCapturer eventCapturer)
237
259
return events;
238
260
}
239
261
240
- private List < ChangeStreamDocument < BsonDocument > > ReadChangeStreamDocuments ( IAsyncCursor < ChangeStreamDocument < BsonDocument > > cursor , BsonDocument test )
262
+ private List < ChangeStreamDocument < BsonDocument >> ReadChangeStreamDocuments ( IAsyncCursor < ChangeStreamDocument < BsonDocument > > cursor , BsonDocument test , bool async )
241
263
{
242
264
var result = new List < ChangeStreamDocument < BsonDocument > > ( ) ;
243
265
var expectedNumberOfDocuments = test[ "result" ] [ "success" ] . AsBsonArray . Count ;
244
266
245
- while ( cursor . MoveNext ( ) )
267
+ while ( async ? cursor . MoveNextAsync ( ) . GetAwaiter ( ) . GetResult ( ) : cursor . MoveNext ( ) )
246
268
{
247
269
result . AddRange ( cursor . Current ) ;
248
270
@@ -405,6 +427,20 @@ protected override string PathPrefix
405
427
}
406
428
}
407
429
430
+ // protected methods
431
+ protected override IEnumerable< JsonDrivenTestCase> CreateTestCases( BsonDocument document)
432
+ {
433
+ foreach ( var testCase in base . CreateTestCases( document) )
434
+ {
435
+ foreach ( var async in new [ ] { false, true } )
436
+ {
437
+ var name = $"{ testCase. Name} : async= { async} ";
438
+ var test = testCase. Test. DeepClone( ) . AsBsonDocument. Add( "async", async) ;
439
+ yield return new JsonDrivenTestCase( name, testCase. Shared, test) ;
440
+ }
441
+ }
442
+ }
443
+
408
444
protected override bool ShouldReadJsonDocument( string path)
409
445
{
410
446
return base . ShouldReadJsonDocument( path) ; // && path.EndsWith("change-streams.json");
0 commit comments