File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
tests/MongoDB.Driver.Tests/Specifications/change-streams Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 15
15
16
16
using System ;
17
17
using System . Collections . Generic ;
18
+ using System . Diagnostics ;
18
19
using System . Linq ;
19
20
using System . Threading ;
20
21
using FluentAssertions ;
@@ -280,19 +281,19 @@ private List<ChangeStreamDocument<BsonDocument>> ReadChangeStreamDocuments(IAsyn
280
281
{
281
282
var result = new List < ChangeStreamDocument < BsonDocument > > ( ) ;
282
283
var resultDocument = test[ "result" ] . AsBsonDocument ;
283
- if ( ! resultDocument . TryGetValue ( "success" , out var successNode ) )
284
- {
285
- // skip an empty batch which is the result of an initial "aggregate" change stream request
286
- // next `MoveNext` will call a server
287
- cursor . MoveNext ( ) ;
288
- }
289
- int expectedNumberOfDocuments = successNode ? . AsBsonArray . Count ?? 0 ;
284
+ var successNode = resultDocument. GetValue( "success" , null ) ? . AsBsonArray ;
290
285
286
+ var stopwatch = Stopwatch. StartNew( ) ;
291
287
while ( async ? cursor . MoveNextAsync( ) . GetAwaiter ( ) . GetResult( ) : cursor . MoveNext ( ) )
292
288
{
293
289
result . AddRange ( cursor . Current ) ;
294
290
295
- if ( result . Count >= expectedNumberOfDocuments )
291
+ if ( successNode != null && result . Count >= successNode . Count )
292
+ {
293
+ break ;
294
+ }
295
+
296
+ if ( stopwatch . Elapsed > TimeSpan . FromSeconds ( 10 ) ) // 10 seconds is enough time to receive all the required change documents or for an exception to be thrown
296
297
{
297
298
break ;
298
299
}
You can’t perform that action at this time.
0 commit comments