summaryrefslogtreecommitdiff
path: root/jstests/sharding/upsert_sharded.js
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 /jstests/sharding/upsert_sharded.js
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.
Diffstat (limited to 'jstests/sharding/upsert_sharded.js')
-rw-r--r--jstests/sharding/upsert_sharded.js40
1 files changed, 19 insertions, 21 deletions
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();
+})();