summaryrefslogtreecommitdiff
path: root/jstests/concurrency
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2016-09-02 11:59:14 -0400
committerJames Wahlin <james.wahlin@10gen.com>2016-09-09 10:59:01 -0400
commitcda2cd6edf49dfa28ff8ccdd7ad4c245c7fb5f1d (patch)
treee26cb7d33e583c46da1cf5d9d2049641774dc742 /jstests/concurrency
parent333fd85fc8b2c4978416f5bc54570c536fce0363 (diff)
downloadmongo-cda2cd6edf49dfa28ff8ccdd7ad4c245c7fb5f1d.tar.gz
SERVER-25807 Test concurrent view creations, modifications, and drops
Diffstat (limited to 'jstests/concurrency')
-rw-r--r--jstests/concurrency/fsm_workloads/view_catalog.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/jstests/concurrency/fsm_workloads/view_catalog.js b/jstests/concurrency/fsm_workloads/view_catalog.js
new file mode 100644
index 00000000000..31ed0072bb3
--- /dev/null
+++ b/jstests/concurrency/fsm_workloads/view_catalog.js
@@ -0,0 +1,91 @@
+'use strict';
+
+/**
+ * view_catalog.js
+ *
+ * Creates, modifies and drops view namespaces concurrently. Each worker operates on their own view,
+ * built on a shared underlying collection.
+ */
+
+load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections
+
+var $config = (function() {
+
+ var data = {
+ // Use the workload name as a prefix for the view name,
+ // since the workload name is assumed to be unique.
+ prefix: 'view_catalog'
+ };
+
+ var states = (function() {
+
+ function init(db, collName) {
+ this.threadCollName = db[collName].getName();
+ this.threadViewName = this.prefix + '_' + this.tid;
+ this.counter = 0;
+ }
+
+ function create(db, collName) {
+ this.counter++;
+ let pipeline = [{$match: {a: this.counter}}];
+ assertAlways.commandWorked(
+ db.createView(this.threadViewName, this.threadCollName, pipeline));
+ confirmViewDefinition(db, this.threadViewName, collName, pipeline);
+ }
+
+ function modify(db, collName) {
+ this.counter++;
+ let pipeline = [{$match: {a: this.counter}}];
+ assertAlways.commandWorked(db.runCommand(
+ {collMod: this.threadViewName, viewOn: this.threadCollName, pipeline: pipeline}));
+ confirmViewDefinition(db, this.threadViewName, collName, pipeline);
+ }
+
+ function drop(db, collName) {
+ assertAlways.commandWorked(db.runCommand({drop: this.threadViewName}));
+
+ let res = db.runCommand({listCollections: 1, filter: {name: this.threadViewName}});
+ assertAlways.commandWorked(res);
+ assertAlways.eq(0, res.cursor.firstBatch.length, tojson(res));
+ }
+
+ function confirmViewDefinition(db, viewName, collName, pipeline) {
+ let res = db.runCommand({listCollections: 1, filter: {name: viewName}});
+ assertAlways.commandWorked(res);
+ assertAlways.eq(1, res.cursor.firstBatch.length, tojson(res));
+ assertAlways.eq({
+ name: viewName,
+ type: "view",
+ options: {viewOn: collName, pipeline: pipeline},
+ info: {readOnly: true}
+ },
+ res.cursor.firstBatch[0],
+ tojson(res));
+ }
+
+ return {init: init, create: create, modify: modify, drop: drop};
+
+ })();
+
+ var transitions = {
+ init: {create: 1},
+ create: {modify: 0.75, drop: 0.25},
+ modify: {modify: 0.5, drop: 0.5},
+ drop: {create: 1}
+ };
+
+ function teardown(db, collName, cluster) {
+ var pattern = new RegExp('^' + this.prefix + '_\\d+$');
+ dropCollections(db, pattern);
+ }
+
+ return {
+ threadCount: 10,
+ iterations: 100,
+ data: data,
+ states: states,
+ transitions: transitions,
+ teardown: teardown
+ };
+
+})();