summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-02-22 10:51:51 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-02-23 10:26:04 -0500
commit5c48613edb4fa209b7b3bd966f35902cb31ede66 (patch)
tree10b7d9bb214a51ac935e9a890efe53ffedf0ece6
parent5a2d2815728c06ad3bc50766354fe7524e02670d (diff)
downloadmongo-5c48613edb4fa209b7b3bd966f35902cb31ede66.tar.gz
SERVER-22765 Improve error checking in sharding tests
Some sharding tests do not check that the enableSharding, shardCollection, moveChunk and etc. commands worked.
-rw-r--r--jstests/sharding/auth_add_shard.js4
-rw-r--r--jstests/sharding/bouncing_count.js51
-rw-r--r--jstests/sharding/major_version_check.js13
-rw-r--r--jstests/sharding/sharding_state_after_stepdown.js5
-rw-r--r--jstests/sharding/test_stacked_migration_cleanup.js3
-rw-r--r--jstests/sharding/update_immutable_fields.js18
-rw-r--r--jstests/sharding/upsert_sharded.js40
7 files changed, 69 insertions, 65 deletions
diff --git a/jstests/sharding/auth_add_shard.js b/jstests/sharding/auth_add_shard.js
index 78db5dd28e6..8435c768c4f 100644
--- a/jstests/sharding/auth_add_shard.js
+++ b/jstests/sharding/auth_add_shard.js
@@ -48,7 +48,7 @@ MongoRunner.stopMongod(conn);
//start mongod again, this time with keyfile
var conn = MongoRunner.runMongod({keyFile: "jstests/libs/key1"});
//try adding the new shard
-printjson(assert.commandWorked(admin.runCommand({ addShard: conn.host })));
+assert.commandWorked(admin.runCommand({ addShard: conn.host }));
//Add some data
var db = mongos.getDB("foo");
@@ -80,7 +80,7 @@ st.startBalancer();
//--------------- Test 3 --------------------
// now drain the shard
-printjson(assert.commandWorked(admin.runCommand({removeShard: conn.host})));
+assert.commandWorked(admin.runCommand({removeShard: conn.host}));
// give it some time to drain
assert.soon(function() {
diff --git a/jstests/sharding/bouncing_count.js b/jstests/sharding/bouncing_count.js
index e148fae1ed6..d2df8c92984 100644
--- a/jstests/sharding/bouncing_count.js
+++ b/jstests/sharding/bouncing_count.js
@@ -1,9 +1,8 @@
// Tests whether new sharding is detected on insert by mongos
(function() {
+'use strict';
-var st = new ShardingTest({ name: "test",
- shards: 10,
- mongos: 3 });
+var st = new ShardingTest({ shards: 10, mongos: 3 });
var mongosA = st.s0;
var mongosB = st.s1;
@@ -12,43 +11,47 @@ var mongosC = st.s2;
var admin = mongosA.getDB("admin");
var config = mongosA.getDB("config");
-var collA = mongosA.getCollection( "foo.bar" );
-var collB = mongosB.getCollection( "" + collA );
-var collC = mongosB.getCollection( "" + collA );
+var collA = mongosA.getCollection("foo.bar");
+var collB = mongosB.getCollection("" + collA);
+var collC = mongosB.getCollection("" + collA);
-admin.runCommand({ enableSharding : "" + collA.getDB() });
-st.ensurePrimaryShard(collA.getDB().getName(), 'shard0001');
-admin.runCommand({ shardCollection : "" + collA, key : { _id : 1 } });
+var shards = config.shards.find().sort({ _id: 1 }).toArray();
-var shards = config.shards.find().sort({ _id : 1 }).toArray();
+assert.commandWorked(admin.runCommand({ enableSharding: "" + collA.getDB() }));
+st.ensurePrimaryShard(collA.getDB().getName(), shards[1]._id);
+assert.commandWorked(admin.runCommand({ shardCollection: "" + collA, key: { _id: 1 } }));
-jsTestLog( "Splitting up the collection..." );
+jsTestLog("Splitting up the collection...");
// Split up the collection
-for( var i = 0; i < shards.length; i++ ){
- printjson( admin.runCommand({ split : "" + collA, middle : { _id : i } }) );
- printjson( admin.runCommand({ moveChunk : "" + collA, find : { _id : i }, to : shards[i]._id }) );
+for(var i = 0; i < shards.length; i++){
+ assert.commandWorked(admin.runCommand({ split: "" + collA, middle: { _id: i } }));
+ assert.commandWorked(
+ admin.runCommand({ moveChunk: "" + collA, find: { _id: i }, to: shards[i]._id }));
}
-mongosB.getDB("admin").runCommand({ flushRouterConfig : 1 });
-mongosC.getDB("admin").runCommand({ flushRouterConfig : 1 });
-printjson( collB.count() );
-printjson( collC.count() );
+mongosB.getDB("admin").runCommand({ flushRouterConfig: 1 });
+mongosC.getDB("admin").runCommand({ flushRouterConfig: 1 });
+
+printjson(collB.count());
+printjson(collC.count());
// Change up all the versions...
-for( var i = 0; i < shards.length; i++ ){
- printjson( admin.runCommand({ moveChunk : "" + collA, find : { _id : i }, to : shards[ (i + 1) % shards.length ]._id }) );
+for(var i = 0; i < shards.length; i++){
+ assert.commandWorked(admin.runCommand({ moveChunk: "" + collA,
+ find: { _id: i },
+ to: shards[ (i + 1) % shards.length ]._id }));
}
// Make sure mongos A is up-to-date
-mongosA.getDB("admin").runCommand({ flushRouterConfig : 1 });
+mongosA.getDB("admin").runCommand({ flushRouterConfig: 1 });
st.printShardingStatus(true);
-jsTestLog( "Running count!" );
+jsTestLog("Running count!");
-printjson( collB.count() );
-printjson( collC.find().toArray() );
+printjson(collB.count());
+printjson(collC.find().toArray());
st.stop();
diff --git a/jstests/sharding/major_version_check.js b/jstests/sharding/major_version_check.js
index 5bfacd59dfc..cef05411e0c 100644
--- a/jstests/sharding/major_version_check.js
+++ b/jstests/sharding/major_version_check.js
@@ -1,9 +1,10 @@
//
// Tests that only a correct major-version is needed to connect to a shard via mongos
//
+(function() {
+'use strict';
var st = new ShardingTest({ shards : 1, mongos : 2 });
-st.stopBalancer();
var mongos = st.s0;
var staleMongos = st.s1;
@@ -12,14 +13,14 @@ var config = mongos.getDB( "config" );
var coll = mongos.getCollection( "foo.bar" );
// Shard collection
-printjson( admin.runCommand({ enableSharding : coll.getDB() + "" }) );
-printjson( admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }) );
+assert.commandWorked(admin.runCommand({ enableSharding : coll.getDB() + "" }));
+assert.commandWorked(admin.runCommand({ shardCollection : coll + "", key : { _id : 1 } }));
// Make sure our stale mongos is up-to-date with no splits
staleMongos.getCollection( coll + "" ).findOne();
// Run one split
-printjson( admin.runCommand({ split : coll + "", middle : { _id : 0 } }) );
+assert.commandWorked(admin.runCommand({ split : coll + "", middle : { _id : 0 } }));
// Make sure our stale mongos is not up-to-date with the split
printjson( admin.runCommand({ getShardVersion : coll + "" }) );
@@ -48,4 +49,6 @@ printjson( staleMongos.getDB( "admin" ).runCommand({ getShardVersion : coll + ""
assert.eq( Timestamp( 1, 0 ),
staleMongos.getDB( "admin" ).runCommand({ getShardVersion : coll + "" }).version );
-st.stop(); \ No newline at end of file
+st.stop();
+
+})();
diff --git a/jstests/sharding/sharding_state_after_stepdown.js b/jstests/sharding/sharding_state_after_stepdown.js
index c130e7964ab..319f00cceaf 100644
--- a/jstests/sharding/sharding_state_after_stepdown.js
+++ b/jstests/sharding/sharding_state_after_stepdown.js
@@ -6,6 +6,7 @@
// @tags: [requires_persistence]
(function() {
+'use strict';
var st = new ShardingTest({ shards: 2,
mongos: 1,
@@ -23,7 +24,7 @@ var coll = mongos.getCollection("foo.bar");
var collSharded = mongos.getCollection("foo.barSharded");
assert.commandWorked(admin.runCommand({ enableSharding : coll.getDB() + "" }));
-printjson(admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id }));
+st.ensurePrimaryShard(coll.getDB() + "", shards[0]._id);
assert.commandWorked(admin.runCommand({ shardCollection : collSharded.toString(),
key : { _id : 1 } }));
assert.commandWorked(admin.runCommand({ moveChunk : collSharded.toString(),
@@ -157,8 +158,6 @@ assert.neq({},
st.rs1.getPrimary().adminCommand(
{ getShardVersion : collSharded.toString(), fullMetadata : true }).metadata);
-jsTest.log( "DONE!" );
-
st.stop();
})();
diff --git a/jstests/sharding/test_stacked_migration_cleanup.js b/jstests/sharding/test_stacked_migration_cleanup.js
index fc4a71933ed..93f9862e756 100644
--- a/jstests/sharding/test_stacked_migration_cleanup.js
+++ b/jstests/sharding/test_stacked_migration_cleanup.js
@@ -41,7 +41,8 @@ jsTest.log("Moving a bunch of chunks to stack cleanup...");
// Move a bunch of chunks, but don't close the cursor so they stack.
for (var i = 0; i < numChunks; i++) {
- printjson(mongos.adminCommand({ moveChunk : coll + "", find : { _id : i }, to : shards[1]._id }));
+ assert.commandWorked(
+ mongos.adminCommand({ moveChunk : coll + "", find : { _id : i }, to : shards[1]._id }));
}
jsTest.log("Dropping and re-creating collection...");
diff --git a/jstests/sharding/update_immutable_fields.js b/jstests/sharding/update_immutable_fields.js
index 7f82d84600b..f0383fcf2f8 100644
--- a/jstests/sharding/update_immutable_fields.js
+++ b/jstests/sharding/update_immutable_fields.js
@@ -1,17 +1,17 @@
// Tests that updates can't change immutable fields (used in sharded system)
-var st = new ShardingTest({shards : 2,
- mongos : 1,
- verbose : 0});
-st.stopBalancer();
+(function() {
+'use strict';
+
+var st = new ShardingTest({ shards : 2, mongos : 1 });
var mongos = st.s;
var config = mongos.getDB("config");
var coll = mongos.getCollection(jsTestName() + ".coll1");
var shard0 = st.shard0;
-printjson(config.adminCommand({enableSharding : coll.getDB() + ""}));
+assert.commandWorked(config.adminCommand({enableSharding : coll.getDB() + ""}));
st.ensurePrimaryShard(coll.getDB().getName(), 'shard0000');
-printjson(config.adminCommand({shardCollection : "" + coll, key : {a : 1}}));
+assert.commandWorked(config.adminCommand({shardCollection : "" + coll, key : {a : 1}}));
var getDirectShardedConn = function( st, collName ) {
@@ -29,8 +29,7 @@ var getDirectShardedConn = function( st, collName ) {
shard: 'shard0000',
versionEpoch : maxChunk.lastmodEpoch };
- printjson( ssvInitCmd );
-
+ printjson(ssvInitCmd);
assert.commandWorked( shardConnWithVersion.getDB( "admin" ).runCommand( ssvInitCmd ) );
return shardConnWithVersion;
@@ -73,5 +72,6 @@ assert.writeOK(shard0Coll.save({ _id: 2, a: { c: 1, b: 1 }}));
assert.writeError(shard0Coll.update({}, { $unset: { "a.c": 1 }}));
assert.writeError(shard0Coll.update({}, { $unset: { "a.b": 1, "a.c": 1 }}));
-jsTest.log("DONE!"); // distinguishes shutdown failures
st.stop();
+
+})();
diff --git a/jstests/sharding/upsert_sharded.js b/jstests/sharding/upsert_sharded.js
index 885dc23fcfa..7a31c350ef1 100644
--- a/jstests/sharding/upsert_sharded.js
+++ b/jstests/sharding/upsert_sharded.js
@@ -2,11 +2,10 @@
// Upsert behavior tests for sharding
// NOTE: Generic upsert behavior tests belong in the core suite
//
+(function() {
+'use strict';
-var options = { shardOptions : { verbose : 2 } };
-
-var st = new ShardingTest({ shards : 2, mongos : 1, other : options });
-st.stopBalancer();
+var st = new ShardingTest({ shards : 2, mongos : 1 });
var mongos = st.s0;
var admin = mongos.getDB( "admin" );
@@ -18,8 +17,7 @@ st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
var upsertedResult = function(query, expr) {
coll.remove({});
- result = coll.update(query, expr, { upsert : true });
- return result;
+ return coll.update(query, expr, { upsert : true });
};
var upsertedField = function(query, expr, fieldName) {
@@ -35,13 +33,13 @@ var upsertedXVal = function(query, expr) {
return upsertedField(query, expr, "x");
};
-printjson( admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id }) );
-assert( admin.runCommand({ shardCollection : coll + "", key : { x : 1 } }).ok );
-assert( admin.runCommand({ split : coll + "", middle : { x : 0 } }).ok );
-assert( admin.runCommand({ moveChunk : coll + "",
- find : { x : 0 },
- to : shards[1]._id,
- _waitForDelete : true }).ok );
+st.ensurePrimaryShard(coll.getDB() + "", shards[0]._id);
+assert.commandWorked(admin.runCommand({ shardCollection : coll + "", key : { x : 1 } }));
+assert.commandWorked(admin.runCommand({ split : coll + "", middle : { x : 0 } }));
+assert.commandWorked(admin.runCommand({ moveChunk : coll + "",
+ find : { x : 0 },
+ to : shards[1]._id,
+ _waitForDelete : true }));
st.printShardingStatus();
@@ -74,13 +72,13 @@ assert.writeError(upsertedResult({ "x.x" : { $eq : 1 } }, { $set : { a : 1 } }))
coll.drop();
-printjson( admin.runCommand({ movePrimary : coll.getDB() + "", to : shards[0]._id }) );
-assert( admin.runCommand({ shardCollection : coll + "", key : { 'x.x' : 1 } }).ok );
-assert( admin.runCommand({ split : coll + "", middle : { 'x.x' : 0 } }).ok );
-assert( admin.runCommand({ moveChunk : coll + "",
- find : { 'x.x' : 0 },
- to : shards[1]._id,
- _waitForDelete : true }).ok );
+st.ensurePrimaryShard(coll.getDB() + "", shards[0]._id);
+assert.commandWorked(admin.runCommand({ shardCollection : coll + "", key : { 'x.x' : 1 } }));
+assert.commandWorked( admin.runCommand({ split : coll + "", middle : { 'x.x' : 0 } }));
+assert.commandWorked( admin.runCommand({ moveChunk : coll + "",
+ find : { 'x.x' : 0 },
+ to : shards[1]._id,
+ _waitForDelete : true }));
st.printShardingStatus();
@@ -104,6 +102,6 @@ assert.writeError(upsertedResult({ x : [{ x : 1 }] }, { $set : { a : 1 } }));
// Can't set sub-fields of nested key
assert.writeError(upsertedResult({ "x.x.x" : { $eq : 1 } }, { $set : { a : 1 } }));
-jsTest.log("DONE!");
st.stop();
+})();