summaryrefslogtreecommitdiff
path: root/jstests/concurrency
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2021-10-27 14:33:37 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-27 15:42:39 +0000
commit9e931d09ba9a1269bf11a689e06e56f61dab7e21 (patch)
treebdcd544bbce9ab90b70b73691a0b16a11309cf44 /jstests/concurrency
parent66ca85ffb72bf822202e32954900469027f1fe8b (diff)
downloadmongo-9e931d09ba9a1269bf11a689e06e56f61dab7e21.tar.gz
SERVER-59662 Test killing time-series inserts
Diffstat (limited to 'jstests/concurrency')
-rw-r--r--jstests/concurrency/fsm_workloads/timeseries_insert_kill_op.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/jstests/concurrency/fsm_workloads/timeseries_insert_kill_op.js b/jstests/concurrency/fsm_workloads/timeseries_insert_kill_op.js
new file mode 100644
index 00000000000..71732f2f831
--- /dev/null
+++ b/jstests/concurrency/fsm_workloads/timeseries_insert_kill_op.js
@@ -0,0 +1,78 @@
+'use strict';
+
+/**
+ * Tests killing time-series inserts.
+ *
+ * @tags: [
+ * requires_timeseries,
+ * ]
+ */
+
+var $config = (function() {
+ const timeFieldName = 'time';
+ const metaFieldName = 'tag';
+
+ const insert = function(db, collName, ordered) {
+ const docs = [];
+ for (let i = 0; i < 1000; ++i) {
+ docs.push({[timeFieldName]: ISODate(), [metaFieldName]: i % 10});
+ }
+ // TODO (SERVER-44673): Use assert.commandWorkedOrFailedWithCode without special handling.
+ const res = db.runCommand({insert: collName, documents: docs, ordered: ordered});
+ if (res.hasOwnProperty('writeErrors') && res.writeErrors.length > 0) {
+ assert.eq(res.writeErrors[0].code, ErrorCodes.Interrupted);
+ } else if (res.hasOwnProperty('writeConcernError')) {
+ assert.eq(res.writeConcernError.code, ErrorCodes.Interrupted);
+ } else {
+ assert.commandWorkedOrFailedWithCode(res, ErrorCodes.Interrupted);
+ }
+ };
+
+ const states = {
+ init: function(db, collName) {},
+
+ insertOrdered: function(db, collName) {
+ insert(db, collName, true);
+ },
+
+ insertUnordered: function(db, collName) {
+ insert(db, collName, false);
+ },
+
+ killInsert: function(db, collName) {
+ const inprog =
+ assert.commandWorked(db.currentOp({ns: db[collName].getFullName(), op: 'insert'}))
+ .inprog;
+ if (inprog.length) {
+ assert.commandWorked(
+ db.adminCommand({killOp: 1, op: inprog[Random.randInt(inprog.length)].opid}));
+ }
+ },
+ };
+
+ const setup = function(db, collName) {
+ assert.commandWorked(db.createCollection(
+ collName, {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
+ };
+
+ const standardTransition = {
+ insertOrdered: 0.4,
+ insertUnordered: 0.4,
+ killInsert: 0.2,
+ };
+
+ const transitions = {
+ init: standardTransition,
+ insertOrdered: standardTransition,
+ insertUnordered: standardTransition,
+ killInsert: standardTransition,
+ };
+
+ return {
+ threadCount: 10,
+ iterations: 100,
+ setup: setup,
+ states: states,
+ transitions: transitions,
+ };
+})();