summaryrefslogtreecommitdiff
path: root/jstests/change_streams
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-08-27 00:13:02 +0000
committerevergreen <evergreen@mongodb.com>2019-08-27 00:13:02 +0000
commit40f226b5a9bfb4863268334d287a46fb226a22cf (patch)
tree98b44b3a3bce352f30f0b05d264ab4e903b9aef9 /jstests/change_streams
parentdd2de577670e9461c31ca9e6fe5c9713b4401181 (diff)
downloadmongo-40f226b5a9bfb4863268334d287a46fb226a22cf.tar.gz
SERVER-33272 Proactively close newly empty databases
Diffstat (limited to 'jstests/change_streams')
-rw-r--r--jstests/change_streams/whole_cluster.js17
-rw-r--r--jstests/change_streams/whole_cluster_metadata_notifications.js7
-rw-r--r--jstests/change_streams/whole_cluster_resumability.js7
-rw-r--r--jstests/change_streams/whole_db_resumability.js7
4 files changed, 33 insertions, 5 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
diff --git a/jstests/change_streams/whole_cluster_metadata_notifications.js b/jstests/change_streams/whole_cluster_metadata_notifications.js
index 8c72df1ba44..839684a054e 100644
--- a/jstests/change_streams/whole_cluster_metadata_notifications.js
+++ b/jstests/change_streams/whole_cluster_metadata_notifications.js
@@ -18,6 +18,13 @@ const adminDB = db.getSiblingDB("admin");
assert.commandWorked(testDB1.dropDatabase());
assert.commandWorked(testDB2.dropDatabase());
+// Create additional collections to prevent the databases from being closed when the other
+// collections are dropped.
+assert.commandWorkedOrFailedWithCode(testDB1.createCollection("unused"),
+ ErrorCodes.NamespaceExists);
+assert.commandWorkedOrFailedWithCode(testDB2.createCollection("unused"),
+ ErrorCodes.NamespaceExists);
+
// Create one collection on each database.
let [db1Coll, db2Coll] =
[testDB1, testDB2].map((testDB) => assertDropAndRecreateCollection(testDB, "test"));
diff --git a/jstests/change_streams/whole_cluster_resumability.js b/jstests/change_streams/whole_cluster_resumability.js
index 8564d01e770..6b6d28d76cf 100644
--- a/jstests/change_streams/whole_cluster_resumability.js
+++ b/jstests/change_streams/whole_cluster_resumability.js
@@ -8,6 +8,13 @@ load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.
// Create two databases, with one collection in each.
const testDBs = [db.getSiblingDB(jsTestName()), db.getSiblingDB(jsTestName() + "_other")];
+
+// Create additional collections to prevent the databases from being closed when the other
+// collections are dropped.
+testDBs.map((db) => {
+ assert.commandWorkedOrFailedWithCode(db.createCollection("unused"), ErrorCodes.NamespaceExists);
+});
+
let [db1Coll, db2Coll] = testDBs.map((db) => assertDropAndRecreateCollection(db, "test"));
const adminDB = db.getSiblingDB("admin");
diff --git a/jstests/change_streams/whole_db_resumability.js b/jstests/change_streams/whole_db_resumability.js
index 2e2c0e183ec..725035c193c 100644
--- a/jstests/change_streams/whole_db_resumability.js
+++ b/jstests/change_streams/whole_db_resumability.js
@@ -9,8 +9,13 @@ load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Col
load("jstests/libs/change_stream_util.js"); // For ChangeStreamTest.
load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers.
-// Drop and recreate the collections to be used in this set of tests.
const testDB = db.getSiblingDB(jsTestName());
+
+// Create an additional collection to prevent the database from being closed when the other
+// collection is dropped.
+assert.commandWorkedOrFailedWithCode(testDB.createCollection("unused"), ErrorCodes.NamespaceExists);
+
+// Drop and recreate the collections to be used in this set of tests.
let coll = assertDropAndRecreateCollection(testDB, "resume_coll");
const otherColl = assertDropAndRecreateCollection(testDB, "resume_coll_other");