diff --git a/lib/retry.js b/lib/retry.js index 5e85e79..6c73b16 100644 --- a/lib/retry.js +++ b/lib/retry.js @@ -22,7 +22,9 @@ exports.timeouts = function(options) { randomize: false }; for (var key in options) { - opts[key] = options[key]; + if (options[key] !== undefined) { + opts[key] = options[key]; + } } if (opts.minTimeout > opts.maxTimeout) { diff --git a/test/integration/test-timeouts.js b/test/integration/test-timeouts.js index 7206b0f..5497d92 100644 --- a/test/integration/test-timeouts.js +++ b/test/integration/test-timeouts.js @@ -67,3 +67,24 @@ var retry = require(common.dir.lib + '/retry'); var timeouts = retry.timeouts({retries: 2}); assert.strictEqual(timeouts.length, 2); })(); + +(function testUndefinedOptionsKeepDefaults() { + var timeouts = retry.timeouts({ + retries: 3, + minTimeout: undefined, + maxTimeout: undefined + }); + + assert.deepEqual(timeouts, [1000, 2000, 4000]); +})(); + +(function testUndefinedRetriesKeepsDefaultCount() { + var timeouts = retry.timeouts({ + retries: undefined, + minTimeout: 1000 + }); + + assert.equal(timeouts.length, 10); + assert.equal(timeouts[0], 1000); + assert.equal(timeouts[1], 2000); +})();