summaryrefslogtreecommitdiff
path: root/jstests/sharding/count_config_servers.js
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2015-10-23 11:26:05 -0400
committerSpencer T Brody <spencer@mongodb.com>2015-10-23 15:51:03 -0400
commit3887f0f51467fe97060bdfdc7e1021d54a73467a (patch)
treee4054eb8a8305cf4bf85cd6aa2016c2c24e213bf /jstests/sharding/count_config_servers.js
parentb314afeac81e704e60743363ba7ab83129d2ba68 (diff)
downloadmongo-3887f0f51467fe97060bdfdc7e1021d54a73467a.tar.gz
SERVER-21098 Clean up some sharding jstests to allow them to run under both CSRS and SCCC mode
Diffstat (limited to 'jstests/sharding/count_config_servers.js')
-rw-r--r--jstests/sharding/count_config_servers.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/jstests/sharding/count_config_servers.js b/jstests/sharding/count_config_servers.js
new file mode 100644
index 00000000000..86517073336
--- /dev/null
+++ b/jstests/sharding/count_config_servers.js
@@ -0,0 +1,64 @@
+/**
+ * Test count commands against the config servers, including when some of them are down.
+ * This test fails when run with authentication due to SERVER-6327
+ */
+(function() {
+"use strict";
+
+var st = new ShardingTest({name: 'sync_conn_cmd', shards: 0});
+st.s.setSlaveOk(true);
+
+var configDB = st.config;
+var coll = configDB.test;
+
+for( var x = 0; x < 10; x++ ){
+ assert.writeOK(coll.insert({ v: x }));
+}
+
+if (st.configRS) {
+ // Make sure the inserts are replicated to all config servers.
+ st.configRS.awaitReplication();
+}
+
+var testNormalCount = function(){
+ var cmdRes = configDB.runCommand({ count: coll.getName() });
+ assert( cmdRes.ok );
+ assert.eq( 10, cmdRes.n );
+};
+
+var testCountWithQuery = function(){
+ var cmdRes = configDB.runCommand({ count: coll.getName(), query: { v: { $gt: 6 }}});
+ assert( cmdRes.ok );
+ assert.eq( 3, cmdRes.n );
+};
+
+// Use invalid query operator to make the count return error
+var testInvalidCount = function(){
+ var cmdRes = configDB.runCommand({ count: coll.getName(), query: { $c: { $abc: 3 }}});
+ assert( !cmdRes.ok );
+ assert( cmdRes.errmsg.length > 0 );
+};
+
+// Test with all config servers up
+testNormalCount();
+testCountWithQuery();
+testInvalidCount();
+
+// Test with the first config server down
+MongoRunner.stopMongod(st.c0);
+
+testNormalCount();
+testCountWithQuery();
+testInvalidCount();
+
+// Test with the first and second config server down
+MongoRunner.stopMongod(st.c1);
+jsTest.log( 'Second server is down' );
+
+testNormalCount();
+testCountWithQuery();
+testInvalidCount();
+
+st.stop();
+
+}());