summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2014-12-01 16:05:14 -0500
committerEric Milkie <milkie@10gen.com>2014-12-01 17:33:01 -0500
commit3967899bf5d0712e456d0549e1ad17acf8d0bebe (patch)
tree5907de9e867e4969ca63dd37600cd55e414d8de2
parent10f463fcf5c57b16b8d6f0d2e007efd46f4d2e70 (diff)
downloadmongo-3967899bf5d0712e456d0549e1ad17acf8d0bebe.tar.gz
SERVER-16371 clean up unit tests
-rw-r--r--jstests/replsets/replset1.js32
-rw-r--r--jstests/replsets/replset3.js153
-rw-r--r--jstests/ssl/libs/ssl_helpers.js95
3 files changed, 141 insertions, 139 deletions
diff --git a/jstests/replsets/replset1.js b/jstests/replsets/replset1.js
index fb5d163cae5..6c6b17d909e 100644
--- a/jstests/replsets/replset1.js
+++ b/jstests/replsets/replset1.js
@@ -40,7 +40,7 @@ doTest = function( signal ) {
replTest.awaitReplication();
- cppconn = new Mongo( replTest.getURL() ).getDB( "foo" );
+ var cppconn = new Mongo( replTest.getURL() ).getDB( "foo" );
assert.eq( 1000 , cppconn.foo.findOne().a , "cppconn 1" );
{
@@ -75,7 +75,7 @@ doTest = function( signal ) {
bulk.execute();
// Here's how to restart the old master node:
- slave = replTest.restart(master_id);
+ var slave = replTest.restart(master_id);
// Now, let's make sure that the old master comes up as a slave
@@ -94,10 +94,10 @@ doTest = function( signal ) {
// And that both slave nodes have all the updates
new_master = replTest.getMaster();
- assert.eq( 1000 , new_master.getDB( "bar" ).runCommand( { count:"bar"} ).n , "assumption 2")
+ assert.eq( 1000 , new_master.getDB( "bar" ).runCommand( { count:"bar"} ).n , "assumption 2");
replTest.awaitReplication();
- slaves = replTest.liveNodes.slaves;
+ var slaves = replTest.liveNodes.slaves;
assert( slaves.length == 2, "Expected 2 slaves but length was " + slaves.length );
slaves.forEach(function(slave) {
slave.setSlaveOk();
@@ -111,30 +111,30 @@ doTest = function( signal ) {
slaves = replTest.liveNodes.slaves;
printjson(replTest.liveNodes);
- db = master.getDB("foo")
- t = db.foo
+ var db = master.getDB("foo");
+ var t = db.foo;
- ts = slaves.map( function(z){ z.setSlaveOk(); return z.getDB( "foo" ).foo; } )
+ var ts = slaves.map( function(z){ z.setSlaveOk(); return z.getDB( "foo" ).foo; } );
t.save({a: 1000});
- t.ensureIndex( { a : 1 } )
+ t.ensureIndex( { a : 1 } );
- result = db.runCommand({getLastError : 1, w: 3 , wtimeout :30000 })
+ var result = db.runCommand({getLastError : 1, w: 3 , wtimeout :30000 });
printjson(result);
- lastOp = result.lastOp;
- lastOplogOp = master.getDB("local").oplog.rs.find().sort({$natural : -1}).limit(1).next();
+ var lastOp = result.lastOp;
+ var lastOplogOp = master.getDB("local").oplog.rs.find().sort({$natural : -1}).limit(1).next();
assert.eq(lastOplogOp['ts'], lastOp);
- ts.forEach( function(z){ assert.eq( 2 , z.getIndexKeys().length , "A " + z.getMongo() ); } )
+ ts.forEach( function(z){ assert.eq( 2 , z.getIndexKeys().length , "A " + z.getMongo() ); } );
- t.reIndex()
+ t.reIndex();
- db.getLastError( 3 , 30000 )
- ts.forEach( function(z){ assert.eq( 2 , z.getIndexKeys().length , "A " + z.getMongo() ); } )
+ db.getLastError( 3 , 30000 );
+ ts.forEach( function(z){ assert.eq( 2 , z.getIndexKeys().length , "A " + z.getMongo() ); } );
// Shut down the set and finish the test.
replTest.stopSet( signal );
-}
+};
doTest( 15 );
print("replset1.js SUCCESS");
diff --git a/jstests/replsets/replset3.js b/jstests/replsets/replset3.js
index 4f97b816c8d..5731e269ce9 100644
--- a/jstests/replsets/replset3.js
+++ b/jstests/replsets/replset3.js
@@ -1,79 +1,78 @@
-
-doTest = function (signal) {
-
- // Test replica set step down
-
- // Replica set testing API
- // Create a new replica set test. Specify set name and the number of nodes you want.
- var replTest = new ReplSetTest({ name: 'testSet', nodes: 3 });
-
- // call startSet() to start each mongod in the replica set
- // this returns a list of nodes
- var nodes = replTest.startSet();
-
- // Call initiate() to send the replSetInitiate command
- // This will wait for initiation
- replTest.initiate();
-
- // Get master node
- var master = replTest.getMaster();
-
- // Write some data to master
- // NOTE: this test fails unless we write some data.
- master.getDB("foo").foo.insert({ a: 1 }, { writeConcern: { w: 3, wtimeout: 20000 }});
-
- var phase = 1;
-
- print(phase++);
-
- // Step down master. Note: this may close our connection!
- try {
- master.getDB("admin").runCommand({ replSetStepDown: true, force: 1 });
- } catch (err) {
- print("caught: " + err + " on stepdown");
- }
-
- print(phase++);
-
- try {
- var new_master = replTest.getMaster();
- }
- catch (err) {
- throw ("Could not elect new master before timeout.");
- }
-
- print(phase++);
-
- assert(master != new_master, "Old master shouldn't be equal to new master.");
-
- print(phase++);
-
- // Make sure that slaves are still up
- var result = new_master.getDB("admin").runCommand({ replSetGetStatus: 1 });
- assert(result['ok'] == 1, "Could not verify that slaves were still up:" + result);
-
- print(phase++);
-
- slaves = replTest.liveNodes.slaves;
- assert.soon(function () {
- try {
- res = slaves[0].getDB("admin").runCommand({ replSetGetStatus: 1 })
- } catch (err) { }
- return res.myState == 2;
- }, "Slave 0 state not ready.");
-
- print(phase++);
-
- assert.soon(function () {
- try {
- res = slaves[1].getDB("admin").runCommand({ replSetGetStatus: 1 })
- } catch (err) { }
- return res.myState == 2;
- }, "Slave 1 state not ready.");
-
- print("replset3.js SUCCESS");
-
- replTest.stopSet(15);
-}
+var doTest = function (signal) {
+ "use strict";
+ // Test replica set step down
+
+ // Replica set testing API
+ // Create a new replica set test. Specify set name and the number of nodes you want.
+ var replTest = new ReplSetTest({ name: 'testSet', nodes: 3 });
+
+ // call startSet() to start each mongod in the replica set
+ // this returns a list of nodes
+ var nodes = replTest.startSet();
+
+ // Call initiate() to send the replSetInitiate command
+ // This will wait for initiation
+ replTest.initiate();
+
+ // Get master node
+ var master = replTest.getMaster();
+
+ // Write some data to master
+ // NOTE: this test fails unless we write some data.
+ master.getDB("foo").foo.insert({ a: 1 }, { writeConcern: { w: 3, wtimeout: 20000 }});
+
+ var phase = 1;
+
+ print(phase++);
+
+ // Step down master. Note: this may close our connection!
+ try {
+ master.getDB("admin").runCommand({ replSetStepDown: true, force: 1 });
+ } catch (err) {
+ print("caught: " + err + " on stepdown");
+ }
+
+ print(phase++);
+
+ try {
+ var new_master = replTest.getMaster();
+ }
+ catch (err) {
+ throw ("Could not elect new master before timeout.");
+ }
+
+ print(phase++);
+
+ assert(master != new_master, "Old master shouldn't be equal to new master.");
+
+ print(phase++);
+
+ // Make sure that slaves are still up
+ var result = new_master.getDB("admin").runCommand({ replSetGetStatus: 1 });
+ assert(result['ok'] == 1, "Could not verify that slaves were still up:" + result);
+
+ print(phase++);
+
+ var slaves = replTest.liveNodes.slaves;
+ assert.soon(function () {
+ try {
+ var res = slaves[0].getDB("admin").runCommand({ replSetGetStatus: 1 });
+ } catch (err) { }
+ return res.myState == 2;
+ }, "Slave 0 state not ready.");
+
+ print(phase++);
+
+ assert.soon(function () {
+ try {
+ var res = slaves[1].getDB("admin").runCommand({ replSetGetStatus: 1 });
+ } catch (err) { }
+ return res.myState == 2;
+ }, "Slave 1 state not ready.");
+
+ print("replset3.js SUCCESS");
+
+ replTest.stopSet(15);
+};
doTest( 15 );
diff --git a/jstests/ssl/libs/ssl_helpers.js b/jstests/ssl/libs/ssl_helpers.js
index 5ff3c9f1ba9..db989660c28 100644
--- a/jstests/ssl/libs/ssl_helpers.js
+++ b/jstests/ssl/libs/ssl_helpers.js
@@ -1,46 +1,49 @@
//=== Shared SSL testing library functions and constants ===
-var KEYFILE = "jstests/libs/key1"
-var SERVER_CERT = "jstests/libs/server.pem"
-var CA_CERT = "jstests/libs/ca.pem"
-var CLIENT_CERT = "jstests/libs/client.pem"
+var KEYFILE = "jstests/libs/key1";
+var SERVER_CERT = "jstests/libs/server.pem";
+var CA_CERT = "jstests/libs/ca.pem";
+var CLIENT_CERT = "jstests/libs/client.pem";
// Note: "sslAllowInvalidCertificates" is enabled to avoid
// hostname conflicts with our testing certificates
-disabled = {sslMode: "disabled"};
-allowSSL = {sslMode : "allowSSL",
+var disabled = {sslMode: "disabled"};
+var allowSSL = {sslMode : "allowSSL",
sslAllowInvalidCertificates: "",
sslPEMKeyFile : SERVER_CERT,
sslCAFile: CA_CERT};
-preferSSL = {sslMode : "preferSSL",
+var preferSSL = {sslMode : "preferSSL",
sslAllowInvalidCertificates: "",
sslPEMKeyFile : SERVER_CERT,
sslCAFile: CA_CERT};
-requireSSL = {sslMode : "requireSSL",
+var requireSSL = {sslMode : "requireSSL",
sslAllowInvalidCertificates: "",
sslPEMKeyFile : SERVER_CERT,
sslCAFile: CA_CERT};
// Test if ssl replset configs work
+
+var replSetTestFile = "jstests/replsets/replset1.js";
+
var replShouldSucceed = function(opt1, opt2) {
ssl_options1 = opt1;
ssl_options2 = opt2;
// try running this file using the given config
- load("jstests/replsets/replset1.js");
-}
+ load(replSetTestFile);
+};
// Test if ssl replset configs fail
var replShouldFail = function(opt1, opt2) {
ssl_options1 = opt1;
ssl_options2 = opt2;
replTest = null;
- assert.throws(load,["jstests/replsets/replset1.js"],
+ assert.throws(load,[replSetTestFile],
"This setup should have failed");
// clean up to continue running...
if (replTest) {
replTest.stopSet(15);
}
-}
+};
/**
* Takes in two mongod/mongos configuration options and runs a basic
@@ -61,7 +64,7 @@ function mixedShardTest(options1, options2, shouldSucceed) {
r = st.adminCommand({ movePrimary: 'test', to: 'shard0001' });
- db1 = st.getDB("test");
+ var db1 = st.getDB("test");
r = st.adminCommand({ shardCollection : "test.col" , key : { _id : 1 } });
assert.eq(r, true, "error sharding collection for this configuration");
@@ -103,25 +106,25 @@ function mixedShardTest(options1, options2, shouldSucceed) {
//
ReplSetTest.prototype.upgradeSet = function( options, user, pwd ){
- options = options || {}
+ options = options || {};
- var nodes = this.nodes
- var primary = this.getPrimary()
+ var nodes = this.nodes;
+ var primary = this.getPrimary();
// Upgrade secondaries first
- var nodesToUpgrade = this.getSecondaries()
+ var nodesToUpgrade = this.getSecondaries();
// Then upgrade primaries
- nodesToUpgrade.push( primary )
+ nodesToUpgrade.push( primary );
// We can upgrade with no primary downtime if we have enough nodes
- var noDowntimePossible = nodes.length > 2
+ var noDowntimePossible = nodes.length > 2;
for( var i = 0; i < nodesToUpgrade.length; i++ ){
- var node = nodesToUpgrade[ i ]
+ var node = nodesToUpgrade[ i ];
if( node == primary ){
- node = this.stepdown( node )
- primary = this.getPrimary()
+ node = this.stepdown( node );
+ primary = this.getPrimary();
}
var prevPrimaryId = this.getNodeId( primary );
@@ -130,50 +133,50 @@ ReplSetTest.prototype.upgradeSet = function( options, user, pwd ){
this.nodeOptions[nodeName] = Object.merge(this.nodeOptions[nodeName], options);
}
printjson(this.nodeOptions);
- this.upgradeNode( node, options, true, user, pwd )
+ this.upgradeNode( node, options, true, user, pwd );
if( noDowntimePossible )
- assert.eq( this.getNodeId( primary ), prevPrimaryId )
+ assert.eq( this.getNodeId( primary ), prevPrimaryId );
}
-}
+};
ReplSetTest.prototype.upgradeNode = function( node, opts, waitForState, user, pwd ){
- var node = this.restart( node, opts )
+ var newNode = this.restart( node, opts );
if (user != undefined) {
- node.getDB("admin").auth(user, pwd);
+ newNode.getDB("admin").auth(user, pwd);
}
// By default, wait for primary or secondary state
- if( waitForState == undefined ) waitForState = true
+ if( waitForState == undefined ) waitForState = true;
if( waitForState == true ) waitForState = [ ReplSetTest.State.PRIMARY,
ReplSetTest.State.SECONDARY,
- ReplSetTest.State.ARBITER ]
+ ReplSetTest.State.ARBITER ];
if( waitForState )
- this.waitForState( node, waitForState )
+ this.waitForState( newNode, waitForState );
- return node
-}
+ return newNode;
+};
ReplSetTest.prototype.stepdown = function( nodeId ){
- nodeId = this.getNodeId( nodeId )
- assert.eq( this.getNodeId( this.getPrimary() ), nodeId )
- var node = this.nodes[ nodeId ]
+ nodeId = this.getNodeId( nodeId );
+ assert.eq( this.getNodeId( this.getPrimary() ), nodeId );
+ var node = this.nodes[ nodeId ];
try {
- node.getDB("admin").runCommand({ replSetStepDown: 50, force : true })
- assert( false )
+ node.getDB("admin").runCommand({ replSetStepDown: 50, force : true });
+ assert( false );
}
catch( e ){
printjson( e );
}
- return this.reconnect( node )
-}
+ return this.reconnect( node );
+};
ReplSetTest.prototype.reconnect = function( node ){
- var nodeId = this.getNodeId( node )
- this.nodes[ nodeId ] = new Mongo( node.host )
- var except = {}
+ var nodeId = this.getNodeId( node );
+ this.nodes[ nodeId ] = new Mongo( node.host );
+ var except = {};
for( var i in node ){
- if( typeof( node[i] ) == "function" ) continue
- this.nodes[ nodeId ][ i ] = node[ i ]
+ if( typeof( node[i] ) == "function" ) continue;
+ this.nodes[ nodeId ][ i ] = node[ i ];
}
- return this.nodes[ nodeId ]
-}
+ return this.nodes[ nodeId ];
+};