summaryrefslogtreecommitdiff
path: root/jstests/change_streams/change_stream.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/change_streams/change_stream.js')
-rw-r--r--jstests/change_streams/change_stream.js38
1 files changed, 21 insertions, 17 deletions
diff --git a/jstests/change_streams/change_stream.js b/jstests/change_streams/change_stream.js
index c1415a2a1f5..80356aa3b48 100644
--- a/jstests/change_streams/change_stream.js
+++ b/jstests/change_streams/change_stream.js
@@ -2,13 +2,14 @@
(function() {
"use strict";
+ load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Collection.
load("jstests/libs/change_stream_util.js");
load('jstests/libs/uuid_util.js');
let cst = new ChangeStreamTest(db);
jsTestLog("Testing single insert");
- db.t1.drop();
+ assertDropCollection(db, "t1");
let cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1});
// Test that if there are no changes, we return an empty batch.
assert.eq(0, cursor.firstBatch.length, "Cursor had changes: " + tojson(cursor));
@@ -40,7 +41,7 @@
jsTestLog("Testing update");
cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1});
- assert.writeOK(db.t1.update({_id: 0}, {a: 3}));
+ assert.writeOK(db.t1.update({_id: 0}, {_id: 0, a: 3}));
expected = {
documentKey: {_id: 0},
fullDocument: {_id: 0, a: 3},
@@ -51,7 +52,7 @@
jsTestLog("Testing update of another field");
cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1});
- assert.writeOK(db.t1.update({_id: 0}, {b: 3}));
+ assert.writeOK(db.t1.update({_id: 0}, {_id: 0, b: 3}));
expected = {
documentKey: {_id: 0},
fullDocument: {_id: 0, b: 3},
@@ -62,7 +63,7 @@
jsTestLog("Testing upsert");
cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1});
- assert.writeOK(db.t1.update({_id: 2}, {a: 4}, {upsert: true}));
+ assert.writeOK(db.t1.update({_id: 2}, {_id: 2, a: 4}, {upsert: true}));
expected = {
documentKey: {_id: 2},
fullDocument: {_id: 2, a: 4},
@@ -94,6 +95,7 @@
cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]});
jsTestLog("Testing intervening write on another collection");
+ assertDropCollection(db, "t2");
cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1});
let t2cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t2});
assert.writeOK(db.t2.insert({_id: 100, c: 1}));
@@ -109,25 +111,28 @@
jsTestLog("Testing drop of unrelated collection");
assert.writeOK(db.dropping.insert({}));
- db.dropping.drop();
+ assertDropCollection(db, db.dropping.getName());
// Should still see the previous change from t2, shouldn't see anything about 'dropping'.
- jsTestLog("Testing rename");
- db.t3.drop();
- t2cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t2});
- assert.writeOK(db.t2.renameCollection("t3"));
- expected = {operationType: "invalidate"};
- cst.assertNextChangesEqual(
- {cursor: t2cursor, expectedChanges: [expected], expectInvalidate: true});
+ // Test collection renaming. Sharded collections cannot be renamed.
+ if (!db.t2.stats().sharded) {
+ jsTestLog("Testing rename");
+ assertDropCollection(db, "t3");
+ t2cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t2});
+ assert.writeOK(db.t2.renameCollection("t3"));
+ expected = {operationType: "invalidate"};
+ cst.assertNextChangesEqual(
+ {cursor: t2cursor, expectedChanges: [expected], expectInvalidate: true});
+ }
jsTestLog("Testing insert that looks like rename");
- db.dne1.drop();
- db.dne2.drop();
+ assertDropCollection(db, "dne1");
+ assertDropCollection(db, "dne2");
const dne1cursor =
cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.dne1});
const dne2cursor =
cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.dne2});
- assert.writeOK(db.t3.insert({_id: 101, renameCollection: "test.dne1", to: "test.dne2"}));
+ assert.writeOK(db.t2.insert({_id: 101, renameCollection: "test.dne1", to: "test.dne2"}));
cst.assertNextChangesEqual({cursor: dne1cursor, expectedChanges: []});
cst.assertNextChangesEqual({cursor: dne2cursor, expectedChanges: []});
@@ -144,8 +149,7 @@
}
jsTestLog("Testing resumability");
- db.resume1.drop();
- assert.commandWorked(db.createCollection("resume1"));
+ assertDropAndRecreateCollection(db, "resume1");
// Note we do not project away 'id.ts' as it is part of the resume token.
let resumeCursor = cst.startWatchingChanges(