From 148c0031f517117a39e0c260051169b2831d5e64 Mon Sep 17 00:00:00 2001 From: Judah Schvimer Date: Mon, 17 Apr 2017 10:02:12 -0400 Subject: SERVER-28053 allow network errors when turning off rollbackHangBeforeStart failpoint --- jstests/replsets/double_rollback_early.js | 4 ++-- jstests/replsets/read_committed_stale_history.js | 4 ++-- jstests/replsets/rollback_too_new.js | 8 +------- .../rollback_with_socket_error_then_steady_state.js | 4 ++-- jstests/replsets/stepdown.js | 10 +--------- src/mongo/shell/assert.js | 16 ++++++++++++++++ src/mongo/shell/replsettest.js | 8 +------- 7 files changed, 25 insertions(+), 29 deletions(-) diff --git a/jstests/replsets/double_rollback_early.js b/jstests/replsets/double_rollback_early.js index 07757270593..11ceb4fefa2 100644 --- a/jstests/replsets/double_rollback_early.js +++ b/jstests/replsets/double_rollback_early.js @@ -130,8 +130,8 @@ // It should fail with a rbid error and get stuck. jsTestLog("Repartition to: [0,3,4] and [1,2]."); nodes[1].reconnect(nodes[2]); - assert.commandWorked( - nodes[2].adminCommand({configureFailPoint: 'rollbackHangBeforeStart', mode: 'off'})); + assert.adminCommandWorkedAllowingNetworkError( + nodes[2], {configureFailPoint: 'rollbackHangBeforeStart', mode: 'off'}); jsTestLog("Wait for node 2 exit ROLLBACK state and go into RECOVERING"); waitForState(nodes[2], ReplSetTest.State.RECOVERING); diff --git a/jstests/replsets/read_committed_stale_history.js b/jstests/replsets/read_committed_stale_history.js index 1129e0118d9..424e0d838ce 100644 --- a/jstests/replsets/read_committed_stale_history.js +++ b/jstests/replsets/read_committed_stale_history.js @@ -127,8 +127,8 @@ checkDocNotCommitted(nodes[0], {a: 2}); jsTest.log("Allow the original primary to roll back its write and catch up to the new primary"); - assert.commandWorked( - nodes[0].adminCommand({configureFailPoint: 'rollbackHangBeforeStart', mode: 'off'})); + assert.adminCommandWorkedAllowingNetworkError( + nodes[0], {configureFailPoint: 'rollbackHangBeforeStart', mode: 'off'}); assert.soonNoExcept(function() { return null == nodes[0].getDB(dbName).getCollection(collName).findOne({a: 2}); diff --git a/jstests/replsets/rollback_too_new.js b/jstests/replsets/rollback_too_new.js index 4e216a6028d..131d80a54fe 100644 --- a/jstests/replsets/rollback_too_new.js +++ b/jstests/replsets/rollback_too_new.js @@ -43,13 +43,7 @@ // We bump the term to make sure node 0's oplog is ahead of node 2's. var term = getLatestOp(conns[0]).t; - try { - assert.commandWorked(conns[0].adminCommand({replSetStepDown: 1, force: true})); - } catch (e) { - if (!isNetworkError(e)) { - throw e; - } - } + assert.adminCommandWorkedAllowingNetworkError(conns[0], {replSetStepDown: 1, force: true}); // After stepping down due to the higher term, it will eventually get reelected. replTest.waitForState(conns[0], ReplSetTest.State.PRIMARY); diff --git a/jstests/replsets/rollback_with_socket_error_then_steady_state.js b/jstests/replsets/rollback_with_socket_error_then_steady_state.js index 8dcea725885..33f6fdf2684 100644 --- a/jstests/replsets/rollback_with_socket_error_then_steady_state.js +++ b/jstests/replsets/rollback_with_socket_error_then_steady_state.js @@ -106,8 +106,8 @@ nodes[4].reconnect(nodes[2]); // Turn off failpoint on node 2 to allow rollback against node 1 to fail with a network error. - assert.commandWorked( - nodes[2].adminCommand({configureFailPoint: 'rollbackHangBeforeStart', mode: 'off'})); + assert.adminCommandWorkedAllowingNetworkError( + nodes[2], {configureFailPoint: 'rollbackHangBeforeStart', mode: 'off'}); // Make node 0 ahead of node 2 again so node 2 will pick it as a sync source. diff --git a/jstests/replsets/stepdown.js b/jstests/replsets/stepdown.js index 6213e47bede..5f222025f18 100644 --- a/jstests/replsets/stepdown.js +++ b/jstests/replsets/stepdown.js @@ -107,15 +107,7 @@ master = replTest.getPrimary(); var firstMaster = master; print("\nmaster is now " + firstMaster); -try { - assert.commandWorked(master.getDB("admin").runCommand({replSetStepDown: 100, force: true})); -} catch (e) { - // ignore errors due to connection failures as we expect the master to close connections - // on stepdown - if (!isNetworkError(e)) { - throw e; - } -} +assert.adminCommandWorkedAllowingNetworkError(master, {replSetStepDown: 100, force: true}); print("\nget a master"); replTest.getPrimary(); diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js index b26380fdb18..f3d984628b5 100644 --- a/src/mongo/shell/assert.js +++ b/src/mongo/shell/assert.js @@ -267,6 +267,22 @@ assert.retryNoExcept = function(func, msg, num_attempts, intervalMS) { assert.retry(safeFunc, msg, num_attempts, intervalMS); }; +/** + * Runs the given command on the 'admin' database of the provided node. Asserts that the command + * worked but allows network errors to occur. + */ +assert.adminCommandWorkedAllowingNetworkError = function(node, commandObj) { + try { + assert.commandWorked(node.adminCommand(commandObj)); + } catch (e) { + // Ignore errors due to connection failures. + if (!isNetworkError(e)) { + throw e; + } + print("Caught network error: " + tojson(e)); + } +}; + assert.time = function(f, msg, timeout /*ms*/) { if (assert._debug && msg) print("in assert for: " + msg); diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js index ad4039fa2b5..fa3834dd03a 100644 --- a/src/mongo/shell/replsettest.js +++ b/src/mongo/shell/replsettest.js @@ -879,13 +879,7 @@ var ReplSetTest = function(opts) { this._setDefaultConfigOptions(config); - try { - assert.commandWorked(this.getPrimary().adminCommand({replSetReconfig: config})); - } catch (e) { - if (!isNetworkError(e)) { - throw e; - } - } + assert.adminCommandWorkedAllowingNetworkError(this.getPrimary(), {replSetReconfig: config}); }; /** -- cgit v1.2.1