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