summaryrefslogtreecommitdiff
path: root/jstests/slow1
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:17:50 -0500
committerJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:18:14 -0500
commit4ae691e8edc87d0e3cfb633bb91c328426be007b (patch)
tree52079a593f54382ca13a2e741633eab1b6271893 /jstests/slow1
parenta025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff)
downloadmongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/slow1')
-rw-r--r--jstests/slow1/election_timing.js209
-rw-r--r--jstests/slow1/large_role_chain.js10
-rw-r--r--jstests/slow1/memory.js47
-rw-r--r--jstests/slow1/replsets_priority1.js86
-rw-r--r--jstests/slow1/sharding_multiple_collections.js105
5 files changed, 237 insertions, 220 deletions
diff --git a/jstests/slow1/election_timing.js b/jstests/slow1/election_timing.js
index e1919bb7b61..2fe83be02ed 100644
--- a/jstests/slow1/election_timing.js
+++ b/jstests/slow1/election_timing.js
@@ -7,99 +7,104 @@
var testStart = Date.now();
var testCases = [
- {
- name: "testV1Stop",
- description: "protocolVersion 1, primary is stopped",
- protocolVersion: 1,
- // testRuns is the number of times a new ReplSetTest will be used.
- testRuns: 1,
- // testCycles is the number of election cycles that will be run per ReplSetTest lifespan.
- testCycles: 5,
- // testSetup is run after the replSet is initiated.
- // Function.prototype is the default.
- testSetup: Function.prototype,
- // Trigger an election by stepping down, stopping, or partitioning the primary.
- // stopPrimary is the default.
- electionTrigger: ElectionTimingTest.prototype.stopPrimary,
- // After the election has completed, make the old primary available again.
- // stopPrimaryReset is the default.
- testReset: ElectionTimingTest.prototype.stopPrimaryReset
- },
-
- /*
- This test case is flakey since waiting for the old primary to shutdown can take longer than the
- allowed timeout, even if a new primary was elected during the shutdown time.
-
- {
- name: "testV1StopTimeout1500",
- description: "protocolVersion 1, primary is stopped, electionTimeoutMillis set to 1500",
- protocolVersion: 1,
- testRuns: 1,
- testCycles: 5,
- // The settings object is merged into the replset config settings object.
- settings: {electionTimeoutMillis: 1500}
- },
- */
-
- {
- name: "testV1StepDown",
- description: "protocolVersion 1, primary is stepped down",
- protocolVersion: 1,
- testRuns: 1,
- testCycles: 5,
- electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
- testReset: ElectionTimingTest.prototype.stepDownPrimaryReset,
- },
-
- {
- name: "testV1StepDown1500",
- description: "protocolVersion 1, primary is stepped down",
- protocolVersion: 1,
- testRuns: 1,
- testCycles: 5,
- electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
- testReset: ElectionTimingTest.prototype.stepDownPrimaryReset,
- // The settings object is merged into the replset config settings object.
- settings: {electionTimeoutMillis: 1500}
- },
-
- {
- name: "testV1StepDownLargeCluster",
- description: "protocolVersion 1, primary is stepped down, 7 electable nodes",
- protocolVersion: 1,
- nodes: 7,
- testRuns: 1,
- testCycles: 5,
- electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
- testReset: function() {},
- waitForNewPrimary : function(rst, secondary) { rst.getPrimary(); }
- },
-
- {
- name: "testV0Stop",
- description: "protocolVersion 0, primary is stopped",
- protocolVersion: 0,
- testRuns: 1,
- testCycles: 1
- },
-
- {
- name: "testV0StepDown",
- description: "protocolVersion 0, primary is stepped down",
- protocolVersion: 0,
- testRuns: 1,
- testCycles: 2,
- stepDownGuardTime: 30,
- // There is a guard time in pv0 that prevents an election right
- // after initiating.
- testSetup: function() {sleep(30 * 1000);},
- electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
- testReset: ElectionTimingTest.prototype.stepDownPrimaryReset
- },
+ {
+ name: "testV1Stop",
+ description: "protocolVersion 1, primary is stopped",
+ protocolVersion: 1,
+ // testRuns is the number of times a new ReplSetTest will be used.
+ testRuns: 1,
+ // testCycles is the number of election cycles that will be run per ReplSetTest lifespan.
+ testCycles: 5,
+ // testSetup is run after the replSet is initiated.
+ // Function.prototype is the default.
+ testSetup: Function.prototype,
+ // Trigger an election by stepping down, stopping, or partitioning the primary.
+ // stopPrimary is the default.
+ electionTrigger: ElectionTimingTest.prototype.stopPrimary,
+ // After the election has completed, make the old primary available again.
+ // stopPrimaryReset is the default.
+ testReset: ElectionTimingTest.prototype.stopPrimaryReset
+ },
+
+ /*
+ This test case is flakey since waiting for the old primary to shutdown can take longer than
+ the
+ allowed timeout, even if a new primary was elected during the shutdown time.
+
+ {
+ name: "testV1StopTimeout1500",
+ description: "protocolVersion 1, primary is stopped, electionTimeoutMillis set to 1500",
+ protocolVersion: 1,
+ testRuns: 1,
+ testCycles: 5,
+ // The settings object is merged into the replset config settings object.
+ settings: {electionTimeoutMillis: 1500}
+ },
+ */
+
+ {
+ name: "testV1StepDown",
+ description: "protocolVersion 1, primary is stepped down",
+ protocolVersion: 1,
+ testRuns: 1,
+ testCycles: 5,
+ electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
+ testReset: ElectionTimingTest.prototype.stepDownPrimaryReset,
+ },
+
+ {
+ name: "testV1StepDown1500",
+ description: "protocolVersion 1, primary is stepped down",
+ protocolVersion: 1,
+ testRuns: 1,
+ testCycles: 5,
+ electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
+ testReset: ElectionTimingTest.prototype.stepDownPrimaryReset,
+ // The settings object is merged into the replset config settings object.
+ settings: {electionTimeoutMillis: 1500}
+ },
+
+ {
+ name: "testV1StepDownLargeCluster",
+ description: "protocolVersion 1, primary is stepped down, 7 electable nodes",
+ protocolVersion: 1,
+ nodes: 7,
+ testRuns: 1,
+ testCycles: 5,
+ electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
+ testReset: function() {},
+ waitForNewPrimary: function(rst, secondary) {
+ rst.getPrimary();
+ }
+ },
+
+ {
+ name: "testV0Stop",
+ description: "protocolVersion 0, primary is stopped",
+ protocolVersion: 0,
+ testRuns: 1,
+ testCycles: 1
+ },
+
+ {
+ name: "testV0StepDown",
+ description: "protocolVersion 0, primary is stepped down",
+ protocolVersion: 0,
+ testRuns: 1,
+ testCycles: 2,
+ stepDownGuardTime: 30,
+ // There is a guard time in pv0 that prevents an election right
+ // after initiating.
+ testSetup: function() {
+ sleep(30 * 1000);
+ },
+ electionTrigger: ElectionTimingTest.prototype.stepDownPrimary,
+ testReset: ElectionTimingTest.prototype.stepDownPrimaryReset
+ },
];
- testCases.forEach(function (tc) {
+ testCases.forEach(function(tc) {
var testRun = new ElectionTimingTest(tc);
tc.testResults = testRun.testResults;
tc.electionTimeoutLimitMillis = testRun.electionTimeoutLimitMillis;
@@ -118,27 +123,27 @@
printjson(tc.testResults);
});
- testCases.forEach(function (tc) {
+ testCases.forEach(function(tc) {
var allResults = [];
- tc.testResults.forEach(function (tr) {
+ tc.testResults.forEach(function(tr) {
allResults = allResults.concat(tr.results);
});
var resAvg = Array.avg(allResults);
- var resMin = Math.min(...allResults);
- var resMax = Math.max(...allResults);
+ var resMin = Math.min(... allResults);
+ var resMax = Math.max(... allResults);
var resStdDev = Array.stdDev(allResults);
- jsTestLog("Results: " + tc.name +
- " Average over " + allResults.length + " runs: " + resAvg +
- " Min: " + resMin + " Max: " + resMax +
- " Limit: " + tc.electionTimeoutLimitMillis/1000 +
- " StdDev: " + resStdDev.toFixed(4));
+ jsTestLog("Results: " + tc.name + " Average over " + allResults.length + " runs: " +
+ resAvg + " Min: " + resMin + " Max: " + resMax + " Limit: " +
+ tc.electionTimeoutLimitMillis / 1000 + " StdDev: " + resStdDev.toFixed(4));
allResults.forEach(function(failoverElapsedMillis) {
- assert.lte(failoverElapsedMillis, tc.electionTimeoutLimitMillis/1000,
- tc.name + ': failover (' + failoverElapsedMillis + ' sec) took too long. limit: ' +
- tc.electionTimeoutLimitMillis/1000 + ' sec');
+ assert.lte(failoverElapsedMillis,
+ tc.electionTimeoutLimitMillis / 1000,
+ tc.name + ': failover (' + failoverElapsedMillis +
+ ' sec) took too long. limit: ' + tc.electionTimeoutLimitMillis / 1000 +
+ ' sec');
});
});
diff --git a/jstests/slow1/large_role_chain.js b/jstests/slow1/large_role_chain.js
index 581db988be5..107263782ef 100644
--- a/jstests/slow1/large_role_chain.js
+++ b/jstests/slow1/large_role_chain.js
@@ -2,12 +2,10 @@
// each role is a member of the next, creating a large chain.
function runTest(conn) {
-
var testdb = conn.getDB("rolechain");
- testdb.runCommand({dropAllRolesFromDatabase:1});
+ testdb.runCommand({dropAllRolesFromDatabase: 1});
var chainLen = 2000;
-
jsTestLog("Generating a chain of " + chainLen + " linked roles");
var roleNameBase = "chainRole";
@@ -15,15 +13,13 @@ function runTest(conn) {
var name = roleNameBase + i;
if (i == 0) {
testdb.runCommand({createRole: name, privileges: [], roles: []});
- }
- else {
+ } else {
jsTestLog("Creating role " + i);
var prevRole = roleNameBase + (i - 1);
- testdb.runCommand({createRole: name, privileges: [], roles: [ prevRole ]});
+ testdb.runCommand({createRole: name, privileges: [], roles: [prevRole]});
var roleInfo = testdb.getRole(name);
}
}
-
}
// run all tests standalone
diff --git a/jstests/slow1/memory.js b/jstests/slow1/memory.js
index a2f84fddc6c..9d67aa7aab6 100644
--- a/jstests/slow1/memory.js
+++ b/jstests/slow1/memory.js
@@ -3,31 +3,45 @@ var col = db.memoryTest;
// test creating many collections to make sure no internal cache goes OOM
for (var i = 0; i < 10000; ++i) {
name = "memoryTest" + i;
- if ((i % 1000) == 0) print("Processing " + name);
- db.eval(function(col) { for (var i = 0; i < 100; ++i) {db[col + "_" + i].find();} }, name);
+ if ((i % 1000) == 0)
+ print("Processing " + name);
+ db.eval(function(col) {
+ for (var i = 0; i < 100; ++i) {
+ db[col + "_" + i].find();
+ }
+ }, name);
}
// test recovery of JS engine after out of memory
-db.system.js.save( { "_id" : "f1", "value" : function(n) {
- a = [];
- b = [];
- c = [];
- for (i = 0; i < n; i++) {
- a.push(Math.random());
- b.push(Math.random());
- c.push(Math.random());
+db.system.js.save({
+ "_id": "f1",
+ "value": function(n) {
+ a = [];
+ b = [];
+ c = [];
+ for (i = 0; i < n; i++) {
+ a.push(Math.random());
+ b.push(Math.random());
+ c.push(Math.random());
+ }
}
-} });
+});
// do mix of calls to make sure OOM is handled with no permanent damage
db.eval("f1(10)");
-assert.throws(function() { db.eval("f1(100000000)"); } );
+assert.throws(function() {
+ db.eval("f1(100000000)");
+});
db.eval("f1(10)");
-assert.throws(function() { db.eval("f1(1000000000)"); } );
+assert.throws(function() {
+ db.eval("f1(1000000000)");
+});
db.eval("f1(1000000)");
db.eval("f1(1000000)");
db.eval("f1(1000000)");
-assert.throws(function() { db.eval("f1(100000000)"); } );
+assert.throws(function() {
+ db.eval("f1(100000000)");
+});
db.eval("f1(10)");
db.eval("f1(1000000)");
db.eval("f1(1000000)");
@@ -37,6 +51,7 @@ db.eval("f1(1000000)");
col.drop();
col.insert({a: 1});
col.findOne({$where: "var arr = []; for (var i = 0; i < 1000000; ++i) {arr.push(0);}"});
-assert.throws(function() { col.findOne({$where: "var arr = []; for (var i = 0; i < 1000000000; ++i) {arr.push(0);}"}); });
+assert.throws(function() {
+ col.findOne({$where: "var arr = []; for (var i = 0; i < 1000000000; ++i) {arr.push(0);}"});
+});
col.findOne({$where: "var arr = []; for (var i = 0; i < 1000000; ++i) {arr.push(0);}"});
-
diff --git a/jstests/slow1/replsets_priority1.js b/jstests/slow1/replsets_priority1.js
index 614c6b7cec7..098af758bdd 100644
--- a/jstests/slow1/replsets_priority1.js
+++ b/jstests/slow1/replsets_priority1.js
@@ -5,7 +5,7 @@ print("\n\n\nreplsets_priority1.js BEGIN\n");
load("jstests/replsets/rslib.js");
-var rs = new ReplSetTest( {name: 'testSet', nodes: 3, nodeOptions: {verbose: 2}} );
+var rs = new ReplSetTest({name: 'testSet', nodes: 3, nodeOptions: {verbose: 2}});
var nodes = rs.startSet();
rs.initiate();
@@ -14,53 +14,51 @@ var master = rs.getPrimary();
var everyoneOkSoon = function() {
var status;
assert.soon(function() {
- var ok = true;
- status = master.adminCommand({replSetGetStatus : 1});
+ var ok = true;
+ status = master.adminCommand({replSetGetStatus: 1});
- if (!status.members) {
- return false;
- }
+ if (!status.members) {
+ return false;
+ }
- for (var i in status.members) {
- if (status.members[i].health == 0) {
- continue;
- }
- ok &= status.members[i].state == 1 || status.members[i].state == 2;
+ for (var i in status.members) {
+ if (status.members[i].health == 0) {
+ continue;
}
- return ok;
- }, tojson(status));
+ ok &= status.members[i].state == 1 || status.members[i].state == 2;
+ }
+ return ok;
+ }, tojson(status));
};
-var checkPrimaryIs = function (node) {
+var checkPrimaryIs = function(node) {
print("nreplsets_priority1.js checkPrimaryIs(" + node.host + ")");
var status;
- assert.soon(function () {
+ assert.soon(function() {
var ok = true;
try {
- status = master.adminCommand({ replSetGetStatus: 1 });
- }
- catch (e) {
+ status = master.adminCommand({replSetGetStatus: 1});
+ } catch (e) {
print(e);
print("nreplsets_priority1.js checkPrimaryIs reconnecting");
reconnect(master);
- status = master.adminCommand({ replSetGetStatus: 1 });
+ status = master.adminCommand({replSetGetStatus: 1});
}
var str = "goal: " + node.host + "==1 states: ";
if (!status || !status.members) {
return false;
}
- status.members.forEach(function (m) {
+ status.members.forEach(function(m) {
str += m.name + ": " + m.state + " ";
if (m.name == node.host) {
ok &= m.state == 1;
- }
- else {
+ } else {
ok &= m.state != 1 || (m.state == 1 && m.health == 0);
}
});
@@ -68,7 +66,7 @@ var checkPrimaryIs = function (node) {
print(str);
print();
- occasionally(function () {
+ occasionally(function() {
print("\nstatus:");
printjson(status);
print();
@@ -85,14 +83,14 @@ everyoneOkSoon();
print("\n\nreplsets_priority1.js initial sync");
// intial sync
-master.getDB("foo").bar.insert({x:1});
+master.getDB("foo").bar.insert({x: 1});
rs.awaitReplication();
print("\n\nreplsets_priority1.js starting loop");
var n = 5;
-for (i=0; i<n; i++) {
- print("Round "+i+": FIGHT!");
+for (i = 0; i < n; i++) {
+ print("Round " + i + ": FIGHT!");
var max = null;
var second = null;
@@ -102,7 +100,7 @@ for (i=0; i<n; i++) {
var version = config.version;
config.version++;
- for (var j=0; j<config.members.length; j++) {
+ for (var j = 0; j < config.members.length; j++) {
var priority = Math.random() * 100;
print("random priority : " + priority);
config.members[j].priority = priority;
@@ -112,7 +110,7 @@ for (i=0; i<n; i++) {
}
}
- for (var j=0; j<config.members.length; j++) {
+ for (var j = 0; j < config.members.length; j++) {
if (config.members[j] == max) {
continue;
}
@@ -121,24 +119,24 @@ for (i=0; i<n; i++) {
}
}
- print("\n\nreplsets_priority1.js max is " + max.host + " with priority " + max.priority + ", reconfiguring...");
+ print("\n\nreplsets_priority1.js max is " + max.host + " with priority " + max.priority +
+ ", reconfiguring...");
var count = 0;
while (config.version != version && count < 100) {
reconnect(master);
occasionally(function() {
- print("version is "+version+", trying to update to "+config.version);
- });
+ print("version is " + version + ", trying to update to " + config.version);
+ });
try {
- master.adminCommand({replSetReconfig : config});
+ master.adminCommand({replSetReconfig: config});
master = rs.getPrimary();
reconnect(master);
version = master.getDB("local").system.replset.findOne().version;
- }
- catch (e) {
+ } catch (e) {
print("nreplsets_priority1.js Caught exception: " + e);
}
@@ -146,7 +144,7 @@ for (i=0; i<n; i++) {
}
print("\nreplsets_priority1.js wait for 2 slaves");
-
+
assert.soon(function() {
rs.getPrimary();
return rs.liveNodes.slaves.length == 2;
@@ -155,16 +153,16 @@ for (i=0; i<n; i++) {
print("\nreplsets_priority1.js wait for new config version " + config.version);
assert.soon(function() {
- versions = [0,0];
- rs.liveNodes.slaves[0].setSlaveOk();
- versions[0] = rs.liveNodes.slaves[0].getDB("local").system.replset.findOne().version;
- rs.liveNodes.slaves[1].setSlaveOk();
- versions[1] = rs.liveNodes.slaves[1].getDB("local").system.replset.findOne().version;
- return versions[0] == config.version && versions[1] == config.version;
- });
+ versions = [0, 0];
+ rs.liveNodes.slaves[0].setSlaveOk();
+ versions[0] = rs.liveNodes.slaves[0].getDB("local").system.replset.findOne().version;
+ rs.liveNodes.slaves[1].setSlaveOk();
+ versions[1] = rs.liveNodes.slaves[1].getDB("local").system.replset.findOne().version;
+ return versions[0] == config.version && versions[1] == config.version;
+ });
print("replsets_priority1.js awaitReplication");
-
+
// the reconfiguration needs to be replicated! the hb sends it out
// separately from the repl
rs.awaitReplication();
@@ -181,7 +179,7 @@ for (i=0; i<n; i++) {
print("\nkilled max primary. Checking statuses.");
- print("second is "+second.host+" with priority "+second.priority);
+ print("second is " + second.host + " with priority " + second.priority);
checkPrimaryIs(second);
print("restart max " + max._id);
diff --git a/jstests/slow1/sharding_multiple_collections.js b/jstests/slow1/sharding_multiple_collections.js
index b844fe6c9dd..46ade14a0ad 100644
--- a/jstests/slow1/sharding_multiple_collections.js
+++ b/jstests/slow1/sharding_multiple_collections.js
@@ -1,61 +1,64 @@
(function() {
-var s = new ShardingTest({ name: "multcollections",
- shards: 2,
- mongos: 1,
- verbose: 1,
- other: { chunkSize: 1, enableBalancer : true } });
-
-s.adminCommand( { enablesharding : "test" } );
-db = s.getDB( "test" );
-s.ensurePrimaryShard('test', 'shard0001');
-
-N = 100000;
-
-S = "";
-while ( S.length < 500 )
- S += "123123312312";
-
-var bulk = db.foo.initializeUnorderedBulkOp();
-var bulk2 = db.bar.initializeUnorderedBulkOp();
-for ( i=0; i<N; i++ ){
- bulk.insert({ _id: i, s: S });
- bulk2.insert({ _id: i, s: S, s2: S });
-}
-assert.writeOK(bulk.execute());
-assert.writeOK(bulk2.execute());
-
-s.printShardingStatus();
-
-function mytest( coll , i , loopNumber ){
- x = coll.find( { _id : i } ).explain();
- if ( x )
- return;
- throw Error( "can't find " + i + " in " + coll.getName() + " on loopNumber: " + loopNumber + " explain: " + tojson( x ) );
-}
-
-loopNumber = 0;
-while ( 1 ){
- for ( i=0; i<N; i++ ){
- mytest( db.foo , i , loopNumber );
- mytest( db.bar , i , loopNumber );
- if ( i % 1000 == 0 )
- print( i );
+ var s = new ShardingTest({
+ name: "multcollections",
+ shards: 2,
+ mongos: 1,
+ verbose: 1,
+ other: {chunkSize: 1, enableBalancer: true}
+ });
+
+ s.adminCommand({enablesharding: "test"});
+ db = s.getDB("test");
+ s.ensurePrimaryShard('test', 'shard0001');
+
+ N = 100000;
+
+ S = "";
+ while (S.length < 500)
+ S += "123123312312";
+
+ var bulk = db.foo.initializeUnorderedBulkOp();
+ var bulk2 = db.bar.initializeUnorderedBulkOp();
+ for (i = 0; i < N; i++) {
+ bulk.insert({_id: i, s: S});
+ bulk2.insert({_id: i, s: S, s2: S});
}
+ assert.writeOK(bulk.execute());
+ assert.writeOK(bulk2.execute());
+
s.printShardingStatus();
- loopNumber++;
- if ( loopNumber == 1 ){
- s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );
- s.adminCommand( { shardcollection : "test.bar" , key : { _id : 1 } } );
+ function mytest(coll, i, loopNumber) {
+ x = coll.find({_id: i}).explain();
+ if (x)
+ return;
+ throw Error("can't find " + i + " in " + coll.getName() + " on loopNumber: " + loopNumber +
+ " explain: " + tojson(x));
}
-
- assert( loopNumber < 1000 , "taking too long" );
- if ( s.chunkDiff( "foo" ) < 12 && s.chunkDiff( "bar" ) < 12 )
- break;
-}
+ loopNumber = 0;
+ while (1) {
+ for (i = 0; i < N; i++) {
+ mytest(db.foo, i, loopNumber);
+ mytest(db.bar, i, loopNumber);
+ if (i % 1000 == 0)
+ print(i);
+ }
+ s.printShardingStatus();
+ loopNumber++;
+
+ if (loopNumber == 1) {
+ s.adminCommand({shardcollection: "test.foo", key: {_id: 1}});
+ s.adminCommand({shardcollection: "test.bar", key: {_id: 1}});
+ }
+
+ assert(loopNumber < 1000, "taking too long");
+
+ if (s.chunkDiff("foo") < 12 && s.chunkDiff("bar") < 12)
+ break;
+ }
-s.stop();
+ s.stop();
})();