You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7 KiB

4 years ago
  1. var common = require('../common');
  2. var assert = common.assert;
  3. var retry = require(common.dir.lib + '/retry');
  4. (function testDefaultValues() {
  5. var timeouts = retry.timeouts();
  6. assert.equal(timeouts.length, 10);
  7. assert.equal(timeouts[0], 1000);
  8. assert.equal(timeouts[1], 2000);
  9. assert.equal(timeouts[2], 4000);
  10. })();
  11. (function testDefaultValuesWithRandomize() {
  12. var minTimeout = 5000;
  13. var timeouts = retry.timeouts({
  14. minTimeout: minTimeout,
  15. randomize: true
  16. });
  17. assert.equal(timeouts.length, 10);
  18. assert.ok(timeouts[0] > minTimeout);
  19. assert.ok(timeouts[1] > timeouts[0]);
  20. assert.ok(timeouts[2] > timeouts[1]);
  21. })();
  22. (function testPassedTimeoutsAreUsed() {
  23. var timeoutsArray = [1000, 2000, 3000];
  24. var timeouts = retry.timeouts(timeoutsArray);
  25. assert.deepEqual(timeouts, timeoutsArray);
  26. assert.notStrictEqual(timeouts, timeoutsArray);
  27. })();
  28. (function testTimeoutsAreWithinBoundaries() {
  29. var minTimeout = 1000;
  30. var maxTimeout = 10000;
  31. var timeouts = retry.timeouts({
  32. minTimeout: minTimeout,
  33. maxTimeout: maxTimeout
  34. });
  35. for (var i = 0; i < timeouts; i++) {
  36. assert.ok(timeouts[i] >= minTimeout);
  37. assert.ok(timeouts[i] <= maxTimeout);
  38. }
  39. })();
  40. (function testTimeoutsAreIncremental() {
  41. var timeouts = retry.timeouts();
  42. var lastTimeout = timeouts[0];
  43. for (var i = 0; i < timeouts; i++) {
  44. assert.ok(timeouts[i] > lastTimeout);
  45. lastTimeout = timeouts[i];
  46. }
  47. })();
  48. (function testTimeoutsAreIncrementalForFactorsLessThanOne() {
  49. var timeouts = retry.timeouts({
  50. retries: 3,
  51. factor: 0.5
  52. });
  53. var expected = [250, 500, 1000];
  54. assert.deepEqual(expected, timeouts);
  55. })();
  56. (function testRetries() {
  57. var timeouts = retry.timeouts({retries: 2});
  58. assert.strictEqual(timeouts.length, 2);
  59. })();