diff options
Diffstat (limited to 'src/mongo/shell')
-rw-r--r-- | src/mongo/shell/assert.js | 20 | ||||
-rw-r--r-- | src/mongo/shell/utils.js | 2 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js index 81e52d4ef2f..b1f2a94a735 100644 --- a/src/mongo/shell/assert.js +++ b/src/mongo/shell/assert.js @@ -202,6 +202,26 @@ assert.soon = function(f, msg, timeout /*ms*/, interval) { } }; +/** + * Wraps assert.soon to try...catch any function passed in. + */ +assert.soonNoExcept = function(func, msg, timeout /*ms*/) { + /** + * Surrounds a function call by a try...catch to convert any exception to a print statement + * and return false. + */ + function _convertExceptionToReturnStatus(func) { + try { + return func(); + } catch (e) { + print("caught exception " + e); + return false; + } + } + + assert.soon((() => _convertExceptionToReturnStatus(func)), msg, timeout); +}; + assert.time = function(f, msg, timeout /*ms*/) { if (assert._debug && msg) print("in assert for: " + msg); diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index b296cb9a048..43925df86a4 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -280,7 +280,7 @@ jsTest.authenticate = function(conn) { }; jsTest.authenticateNodes = function(nodes) { - assert.soon(function() { + assert.soonNoExcept(function() { for (var i = 0; i < nodes.length; i++) { // Don't try to authenticate to arbiters res = nodes[i].getDB("admin").runCommand({replSetGetStatus: 1}); |