retriable 3.1.0 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.hound.yml +2 -0
- data/.rspec +2 -0
- data/.rubocop.yml +4 -7
- data/.travis.yml +10 -9
- data/CHANGELOG.md +12 -1
- data/Gemfile +1 -3
- data/README.md +136 -59
- data/lib/retriable/config.rb +1 -1
- data/lib/retriable/exponential_backoff.rb +0 -1
- data/lib/retriable/version.rb +1 -1
- data/lib/retriable.rb +3 -3
- data/retriable.gemspec +3 -7
- data/spec/config_spec.rb +36 -40
- data/spec/exponential_backoff_spec.rb +22 -45
- data/spec/retriable_spec.rb +174 -343
- data/spec/spec_helper.rb +7 -3
- data/spec/support/exceptions.rb +3 -0
- metadata +12 -52
- data/Guardfile +0 -8
- data/Rakefile +0 -12
@@ -1,32 +1,26 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
1
|
describe Retriable::ExponentialBackoff do
|
4
|
-
|
5
|
-
|
6
|
-
end
|
2
|
+
context "defaults" do
|
3
|
+
let(:backoff_config) { described_class.new }
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
it "tries defaults to 3" do
|
6
|
+
expect(backoff_config.tries).to eq(3)
|
7
|
+
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
it "max interval defaults to 60" do
|
10
|
+
expect(backoff_config.max_interval).to eq(60)
|
11
|
+
end
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
it "randomization factor defaults to 0.5" do
|
14
|
+
expect(backoff_config.base_interval).to eq(0.5)
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
it "multiplier defaults to 1.5" do
|
25
|
-
expect(subject.new.multiplier).must_equal 1.5
|
17
|
+
it "multiplier defaults to 1.5" do
|
18
|
+
expect(backoff_config.multiplier).to eq(1.5)
|
19
|
+
end
|
26
20
|
end
|
27
21
|
|
28
22
|
it "generates 10 randomized intervals" do
|
29
|
-
expect(
|
23
|
+
expect(described_class.new(tries: 9).intervals).to eq([
|
30
24
|
0.5244067512211441,
|
31
25
|
0.9113920238761231,
|
32
26
|
1.2406087918999114,
|
@@ -40,11 +34,11 @@ describe Retriable::ExponentialBackoff do
|
|
40
34
|
end
|
41
35
|
|
42
36
|
it "generates defined number of intervals" do
|
43
|
-
expect(
|
37
|
+
expect(described_class.new(tries: 5).intervals.size).to eq(5)
|
44
38
|
end
|
45
39
|
|
46
40
|
it "generates intervals with a defined base interval" do
|
47
|
-
expect(
|
41
|
+
expect(described_class.new(base_interval: 1).intervals).to eq([
|
48
42
|
1.0488135024422882,
|
49
43
|
1.8227840477522461,
|
50
44
|
2.4812175837998227,
|
@@ -52,7 +46,7 @@ describe Retriable::ExponentialBackoff do
|
|
52
46
|
end
|
53
47
|
|
54
48
|
it "generates intervals with a defined multiplier" do
|
55
|
-
expect(
|
49
|
+
expect(described_class.new(multiplier: 1).intervals).to eq([
|
56
50
|
0.5244067512211441,
|
57
51
|
0.607594682584082,
|
58
52
|
0.5513816852888495,
|
@@ -60,15 +54,11 @@ describe Retriable::ExponentialBackoff do
|
|
60
54
|
end
|
61
55
|
|
62
56
|
it "generates intervals with a defined max interval" do
|
63
|
-
expect(
|
64
|
-
0.5,
|
65
|
-
0.75,
|
66
|
-
1.0,
|
67
|
-
])
|
57
|
+
expect(described_class.new(max_interval: 1.0, rand_factor: 0.0).intervals).to eq([0.5, 0.75, 1.0])
|
68
58
|
end
|
69
59
|
|
70
60
|
it "generates intervals with a defined rand_factor" do
|
71
|
-
expect(
|
61
|
+
expect(described_class.new(rand_factor: 0.2).intervals).to eq([
|
72
62
|
0.5097627004884576,
|
73
63
|
0.8145568095504492,
|
74
64
|
1.1712435167599646,
|
@@ -76,20 +66,7 @@ describe Retriable::ExponentialBackoff do
|
|
76
66
|
end
|
77
67
|
|
78
68
|
it "generates 10 non-randomized intervals" do
|
79
|
-
|
80
|
-
|
81
|
-
rand_factor: 0.0,
|
82
|
-
).intervals).must_equal([
|
83
|
-
0.5,
|
84
|
-
0.75,
|
85
|
-
1.125,
|
86
|
-
1.6875,
|
87
|
-
2.53125,
|
88
|
-
3.796875,
|
89
|
-
5.6953125,
|
90
|
-
8.54296875,
|
91
|
-
12.814453125,
|
92
|
-
19.2216796875,
|
93
|
-
])
|
69
|
+
non_random_intervals = 9.times.inject([0.5]) { |memo, _i| memo + [memo.last * 1.5] }
|
70
|
+
expect(described_class.new(tries: 10, rand_factor: 0.0).intervals).to eq(non_random_intervals)
|
94
71
|
end
|
95
72
|
end
|