diff options
-rw-r--r-- | jstests/change_streams/report_post_batch_resume_token.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/jstests/change_streams/report_post_batch_resume_token.js b/jstests/change_streams/report_post_batch_resume_token.js index 37f5f6cea3f..219fd4078b9 100644 --- a/jstests/change_streams/report_post_batch_resume_token.js +++ b/jstests/change_streams/report_post_batch_resume_token.js @@ -224,4 +224,26 @@ assert.gt(bsonWoCompare(txnEvent3._id, previousGetMorePBRT), 0); // appear in the batch. Confirm that the postBatchResumeToken has been set correctly. getMorePBRT = csCursor.getResumeToken(); assert.gte(bsonWoCompare(getMorePBRT, txnEvent3._id), 0); + +// Watch a collection, drop it, and then resume before the invalidate but filter out all events +// This scenario means that we shouldn't get any events but the resume token should still be +// present. This way the pbrt can't come from a document in the batch, and even if there is an +// invalidate the pbrt should still be set. +csCursor = testCollection.watch([], {cursor: {batchSize: 0}}); +assert.eq(csCursor.objsLeftInBatch(), 0); +assert.neq(undefined, csCursor.getResumeToken()); +testCollection.drop(); + +csCursor = testCollection.watch([{$match: {dontMatchAnything: true}}], + {resumeAfter: previousGetMorePBRT, cursor: {batchSize: 0}}); +assert.eq(csCursor.objsLeftInBatch(), 0); +initialAggPBRT = csCursor.getResumeToken(); +assert.neq(undefined, initialAggPBRT); + +// Trigger a getMore and make sure we can get another PBRT. +assert.soon(() => { + csCursor.hasNext(); + assert.neq(undefined, csCursor.getResumeToken()); + return initialAggPBRT != csCursor.getResumeToken(); +}); })(); |