summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2016-11-08 15:59:32 -0500
committerWilliam Schultz <william.schultz@mongodb.com>2016-11-09 14:30:41 -0500
commitb3a7f6c5c9480b7713a09339b10d616f61765a48 (patch)
tree060d806c2d3d2be9c11006a650597263967eb844
parent80f8ffa2121c264ead069f3ed39a34a57ac3f5a7 (diff)
downloadmongo-b3a7f6c5c9480b7713a09339b10d616f61765a48.tar.gz
SERVER-26933 Add sleep interval to assert retry
-rw-r--r--src/mongo/shell/assert.js24
-rw-r--r--src/mongo/shell/replsettest.js2
2 files changed, 16 insertions, 10 deletions
diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js
index e9a3c69408e..2ce8e1e3dce 100644
--- a/src/mongo/shell/assert.js
+++ b/src/mongo/shell/assert.js
@@ -216,11 +216,14 @@ assert.soonNoExcept = function(func, msg, timeout) {
};
/*
- * Calls the given function 'func' repeatedly until either func() returns true
- * or the number of attempted function calls is equal to 'num_attempts'.
- * Throws an exception with message 'msg' after all attempts are used up.
+ * Calls the given function 'func' repeatedly at time intervals specified by
+ * 'intervalMS' (milliseconds) until either func() returns true or the number of
+ * attempted function calls is equal to 'num_attempts'. Throws an exception with
+ * message 'msg' after all attempts are used up. If no 'intervalMS' argument is passed,
+ * it defaults to 0.
*/
-assert.retry = function(func, msg, num_attempts) {
+assert.retry = function(func, msg, num_attempts, intervalMS) {
+ var intervalMS = intervalMS || 0;
var attempts_made = 0;
while (attempts_made < num_attempts) {
if (func()) {
@@ -228,6 +231,7 @@ assert.retry = function(func, msg, num_attempts) {
} else {
attempts_made += 1;
print("assert.retry failed on attempt " + attempts_made + " of " + num_attempts);
+ sleep(intervalMS);
}
}
// Used up all attempts
@@ -235,13 +239,15 @@ assert.retry = function(func, msg, num_attempts) {
};
/*
- * Calls the given function 'func' repeatedly until either func() returns true without
- * throwing an exception or the number of attempted function calls is equal to 'num_attempts'.
- * Throws an exception with message 'msg' after all attempts are used up.
+ * Calls the given function 'func' repeatedly at time intervals specified by
+ * 'intervalMS' (milliseconds) until either func() returns true without throwing
+ * an exception or the number of attempted function calls is equal to 'num_attempts'.
+ * Throws an exception with message 'msg' after all attempts are used up. If no 'intervalMS'
+ * argument is passed, it defaults to 0.
*/
-assert.retryNoExcept = function(func, msg, num_attempts) {
+assert.retryNoExcept = function(func, msg, num_attempts, intervalMS) {
var safeFunc = _convertExceptionToReturnStatus(func, "assert.retryNoExcept caught exception");
- assert.retry(safeFunc, msg, num_attempts);
+ assert.retry(safeFunc, msg, num_attempts, intervalMS);
};
assert.time = function(f, msg, timeout /*ms*/) {
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index ea38358ec9a..bdb0980304f 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -770,7 +770,7 @@ var ReplSetTest = function(opts) {
masterConfigVersion = this.getReplSetConfigFromNode().version;
masterName = master.toString().substr(14); // strip "connection to "
return true;
- }, "ReplSetTest awaitReplication: couldnt get repl set config.", num_attempts);
+ }, "ReplSetTest awaitReplication: couldnt get repl set config.", num_attempts, 1000);
print("ReplSetTest awaitReplication: starting: optime for primary, " + masterName +
", is " + tojson(masterLatestOpTime));