diff options
Diffstat (limited to 'jstests/change_streams/whole_cluster.js')
-rw-r--r-- | jstests/change_streams/whole_cluster.js | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/jstests/change_streams/whole_cluster.js b/jstests/change_streams/whole_cluster.js index a1cc114cd9a..f9c47ee1c4f 100644 --- a/jstests/change_streams/whole_cluster.js +++ b/jstests/change_streams/whole_cluster.js @@ -11,6 +11,12 @@ db = db.getSiblingDB(jsTestName()); const adminDB = db.getSiblingDB("admin"); const otherDB = db.getSiblingDB(jsTestName() + "_other"); +// Create additional collections to prevent the databases from being closed when the other +// collections are dropped. +assert.commandWorkedOrFailedWithCode(db.createCollection("unused"), ErrorCodes.NamespaceExists); +assert.commandWorkedOrFailedWithCode(otherDB.createCollection("unused"), + ErrorCodes.NamespaceExists); + // Drop and recreate the collections to be used in this set of tests. assertDropAndRecreateCollection(db, "t1"); assertDropAndRecreateCollection(otherDB, "t2"); @@ -65,12 +71,13 @@ const validUserDBs = [ "_config_" ]; validUserDBs.forEach(dbName => { - assert.commandWorked(db.getSiblingDB(dbName).test.insert({_id: 0, a: 1})); + const collName = "test" + Random.srand(); + assert.commandWorked(db.getSiblingDB(dbName).getCollection(collName).insert({_id: 0, a: 1})); expected = [ { documentKey: {_id: 0}, fullDocument: {_id: 0, a: 1}, - ns: {db: dbName, coll: "test"}, + ns: {db: dbName, coll: collName}, operationType: "insert", }, ]; @@ -101,7 +108,9 @@ filteredDBs.forEach(dbName => { if (FixtureHelpers.isMongos(db) && dbName == "local") return; - assert.commandWorked(db.getSiblingDB(dbName).test.insert({_id: 0, a: 1})); + const collName = "test" + Random.srand(); + assert.commandWorked(db.getSiblingDB(dbName).getCollection(collName).insert({_id: 0, a: 1})); + // Insert to the test collection to ensure that the change stream has something to // return. assert.commandWorked(db.t1.insert({_id: dbName})); @@ -116,7 +125,7 @@ filteredDBs.forEach(dbName => { cst.assertNextChangesEqual({cursor: cursor, expectedChanges: expected}); // Drop the test collection to avoid duplicate key errors if this test is run multiple // times. - assertDropCollection(db.getSiblingDB(dbName), "test"); + assertDropCollection(db.getSiblingDB(dbName), collName); }); // Dropping a database should generate drop entries for each collection followed by a database |