diff options
author | James Wahlin <james.wahlin@mongodb.com> | 2019-08-14 13:52:59 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-08-14 13:52:59 +0000 |
commit | 39c3a5d77b976e131d37476f2e7255d6058f5093 (patch) | |
tree | 01cc28719f215b17196ec913f475cd8efda9b37d /jstests/change_streams | |
parent | 69d0dd1dc4fb1f78d21c47aa5dd82aa9077b69eb (diff) | |
download | mongo-39c3a5d77b976e131d37476f2e7255d6058f5093.tar.gz |
SERVER-42773 Replace uses of the assert.writeOK() Javascript assertion with assert.commandWorked()
Diffstat (limited to 'jstests/change_streams')
-rw-r--r-- | jstests/change_streams/ban_from_lookup.js | 2 | ||||
-rw-r--r-- | jstests/change_streams/ban_from_views.js | 2 | ||||
-rw-r--r-- | jstests/change_streams/change_stream.js | 46 | ||||
-rw-r--r-- | jstests/change_streams/collation.js | 34 | ||||
-rw-r--r-- | jstests/change_streams/lookup_post_image.js | 38 | ||||
-rw-r--r-- | jstests/change_streams/metadata_notifications.js | 20 | ||||
-rw-r--r-- | jstests/change_streams/only_wake_getmore_for_relevant_changes.js | 8 | ||||
-rw-r--r-- | jstests/change_streams/shell_helper.js | 8 | ||||
-rw-r--r-- | jstests/change_streams/start_at_cluster_time.js | 8 | ||||
-rw-r--r-- | jstests/change_streams/whole_cluster.js | 12 | ||||
-rw-r--r-- | jstests/change_streams/whole_cluster_metadata_notifications.js | 32 | ||||
-rw-r--r-- | jstests/change_streams/whole_cluster_resumability.js | 14 | ||||
-rw-r--r-- | jstests/change_streams/whole_db.js | 8 | ||||
-rw-r--r-- | jstests/change_streams/whole_db_metadata_notifications.js | 30 | ||||
-rw-r--r-- | jstests/change_streams/whole_db_resumability.js | 14 |
15 files changed, 138 insertions, 138 deletions
diff --git a/jstests/change_streams/ban_from_lookup.js b/jstests/change_streams/ban_from_lookup.js index 45d3c692eea..9e2f6ee8c1b 100644 --- a/jstests/change_streams/ban_from_lookup.js +++ b/jstests/change_streams/ban_from_lookup.js @@ -10,7 +10,7 @@ load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Col const coll = assertDropAndRecreateCollection(db, "change_stream_ban_from_lookup"); const foreignColl = "unsharded"; -assert.writeOK(coll.insert({_id: 1})); +assert.commandWorked(coll.insert({_id: 1})); // Verify that we cannot create a $lookup using a pipeline which begins with $changeStream. assertErrorCode( diff --git a/jstests/change_streams/ban_from_views.js b/jstests/change_streams/ban_from_views.js index 29f78710544..f3a7185b6ea 100644 --- a/jstests/change_streams/ban_from_views.js +++ b/jstests/change_streams/ban_from_views.js @@ -7,7 +7,7 @@ load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Collection. const coll = assertDropAndRecreateCollection(db, "change_stream_ban_from_views"); -assert.writeOK(coll.insert({_id: 1})); +assert.commandWorked(coll.insert({_id: 1})); const normalViewName = "nonChangeStreamView"; const csViewName = "changeStreamView"; diff --git a/jstests/change_streams/change_stream.js b/jstests/change_streams/change_stream.js index 6c03864cedd..faa6a816077 100644 --- a/jstests/change_streams/change_stream.js +++ b/jstests/change_streams/change_stream.js @@ -47,13 +47,13 @@ assertValidChangeStreamNss(db.getName(), "systemindexes"); assertValidChangeStreamNss(db.getName(), "system_users"); // Similar test but for DB names that are not considered internal. -assert.writeOK(db.getSiblingDB("admincustomDB")["test"].insert({})); +assert.commandWorked(db.getSiblingDB("admincustomDB")["test"].insert({})); assertValidChangeStreamNss("admincustomDB"); -assert.writeOK(db.getSiblingDB("local_")["test"].insert({})); +assert.commandWorked(db.getSiblingDB("local_")["test"].insert({})); assertValidChangeStreamNss("local_"); -assert.writeOK(db.getSiblingDB("_config_")["test"].insert({})); +assert.commandWorked(db.getSiblingDB("_config_")["test"].insert({})); assertValidChangeStreamNss("_config_"); let cst = new ChangeStreamTest(db); @@ -63,7 +63,7 @@ jsTestLog("Testing single insert"); // Test that if there are no changes, we return an empty batch. assert.eq(0, cursor.firstBatch.length, "Cursor had changes: " + tojson(cursor)); -assert.writeOK(db.t1.insert({_id: 0, a: 1})); +assert.commandWorked(db.t1.insert({_id: 0, a: 1})); let expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, a: 1}, @@ -78,7 +78,7 @@ assert.eq(0, cursor.nextBatch.length, "Cursor had changes: " + tojson(cursor)); jsTestLog("Testing second insert"); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.insert({_id: 1, a: 2})); +assert.commandWorked(db.t1.insert({_id: 1, a: 2})); expected = { documentKey: {_id: 1}, fullDocument: {_id: 1, a: 2}, @@ -89,7 +89,7 @@ cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); jsTestLog("Testing update"); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.update({_id: 0}, {_id: 0, a: 3})); +assert.commandWorked(db.t1.update({_id: 0}, {_id: 0, a: 3})); expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, a: 3}, @@ -100,7 +100,7 @@ cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); jsTestLog("Testing update of another field"); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.update({_id: 0}, {_id: 0, b: 3})); +assert.commandWorked(db.t1.update({_id: 0}, {_id: 0, b: 3})); expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, b: 3}, @@ -111,7 +111,7 @@ cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); jsTestLog("Testing upsert"); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.update({_id: 2}, {_id: 2, a: 4}, {upsert: true})); +assert.commandWorked(db.t1.update({_id: 2}, {_id: 2, a: 4}, {upsert: true})); expected = { documentKey: {_id: 2}, fullDocument: {_id: 2, a: 4}, @@ -121,9 +121,9 @@ expected = { cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); jsTestLog("Testing partial update with $inc"); -assert.writeOK(db.t1.insert({_id: 3, a: 5, b: 1})); +assert.commandWorked(db.t1.insert({_id: 3, a: 5, b: 1})); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.update({_id: 3}, {$inc: {b: 2}})); +assert.commandWorked(db.t1.update({_id: 3}, {$inc: {b: 2}})); expected = { documentKey: {_id: 3}, ns: {db: "test", coll: "t1"}, @@ -133,10 +133,10 @@ expected = { cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); jsTestLog("Testing multi:true update"); -assert.writeOK(db.t1.insert({_id: 4, a: 0, b: 1})); -assert.writeOK(db.t1.insert({_id: 5, a: 0, b: 1})); +assert.commandWorked(db.t1.insert({_id: 4, a: 0, b: 1})); +assert.commandWorked(db.t1.insert({_id: 5, a: 0, b: 1})); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.update({a: 0}, {$set: {b: 2}}, {multi: true})); +assert.commandWorked(db.t1.update({a: 0}, {$set: {b: 2}}, {multi: true})); expected = [ { documentKey: {_id: 4}, @@ -155,7 +155,7 @@ cst.assertNextChangesEqual({cursor: cursor, expectedChanges: expected}); jsTestLog("Testing delete"); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.remove({_id: 1})); +assert.commandWorked(db.t1.remove({_id: 1})); expected = { documentKey: {_id: 1}, ns: {db: "test", coll: "t1"}, @@ -164,10 +164,10 @@ expected = { cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); jsTestLog("Testing justOne:false delete"); -assert.writeOK(db.t1.insert({_id: 6, a: 1, b: 1})); -assert.writeOK(db.t1.insert({_id: 7, a: 1, b: 1})); +assert.commandWorked(db.t1.insert({_id: 6, a: 1, b: 1})); +assert.commandWorked(db.t1.insert({_id: 7, a: 1, b: 1})); cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1}); -assert.writeOK(db.t1.remove({a: 1}, {justOne: false})); +assert.commandWorked(db.t1.remove({a: 1}, {justOne: false})); expected = [ { documentKey: {_id: 6}, @@ -185,7 +185,7 @@ cst.assertNextChangesEqual({cursor: cursor, expectedChanges: expected}); jsTestLog("Testing intervening write on another collection"); 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})); +assert.commandWorked(db.t2.insert({_id: 100, c: 1})); cst.assertNoChange(cursor); expected = { documentKey: {_id: 100}, @@ -196,7 +196,7 @@ expected = { cst.assertNextChangesEqual({cursor: t2cursor, expectedChanges: [expected]}); jsTestLog("Testing drop of unrelated collection"); -assert.writeOK(db.dropping.insert({})); +assert.commandWorked(db.dropping.insert({})); assertDropCollection(db, db.dropping.getName()); // Should still see the previous change from t2, shouldn't see anything about 'dropping'. @@ -205,7 +205,7 @@ 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.t2.insert({_id: 101, renameCollection: "test.dne1", to: "test.dne2"})); +assert.commandWorked(db.t2.insert({_id: 101, renameCollection: "test.dne1", to: "test.dne2"})); cst.assertNoChange(dne1cursor); cst.assertNoChange(dne2cursor); @@ -227,7 +227,7 @@ let resumeCursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.resume1}); // Insert a document and save the resulting change stream. -assert.writeOK(db.resume1.insert({_id: 1})); +assert.commandWorked(db.resume1.insert({_id: 1})); const firstInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(firstInsertChangeDoc.fullDocument, {_id: 1}); @@ -239,10 +239,10 @@ resumeCursor = cst.startWatchingChanges({ }); jsTestLog("Inserting additional documents."); -assert.writeOK(db.resume1.insert({_id: 2})); +assert.commandWorked(db.resume1.insert({_id: 2})); const secondInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(secondInsertChangeDoc.fullDocument, {_id: 2}); -assert.writeOK(db.resume1.insert({_id: 3})); +assert.commandWorked(db.resume1.insert({_id: 3})); const thirdInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(thirdInsertChangeDoc.fullDocument, {_id: 3}); diff --git a/jstests/change_streams/collation.js b/jstests/change_streams/collation.js index 3d50b564711..4abc2f06ffb 100644 --- a/jstests/change_streams/collation.js +++ b/jstests/change_streams/collation.js @@ -63,8 +63,8 @@ let explicitCaseInsensitiveStream = cst.startWatchingChanges({ aggregateOptions: {collation: caseInsensitive} }); -assert.writeOK(caseInsensitiveCollection.insert({_id: 0, text: "aBc"})); -assert.writeOK(caseInsensitiveCollection.insert({_id: 1, text: "abc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: 0, text: "aBc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: 1, text: "abc"})); // 'didNotInheritCollationStream' should not have inherited the collection's case-insensitive // default collation, and should only see the second insert. 'explicitCaseInsensitiveStream' @@ -90,8 +90,8 @@ explicitCaseInsensitiveStream = cst.startWatchingChanges({ doNotModifyInPassthroughs: true }); -assert.writeOK(similarNameCollection.insert({_id: 0, text: "aBc"})); -assert.writeOK(caseInsensitiveCollection.insert({_id: 2, text: "ABC"})); +assert.commandWorked(similarNameCollection.insert({_id: 0, text: "aBc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: 2, text: "ABC"})); // The case-insensitive stream should not see the first insert (to the other collection), only // the second. We do not expect to see the insert in 'didNotInheritCollationStream'. @@ -109,7 +109,7 @@ const streamCreatedBeforeNoCollationCollection = cst.startWatchingChanges({ }); noCollationCollection = assertCreateCollection(db, noCollationCollection); -assert.writeOK(noCollationCollection.insert({_id: 0})); +assert.commandWorked(noCollationCollection.insert({_id: 0})); cst.assertNextChangesEqual( {cursor: streamCreatedBeforeNoCollationCollection, expectedChanges: [{docId: 0}]}); @@ -128,7 +128,7 @@ const streamCreatedBeforeSimpleCollationCollection = cst.startWatchingChanges({ simpleCollationCollection = assertCreateCollection(db, simpleCollationCollection, {collation: {locale: "simple"}}); -assert.writeOK(simpleCollationCollection.insert({_id: 0})); +assert.commandWorked(simpleCollationCollection.insert({_id: 0})); cst.assertNextChangesEqual( {cursor: streamCreatedBeforeSimpleCollationCollection, expectedChanges: [{docId: 0}]}); @@ -147,7 +147,7 @@ const frenchChangeStream = cst.startWatchingChanges({ }); frenchCollection = assertCreateCollection(db, frenchCollection, {collation: {locale: "fr"}}); -assert.writeOK(frenchCollection.insert({_id: 0})); +assert.commandWorked(frenchCollection.insert({_id: 0})); cst.assertNextChangesEqual({cursor: frenchChangeStream, expectedChanges: [{docId: 0}]}); }()); @@ -169,7 +169,7 @@ const englishCaseInsensitiveStream = cst.startWatchingChanges({ }); germanCollection = assertCreateCollection(db, germanCollection, {collation: {locale: "de"}}); -assert.writeOK(germanCollection.insert({_id: 0, text: "aBc"})); +assert.commandWorked(germanCollection.insert({_id: 0, text: "aBc"})); cst.assertNextChangesEqual({cursor: englishCaseInsensitiveStream, expectedChanges: [{docId: 0}]}); }()); @@ -190,8 +190,8 @@ const englishCaseSensitiveStream = cst.startWatchingChanges({ collection: caseInsensitiveCollection }); -assert.writeOK(caseInsensitiveCollection.insert({_id: 0, text: "aBc"})); -assert.writeOK(caseInsensitiveCollection.insert({_id: 1, text: "abc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: 0, text: "aBc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: 1, text: "abc"})); cst.assertNextChangesEqual({cursor: englishCaseSensitiveStream, expectedChanges: [{docId: 1}]}); }()); @@ -206,8 +206,8 @@ const cursor = noCollationCollection.watch( [{$match: {"fullDocument.text": "abc"}}, {$project: {docId: "$documentKey._id"}}], {collation: caseInsensitive}); assert(!cursor.hasNext()); -assert.writeOK(noCollationCollection.insert({_id: 0, text: "aBc"})); -assert.writeOK(noCollationCollection.insert({_id: 1, text: "abc"})); +assert.commandWorked(noCollationCollection.insert({_id: 0, text: "aBc"})); +assert.commandWorked(noCollationCollection.insert({_id: 1, text: "abc"})); assert.soon(() => cursor.hasNext()); assertChangeStreamEventEq(cursor.next(), {docId: 0}); assert.soon(() => cursor.hasNext()); @@ -225,7 +225,7 @@ let caseInsensitiveCollection = let changeStream = caseInsensitiveCollection.watch([{$match: {"fullDocument.text": "abc"}}], {collation: caseInsensitive}); -assert.writeOK(caseInsensitiveCollection.insert({_id: 0, text: "abc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: 0, text: "abc"})); assert.soon(() => changeStream.hasNext()); const next = changeStream.next(); @@ -233,7 +233,7 @@ assert.docEq(next.documentKey, {_id: 0}); const resumeToken = next._id; // Insert a second document to see after resuming. -assert.writeOK(caseInsensitiveCollection.insert({_id: "dropped_coll", text: "ABC"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: "dropped_coll", text: "ABC"})); // Drop the collection to invalidate the stream. assertDropCollection(db, collName); @@ -276,7 +276,7 @@ let caseInsensitiveCollection = let changeStream = caseInsensitiveCollection.watch([{$match: {"fullDocument.text": "abc"}}], {collation: caseInsensitive}); -assert.writeOK(caseInsensitiveCollection.insert({_id: 0, text: "abc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: 0, text: "abc"})); assert.soon(() => changeStream.hasNext()); const next = changeStream.next(); @@ -284,12 +284,12 @@ assert.docEq(next.documentKey, {_id: 0}); const resumeToken = next._id; // Insert a second document to see after resuming. -assert.writeOK(caseInsensitiveCollection.insert({_id: "dropped_coll", text: "ABC"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: "dropped_coll", text: "ABC"})); // Recreate the collection with a different collation. caseInsensitiveCollection = assertDropAndRecreateCollection( db, caseInsensitiveCollection.getName(), {collation: {locale: "simple"}}); -assert.writeOK(caseInsensitiveCollection.insert({_id: "new collection", text: "abc"})); +assert.commandWorked(caseInsensitiveCollection.insert({_id: "new collection", text: "abc"})); // Verify that the stream sees the insert before the drop and then is exhausted. We won't // see the invalidate because the pipeline has a $match stage after the $changeStream. diff --git a/jstests/change_streams/lookup_post_image.js b/jstests/change_streams/lookup_post_image.js index fa2658ed6f8..c918fd22110 100644 --- a/jstests/change_streams/lookup_post_image.js +++ b/jstests/change_streams/lookup_post_image.js @@ -20,22 +20,22 @@ jsTestLog("Testing change streams without 'fullDocument' specified"); // Test that not specifying 'fullDocument' does include a 'fullDocument' in the result for // an insert. let cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: coll}); -assert.writeOK(coll.insert({_id: "fullDocument not specified"})); +assert.commandWorked(coll.insert({_id: "fullDocument not specified"})); let latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "insert"); assert.eq(latestChange.fullDocument, {_id: "fullDocument not specified"}); // Test that not specifying 'fullDocument' does include a 'fullDocument' in the result for a // replacement-style update. -assert.writeOK(coll.update({_id: "fullDocument not specified"}, - {_id: "fullDocument not specified", replaced: true})); +assert.commandWorked(coll.update({_id: "fullDocument not specified"}, + {_id: "fullDocument not specified", replaced: true})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "replace"); assert.eq(latestChange.fullDocument, {_id: "fullDocument not specified", replaced: true}); // Test that not specifying 'fullDocument' does not include a 'fullDocument' in the result // for a non-replacement update. -assert.writeOK(coll.update({_id: "fullDocument not specified"}, {$set: {updated: true}})); +assert.commandWorked(coll.update({_id: "fullDocument not specified"}, {$set: {updated: true}})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "update"); assert(!latestChange.hasOwnProperty("fullDocument")); @@ -46,22 +46,22 @@ jsTestLog("Testing change streams with 'fullDocument' specified as 'default'"); // result for an insert. cursor = cst.startWatchingChanges( {collection: coll, pipeline: [{$changeStream: {fullDocument: "default"}}]}); -assert.writeOK(coll.insert({_id: "fullDocument is default"})); +assert.commandWorked(coll.insert({_id: "fullDocument is default"})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "insert"); assert.eq(latestChange.fullDocument, {_id: "fullDocument is default"}); // Test that specifying 'fullDocument' as 'default' does include a 'fullDocument' in the // result for a replacement-style update. -assert.writeOK(coll.update({_id: "fullDocument is default"}, - {_id: "fullDocument is default", replaced: true})); +assert.commandWorked(coll.update({_id: "fullDocument is default"}, + {_id: "fullDocument is default", replaced: true})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "replace"); assert.eq(latestChange.fullDocument, {_id: "fullDocument is default", replaced: true}); // Test that specifying 'fullDocument' as 'default' does not include a 'fullDocument' in the // result for a non-replacement update. -assert.writeOK(coll.update({_id: "fullDocument is default"}, {$set: {updated: true}})); +assert.commandWorked(coll.update({_id: "fullDocument is default"}, {$set: {updated: true}})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "update"); assert(!latestChange.hasOwnProperty("fullDocument")); @@ -72,14 +72,14 @@ jsTestLog("Testing change streams with 'fullDocument' specified as 'updateLookup // the result for an insert. cursor = cst.startWatchingChanges( {collection: coll, pipeline: [{$changeStream: {fullDocument: "updateLookup"}}]}); -assert.writeOK(coll.insert({_id: "fullDocument is lookup"})); +assert.commandWorked(coll.insert({_id: "fullDocument is lookup"})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "insert"); assert.eq(latestChange.fullDocument, {_id: "fullDocument is lookup"}); // Test that specifying 'fullDocument' as 'updateLookup' does include a 'fullDocument' in // the result for a replacement-style update. -assert.writeOK( +assert.commandWorked( coll.update({_id: "fullDocument is lookup"}, {_id: "fullDocument is lookup", replaced: true})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "replace"); @@ -87,7 +87,7 @@ assert.eq(latestChange.fullDocument, {_id: "fullDocument is lookup", replaced: t // Test that specifying 'fullDocument' as 'updateLookup' does include a 'fullDocument' in // the result for a non-replacement update. -assert.writeOK(coll.update({_id: "fullDocument is lookup"}, {$set: {updated: true}})); +assert.commandWorked(coll.update({_id: "fullDocument is lookup"}, {$set: {updated: true}})); latestChange = cst.getOneChange(cursor); assert.eq(latestChange.operationType, "update"); assert.eq(latestChange.fullDocument, @@ -99,8 +99,8 @@ cursor = cst.startWatchingChanges({ collection: coll, pipeline: [{$changeStream: {fullDocument: "updateLookup"}}, {$match: {operationType: "update"}}] }); -assert.writeOK(coll.update({_id: "fullDocument is lookup"}, {$set: {updatedAgain: true}})); -assert.writeOK(coll.remove({_id: "fullDocument is lookup"})); +assert.commandWorked(coll.update({_id: "fullDocument is lookup"}, {$set: {updatedAgain: true}})); +assert.commandWorked(coll.remove({_id: "fullDocument is lookup"})); // If this test is running with secondary read preference, it's necessary for the remove // to propagate to all secondary nodes and be available for majority reads before we can // assume looking up the document will fail. @@ -115,8 +115,8 @@ const deleteDocResumePoint = latestChange._id; // Test that looking up the post image of an update after the collection has been dropped // will result in 'fullDocument' with a value of null. This must be done using getMore // because new cursors cannot be established after a collection drop. -assert.writeOK(coll.insert({_id: "fullDocument is lookup 2"})); -assert.writeOK(coll.update({_id: "fullDocument is lookup 2"}, {$set: {updated: true}})); +assert.commandWorked(coll.insert({_id: "fullDocument is lookup 2"})); +assert.commandWorked(coll.update({_id: "fullDocument is lookup 2"}, {$set: {updated: true}})); // Open a $changeStream cursor with batchSize 0, so that no oplog entries are retrieved yet. cursor = cst.startWatchingChanges({ @@ -200,7 +200,7 @@ assert.eq(latestChange.fullDocument, null); // Insert a document with the same _id, verify the change stream won't return it due to // different UUID. assertCreateCollection(db, coll.getName()); -assert.writeOK(coll.insert({_id: "fullDocument is lookup 2"})); +assert.commandWorked(coll.insert({_id: "fullDocument is lookup 2"})); // Confirm that the next entry's post-image is null since new collection has a different // UUID. @@ -210,13 +210,13 @@ assert(latestChange.hasOwnProperty("fullDocument")); assert.eq(latestChange.fullDocument, null); jsTestLog("Testing full document lookup with a real getMore"); -assert.writeOK(coll.insert({_id: "getMoreEnabled"})); +assert.commandWorked(coll.insert({_id: "getMoreEnabled"})); cursor = cst.startWatchingChanges({ collection: coll, pipeline: [{$changeStream: {fullDocument: "updateLookup"}}], }); -assert.writeOK(coll.update({_id: "getMoreEnabled"}, {$set: {updated: true}})); +assert.commandWorked(coll.update({_id: "getMoreEnabled"}, {$set: {updated: true}})); const doc = cst.getOneChange(cursor); assert.docEq(doc["fullDocument"], {_id: "getMoreEnabled", updated: true}); @@ -228,7 +228,7 @@ cursor = cst.startWatchingChanges({ pipeline: [{$changeStream: {fullDocument: "updateLookup"}}], aggregateOptions: {cursor: {batchSize: 0}} }); -assert.writeOK(coll.insert({_id: "testing invalidate"})); +assert.commandWorked(coll.insert({_id: "testing invalidate"})); assertDropCollection(db, coll.getName()); // Wait until two-phase drop finishes. assert.soon(function() { diff --git a/jstests/change_streams/metadata_notifications.js b/jstests/change_streams/metadata_notifications.js index 8b3aae094fe..a6d33b0335d 100644 --- a/jstests/change_streams/metadata_notifications.js +++ b/jstests/change_streams/metadata_notifications.js @@ -51,7 +51,7 @@ assert.eq(change.nextBatch.length, 0, tojson(change.nextBatch)); // After collection creation, we expect to see oplog entries for each subsequent operation. let coll = assertCreateCollection(db, collName); -assert.writeOK(coll.insert({_id: 0})); +assert.commandWorked(coll.insert({_id: 0})); // Determine the number of shards that the collection is distributed across. const numShards = FixtureHelpers.numberOfShardsForCollection(coll); @@ -60,9 +60,9 @@ change = cst.getOneChange(cursor); assert.eq(change.operationType, "insert", tojson(change)); // Create oplog entries of type insert, update, delete, and drop. -assert.writeOK(coll.insert({_id: 1})); -assert.writeOK(coll.update({_id: 1}, {$set: {a: 1}})); -assert.writeOK(coll.remove({_id: 1})); +assert.commandWorked(coll.insert({_id: 1})); +assert.commandWorked(coll.update({_id: 1}, {$set: {a: 1}})); +assert.commandWorked(coll.remove({_id: 1})); assertDropCollection(db, coll.getName()); // We should get oplog entries of type insert, update, delete, drop, and invalidate. The cursor @@ -100,7 +100,7 @@ assert.commandWorked(db.runCommand({ // Recreate the collection. coll = assertCreateCollection(db, collName); -assert.writeOK(coll.insert({_id: "after recreate"})); +assert.commandWorked(coll.insert({_id: "after recreate"})); // Test resuming the change stream from the collection drop using 'resumeAfter'. If running in a // sharded passthrough suite, resuming from the drop will first return the drop from the other @@ -156,7 +156,7 @@ cst.consumeDropUpTo({ if (!FixtureHelpers.isSharded(coll)) { cursor = cst.startWatchingChanges({collection: collName, pipeline: [{$changeStream: {}}]}); assertDropCollection(db, "renamed_coll"); - assert.writeOK(coll.renameCollection("renamed_coll")); + assert.commandWorked(coll.renameCollection("renamed_coll")); expectedChanges = [ { operationType: "rename", @@ -172,7 +172,7 @@ if (!FixtureHelpers.isSharded(coll)) { // Repeat the test, this time with a change stream open on the target. cursor = cst.startWatchingChanges({collection: collName, pipeline: [{$changeStream: {}}]}); - assert.writeOK(coll.renameCollection(collName)); + assert.commandWorked(coll.renameCollection(collName)); expectedChanges = [ { operationType: "rename", @@ -186,7 +186,7 @@ if (!FixtureHelpers.isSharded(coll)) { const resumeTokenInvalidate = changes[1]._id; coll = db[collName]; - assert.writeOK(coll.insert({_id: "after rename"})); + assert.commandWorked(coll.insert({_id: "after rename"})); // Test resuming the change stream from the collection rename using 'resumeAfter'. assertResumeExpected({ @@ -224,13 +224,13 @@ if (!FixtureHelpers.isSharded(coll)) { }); assertDropAndRecreateCollection(db, "renamed_coll"); - assert.writeOK(db.renamed_coll.insert({_id: 0})); + assert.commandWorked(db.renamed_coll.insert({_id: 0})); // Repeat the test again, this time using the 'dropTarget' option with an existing target // collection. cursor = cst.startWatchingChanges({collection: "renamed_coll", pipeline: [{$changeStream: {}}]}); - assert.writeOK(coll.renameCollection("renamed_coll", true /* dropTarget */)); + assert.commandWorked(coll.renameCollection("renamed_coll", true /* dropTarget */)); expectedChanges = [ { operationType: "rename", diff --git a/jstests/change_streams/only_wake_getmore_for_relevant_changes.js b/jstests/change_streams/only_wake_getmore_for_relevant_changes.js index 16400360d55..bfe84bcbd32 100644 --- a/jstests/change_streams/only_wake_getmore_for_relevant_changes.js +++ b/jstests/change_streams/only_wake_getmore_for_relevant_changes.js @@ -32,7 +32,7 @@ function runGetMoreInParallelWithEvent( const awaitShellDoingEventDuringGetMore = startParallelShell(` // Signal that the parallel shell has started. -assert.writeOK(db.getCollection("${ shellSentinelCollection.getName() }").insert({})); +assert.commandWorked(db.getCollection("${ shellSentinelCollection.getName() }").insert({})); // Wait for the getMore to appear in currentOp. assert.soon(function() { @@ -132,7 +132,7 @@ const getMoreResponse = assertEventWakesCursor({ collection: changesCollection, awaitDataCursorId: changeCursorId, identifyingComment: wholeCollectionStreamComment, - event: () => assert.writeOK(db.changes.insert({_id: "wake up"})) + event: () => assert.commandWorked(db.changes.insert({_id: "wake up"})) }); assert.eq(getMoreResponse.cursor.nextBatch.length, 1); assert.eq(getMoreResponse.cursor.nextBatch[0].operationType, @@ -148,7 +148,7 @@ assertEventDoesNotWakeCursor({ collection: changesCollection, awaitDataCursorId: changeCursorId, identifyingComment: wholeCollectionStreamComment, - event: () => assert.writeOK(db.unrelated_collection.insert({_id: "unrelated change"})) + event: () => assert.commandWorked(db.unrelated_collection.insert({_id: "unrelated change"})) }); assert.commandWorked( db.runCommand({killCursors: changesCollection.getName(), cursors: [changeCursorId]})); @@ -171,7 +171,7 @@ assertEventDoesNotWakeCursor({ collection: changesCollection, awaitDataCursorId: res.cursor.id, identifyingComment: noInvalidatesComment, - event: () => assert.writeOK(db.changes.insert({_id: "should not appear"})) + event: () => assert.commandWorked(db.changes.insert({_id: "should not appear"})) }); assert.commandWorked( db.runCommand({killCursors: changesCollection.getName(), cursors: [res.cursor.id]})); diff --git a/jstests/change_streams/shell_helper.js b/jstests/change_streams/shell_helper.js index b4e8aae00b3..f57d929e5c3 100644 --- a/jstests/change_streams/shell_helper.js +++ b/jstests/change_streams/shell_helper.js @@ -54,7 +54,7 @@ let changeStreamCursor = coll.watch(); assert(!changeStreamCursor.hasNext()); // Write the first document into the collection. We will save the resume token from this change. -assert.writeOK(coll.insert({_id: 0, x: 1})); +assert.commandWorked(coll.insert({_id: 0, x: 1})); let resumeToken; // Test that each of the change stream cursors picks up the change. @@ -110,7 +110,7 @@ checkNextChange(changeStreamCursor, {docId: 1}); jsTestLog("Testing watch() with updateLookup"); changeStreamCursor = coll.watch([], {fullDocument: "updateLookup"}); -assert.writeOK(coll.update({_id: 0}, {$set: {x: 10}})); +assert.commandWorked(coll.update({_id: 0}, {$set: {x: 10}})); expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, x: 10}, @@ -127,7 +127,7 @@ const isMongos = FixtureHelpers.isMongos(db); if (!isMongos) { // Increase a field by 5 times and verify the batch size is respected. for (let i = 0; i < 5; i++) { - assert.writeOK(coll.update({_id: 1}, {$inc: {x: 1}})); + assert.commandWorked(coll.update({_id: 1}, {$inc: {x: 1}})); } // Only watch the "update" changes of the specific doc since the beginning. @@ -166,7 +166,7 @@ testCommandIsCalled(() => assert(!changeStreamCursor.hasNext()), (cmdObj) => { jsTestLog("Testing the cursor gets closed when the collection gets dropped"); changeStreamCursor = coll.watch([{$project: {clusterTime: 0}}]); -assert.writeOK(coll.insert({_id: 2, x: 1})); +assert.commandWorked(coll.insert({_id: 2, x: 1})); expected = { documentKey: {_id: 2}, fullDocument: {_id: 2, x: 1}, diff --git a/jstests/change_streams/start_at_cluster_time.js b/jstests/change_streams/start_at_cluster_time.js index 2edcb530e20..9b289f26bc9 100644 --- a/jstests/change_streams/start_at_cluster_time.js +++ b/jstests/change_streams/start_at_cluster_time.js @@ -8,14 +8,14 @@ const coll = assertDropAndRecreateCollection(db, jsTestName()); const testStartTime = db.runCommand({isMaster: 1}).$clusterTime.clusterTime; // Write a document to each chunk, and wait for replication. -assert.writeOK(coll.insert({_id: -1}, {writeConcern: {w: "majority"}})); -assert.writeOK(coll.insert({_id: 1}, {writeConcern: {w: "majority"}})); +assert.commandWorked(coll.insert({_id: -1}, {writeConcern: {w: "majority"}})); +assert.commandWorked(coll.insert({_id: 1}, {writeConcern: {w: "majority"}})); // Perform two updates, then use a change stream to capture the cluster time of the first update // to be resumed from. const streamToFindClusterTime = coll.watch(); -assert.writeOK(coll.update({_id: -1}, {$set: {updated: true}})); -assert.writeOK(coll.update({_id: 1}, {$set: {updated: true}})); +assert.commandWorked(coll.update({_id: -1}, {$set: {updated: true}})); +assert.commandWorked(coll.update({_id: 1}, {$set: {updated: true}})); assert.soon(() => streamToFindClusterTime.hasNext()); let next = streamToFindClusterTime.next(); assert.eq(next.operationType, "update"); diff --git a/jstests/change_streams/whole_cluster.js b/jstests/change_streams/whole_cluster.js index 7d2d3f22dbb..a1cc114cd9a 100644 --- a/jstests/change_streams/whole_cluster.js +++ b/jstests/change_streams/whole_cluster.js @@ -32,7 +32,7 @@ let cursor = cst.startWatchingAllChangesForCluster(); assert.eq(0, cursor.firstBatch.length, "Cursor had changes: " + tojson(cursor)); // Test that the change stream returns an inserted doc. -assert.writeOK(db.t1.insert({_id: 0, a: 1})); +assert.commandWorked(db.t1.insert({_id: 0, a: 1})); let expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, a: 1}, @@ -42,7 +42,7 @@ let expected = { cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); // Test that the change stream returns another inserted doc in a different database. -assert.writeOK(otherDB.t2.insert({_id: 0, a: 2})); +assert.commandWorked(otherDB.t2.insert({_id: 0, a: 2})); expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, a: 2}, @@ -65,7 +65,7 @@ const validUserDBs = [ "_config_" ]; validUserDBs.forEach(dbName => { - assert.writeOK(db.getSiblingDB(dbName).test.insert({_id: 0, a: 1})); + assert.commandWorked(db.getSiblingDB(dbName).test.insert({_id: 0, a: 1})); expected = [ { documentKey: {_id: 0}, @@ -81,7 +81,7 @@ validUserDBs.forEach(dbName => { // includes "system" but is not considered an internal collection. const validSystemColls = ["system", "systems.views", "ssystem.views", "test.system"]; validSystemColls.forEach(collName => { - assert.writeOK(db.getCollection(collName).insert({_id: 0, a: 1})); + assert.commandWorked(db.getCollection(collName).insert({_id: 0, a: 1})); expected = [ { documentKey: {_id: 0}, @@ -101,10 +101,10 @@ filteredDBs.forEach(dbName => { if (FixtureHelpers.isMongos(db) && dbName == "local") return; - assert.writeOK(db.getSiblingDB(dbName).test.insert({_id: 0, a: 1})); + assert.commandWorked(db.getSiblingDB(dbName).test.insert({_id: 0, a: 1})); // Insert to the test collection to ensure that the change stream has something to // return. - assert.writeOK(db.t1.insert({_id: dbName})); + assert.commandWorked(db.t1.insert({_id: dbName})); expected = [ { documentKey: {_id: dbName}, diff --git a/jstests/change_streams/whole_cluster_metadata_notifications.js b/jstests/change_streams/whole_cluster_metadata_notifications.js index 0ac9c660ea6..8c72df1ba44 100644 --- a/jstests/change_streams/whole_cluster_metadata_notifications.js +++ b/jstests/change_streams/whole_cluster_metadata_notifications.js @@ -29,9 +29,9 @@ let aggCursor = cst.startWatchingAllChangesForCluster(); // Generate oplog entries of type insert, update, and delete across both databases. for (let coll of [db1Coll, db2Coll]) { - assert.writeOK(coll.insert({_id: 1})); - assert.writeOK(coll.update({_id: 1}, {$set: {a: 1}})); - assert.writeOK(coll.remove({_id: 1})); + assert.commandWorked(coll.insert({_id: 1})); + assert.commandWorked(coll.update({_id: 1}, {$set: {a: 1}})); + assert.commandWorked(coll.remove({_id: 1})); } // Drop the second database, which should generate a 'drop' entry for the collection followed @@ -64,7 +64,7 @@ db1Coll = assertDropAndRecreateCollection(testDB1, db1Coll.getName()); // Get a valid resume token that the next change stream can use. aggCursor = cst.startWatchingAllChangesForCluster(); -assert.writeOK(db1Coll.insert({_id: 1}, {writeConcern: {w: "majority"}})); +assert.commandWorked(db1Coll.insert({_id: 1}, {writeConcern: {w: "majority"}})); let change = cst.getOneChange(aggCursor, false); const resumeToken = change._id; @@ -96,7 +96,7 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { // Insert into the collections on both databases, and verify the change stream is able to // pick them up. for (let collToWrite of [db1Coll, db2Coll]) { - assert.writeOK(collToWrite.insert({_id: _idForTest})); + assert.commandWorked(collToWrite.insert({_id: _idForTest})); change = cst.getOneChange(aggCursor); assert.eq(change.operationType, "insert", tojson(change)); assert.eq(change.documentKey._id, _idForTest); @@ -112,7 +112,7 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { // Start watching all changes in the cluster. aggCursor = cst.startWatchingAllChangesForCluster(); - assert.writeOK(collToInvalidate.renameCollection("renamed_coll")); + assert.commandWorked(collToInvalidate.renameCollection("renamed_coll")); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [ @@ -128,8 +128,8 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { // collection. collToInvalidate = testDB.getCollection("renamed_coll"); assertDropAndRecreateCollection(testDB, collName); - assert.writeOK(testDB[collName].insert({_id: 0})); - assert.writeOK(collToInvalidate.renameCollection(collName, true /* dropTarget */)); + assert.commandWorked(testDB[collName].insert({_id: 0})); + assert.commandWorked(collToInvalidate.renameCollection(collName, true /* dropTarget */)); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [ @@ -188,14 +188,14 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { // The change stream should not be invalidated by the rename(s). assert.eq(0, cst.getNextBatch(aggCursor).nextBatch.length); - assert.writeOK(collToInvalidate.insert({_id: 2})); + assert.commandWorked(collToInvalidate.insert({_id: 2})); assert.eq(cst.getOneChange(aggCursor).operationType, "insert"); // Test that renaming a "system" collection to a user collection *does* return a rename // notification. assert.commandWorked( testDB.runCommand({create: "view1", viewOn: collToInvalidate.getName(), pipeline: []})); - assert.writeOK(testDB.system.views.renameCollection("non_system_collection")); + assert.commandWorked(testDB.system.views.renameCollection("non_system_collection")); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [{ @@ -211,17 +211,17 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { assert.commandWorked( testDB.runCommand({create: "view1", viewOn: collToInvalidate.getName(), pipeline: []})); // Note that the target of the rename must be a valid "system" collection. - assert.writeOK(testDB.system.views.renameCollection("system.users")); + assert.commandWorked(testDB.system.views.renameCollection("system.users")); // Verify that the change stream filters out the rename above, instead returning the // next insert to the test collection. - assert.writeOK(collToInvalidate.insert({_id: 1})); + assert.commandWorked(collToInvalidate.insert({_id: 1})); change = cst.getOneChange(aggCursor); assert.eq(change.operationType, "insert", tojson(change)); assert.eq(change.ns, {db: testDB.getName(), coll: collToInvalidate.getName()}); // Test that renaming a user collection to a "system" collection *does* return a rename // notification. - assert.writeOK(collToInvalidate.renameCollection("system.views")); + assert.commandWorked(collToInvalidate.renameCollection("system.views")); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [{ @@ -235,7 +235,7 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { assertDropCollection(testDB, "system.views"); // Recreate the test collection for the remainder of the test. - assert.writeOK(collToInvalidate.insert({_id: 0})); + assert.commandWorked(collToInvalidate.insert({_id: 0})); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [{ @@ -252,7 +252,7 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { // Insert to the test collection to queue up another change after the drop. This is needed // since the number of 'drop' notifications is not deterministic in the sharded passthrough // suites. - assert.writeOK(collToInvalidate.insert({_id: 0})); + assert.commandWorked(collToInvalidate.insert({_id: 0})); cst.consumeDropUpTo({ cursor: aggCursor, dropType: "drop", @@ -275,7 +275,7 @@ for (let collToInvalidate of [db1Coll, db2Coll]) { // Verify that the change stream does not report the insertion into "system.views", and is // not invalidated by dropping the system collection. Instead, it correctly reports the next // write to the test collection. - assert.writeOK(collToInvalidate.insert({_id: 1})); + assert.commandWorked(collToInvalidate.insert({_id: 1})); change = cst.getOneChange(aggCursor); assert.eq(change.operationType, "insert", tojson(change)); assert.eq(change.ns, {db: testDB.getName(), coll: collToInvalidate.getName()}); diff --git a/jstests/change_streams/whole_cluster_resumability.js b/jstests/change_streams/whole_cluster_resumability.js index 270f6c465db..8564d01e770 100644 --- a/jstests/change_streams/whole_cluster_resumability.js +++ b/jstests/change_streams/whole_cluster_resumability.js @@ -15,7 +15,7 @@ let cst = new ChangeStreamTest(adminDB); let resumeCursor = cst.startWatchingAllChangesForCluster(); // Insert a document in the first database and save the resulting change stream. -assert.writeOK(db1Coll.insert({_id: 1})); +assert.commandWorked(db1Coll.insert({_id: 1})); const firstInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(firstInsertChangeDoc.fullDocument, {_id: 1}); @@ -28,12 +28,12 @@ resumeCursor = cst.startWatchingChanges({ }); // Write the next document into the second database. -assert.writeOK(db2Coll.insert({_id: 2})); +assert.commandWorked(db2Coll.insert({_id: 2})); const secondInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(secondInsertChangeDoc.fullDocument, {_id: 2}); // Write the third document into the first database again. -assert.writeOK(db1Coll.insert({_id: 3})); +assert.commandWorked(db1Coll.insert({_id: 3})); const thirdInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(thirdInsertChangeDoc.fullDocument, {_id: 3}); @@ -68,7 +68,7 @@ if (!FixtureHelpers.isSharded(db1Coll)) { pipeline: [{$changeStream: {allChangesForCluster: true}}], aggregateOptions: {cursor: {batchSize: 0}} }); - assert.writeOK(db1Coll.renameCollection(renameColl.getName())); + assert.commandWorked(db1Coll.renameCollection(renameColl.getName())); const renameChanges = cst.assertNextChangesEqual({ cursor: resumeCursor, @@ -83,7 +83,7 @@ if (!FixtureHelpers.isSharded(db1Coll)) { const resumeTokenRename = renameChanges[0]._id; // Insert into the renamed collection. - assert.writeOK(renameColl.insert({_id: "after rename"})); + assert.commandWorked(renameColl.insert({_id: "after rename"})); // Resume from the rename notification using 'resumeAfter' and verify that the change stream // returns the next insert. @@ -117,7 +117,7 @@ if (!FixtureHelpers.isSharded(db1Coll)) { // Rename back to the original collection for reliability of the collection drops when // dropping the database. - assert.writeOK(renameColl.renameCollection(db1Coll.getName())); + assert.commandWorked(renameColl.renameCollection(db1Coll.getName())); } // Dropping a database should generate a 'drop' notification for the collection followed by a @@ -128,7 +128,7 @@ const dropDbChanges = cst.assertDatabaseDrop({cursor: resumeCursor, db: testDBs[ const resumeTokenDbDrop = dropDbChanges[dropDbChanges.length - 1]._id; // Recreate the collection and insert a document. -assert.writeOK(db1Coll.insert({_id: "after recreate"})); +assert.commandWorked(db1Coll.insert({_id: "after recreate"})); let expectedInsert = { operationType: "insert", diff --git a/jstests/change_streams/whole_db.js b/jstests/change_streams/whole_db.js index aaa6fd0a29f..099bf388525 100644 --- a/jstests/change_streams/whole_db.js +++ b/jstests/change_streams/whole_db.js @@ -27,7 +27,7 @@ let cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collecti assert.eq(0, cursor.firstBatch.length, "Cursor had changes: " + tojson(cursor)); // Test that the change stream returns an inserted doc. -assert.writeOK(db.t1.insert({_id: 0, a: 1})); +assert.commandWorked(db.t1.insert({_id: 0, a: 1})); let expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, a: 1}, @@ -38,7 +38,7 @@ cst.assertNextChangesEqual({cursor: cursor, expectedChanges: [expected]}); // Test that the change stream returns another inserted doc in a different collection but still // in the target db. -assert.writeOK(db.t2.insert({_id: 0, a: 2})); +assert.commandWorked(db.t2.insert({_id: 0, a: 2})); expected = { documentKey: {_id: 0}, fullDocument: {_id: 0, a: 2}, @@ -53,7 +53,7 @@ const validSystemColls = ["system", "systems.views", "ssystem.views", "test.syst validSystemColls.forEach(collName => { cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: 1}); const coll = db.getCollection(collName); - assert.writeOK(coll.insert({_id: 0, a: 1})); + assert.commandWorked(coll.insert({_id: 0, a: 1})); expected = [ { documentKey: {_id: 0}, @@ -69,7 +69,7 @@ validSystemColls.forEach(collName => { // Insert to the test collection to queue up another change after the drop. This is needed // since the number of 'drop' notifications is not deterministic in the sharded passthrough // suites. - assert.writeOK(coll.insert({_id: 0})); + assert.commandWorked(coll.insert({_id: 0})); cst.consumeDropUpTo({ cursor: cursor, dropType: "drop", diff --git a/jstests/change_streams/whole_db_metadata_notifications.js b/jstests/change_streams/whole_db_metadata_notifications.js index 7b659ff4e12..1500402bc1c 100644 --- a/jstests/change_streams/whole_db_metadata_notifications.js +++ b/jstests/change_streams/whole_db_metadata_notifications.js @@ -22,9 +22,9 @@ let coll = assertDropAndRecreateCollection(testDB, collName); let aggCursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: 1}); // Create oplog entries of type insert, update, and delete. -assert.writeOK(coll.insert({_id: 1})); -assert.writeOK(coll.update({_id: 1}, {$set: {a: 1}})); -assert.writeOK(coll.remove({_id: 1})); +assert.commandWorked(coll.insert({_id: 1})); +assert.commandWorked(coll.update({_id: 1}, {$set: {a: 1}})); +assert.commandWorked(coll.remove({_id: 1})); // Drop and recreate the collection. const collAgg = assertDropAndRecreateCollection(testDB, collName); @@ -40,7 +40,7 @@ change = cst.getOneChange(aggCursor); assert.eq(change.operationType, "drop", tojson(change)); // Get a valid resume token that the next change stream can use. -assert.writeOK(collAgg.insert({_id: 1})); +assert.commandWorked(collAgg.insert({_id: 1})); change = cst.getOneChange(aggCursor, false); const resumeToken = change._id; @@ -57,7 +57,7 @@ assert.commandWorked(testDB.runCommand( // Test that invalidation entries for other databases are filtered out. const otherDB = testDB.getSiblingDB(jsTestName() + "other"); const otherDBColl = otherDB[collName + "_other"]; -assert.writeOK(otherDBColl.insert({_id: 0})); +assert.commandWorked(otherDBColl.insert({_id: 0})); // Create collection on the database being watched. coll = assertDropAndRecreateCollection(testDB, collName); @@ -73,7 +73,7 @@ assertDropCollection(otherDB, otherDBColl.getName()); // Insert into the collection in the watched database, and verify the change stream is able to // pick it up. -assert.writeOK(coll.insert({_id: 1})); +assert.commandWorked(coll.insert({_id: 1})); change = cst.getOneChange(aggCursor); assert.eq(change.operationType, "insert", tojson(change)); assert.eq(change.documentKey._id, 1); @@ -85,7 +85,7 @@ if (!FixtureHelpers.isSharded(coll)) { assertDropAndRecreateCollection(testDB, coll.getName()); assertDropCollection(testDB, "renamed_coll"); aggCursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: 1}); - assert.writeOK(coll.renameCollection("renamed_coll")); + assert.commandWorked(coll.renameCollection("renamed_coll")); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [{ @@ -99,8 +99,8 @@ if (!FixtureHelpers.isSharded(coll)) { // collection. coll = testDB["renamed_coll"]; assertCreateCollection(testDB, collName); - assert.writeOK(testDB[collName].insert({_id: 0})); - assert.writeOK(coll.renameCollection(collName, true /* dropTarget */)); + assert.commandWorked(testDB[collName].insert({_id: 0})); + assert.commandWorked(coll.renameCollection(collName, true /* dropTarget */)); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [ @@ -159,7 +159,7 @@ if (!FixtureHelpers.isSharded(coll)) { // The change stream should not be invalidated by the rename(s). assert.eq(0, cst.getNextBatch(aggCursor).nextBatch.length); - assert.writeOK(coll.insert({_id: 2})); + assert.commandWorked(coll.insert({_id: 2})); assert.eq(cst.getOneChange(aggCursor).operationType, "insert"); // Drop the new collection to avoid an additional 'drop' notification when the database is @@ -189,7 +189,7 @@ assertDropCollection(testDB, "system.views"); // Verify that the change stream does not report the insertion into "system.views", and is // not invalidated by dropping the system collection. Instead, it correctly reports the next // write to the test collection. -assert.writeOK(coll.insert({_id: 0})); +assert.commandWorked(coll.insert({_id: 0})); change = cst.getOneChange(aggCursor); assert.eq(change.operationType, "insert", tojson(change)); assert.eq(change.ns, {db: testDB.getName(), coll: coll.getName()}); @@ -197,7 +197,7 @@ assert.eq(change.ns, {db: testDB.getName(), coll: coll.getName()}); // Test that renaming a "system" collection *does* return a notification if the target of // the rename is a non-system collection. assert.commandWorked(testDB.runCommand({create: "view1", viewOn: coll.getName(), pipeline: []})); -assert.writeOK(testDB.system.views.renameCollection("non_system_collection")); +assert.commandWorked(testDB.system.views.renameCollection("non_system_collection")); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [{ @@ -212,17 +212,17 @@ cst.assertNextChangesEqual({ aggCursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: 1}); assert.commandWorked(testDB.runCommand({create: "view1", viewOn: coll.getName(), pipeline: []})); // Note that the target of the rename must be a valid "system" collection. -assert.writeOK(testDB.system.views.renameCollection("system.users")); +assert.commandWorked(testDB.system.views.renameCollection("system.users")); // Verify that the change stream filters out the rename above, instead returning the next insert // to the test collection. -assert.writeOK(coll.insert({_id: 1})); +assert.commandWorked(coll.insert({_id: 1})); change = cst.getOneChange(aggCursor); assert.eq(change.operationType, "insert", tojson(change)); assert.eq(change.ns, {db: testDB.getName(), coll: coll.getName()}); // Test that renaming a user collection to a "system" collection *is* returned in the change // stream. -assert.writeOK(coll.renameCollection("system.views")); +assert.commandWorked(coll.renameCollection("system.views")); cst.assertNextChangesEqual({ cursor: aggCursor, expectedChanges: [{ diff --git a/jstests/change_streams/whole_db_resumability.js b/jstests/change_streams/whole_db_resumability.js index 697f72ddcf9..2e2c0e183ec 100644 --- a/jstests/change_streams/whole_db_resumability.js +++ b/jstests/change_streams/whole_db_resumability.js @@ -18,8 +18,8 @@ let cst = new ChangeStreamTest(testDB); let resumeCursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: 1}); // Insert a single document to each collection and save the resume token from the first insert. -assert.writeOK(coll.insert({_id: 1})); -assert.writeOK(otherColl.insert({_id: 2})); +assert.commandWorked(coll.insert({_id: 1})); +assert.commandWorked(otherColl.insert({_id: 2})); const firstInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(firstInsertChangeDoc.fullDocument, {_id: 1}); assert.eq(firstInsertChangeDoc.ns, {db: testDB.getName(), coll: coll.getName()}); @@ -37,7 +37,7 @@ assert.docEq(secondInsertChangeDoc.fullDocument, {_id: 2}); assert.eq(secondInsertChangeDoc.ns, {db: testDB.getName(), coll: otherColl.getName()}); // Insert a third document to the first collection and test that the change stream picks it up. -assert.writeOK(coll.insert({_id: 3})); +assert.commandWorked(coll.insert({_id: 3})); const thirdInsertChangeDoc = cst.getOneChange(resumeCursor); assert.docEq(thirdInsertChangeDoc.fullDocument, {_id: 3}); assert.eq(thirdInsertChangeDoc.ns, {db: testDB.getName(), coll: coll.getName()}); @@ -67,7 +67,7 @@ if (!FixtureHelpers.isSharded(coll)) { assertDropCollection(renameColl.getDB(), renameColl.getName()); resumeCursor = cst.startWatchingChanges({collection: 1, pipeline: [{$changeStream: {}}]}); - assert.writeOK(coll.renameCollection(renameColl.getName())); + assert.commandWorked(coll.renameCollection(renameColl.getName())); const renameChanges = cst.assertNextChangesEqual({ cursor: resumeCursor, @@ -82,7 +82,7 @@ if (!FixtureHelpers.isSharded(coll)) { const resumeTokenRename = renameChanges[0]._id; // Insert into the renamed collection. - assert.writeOK(renameColl.insert({_id: "after rename"})); + assert.commandWorked(renameColl.insert({_id: "after rename"})); // Resume from the rename notification using 'resumeAfter' and verify that the change stream // returns the next insert. @@ -110,7 +110,7 @@ if (!FixtureHelpers.isSharded(coll)) { // Rename back to the original collection for reliability of the collection drops when // dropping the database. - assert.writeOK(renameColl.renameCollection(coll.getName())); + assert.commandWorked(renameColl.renameCollection(coll.getName())); } // Explicitly drop one collection to ensure reliability of the order of notifications from the @@ -149,7 +149,7 @@ const resumeTokenInvalidate = }); // Recreate the test collection. -assert.writeOK(coll.insert({_id: "after recreate"})); +assert.commandWorked(coll.insert({_id: "after recreate"})); // Test resuming from the 'dropDatabase' entry using 'resumeAfter'. resumeCursor = cst.startWatchingChanges({ |