diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2016-02-26 16:33:23 -0500 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2016-03-10 11:03:15 -0500 |
commit | 6efa681435ec30467ca88edc449b241bb2c326bf (patch) | |
tree | 41f788b7cb9f2058247266f0f51f3b7947fa267b /jstests/readonly | |
parent | 947307dbf80d59313e8c154eea1612fedb01a321 (diff) | |
download | mongo-6efa681435ec30467ca88edc449b241bb2c326bf.tar.gz |
SERVER-22356 add read_only_sharded suite
Diffstat (limited to 'jstests/readonly')
-rw-r--r-- | jstests/readonly/aggregate.js | 14 | ||||
-rw-r--r-- | jstests/readonly/geo.js | 16 | ||||
-rw-r--r-- | jstests/readonly/lib/read_only_test.js | 122 |
3 files changed, 116 insertions, 36 deletions
diff --git a/jstests/readonly/aggregate.js b/jstests/readonly/aggregate.js index 9f74f739c4d..aba6a7aa3a3 100644 --- a/jstests/readonly/aggregate.js +++ b/jstests/readonly/aggregate.js @@ -69,13 +69,17 @@ runReadOnlyTest(function() { // Find titles nominated for the most awards. var mostAwardsPipeline = [ {$unwind: "$nominations"}, - {$group: {_id: "$nominations.title", count: {$sum: 1}}}, - {$sort: {count: -1}}, - {$limit: 2} + {$group: { + _id: "$nominations.title", + count: {$sum: 1}}}, + {$sort: {count: -1, _id: 1}}, + {$limit: 2}, ]; - assert.docEq(readableCollection.aggregate(mostAwardsPipeline).toArray(), - [{_id: "The Revenant", count: 3}, {_id: "Spotlight", count: 3}]); + assert.docEq(readableCollection.aggregate(mostAwardsPipeline).toArray(), [ + {_id: "Spotlight", count: 3}, + {_id: "The Revenant", count: 3} + ]); // Check that pipelines fail with allowDiskUse true. We use runCommand manually because // the helper has conflicting error handling logic. diff --git a/jstests/readonly/geo.js b/jstests/readonly/geo.js index 367cb89be96..f8113dabb06 100644 --- a/jstests/readonly/geo.js +++ b/jstests/readonly/geo.js @@ -33,11 +33,17 @@ runReadOnlyTest(function() { writableCollection.insertMany(locDocs); }, exec: function(readableCollection) { - var res = readableCollection.find({ - loc: - {$near: {$geometry: {type: "Point", coordinates: [40.7211404, -73.9591494]}}} - }).limit(1).toArray(); - assert.eq(res[0].name, "The Counting Room"); + var res = readableCollection.runCommand({ + geoNear: readableCollection.getName(), + near: { + type: "Point", + coordinates: [40.7211404, -73.9591494] + }, + spherical: true, + limit: 1 + }); + assert.commandWorked(res); + assert.eq(res.results[0].obj.name, "The Counting Room", printjson(res)); } }; }()); diff --git a/jstests/readonly/lib/read_only_test.js b/jstests/readonly/lib/read_only_test.js index 55af207a399..c0ee79a7370 100644 --- a/jstests/readonly/lib/read_only_test.js +++ b/jstests/readonly/lib/read_only_test.js @@ -1,4 +1,4 @@ -'use_strict'; +"use_strict"; function makeDirectoryReadOnly(dir) { if (_isWindows()) { @@ -16,44 +16,114 @@ function makeDirectoryWritable(dir) { } } -function runReadOnlyTest(test) { - printjson(test); +function StandaloneFixture() { +} + +StandaloneFixture.prototype.runLoadPhase = function runLoadPhase(test) { + this.mongod = MongoRunner.runMongod({}); + this.dbpath = this.mongod.dbpath; + + test.load(this.mongod.getDB("test")[test.name]); + MongoRunner.stopMongod(this.mongod); +}; + +StandaloneFixture.prototype.runExecPhase = function runExecPhase(test) { + try { + makeDirectoryReadOnly(this.dbpath); - assert.eq(typeof(test.exec), 'function'); - assert.eq(typeof(test.load), 'function'); - assert.eq(typeof(test.name), 'string'); + var options = { + readOnly: "", + noCleanData: true, + dbpath: this.dbpath + }; + + this.mongod = MongoRunner.runMongod(options); + + test.exec(this.mongod.getDB("test")[test.name]); + + MongoRunner.stopMongod(this.mongod); + } finally { + makeDirectoryWritable(this.dbpath); + } +}; + +function ShardedFixture() { + this.nShards = 3; +} - var options = { - storageEngine: TestData.storageEngine, - nopreallocj: '' - }; +ShardedFixture.prototype.runLoadPhase = function runLoadPhase(test) { + this.shardingTest = new ShardingTest({ + nopreallocj: true, + mongos: 1, + shards: this.nShards + }); - var writableMongod = MongoRunner.runMongod(options); - var dbpath = writableMongod.dbpath; + this.paths = this.shardingTest.getDBPaths(); - jsTest.log('starting load phase for test: ' + test.name); - test.load(writableMongod.getDB('test')[test.name]); + jsTest.log("sharding test collection..."); - MongoRunner.stopMongod(writableMongod); + // Use a hashed shard key so we actually hit multiple shards. + this.shardingTest.shardColl(test.name, {_id: "hashed"}); - makeDirectoryReadOnly(dbpath); + test.load(this.shardingTest.getDB("test")[test.name]); +}; +ShardedFixture.prototype.runExecPhase = function runExecPhase(test) { + jsTest.log("restarting shards..."); try { - var readOnlyOptions = - Object.extend(options, {readOnly: '', dbpath: dbpath, noCleanData: true}); + for (var i = 0; i < this.nShards; ++i) { + var opts = { + readOnly: "", + dbpath: this.paths[i] + }; + + this.shardingTest.restartMongod(i, opts, () => { + makeDirectoryReadOnly(this.paths[i]); + }); + } + + jsTest.log("restarting mongos..."); - var readOnlyMongod = MongoRunner.runMongod(readOnlyOptions); + this.shardingTest.restartMongos(0); - jsTest.log('starting execution phase for test: ' + test.name); - test.exec(readOnlyMongod.getDB('test')[test.name]); + test.exec(this.shardingTest.getDB("test")[test.name]); - // We need to make the directory writable so that MongoRunner can clean the dbpath. - makeDirectoryWritable(dbpath); - MongoRunner.stopMongod(readOnlyMongod); + this.paths.forEach((path) => { + makeDirectoryWritable(path); + }); + + this.shardingTest.stop(); } finally { - // One last time, just in case. - makeDirectoryWritable(dbpath); + this.paths.forEach((path) => { + makeDirectoryWritable(path); + }); + } +}; + +function runReadOnlyTest(test) { + + printjson(test); + + assert.eq(typeof(test.exec), "function"); + assert.eq(typeof(test.load), "function"); + assert.eq(typeof(test.name), "string"); + + var fixtureType = TestData.fixture || "standalone"; + + var fixture = null; + if (fixtureType === "standalone") { + fixture = new StandaloneFixture(); + } else if (fixtureType === "sharded") { + fixture = new ShardedFixture(); + } else { + throw new Error("fixtureType must be one of either 'standalone' or 'sharded'"); } + + jsTest.log("starting load phase for test: " + test.name); + fixture.runLoadPhase(test); + + jsTest.log("starting execution phase for test: " + test.name); + fixture.runExecPhase(test); } function * cycleN(arr, N) { |