diff options
Diffstat (limited to 'jstests/change_streams/include_cluster_time.js')
-rw-r--r-- | jstests/change_streams/include_cluster_time.js | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/jstests/change_streams/include_cluster_time.js b/jstests/change_streams/include_cluster_time.js index 387c368ecc1..6d0c33785e8 100644 --- a/jstests/change_streams/include_cluster_time.js +++ b/jstests/change_streams/include_cluster_time.js @@ -2,16 +2,12 @@ (function() { "use strict"; - load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Collection. + load("jstests/libs/collection_drop_recreate.js"); // For assertDropAndRecreateCollection. // Drop and recreate the collections to be used in this set of tests. const coll = assertDropAndRecreateCollection(db, "include_cluster_time"); - const collectionStream = coll.watch(); - const dbStream = - db.watch([{$match: {$or: [{operationType: "invalidate"}, {"ns.coll": coll.getName()}]}}]); - const clusterStream = db.getMongo().watch( - [{$match: {$or: [{operationType: "invalidate"}, {"ns.coll": coll.getName()}]}}]); + const changeStream = coll.watch(); const insertClusterTime = assert.commandWorked(coll.runCommand("insert", {documents: [{_id: 0}]})) @@ -30,34 +26,30 @@ const dropClusterTime = assert.commandWorked(db.runCommand({drop: coll.getName()})).$clusterTime.clusterTime; - for (let changeStream of[collectionStream, dbStream, clusterStream]) { - jsTestLog(`Testing stream on ns ${changeStream._ns}`); - - // Make sure each operation has a reasonable cluster time. Note that we should not assert - // that the cluster times are equal, because the cluster time returned from the command is - // generated by a second, independent read of the logical clock than the one used to - // generate the oplog entry. It's possible that the system did something to advance the time - // between the two reads of the clock. - assert.soon(() => changeStream.hasNext()); - let next = changeStream.next(); - assert.eq(next.operationType, "insert"); - assert.lte(next.clusterTime, insertClusterTime); - - assert.soon(() => changeStream.hasNext()); - next = changeStream.next(); - assert.eq(next.operationType, "update"); - assert.lte(next.clusterTime, updateClusterTime); - - assert.soon(() => changeStream.hasNext()); - next = changeStream.next(); - assert.eq(next.operationType, "delete"); - assert.lte(next.clusterTime, deleteClusterTime); - - assert.soon(() => changeStream.hasNext()); - next = changeStream.next(); - assert.eq(next.operationType, "invalidate"); - assert.lte(next.clusterTime, dropClusterTime); - - changeStream.close(); - } + // Make sure each operation has a reasonable cluster time. Note that we should not assert + // that the cluster times are equal, because the cluster time returned from the command is + // generated by a second, independent read of the logical clock than the one used to + // generate the oplog entry. It's possible that the system did something to advance the time + // between the two reads of the clock. + assert.soon(() => changeStream.hasNext()); + let next = changeStream.next(); + assert.eq(next.operationType, "insert"); + assert.lte(next.clusterTime, insertClusterTime); + + assert.soon(() => changeStream.hasNext()); + next = changeStream.next(); + assert.eq(next.operationType, "update"); + assert.lte(next.clusterTime, updateClusterTime); + + assert.soon(() => changeStream.hasNext()); + next = changeStream.next(); + assert.eq(next.operationType, "delete"); + assert.lte(next.clusterTime, deleteClusterTime); + + assert.soon(() => changeStream.hasNext()); + next = changeStream.next(); + assert.eq(next.operationType, "invalidate"); + assert.lte(next.clusterTime, dropClusterTime); + + changeStream.close(); }()); |