summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2021-06-16 17:39:51 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-17 18:22:55 +0000
commit2450d18b845ea3477a9e418bb5c7b1f61f08c786 (patch)
tree42f785c6de65a18fd66a3611bf0609beff495171 /jstests
parentddca135c85508646315700bfb112d846756ec1a0 (diff)
downloadmongo-2450d18b845ea3477a9e418bb5c7b1f61f08c786.tar.gz
SERVER-57660 Fail time-series inserts if buckets collection does not exist
(cherry picked from commit e3dbc111bf3e3167346aa20f9b9558b8b7c70303)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/timeseries_insert_no_buckets_collection.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/jstests/noPassthrough/timeseries_insert_no_buckets_collection.js b/jstests/noPassthrough/timeseries_insert_no_buckets_collection.js
new file mode 100644
index 00000000000..d3515e0a9ca
--- /dev/null
+++ b/jstests/noPassthrough/timeseries_insert_no_buckets_collection.js
@@ -0,0 +1,64 @@
+/**
+ * Tests that inserting into a time-series collection fails if the corresponding buckets collection
+ * does not exist.
+ */
+(function() {
+'use strict';
+
+load('jstests/libs/fail_point_util.js');
+load("jstests/libs/parallel_shell_helpers.js");
+
+const conn = MongoRunner.runMongod();
+const testDB = conn.getDB('test');
+
+const timeFieldName = 'time';
+
+let testCounter = 0;
+const runTest = function(ordered, insertBeforeDrop, dropBucketsColl) {
+ const coll = testDB[jsTestName() + '_' + testCounter++];
+
+ assert.commandWorked(
+ testDB.createCollection(coll.getName(), {timeseries: {timeField: timeFieldName}}));
+
+ if (insertBeforeDrop) {
+ assert.commandWorked(coll.insert({_id: 0, [timeFieldName]: ISODate()}));
+ }
+
+ const fp = configureFailPoint(conn, 'hangTimeseriesInsertBeforeWrite');
+
+ const awaitDrop = startParallelShell(
+ funWithArgs(
+ function(collName, fpName, fpTimesEntered) {
+ load("jstests/libs/fail_point_util.js");
+
+ assert.commandWorked(db.adminCommand({
+ waitForFailPoint: fpName,
+ timesEntered: fpTimesEntered + 1,
+ maxTimeMS: kDefaultWaitForFailPointTimeout,
+ }));
+
+ assert(db[collName].drop());
+
+ assert.commandWorked(db.adminCommand({configureFailPoint: fpName, mode: 'off'}));
+ },
+ dropBucketsColl ? 'system.buckets.' + coll.getName() : coll.getName(),
+ fp.failPointName,
+ fp.timesEntered),
+ conn.port);
+
+ assert.commandFailedWithCode(
+ coll.insert({_id: 1, [timeFieldName]: ISODate()}, {ordered: ordered}),
+ ErrorCodes.NamespaceNotFound);
+
+ awaitDrop();
+};
+
+for (const dropBucketsColl of [false, true]) {
+ runTest(false /* ordered */, false /* insertBeforeDrop */, dropBucketsColl);
+ runTest(false /* ordered */, true /* insertBeforeDrop */, dropBucketsColl);
+ runTest(true /* ordered */, false /* insertBeforeDrop */, dropBucketsColl);
+ runTest(true /* ordered */, true /* insertBeforeDrop */, dropBucketsColl);
+}
+
+MongoRunner.stopMongod(conn);
+})();