Skip to content

Commit d31c026

Browse files
CSHARP-2891: Fix Change Stream should error when _id is projected out assertion.
1 parent 910e9da commit d31c026

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

tests/MongoDB.Driver.Tests/Specifications/change-streams/ChangeStreamTestRunner.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18+
using System.Diagnostics;
1819
using System.Linq;
1920
using System.Threading;
2021
using FluentAssertions;
@@ -280,19 +281,19 @@ private List<ChangeStreamDocument<BsonDocument>> ReadChangeStreamDocuments(IAsyn
280281
{
281282
var result = new List<ChangeStreamDocument<BsonDocument>>();
282283
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;
290285

286+
var stopwatch = Stopwatch.StartNew();
291287
while (async ? cursor.MoveNextAsync().GetAwaiter().GetResult() : cursor.MoveNext())
292288
{
293289
result.AddRange(cursor.Current);
294290

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
296297
{
297298
break;
298299
}

0 commit comments

Comments
 (0)