summaryrefslogtreecommitdiff
path: root/jstests/sharding/mongos_validate_backoff.js
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-11-25 11:20:43 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-12-08 13:05:00 -0500
commit3ed6635a5fb26c354046d275a1217c4526b2fe02 (patch)
treef40aa20b5e62996843ce3df0f47b82042dd683a7 /jstests/sharding/mongos_validate_backoff.js
parent4f24dc58f48cb087db8a4832421d298e9e2633a0 (diff)
downloadmongo-3ed6635a5fb26c354046d275a1217c4526b2fe02.tar.gz
SERVER-21050 Cleanup ReplSetTest
This is just a cleanup work to hide some of the private state of ReplSetTest so it is easier to encapsulate and add new logic. Also enables strict mode.
Diffstat (limited to 'jstests/sharding/mongos_validate_backoff.js')
-rw-r--r--jstests/sharding/mongos_validate_backoff.js64
1 files changed, 33 insertions, 31 deletions
diff --git a/jstests/sharding/mongos_validate_backoff.js b/jstests/sharding/mongos_validate_backoff.js
index 877ab808dcc..4faff61698d 100644
--- a/jstests/sharding/mongos_validate_backoff.js
+++ b/jstests/sharding/mongos_validate_backoff.js
@@ -1,28 +1,27 @@
-//
// Ensures that single mongos shard-key errors are fast, but slow down when many are triggered
-//
+(function() {
+'use strict';
-var st = new ShardingTest({ shards : 1, mongos : 1 })
+var st = new ShardingTest({ shards : 1, mongos : 1 });
-var mongos = st.s0
-var admin = mongos.getDB( "admin" )
-var coll = mongos.getCollection( "foo.bar" )
+var mongos = st.s0;
+var admin = mongos.getDB("admin");
+var coll = mongos.getCollection("foo.bar");
-printjson( admin.runCommand({ enableSharding : coll.getDB() + "" }) )
+assert.commandWorked(admin.runCommand({ enableSharding : coll.getDB() + "" }));
-coll.ensureIndex({ shardKey : 1 })
-printjson( admin.runCommand({ shardCollection : coll + "", key : { shardKey : 1 } }) )
+coll.ensureIndex({ shardKey : 1 });
+assert.commandWorked(admin.runCommand({ shardCollection : coll + "", key : { shardKey : 1 } }));
-var timeBadInsert = function(){
-
- var start = new Date().getTime()
+var timeBadInsert = function() {
+ var start = new Date().getTime();
// Bad insert, no shard key
assert.writeError(coll.insert({ hello : "world" }));
- var end = new Date().getTime()
+ var end = new Date().getTime();
- return end - start
+ return end - start;
}
// We need to work at least twice in order to check resetting the counter
@@ -31,28 +30,31 @@ var success = 0;
// Loop over this test a few times, to ensure that the error counters get reset if we don't have
// bad inserts over a long enough time.
-for( var test = 0; test < 5; test++ ){
-
- var firstWait = timeBadInsert()
- var lastWait = 0
-
- for( var i = 0; i < 20; i++ ){
- printjson( lastWait = timeBadInsert() )
+for (var test = 0; test < 5; test++) {
+ var firstWait = timeBadInsert();
+ var lastWait = 0;
+
+ for(var i = 0; i < 20; i++) {
+ printjson(lastWait = timeBadInsert());
}
- // Kind a heuristic test, we want to make sure that the error wait after sleeping is much less
- // than the error wait after a lot of errors
- if( lastWait > firstWait * 2 * 2 ) success++; // Success!
-
- if( success >= successNeeded ) break;
+ // As a heuristic test, we want to make sure that the error wait after sleeping is much less
+ // than the error wait after a lot of errors.
+ if (lastWait > firstWait * 2 * 2) {
+ success++;
+ }
+ if (success >= successNeeded) {
+ break;
+ }
+
// Abort if we've failed too many times
- assert.lt( test, 4 );
-
+ assert.lt(test, 4);
+
// Sleeping for long enough to reset our exponential counter
- sleep( 3000 )
+ sleep(3000);
}
-jsTest.log( "DONE!" )
+st.stop();
-st.stop()
+})();