diff options
author | Benety Goh <benety@mongodb.com> | 2015-10-20 13:32:50 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-10-21 21:43:50 -0400 |
commit | fb06c1447621f410f9cbcd9947f3fa5bfa898b37 (patch) | |
tree | c617512fa01cb3f13fa59519bf197c6d53b80b5d /jstests | |
parent | ce438c5dcac373a272eb7dc80ce8d37a74394e4d (diff) | |
download | mongo-fb06c1447621f410f9cbcd9947f3fa5bfa898b37.tar.gz |
SERVER-20979 added ReplicationCoordinator::waitForMemberState() and waitForDrainFinish()
also added subcommands to replSetTest to access these functions from JS tests
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/replsets/drain.js | 21 | ||||
-rw-r--r-- | jstests/replsets/test_command.js | 145 |
2 files changed, 164 insertions, 2 deletions
diff --git a/jstests/replsets/drain.js b/jstests/replsets/drain.js index 1d73411ae3f..d5e189f0345 100644 --- a/jstests/replsets/drain.js +++ b/jstests/replsets/drain.js @@ -77,14 +77,31 @@ assert.eq(ErrorCodes.NotMasterOrSecondary, res.code, "find failed with unexpected error code: " + tojson(res)); secondary.slaveOk = false; - + + assert.commandFailedWithCode( + secondary.adminCommand({ + replSetTest: 1, + waitForDrainFinish: 5000, + }), + ErrorCodes.ExceededTimeLimit, + 'replSetTest waitForDrainFinish should time out when draining is not allowed to complete' + ); + // Allow draining to complete - jsTestLog('Enabling fail point on new primary to allow draining to complete'); + jsTestLog('Disabling fail point on new primary to allow draining to complete'); assert.commandWorked( secondary.getDB("admin").runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'off'}), 'failed to disable fail point on new primary'); primary = replSet.getPrimary(); + assert.commandWorked( + secondary.adminCommand({ + replSetTest: 1, + waitForDrainFinish: 5000, + }), + 'replSetTest waitForDrainFinish should work when draining is allowed to complete' + ); + // Ensure new primary is writable jsTestLog('New primary should be writable after draining is complete'); assert.writeOK(primary.getDB("foo").flag.insert({sentinel:1})); diff --git a/jstests/replsets/test_command.js b/jstests/replsets/test_command.js new file mode 100644 index 00000000000..8935b6fbfc3 --- /dev/null +++ b/jstests/replsets/test_command.js @@ -0,0 +1,145 @@ +// Tests 'replSetTest' command: +// waitForMemberState - waits for node's state to become 'expectedState'. +// waitForDrainFinish - waits for primary to finish draining its applier queue. + +(function () { + 'use strict'; + var name = 'test_command'; + var replSet = new ReplSetTest({name: name, nodes: 3}); + var nodes = replSet.nodeList(); + replSet.startSet(); + replSet.initiate({ + _id: name, + members: [ + {_id: 0, host: nodes[0], priority: 3}, + {_id: 1, host: nodes[1]}, + {_id: 2, host: nodes[2], arbiterOnly: true}, + ], + }); + + assert.commandFailedWithCode( + replSet.nodes[0].getDB(name).runCommand({ + replSetTest: 1, + waitForMemberState: replSet.PRIMARY, + timeoutMillis: 60 * 1000, + }), + ErrorCodes.Unauthorized, + 'replSetTest should fail against non-admin database' + ); + + assert.commandWorked( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + }), + 'failed to check replication mode' + ); + + // waitForMemberState tests. + + assert.commandFailedWithCode( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForMemberState: 'what state', + timeoutMillis: 1000, + }), + ErrorCodes.TypeMismatch, + 'replSetTest waitForMemberState should fail on non-numerical state' + ); + + assert.commandFailedWithCode( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForMemberState: replSet.PRIMARY, + timeoutMillis: "what timeout", + }), + ErrorCodes.TypeMismatch, + 'replSetTest waitForMemberState should fail on non-numerical timeout' + ); + + assert.commandFailedWithCode( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForMemberState: 9999, + timeoutMillis: 1000, + }), + ErrorCodes.BadValue, + 'replSetTest waitForMemberState should fail on invalid state' + ); + + assert.commandFailedWithCode( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForMemberState: replSet.PRIMARY, + timeoutMillis: -1000, + }), + ErrorCodes.BadValue, + 'replSetTest waitForMemberState should fail on negative timeout' + ); + + assert.commandWorked( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForMemberState: replSet.PRIMARY, + timeoutMillis: 60 * 1000, + }), + 'node 0' + replSet.nodes[0] + ' failed to become primary' + ); + + assert.commandWorked( + replSet.nodes[1].adminCommand({ + replSetTest: 1, + waitForMemberState: replSet.SECONDARY, + timeoutMillis: 1000, + }), + ErrorCodes.ExceededTimeLimit, + 'replSetTest waitForMemberState(SECONDARY) failed on node 1 ' + + replSet.nodes[1] + ); + + assert.commandFailedWithCode( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForMemberState: replSet.SECONDARY, + timeoutMillis: 1000, + }), + ErrorCodes.ExceededTimeLimit, + 'replSetTest waitForMemberState(SECONDARY) should time out on node 0 ' + + replSet.nodes[0] + ); + + // waitForDrainFinish tests. + + assert.commandFailedWithCode( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForDrainFinish: 'what state', + }), + ErrorCodes.TypeMismatch, + 'replSetTest waitForDrainFinish should fail on non-numerical timeout' + ); + + assert.commandFailedWithCode( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForDrainFinish: -1000, + }), + ErrorCodes.BadValue, + 'replSetTest waitForDrainFinish should fail on negative timeout' + ); + + assert.commandWorked( + replSet.nodes[0].adminCommand({ + replSetTest: 1, + waitForDrainFinish: 1000, + }), + 'node 0' + replSet.nodes[0] + ' failed to wait for drain to finish' + ); + + assert.commandWorked( + replSet.nodes[1].adminCommand({ + replSetTest: 1, + waitForDrainFinish: 0, + }), + 'node 1' + replSet.nodes[0] + ' failed to wait for drain to finish' + ); + })(); |