From d623f873409bba46b82454ee03140f67274363a7 Mon Sep 17 00:00:00 2001 From: William Schultz Date: Mon, 21 Nov 2016 10:52:28 -0500 Subject: SERVER-27024 Added test for stepdown needs majority behavior (cherry picked from commit 48741605f13b278f3c51bfc11660bd0a2dbb498b) --- jstests/libs/write_concern_util.js | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 jstests/libs/write_concern_util.js (limited to 'jstests/libs') diff --git a/jstests/libs/write_concern_util.js b/jstests/libs/write_concern_util.js new file mode 100644 index 00000000000..476a9c3e818 --- /dev/null +++ b/jstests/libs/write_concern_util.js @@ -0,0 +1,47 @@ +/** + * Utilities for testing writeConcern. + */ +// Stops replication at a server. +function stopServerReplication(conn) { + var errMsg = 'Failed to enable rsSyncApplyStop failpoint.'; + assert.commandWorked( + conn.getDB('admin').runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'alwaysOn'}), + errMsg); +} + +// Stops replication at all replicaset secondaries. +function stopReplicationOnSecondaries(rs) { + var secondaries = rs.getSecondaries(); + secondaries.forEach(stopServerReplication); +} + +// Stops replication at all shard secondaries. +function stopReplicationOnSecondariesOfAllShards(st) { + st._rsObjects.forEach(stopReplicationOnSecondaries); +} + +// Restarts replication at a server. +function restartServerReplication(conn) { + var errMsg = 'Failed to disable rsSyncApplyStop failpoint.'; + assert.commandWorked( + conn.getDB('admin').runCommand({configureFailPoint: 'rsSyncApplyStop', mode: 'off'}), + errMsg); +} + +// Restarts replication at all nodes in a replicaset. +function restartReplSetReplication(rs) { + rs.nodes.forEach(restartServerReplication); +} + +// Restarts replication at all nodes in a sharded cluster. +function restartReplicationOnAllShards(st) { + st._rsObjects.forEach(restartReplSetReplication); + restartReplSetReplication(st.configRS); +} + +// Asserts that a writeConcernError was received. +function assertWriteConcernError(res) { + assert(res.writeConcernError, "No writeConcernError received, got: " + tojson(res)); + assert(res.writeConcernError.code); + assert(res.writeConcernError.errmsg); +} -- cgit v1.2.1