summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2017-11-28 11:51:08 -0500
committerKyle Suarez <kyle.suarez@mongodb.com>2017-11-29 11:02:58 -0500
commit03f043b5ce4d29f498afffaa19e17fedb59fc20f (patch)
tree55f3d40c2a331aa64e21fba90943359f11df9630
parentfc8bff9cb031088e96cf8691b798e8d0a1be0207 (diff)
downloadmongo-03f043b5ce4d29f498afffaa19e17fedb59fc20f.tar.gz
SERVER-30384 unblacklist tests from causally consistent jscore passthroughs
Refactors more tests that should be allowed to run in the causally consistent passthroughs. (cherry picked from commit 92d366961e353f2552069091a3ae686db4e6c8eb)
-rw-r--r--buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough.yml10
-rw-r--r--buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough_auth.yml10
-rw-r--r--jstests/core/coveredIndex1.js158
-rw-r--r--jstests/core/fts_spanish.js66
-rw-r--r--jstests/core/null2.js67
-rw-r--r--jstests/core/sorta.js41
-rw-r--r--jstests/core/sortc.js51
7 files changed, 190 insertions, 213 deletions
diff --git a/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough.yml
index 67faf503c33..91ec0dc9f48 100644
--- a/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough.yml
@@ -115,15 +115,7 @@ selector:
# causally consistent.
- jstests/core/snapshot_queries.js
- jstests/core/find1.js
- # Tests that fail for Causal Consistency with default injected readPreference 'secondary'
- # "TODO SERVER-30384: These tests assume that documents are returned in the same order they are
- # written when no sort is specified; however, the order of documents within a collection can
- # be different across a primary and secondary."
- - jstests/core/coveredIndex1.js
- - jstests/core/fts_spanish.js
- - jstests/core/null2.js
- - jstests/core/sorta.js
- - jstests/core/sortc.js
+ # An index drop does not necessarily cause cursors to be killed on the secondary.
- jstests/core/ord.js
# plan_cache tests does not work because they check the plan_cache on the primary while the
# cache is created on the secondary.
diff --git a/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough_auth.yml b/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough_auth.yml
index 9af91f857a9..735cadb9bc8 100644
--- a/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough_auth.yml
+++ b/buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough_auth.yml
@@ -130,15 +130,7 @@ selector:
# causally consistent.
- jstests/core/snapshot_queries.js
- jstests/core/find1.js
- # Tests that fail for Causal Consistency with default injected readPreference 'secondary'
- # "TODO SERVER-30384: These tests assume that documents are returned in the same order they are
- # written when no sort is specified; however, the order of documents within a collection can
- # be different across a primary and secondary."
- - jstests/core/coveredIndex1.js
- - jstests/core/fts_spanish.js
- - jstests/core/null2.js
- - jstests/core/sorta.js
- - jstests/core/sortc.js
+ # An index drop does not necessarily cause cursors to be killed on the secondary.
- jstests/core/ord.js
# plan_cache tests does not work because they check the plan_cache on the primary while the
# cache is created on the secondary.
diff --git a/jstests/core/coveredIndex1.js b/jstests/core/coveredIndex1.js
index 1e982f0a8ea..9e6c892567e 100644
--- a/jstests/core/coveredIndex1.js
+++ b/jstests/core/coveredIndex1.js
@@ -1,90 +1,88 @@
-// Cannot implicitly shard accessed collections because queries on a sharded collection are not
-// able to be covered when they aren't on the shard key since the document needs to be fetched in
-// order to apply the SHARDING_FILTER stage.
-// @tags: [assumes_unsharded_collection]
+/**
+ * Tests queries that are covered by an index.
+ *
+ * This test cannot implicitly shard accessed collections because queries on a sharded collection
+ * cannot be covered when they aren't on the shard key since the document needs to be fetched in
+ * order to apply the SHARDING_FILTER stage.
+ * @tags: [assumes_unsharded_collection]
+ */
+(function() {
+ "use strict";
-t = db["jstests_coveredIndex1"];
-t.drop();
+ const coll = db["jstests_coveredIndex1"];
+ coll.drop();
-// Include helpers for analyzing explain output.
-load("jstests/libs/analyze_plan.js");
+ // Include helpers for analyzing explain output.
+ load("jstests/libs/analyze_plan.js");
-t.save({fn: "john", ln: "doe"});
-t.save({fn: "jack", ln: "doe"});
-t.save({fn: "john", ln: "smith"});
-t.save({fn: "jack", ln: "black"});
-t.save({fn: "bob", ln: "murray"});
-t.save({fn: "aaa", ln: "bbb", obj: {a: 1, b: "blah"}});
-assert.eq(t.findOne({ln: "doe"}).fn, "john", "Cannot find right record");
-assert.eq(t.count(), 6, "Not right length");
+ assert.writeOK(coll.insert({order: 0, fn: "john", ln: "doe"}));
+ assert.writeOK(coll.insert({order: 1, fn: "jack", ln: "doe"}));
+ assert.writeOK(coll.insert({order: 2, fn: "john", ln: "smith"}));
+ assert.writeOK(coll.insert({order: 3, fn: "jack", ln: "black"}));
+ assert.writeOK(coll.insert({order: 4, fn: "bob", ln: "murray"}));
+ assert.writeOK(coll.insert({order: 5, fn: "aaa", ln: "bbb", obj: {a: 1, b: "blah"}}));
-// use simple index
-t.ensureIndex({ln: 1});
-assert(!isIndexOnly(t.find({ln: "doe"}).explain().queryPlanner.winningPlan),
- "Find using covered index but all fields are returned");
-assert(!isIndexOnly(t.find({ln: "doe"}, {ln: 1}).explain().queryPlanner.winningPlan),
- "Find using covered index but _id is returned");
-assert(isIndexOnly(t.find({ln: "doe"}, {ln: 1, _id: 0}).explain().queryPlanner.winningPlan),
- "Find is not using covered index");
+ /**
+ * Asserts that running the find command with query 'query' and projection 'projection' is
+ * covered if 'isCovered' is true, or not covered otherwise.
+ *
+ * If 'hint' is specified, use 'hint' as the suggested index.
+ */
+ function assertIfQueryIsCovered(query, projection, isCovered, hint) {
+ let cursor = coll.find(query, projection);
+ if (hint) {
+ cursor = cursor.hint(hint);
+ }
+ const explain = cursor.explain();
+ assert.commandWorked(explain);
-// this time, without a query spec
-// SERVER-2109
-// assert.eq( t.find({}, {ln: 1, _id: 0}).explain().indexOnly, true, "Find is not using covered
-// index");
-assert(isIndexOnly(t.find({}, {ln: 1, _id: 0}).hint({ln: 1}).explain().queryPlanner.winningPlan),
- "Find is not using covered index");
+ assert(explain.hasOwnProperty("queryPlanner"), tojson(explain));
+ assert(explain.queryPlanner.hasOwnProperty("winningPlan"), tojson(explain));
+ const winningPlan = explain.queryPlanner.winningPlan;
+ if (isCovered) {
+ assert(isIndexOnly(winningPlan),
+ "Query " + tojson(query) + " with projection " + tojson(projection) +
+ " should have been covered, but got this plan: " + tojson(winningPlan));
+ } else {
+ assert(!isIndexOnly(winningPlan),
+ "Query " + tojson(query) + " with projection " + tojson(projection) +
+ " should not have been covered, but got this plan: " + tojson(winningPlan));
+ }
+ }
-// use compound index
-t.dropIndex({ln: 1});
-t.ensureIndex({ln: 1, fn: 1});
-// return 1 field
-var plan = t.find({ln: "doe"}, {ln: 1, _id: 0}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
-// return both fields, multiple docs returned
-var plan = t.find({ln: "doe"}, {ln: 1, fn: 1, _id: 0}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
-// match 1 record using both fields
-var plan = t.find({ln: "doe", fn: "john"}, {ln: 1, fn: 1, _id: 0}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
-// change ordering
-var plan = t.find({fn: "john", ln: "doe"}, {fn: 1, ln: 1, _id: 0}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
-// ask from 2nd index key
-var plan = t.find({fn: "john"}, {fn: 1, _id: 0}).explain();
-assert(!isIndexOnly(plan.queryPlanner.winningPlan),
- "Find is using covered index, but doesnt have 1st key");
+ // Create an index on one field.
+ assert.commandWorked(coll.createIndex({ln: 1}));
+ assertIfQueryIsCovered({}, {}, false);
+ assertIfQueryIsCovered({ln: "doe"}, {}, false);
+ assertIfQueryIsCovered({ln: "doe"}, {ln: 1}, false);
+ assertIfQueryIsCovered({ln: "doe"}, {ln: 1, _id: 0}, true, {ln: 1});
-// repeat above but with _id field
-t.dropIndex({ln: 1, fn: 1});
-t.ensureIndex({_id: 1, ln: 1});
-// return 1 field
-var plan = t.find({_id: 123, ln: "doe"}, {_id: 1}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
-// match 1 record using both fields
-var plan = t.find({_id: 123, ln: "doe"}, {ln: 1}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
-// change ordering
-var plan = t.find({ln: "doe", _id: 123}, {ln: 1, _id: 1}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
-// ask from 2nd index key
-var plan = t.find({ln: "doe"}, {ln: 1}).explain();
-assert(!isIndexOnly(plan.queryPlanner.winningPlan),
- "Find is using covered index, but doesnt have 1st key");
+ // Create a compound index.
+ assert.commandWorked(coll.dropIndex({ln: 1}));
+ assert.commandWorked(coll.createIndex({ln: 1, fn: 1}));
+ assertIfQueryIsCovered({ln: "doe"}, {ln: 1, _id: 0}, true);
+ assertIfQueryIsCovered({ln: "doe"}, {ln: 1, fn: 1, _id: 0}, true);
+ assertIfQueryIsCovered({ln: "doe", fn: "john"}, {ln: 1, fn: 1, _id: 0}, true);
+ assertIfQueryIsCovered({fn: "john", ln: "doe"}, {fn: 1, ln: 1, _id: 0}, true);
+ assertIfQueryIsCovered({fn: "john"}, {fn: 1, _id: 0}, false);
-// repeat above but with embedded obj
-t.dropIndex({_id: 1, ln: 1});
-t.ensureIndex({obj: 1});
-var plan = t.find({"obj.a": 1}, {obj: 1}).explain();
-assert(!isIndexOnly(plan.queryPlanner.winningPlan), "Shouldnt use index when introspecting object");
-var plan = t.find({obj: {a: 1, b: "blah"}}).explain();
-assert(!isIndexOnly(plan.queryPlanner.winningPlan), "Index doesnt have all fields to cover");
-var plan = t.find({obj: {a: 1, b: "blah"}}, {obj: 1, _id: 0}).explain();
-assert(isIndexOnly(plan.queryPlanner.winningPlan), "Find is not using covered index");
+ // Repeat the above test, but with a compound index involving _id.
+ assert.commandWorked(coll.dropIndex({ln: 1, fn: 1}));
+ assert.commandWorked(coll.createIndex({_id: 1, ln: 1}));
+ assertIfQueryIsCovered({_id: 123, ln: "doe"}, {_id: 1}, true);
+ assertIfQueryIsCovered({_id: 123, ln: "doe"}, {ln: 1}, true);
+ assertIfQueryIsCovered({ln: "doe", _id: 123}, {ln: 1, _id: 1}, true);
+ assertIfQueryIsCovered({ln: "doe"}, {ln: 1}, false);
-// repeat above but with index on sub obj field
-t.dropIndex({obj: 1});
-t.ensureIndex({"obj.a": 1, "obj.b": 1});
-var plan = t.find({"obj.a": 1}, {obj: 1}).explain();
-assert(!isIndexOnly(plan.queryPlanner.winningPlan), "Shouldnt use index when introspecting object");
+ // Create an index on an embedded object.
+ assert.commandWorked(coll.dropIndex({_id: 1, ln: 1}));
+ assert.commandWorked(coll.createIndex({obj: 1}));
+ assertIfQueryIsCovered({"obj.a": 1}, {obj: 1}, false);
+ assertIfQueryIsCovered({obj: {a: 1, b: "blah"}}, false);
+ assertIfQueryIsCovered({obj: {a: 1, b: "blah"}}, {obj: 1, _id: 0}, true);
-assert(t.validate().valid);
+ // Create indexes on fields inside an embedded object.
+ assert.commandWorked(coll.dropIndex({obj: 1}));
+ assert.commandWorked(coll.createIndex({"obj.a": 1, "obj.b": 1}));
+ assertIfQueryIsCovered({"obj.a": 1}, {obj: 1}, false);
+}());
diff --git a/jstests/core/fts_spanish.js b/jstests/core/fts_spanish.js
index 74d71cceddf..89915cf2889 100644
--- a/jstests/core/fts_spanish.js
+++ b/jstests/core/fts_spanish.js
@@ -1,29 +1,37 @@
-
-load("jstests/libs/fts.js");
-
-t = db.text_spanish;
-t.drop();
-
-t.save({_id: 1, title: "mi blog", text: "Este es un blog de prueba"});
-t.save({_id: 2, title: "mi segundo post", text: "Este es un blog de prueba"});
-t.save({_id: 3, title: "cuchillos son divertidos", text: "este es mi tercer blog stemmed"});
-t.save({_id: 4, language: "en", title: "My fourth blog", text: "This stemmed blog is in english"});
-
-// default weight is 1
-// specify weights if you want a field to be more meaningull
-t.ensureIndex({"title": "text", text: "text"}, {weights: {title: 10}, default_language: "es"});
-
-res = t.find({"$text": {"$search": "blog"}});
-assert.eq(4, res.length());
-
-assert.eq([4], queryIDS(t, "stem"));
-assert.eq([3], queryIDS(t, "stemmed"));
-assert.eq([4], queryIDS(t, "stemmed", null, {"$language": "en"}));
-
-assert.eq([1, 2], queryIDS(t, "prueba"));
-
-assert.writeError(t.save({_id: 5, language: "spanglish", title: "", text: ""}));
-
-t.dropIndexes();
-res = t.ensureIndex({"title": "text", text: "text"}, {default_language: "spanglish"});
-assert.neq(null, res);
+(function() {
+ "use strict";
+
+ load("jstests/libs/fts.js");
+
+ const coll = db.text_spanish;
+ coll.drop();
+
+ assert.writeOK(coll.insert({_id: 1, title: "mi blog", text: "Este es un blog de prueba"}));
+ assert.writeOK(
+ coll.insert({_id: 2, title: "mi segundo post", text: "Este es un blog de prueba"}));
+ assert.writeOK(coll.insert(
+ {_id: 3, title: "cuchillos son divertidos", text: "este es mi tercer blog stemmed"}));
+ assert.writeOK(coll.insert({
+ _id: 4,
+ language: "en",
+ title: "My fourth blog",
+ text: "This stemmed blog is in english"
+ }));
+
+ // Create a text index, giving more weight to the "title" field.
+ assert.commandWorked(coll.createIndex({title: "text", text: "text"},
+ {weights: {title: 10}, default_language: "es"}));
+
+ assert.eq(4, coll.count({$text: {$search: "blog"}}));
+ assert.eq([4], queryIDS(coll, "stem"));
+ assert.eq([3], queryIDS(coll, "stemmed"));
+ assert.eq([4], queryIDS(coll, "stemmed", null, {"$language": "en"}));
+ assert.eq([1, 2], queryIDS(coll, "prueba").sort());
+
+ assert.writeError(coll.insert({_id: 5, language: "spanglish", title: "", text: ""}));
+
+ assert.commandWorked(coll.dropIndexes());
+ assert.commandFailedWithCode(
+ coll.createIndex({title: "text", text: "text"}, {default_language: "spanglish"}),
+ ErrorCodes.CannotCreateIndex);
+}());
diff --git a/jstests/core/null2.js b/jstests/core/null2.js
index 0e8173bf874..bc18c66b945 100644
--- a/jstests/core/null2.js
+++ b/jstests/core/null2.js
@@ -1,39 +1,28 @@
-
-t = db.null2;
-t.drop();
-
-t.insert({_id: 1, a: [{b: 5}]});
-t.insert({_id: 2, a: [{}]});
-t.insert({_id: 3, a: []});
-t.insert({_id: 4, a: [{}, {b: 5}]});
-t.insert({_id: 5, a: [5, {b: 5}]});
-
-function doQuery(query) {
- printjson(query);
- t.find(query).forEach(function(z) {
- print("\t" + tojson(z));
- });
- return t.find(query).count();
-}
-
-function getIds(query) {
- var ids = [];
- t.find(query).forEach(function(z) {
- ids.push(z._id);
- });
- return ids;
-}
-
-theQueries = [{"a.b": null}, {"a.b": {$in: [null]}}];
-
-for (var i = 0; i < theQueries.length; i++) {
- assert.eq(2, doQuery(theQueries[i]));
- assert.eq([2, 4], getIds(theQueries[i]));
-}
-
-t.ensureIndex({"a.b": 1});
-
-for (var i = 0; i < theQueries.length; i++) {
- assert.eq(2, doQuery(theQueries[i]));
- assert.eq([2, 4], getIds(theQueries[i]));
-}
+(function() {
+ "use strict";
+
+ const coll = db.null2;
+ coll.drop();
+
+ assert.writeOK(coll.insert({_id: 1, a: [{b: 5}]}));
+ assert.writeOK(coll.insert({_id: 2, a: [{}]}));
+ assert.writeOK(coll.insert({_id: 3, a: []}));
+ assert.writeOK(coll.insert({_id: 4, a: [{}, {b: 5}]}));
+ assert.writeOK(coll.insert({_id: 5, a: [5, {b: 5}]}));
+
+ function getIds(query) {
+ let ids = [];
+ coll.find(query).sort({_id: 1}).forEach(doc => ids.push(doc._id));
+ return ids;
+ }
+
+ const queries = [{"a.b": null}, {"a.b": {$in: [null]}}];
+ for (let query of queries) {
+ assert.eq([2, 4], getIds(query), "Did not match the expected documents");
+ }
+
+ assert.commandWorked(coll.createIndex({"a.b": 1}));
+ for (let query of queries) {
+ assert.eq([2, 4], getIds(query), "Did not match the expected documents");
+ }
+}());
diff --git a/jstests/core/sorta.js b/jstests/core/sorta.js
index 2b78b8493e4..91f36ba3621 100644
--- a/jstests/core/sorta.js
+++ b/jstests/core/sorta.js
@@ -3,27 +3,28 @@
(function() {
'use strict';
- var t = db.jstests_sorta;
- t.drop();
+ var coll = db.jstests_sorta;
+ coll.drop();
- assert.writeOK(t.insert({_id: 0, a: MinKey}));
- assert.writeOK(t.save({_id: 3, a: null}));
- assert.writeOK(t.save({_id: 1, a: []}));
- assert.writeOK(t.save({_id: 7, a: [2]}));
- assert.writeOK(t.save({_id: 4}));
- assert.writeOK(t.save({_id: 5, a: null}));
- assert.writeOK(t.save({_id: 2, a: []}));
- assert.writeOK(t.save({_id: 6, a: 1}));
- assert.writeOK(t.insert({_id: 8, a: MaxKey}));
-
- function sorted(arr) {
- assert.eq(9, arr.length, tojson(arr));
- for (var i = 1; i < arr.length; ++i) {
- assert.lte(arr[i - 1]._id, arr[i]._id);
- }
+ const docs = [
+ {_id: 0, a: MinKey},
+ {_id: 1, a: []},
+ {_id: 2, a: []},
+ {_id: 3, a: null},
+ {_id: 4},
+ {_id: 5, a: null},
+ {_id: 6, a: 1},
+ {_id: 7, a: [2]},
+ {_id: 8, a: MaxKey}
+ ];
+ const bulk = coll.initializeUnorderedBulkOp();
+ for (let doc of docs) {
+ bulk.insert(doc);
}
+ assert.writeOK(bulk.execute());
+
+ assert.eq(coll.find().sort({a: 1, _id: 1}).toArray(), docs);
- sorted(t.find().sort({a: 1}).toArray());
- assert.commandWorked(t.ensureIndex({a: 1}));
- sorted(t.find().sort({a: 1}).hint({a: 1}).toArray());
+ assert.commandWorked(coll.createIndex({a: 1, _id: 1}));
+ assert.eq(coll.find().sort({a: 1, _id: 1}).toArray(), docs);
})();
diff --git a/jstests/core/sortc.js b/jstests/core/sortc.js
index e2443599955..2b1070b8b6b 100644
--- a/jstests/core/sortc.js
+++ b/jstests/core/sortc.js
@@ -1,37 +1,34 @@
// Test sorting with skipping and multiple candidate query plans.
+(function() {
+ "use strict";
-t = db.jstests_sortc;
-t.drop();
+ const coll = db.jstests_sortc;
+ coll.drop();
-t.save({a: 1});
-t.save({a: 2});
+ assert.writeOK(coll.insert({a: 1}));
+ assert.writeOK(coll.insert({a: 2}));
-function checkA(a, sort, skip, query) {
- query = query || {};
- assert.eq(a, t.find(query).sort(sort).skip(skip)[0].a);
-}
+ function checkA(a, sort, skip, query) {
+ query = query || {};
+ assert.eq(a, coll.find(query).sort(sort).skip(skip)[0].a);
+ }
-function checkSortAndSkip() {
- checkA(1, {a: 1}, 0);
- checkA(2, {a: 1}, 1);
+ function checkSortAndSkip() {
+ checkA(1, {a: 1}, 0);
+ checkA(2, {a: 1}, 1);
- checkA(1, {a: 1}, 0, {a: {$gt: 0}, b: null});
- checkA(2, {a: 1}, 1, {a: {$gt: 0}, b: null});
+ checkA(1, {a: 1}, 0, {a: {$gt: 0}, b: null});
+ checkA(2, {a: 1}, 1, {a: {$gt: 0}, b: null});
- checkA(2, {a: -1}, 0);
- checkA(1, {a: -1}, 1);
+ checkA(2, {a: -1}, 0);
+ checkA(1, {a: -1}, 1);
- checkA(2, {a: -1}, 0, {a: {$gt: 0}, b: null});
- checkA(1, {a: -1}, 1, {a: {$gt: 0}, b: null});
+ checkA(2, {a: -1}, 0, {a: {$gt: 0}, b: null});
+ checkA(1, {a: -1}, 1, {a: {$gt: 0}, b: null});
+ }
- checkA(1, {$natural: 1}, 0);
- checkA(2, {$natural: 1}, 1);
+ checkSortAndSkip();
- checkA(2, {$natural: -1}, 0);
- checkA(1, {$natural: -1}, 1);
-}
-
-checkSortAndSkip();
-
-t.ensureIndex({a: 1});
-checkSortAndSkip();
+ assert.commandWorked(coll.createIndex({a: 1}));
+ checkSortAndSkip();
+}());