2015-10-20 13:32:50 -04:00
|
|
|
// 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},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-22 17:07:55 -04:00
|
|
|
// Stabilize replica set with node 0 as primary.
|
|
|
|
|
|
|
|
|
|
assert.commandWorked(
|
|
|
|
|
replSet.nodes[0].adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
2015-12-10 10:21:51 -05:00
|
|
|
waitForMemberState: ReplSetTest.State.PRIMARY,
|
2015-10-20 13:32:50 -04:00
|
|
|
timeoutMillis: 60 * 1000,
|
|
|
|
|
}),
|
2015-10-22 17:07:55 -04:00
|
|
|
'node 0' + replSet.nodes[0].host + ' failed to become primary'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var primary = replSet.getPrimary();
|
|
|
|
|
var secondary = replSet.getSecondary();
|
|
|
|
|
|
|
|
|
|
// Check replication mode.
|
|
|
|
|
|
|
|
|
|
assert.commandFailedWithCode(
|
|
|
|
|
primary.getDB(name).runCommand({
|
|
|
|
|
replSetTest: 1,
|
|
|
|
|
}),
|
2015-10-20 13:32:50 -04:00
|
|
|
ErrorCodes.Unauthorized,
|
|
|
|
|
'replSetTest should fail against non-admin database'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.commandWorked(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
|
|
|
|
}),
|
|
|
|
|
'failed to check replication mode'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// waitForMemberState tests.
|
|
|
|
|
|
|
|
|
|
assert.commandFailedWithCode(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
|
|
|
|
waitForMemberState: 'what state',
|
|
|
|
|
timeoutMillis: 1000,
|
|
|
|
|
}),
|
|
|
|
|
ErrorCodes.TypeMismatch,
|
|
|
|
|
'replSetTest waitForMemberState should fail on non-numerical state'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.commandFailedWithCode(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
2015-12-10 10:21:51 -05:00
|
|
|
waitForMemberState: ReplSetTest.State.PRIMARY,
|
2015-10-20 13:32:50 -04:00
|
|
|
timeoutMillis: "what timeout",
|
|
|
|
|
}),
|
|
|
|
|
ErrorCodes.TypeMismatch,
|
|
|
|
|
'replSetTest waitForMemberState should fail on non-numerical timeout'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.commandFailedWithCode(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
|
|
|
|
waitForMemberState: 9999,
|
|
|
|
|
timeoutMillis: 1000,
|
|
|
|
|
}),
|
|
|
|
|
ErrorCodes.BadValue,
|
|
|
|
|
'replSetTest waitForMemberState should fail on invalid state'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.commandFailedWithCode(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
2015-12-10 10:21:51 -05:00
|
|
|
waitForMemberState: ReplSetTest.State.PRIMARY,
|
2015-10-20 13:32:50 -04:00
|
|
|
timeoutMillis: -1000,
|
|
|
|
|
}),
|
|
|
|
|
ErrorCodes.BadValue,
|
|
|
|
|
'replSetTest waitForMemberState should fail on negative timeout'
|
|
|
|
|
);
|
|
|
|
|
|
2015-10-22 17:07:55 -04:00
|
|
|
assert.commandFailedWithCode(
|
|
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
2015-12-10 10:21:51 -05:00
|
|
|
waitForMemberState: ReplSetTest.State.SECONDARY,
|
2015-10-20 13:32:50 -04:00
|
|
|
timeoutMillis: 1000,
|
|
|
|
|
}),
|
|
|
|
|
ErrorCodes.ExceededTimeLimit,
|
2015-10-22 17:07:55 -04:00
|
|
|
'replSetTest waitForMemberState(SECONDARY) should time out on node 0 ' +
|
|
|
|
|
primary.host
|
2015-10-20 13:32:50 -04:00
|
|
|
);
|
|
|
|
|
|
2015-10-22 17:07:55 -04:00
|
|
|
assert.commandWorked(
|
|
|
|
|
secondary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
2015-12-10 10:21:51 -05:00
|
|
|
waitForMemberState: ReplSetTest.State.SECONDARY,
|
2015-10-20 13:32:50 -04:00
|
|
|
timeoutMillis: 1000,
|
|
|
|
|
}),
|
2015-10-22 17:07:55 -04:00
|
|
|
'replSetTest waitForMemberState(SECONDARY) failed on node 1 ' +
|
|
|
|
|
secondary.host
|
2015-10-20 13:32:50 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// waitForDrainFinish tests.
|
|
|
|
|
|
|
|
|
|
assert.commandFailedWithCode(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
|
|
|
|
waitForDrainFinish: 'what state',
|
|
|
|
|
}),
|
|
|
|
|
ErrorCodes.TypeMismatch,
|
|
|
|
|
'replSetTest waitForDrainFinish should fail on non-numerical timeout'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.commandFailedWithCode(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
|
|
|
|
waitForDrainFinish: -1000,
|
|
|
|
|
}),
|
|
|
|
|
ErrorCodes.BadValue,
|
|
|
|
|
'replSetTest waitForDrainFinish should fail on negative timeout'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.commandWorked(
|
2015-10-22 17:07:55 -04:00
|
|
|
primary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
|
|
|
|
waitForDrainFinish: 1000,
|
|
|
|
|
}),
|
2015-10-22 17:07:55 -04:00
|
|
|
'node 0' + primary.host + ' failed to wait for drain to finish'
|
2015-10-20 13:32:50 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.commandWorked(
|
2015-10-22 17:07:55 -04:00
|
|
|
secondary.adminCommand({
|
2015-10-20 13:32:50 -04:00
|
|
|
replSetTest: 1,
|
|
|
|
|
waitForDrainFinish: 0,
|
|
|
|
|
}),
|
2015-10-22 17:07:55 -04:00
|
|
|
'node 1' + primary.host + ' failed to wait for drain to finish'
|
2015-10-20 13:32:50 -04:00
|
|
|
);
|
|
|
|
|
})();
|