summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/agg_explain_read_concern.js
diff options
context:
space:
mode:
authorJames Wahlin <james@mongodb.com>2018-03-22 15:02:08 -0400
committerJames Wahlin <james@mongodb.com>2018-03-23 11:19:17 -0400
commit56d96190ed8e2eb3bf4403300dd8d3822abb4e81 (patch)
treed9ea2c90b9608ec617710f1b453f93989a7bb822 /jstests/noPassthrough/agg_explain_read_concern.js
parent33e1da096f88609b27881d677f49e8d8147335ba (diff)
downloadmongo-56d96190ed8e2eb3bf4403300dd8d3822abb4e81.tar.gz
SERVER-33667 Test that readConcern level snapshot is not allowed for agg explain
Diffstat (limited to 'jstests/noPassthrough/agg_explain_read_concern.js')
-rw-r--r--jstests/noPassthrough/agg_explain_read_concern.js44
1 files changed, 29 insertions, 15 deletions
diff --git a/jstests/noPassthrough/agg_explain_read_concern.js b/jstests/noPassthrough/agg_explain_read_concern.js
index 408c1e4cc80..c5b7e2b8621 100644
--- a/jstests/noPassthrough/agg_explain_read_concern.js
+++ b/jstests/noPassthrough/agg_explain_read_concern.js
@@ -24,43 +24,57 @@
rst.startSet();
rst.initiate();
- let primary = rst.getPrimary();
- let testDB = primary.getDB("test");
- let coll = testDB.agg_explain_read_concern;
+ const primary = rst.getPrimary();
+ const session = primary.getDB("test").getMongo().startSession({causalConsistency: false});
+ const sessionDB = session.getDatabase("test");
+ const coll = sessionDB.agg_explain_read_concern;
// Test that explain is legal with readConcern "local".
assert.commandWorked(coll.explain().aggregate([], {readConcern: {level: "local"}}));
- assert.commandWorked(testDB.runCommand(
+ assert.commandWorked(sessionDB.runCommand(
{aggregate: coll.getName(), pipeline: [], explain: true, readConcern: {level: "local"}}));
- assert.commandWorked(testDB.runCommand({
+ assert.commandWorked(sessionDB.runCommand({
explain: {aggregate: coll.getName(), pipeline: [], cursor: {}},
readConcern: {level: "local"}
}));
// Test that explain is illegal with other readConcern levels.
- // TODO SERVER-33354: Add "snapshot" once the aggregate command supports.
- let nonLocalReadConcerns = ["majority", "available", "linearizable"];
+ const nonLocalReadConcerns = ["majority", "available", "linearizable", "snapshot"];
nonLocalReadConcerns.forEach(function(readConcernLevel) {
- assert.throws(() => coll.explain().aggregate([], {readConcern: {level: readConcernLevel}}));
-
- let cmdRes = testDB.runCommand({
+ let aggCmd = {
aggregate: coll.getName(),
pipeline: [],
explain: true,
readConcern: {level: readConcernLevel}
- });
+ };
+ let explainCmd = {
+ explain: {aggregate: coll.getName(), pipeline: [], cursor: {}},
+ readConcern: {level: readConcernLevel}
+ };
+
+ if (readConcernLevel === "snapshot") {
+ if (!sessionDB.serverStatus().storageEngine.supportsSnapshotReadConcern) {
+ return;
+ }
+ aggCmd.txnNumber = NumberLong(0);
+ explainCmd.txnNumber = NumberLong(1);
+
+ } else {
+ assert.throws(
+ () => coll.explain().aggregate([], {readConcern: {level: readConcernLevel}}));
+ }
+
+ let cmdRes = sessionDB.runCommand(aggCmd);
assert.commandFailedWithCode(cmdRes, ErrorCodes.InvalidOptions, tojson(cmdRes));
let expectedErrStr = "aggregate command does not support non-local readConcern";
assert.neq(cmdRes.errmsg.indexOf(expectedErrStr), -1, tojson(cmdRes));
- cmdRes = testDB.runCommand({
- explain: {aggregate: coll.getName(), pipeline: [], cursor: {}},
- readConcern: {level: readConcernLevel}
- });
+ cmdRes = sessionDB.runCommand(explainCmd);
assert.commandFailedWithCode(cmdRes, ErrorCodes.InvalidOptions, tojson(cmdRes));
expectedErrStr = "Command does not support read concern";
assert.neq(cmdRes.errmsg.indexOf(expectedErrStr), -1, tojson(cmdRes));
});
+ session.endSession();
rst.stopSet();
}());