source: trip-planner-front/node_modules/retry/test/integration/test-timeouts.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1var common = require('../common');
2var assert = common.assert;
3var retry = require(common.dir.lib + '/retry');
4
5(function testDefaultValues() {
6 var timeouts = retry.timeouts();
7
8 assert.equal(timeouts.length, 10);
9 assert.equal(timeouts[0], 1000);
10 assert.equal(timeouts[1], 2000);
11 assert.equal(timeouts[2], 4000);
12})();
13
14(function testDefaultValuesWithRandomize() {
15 var minTimeout = 5000;
16 var timeouts = retry.timeouts({
17 minTimeout: minTimeout,
18 randomize: true
19 });
20
21 assert.equal(timeouts.length, 10);
22 assert.ok(timeouts[0] > minTimeout);
23 assert.ok(timeouts[1] > timeouts[0]);
24 assert.ok(timeouts[2] > timeouts[1]);
25})();
26
27(function testPassedTimeoutsAreUsed() {
28 var timeoutsArray = [1000, 2000, 3000];
29 var timeouts = retry.timeouts(timeoutsArray);
30 assert.deepEqual(timeouts, timeoutsArray);
31 assert.notStrictEqual(timeouts, timeoutsArray);
32})();
33
34(function testTimeoutsAreWithinBoundaries() {
35 var minTimeout = 1000;
36 var maxTimeout = 10000;
37 var timeouts = retry.timeouts({
38 minTimeout: minTimeout,
39 maxTimeout: maxTimeout
40 });
41 for (var i = 0; i < timeouts; i++) {
42 assert.ok(timeouts[i] >= minTimeout);
43 assert.ok(timeouts[i] <= maxTimeout);
44 }
45})();
46
47(function testTimeoutsAreIncremental() {
48 var timeouts = retry.timeouts();
49 var lastTimeout = timeouts[0];
50 for (var i = 0; i < timeouts; i++) {
51 assert.ok(timeouts[i] > lastTimeout);
52 lastTimeout = timeouts[i];
53 }
54})();
55
56(function testTimeoutsAreIncrementalForFactorsLessThanOne() {
57 var timeouts = retry.timeouts({
58 retries: 3,
59 factor: 0.5
60 });
61
62 var expected = [250, 500, 1000];
63 assert.deepEqual(expected, timeouts);
64})();
65
66(function testRetries() {
67 var timeouts = retry.timeouts({retries: 2});
68 assert.strictEqual(timeouts.length, 2);
69})();
Note: See TracBrowser for help on using the repository browser.