Skip to content

Commit c0c973a

Browse files
committed
CSHARP-4046: getMore helper should explicitly send inherited comment
1 parent 44eb24b commit c0c973a

File tree

17 files changed

+177
-27
lines changed

17 files changed

+177
-27
lines changed

src/MongoDB.Driver.Core/Core/Operations/AggregateOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ private AsyncCursor<TResult> CreateCursorFromCursorResult(IChannelSourceHandle c
401401
return new AsyncCursor<TResult>(
402402
getMoreChannelSource,
403403
result.CollectionNamespace,
404+
_comment,
404405
result.Results,
405406
cursorId,
406407
result.PostBatchResumeToken,
@@ -416,6 +417,7 @@ private AsyncCursor<TResult> CreateCursorFromInlineResult(AggregateResult result
416417
return new AsyncCursor<TResult>(
417418
null, // channelSource
418419
CollectionNamespace,
420+
_comment,
419421
result.Results,
420422
0, // cursorId
421423
null, // postBatchResumeToken

src/MongoDB.Driver.Core/Core/Operations/AsyncCursor.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class AsyncCursor<TDocument> : IAsyncCursor<TDocument>, ICursorBatchInfo
4949
private readonly CollectionNamespace _collectionNamespace;
5050
private IChannelSource _channelSource;
5151
private bool _closed;
52+
private readonly BsonValue _comment;
5253
private int _count;
5354
private IReadOnlyList<TDocument> _currentBatch;
5455
private long _cursorId;
@@ -68,6 +69,7 @@ public class AsyncCursor<TDocument> : IAsyncCursor<TDocument>, ICursorBatchInfo
6869
/// </summary>
6970
/// <param name="channelSource">The channel source.</param>
7071
/// <param name="collectionNamespace">The collection namespace.</param>
72+
/// <param name="comment">The comment.</param>
7173
/// <param name="firstBatch">The first batch.</param>
7274
/// <param name="cursorId">The cursor identifier.</param>
7375
/// <param name="batchSize">The size of a batch.</param>
@@ -78,6 +80,7 @@ public class AsyncCursor<TDocument> : IAsyncCursor<TDocument>, ICursorBatchInfo
7880
public AsyncCursor(
7981
IChannelSource channelSource,
8082
CollectionNamespace collectionNamespace,
83+
BsonValue comment,
8184
IReadOnlyList<TDocument> firstBatch,
8285
long cursorId,
8386
int? batchSize,
@@ -88,6 +91,7 @@ public AsyncCursor(
8891
: this(
8992
channelSource,
9093
collectionNamespace,
94+
comment,
9195
firstBatch,
9296
cursorId,
9397
null, // postBatchResumeToken
@@ -169,6 +173,7 @@ public AsyncCursor(
169173
: this(
170174
channelSource,
171175
collectionNamespace,
176+
comment: null,
172177
firstBatch,
173178
cursorId,
174179
postBatchResumeToken,
@@ -185,6 +190,7 @@ public AsyncCursor(
185190
/// </summary>
186191
/// <param name="channelSource">The channel source.</param>
187192
/// <param name="collectionNamespace">The collection namespace.</param>
193+
/// <param name="comment">The comment.</param>
188194
/// <param name="firstBatch">The first batch.</param>
189195
/// <param name="cursorId">The cursor identifier.</param>
190196
/// <param name="postBatchResumeToken">The post batch resume token.</param>
@@ -196,6 +202,7 @@ public AsyncCursor(
196202
public AsyncCursor(
197203
IChannelSource channelSource,
198204
CollectionNamespace collectionNamespace,
205+
BsonValue comment,
199206
IReadOnlyList<TDocument> firstBatch,
200207
long cursorId,
201208
BsonDocument postBatchResumeToken,
@@ -207,6 +214,7 @@ public AsyncCursor(
207214
{
208215
_operationId = EventContext.OperationId;
209216
_channelSource = channelSource;
217+
_comment = comment;
210218
_collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace));
211219
_firstBatch = Ensure.IsNotNull(firstBatch, nameof(firstBatch));
212220
_cursorId = cursorId;
@@ -326,7 +334,8 @@ private BsonDocument CreateGetMoreCommand()
326334
{ "getMore", _cursorId },
327335
{ "collection", _collectionNamespace.CollectionName },
328336
{ "batchSize", () => CalculateGetMoreNumberToReturn(), _batchSize > 0 || _limit > 0 },
329-
{ "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }
337+
{ "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
338+
{ "comment", _comment, _comment != null },
330339
};
331340

332341
return command;

src/MongoDB.Driver.Core/Core/Operations/FindOperation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ private AsyncCursor<TDocument> CreateCursor(IChannelSourceHandle channelSource,
553553
return new AsyncCursor<TDocument>(
554554
getMoreChannelSource,
555555
collectionNamespace,
556+
_comment,
556557
firstBatch.Documents,
557558
firstBatch.CursorId,
558559
_batchSize,

src/MongoDB.Driver.Core/Core/Operations/ListCollectionsOperation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ private IAsyncCursor<BsonDocument> CreateCursor(IChannelSourceHandle channelSour
221221
var cursor = new AsyncCursor<BsonDocument>(
222222
getMoreChannelSource,
223223
CollectionNamespace.FromFullName(cursorDocument["ns"].AsString),
224+
_comment,
224225
cursorDocument["firstBatch"].AsBsonArray.OfType<BsonDocument>().ToList(),
225226
cursorId,
226227
batchSize: _batchSize ?? 0,

src/MongoDB.Driver.Core/Core/Operations/ListIndexesUsingCommandOperation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ private IAsyncCursor<BsonDocument> CreateCursor(IChannelSourceHandle channelSour
198198
var cursor = new AsyncCursor<BsonDocument>(
199199
getMoreChannelSource,
200200
CollectionNamespace.FromFullName(cursorDocument["ns"].AsString),
201+
_comment,
201202
cursorDocument["firstBatch"].AsBsonArray.OfType<BsonDocument>().ToList(),
202203
cursorId,
203204
batchSize: _batchSize ?? 0,

src/MongoDB.Driver.Core/Core/Operations/ParallelScanOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ private IReadOnlyList<IAsyncCursor<TDocument>> CreateCursors(IChannelSourceHandl
180180
var cursor = new AsyncCursor<TDocument>(
181181
getMoreChannelSource.Fork(),
182182
_collectionNamespace,
183+
comment: null,
183184
firstBatch,
184185
cursorId,
185186
_batchSize ?? 0,
186-
0, // limit
187+
limit: 0,
187188
_serializer,
188189
_messageEncoderSettings);
189190

tests/MongoDB.Driver.Core.Tests/Core/Operations/AsyncCursorEnumeratorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private AsyncCursorEnumerator<BsonDocument> CreateSubject(int count)
180180
var cursor = new AsyncCursor<BsonDocument>(
181181
channelSource: new Mock<IChannelSource>().Object,
182182
collectionNamespace: new CollectionNamespace("foo", "bar"),
183+
comment: null,
183184
firstBatch: firstBatch,
184185
cursorId: 0,
185186
batchSize: null,

tests/MongoDB.Driver.Core.Tests/Core/Operations/AsyncCursorTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public void constructor_should_initialize_instance()
194194
var result = new AsyncCursor<BsonDocument>(
195195
channelSource,
196196
collectionNamespace,
197+
comment: null,
197198
firstBatch,
198199
cursorId,
199200
batchSize,
@@ -496,6 +497,7 @@ private AsyncCursor<BsonDocument> CreateSubject(
496497
return new AsyncCursor<BsonDocument>(
497498
channelSource.WithDefault(new Mock<IChannelSource>().Object),
498499
collectionNamespace.WithDefault(new CollectionNamespace("test", "test")),
500+
comment: null,
499501
firstBatch.WithDefault(new List<BsonDocument>()),
500502
cursorId.WithDefault(0),
501503
batchSize.WithDefault(null),
@@ -661,7 +663,7 @@ public void Session_reference_count_should_be_decremented_as_soon_as_possible(in
661663
long cursorId;
662664
var firstBatch = GetFirstBatch(channel, query, batchSize, cancellationToken, out cursorId);
663665

664-
using (var cursor = new AsyncCursor<BsonDocument>(channelSource, _collectionNamespace, firstBatch, cursorId, batchSize, null, BsonDocumentSerializer.Instance, new MessageEncoderSettings()))
666+
using (var cursor = new AsyncCursor<BsonDocument>(channelSource, _collectionNamespace, comment: null, firstBatch, cursorId, batchSize, null, BsonDocumentSerializer.Instance, new MessageEncoderSettings()))
665667
{
666668
AssertExpectedSessionReferenceCount(_session, cursor);
667669
while (cursor.MoveNext(cancellationToken))

tests/MongoDB.Driver.Core.Tests/Core/Operations/CursorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void Constructor_should_call_Dispose_on_channelSource_if_cursorId_is_zero
3232
new AsyncCursor<BsonDocument>(
3333
mockChannelSource.Object,
3434
new CollectionNamespace("databaseName", "collectionName"),
35+
comment: null,
3536
new BsonDocument[0], // firstBatch
3637
cursorId,
3738
null, // batchSize

tests/MongoDB.Driver.Core.Tests/IAsyncCursorExtensionsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ private IAsyncCursor<BsonDocument> CreateCursor(int count)
284284
return new AsyncCursor<BsonDocument>(
285285
channelSource: new Mock<IChannelSource>().Object,
286286
collectionNamespace: new CollectionNamespace("foo", "bar"),
287+
comment: null,
287288
firstBatch: firstBatch,
288289
cursorId: 0,
289290
batchSize: null,

0 commit comments

Comments
 (0)