summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/libs/multi_rs.js
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2012-07-27 19:23:20 -0400
committerGreg Studer <greg@10gen.com>2012-07-30 14:53:53 -0400
commitb88ce8e3a6dcc435e1f671e1127eedb8a597f8c1 (patch)
tree946c7f534062f916cb41c190e19d21230d953ec3 /jstests/multiVersion/libs/multi_rs.js
parent26bac65b80ea0259b67b3d60c4c618bf7d55a094 (diff)
downloadmongo-b88ce8e3a6dcc435e1f671e1127eedb8a597f8c1.tar.gz
Tests for replica set and cluster upgrade
Diffstat (limited to 'jstests/multiVersion/libs/multi_rs.js')
-rw-r--r--jstests/multiVersion/libs/multi_rs.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/jstests/multiVersion/libs/multi_rs.js b/jstests/multiVersion/libs/multi_rs.js
new file mode 100644
index 00000000000..6ff098201f7
--- /dev/null
+++ b/jstests/multiVersion/libs/multi_rs.js
@@ -0,0 +1,90 @@
+//
+// Utility functions for multi-version replica sets
+//
+
+ReplSetTest.prototype.upgradeSet = function( binVersion, options ){
+
+ options = options || {}
+ if( options.primaryStepdown == undefined ) options.primaryStepdown = true
+
+ var nodes = this.nodes
+ var primary = this.getPrimary()
+
+ // Upgrade secondaries first
+ var nodesToUpgrade = this.getSecondaries()
+
+ // Then upgrade primaries
+ nodesToUpgrade.push( primary )
+
+ // We can upgrade with no primary downtime if we have enough nodes
+ var noDowntimePossible = nodes.length > 2
+
+ for( var i = 0; i < nodesToUpgrade.length; i++ ){
+
+ var node = nodesToUpgrade[ i ]
+
+ if( node == primary && options.primaryStepdown ){
+
+ node = this.stepdown( node )
+ primary = this.getPrimary()
+ }
+
+ var prevPrimaryId = this.getNodeId( primary )
+
+ this.upgradeNode( node, binVersion, true )
+
+ if( noDowntimePossible )
+ assert.eq( this.getNodeId( primary ), prevPrimaryId )
+ }
+}
+
+ReplSetTest.prototype.upgradeNode = function( node, binVersion, waitForState ){
+
+ var node = this.restart( node, { binVersion : binVersion } )
+
+ // By default, wait for primary or secondary state
+ if( waitForState == undefined ) waitForState = true
+ if( waitForState == true ) waitForState = [ ReplSetTest.State.PRIMARY,
+ ReplSetTest.State.SECONDARY,
+ ReplSetTest.State.ARBITER ]
+ if( waitForState )
+ this.waitForState( node, waitForState )
+
+ return node
+}
+
+ReplSetTest.prototype.stepdown = function( 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 )
+ }
+ catch( e ){
+ printjson( e );
+ }
+
+ return this.reconnect( node )
+}
+
+ReplSetTest.prototype.reconnect = function( node ){
+
+ var nodeId = this.getNodeId( node )
+
+ this.nodes[ nodeId ] = new Mongo( node.host )
+
+ // TODO
+ var except = {}
+
+ for( var i in node ){
+ if( typeof( node[i] ) == "function" ) continue
+ this.nodes[ nodeId ][ i ] = node[ i ]
+ }
+
+ return this.nodes[ nodeId ]
+}