greenjaguar 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/greenjaguar/version.rb +1 -1
- data/lib/greenjaguar.rb +4 -11
- data/spec/greenjaguar_spec.rb +22 -21
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4fc61d4fffe390ea3af3fabff9edd69042b4586
|
|
4
|
+
data.tar.gz: 64b48478ccdfa7af0887c669d969aa11865b135c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5fc9b39e21fbe19bc83d2bf767005614298df222cd990c8853bbcc987b37fa3b7bcd13ae1ca50c8fc23767a1e328c3700bfd85730709b69f2235fde25caaf92
|
|
7
|
+
data.tar.gz: 1d30022a6c2d4506cdf8c200aec18af14b3dfd598c84886e85804a6d776db767b00b8d38750a5b265cece72269af86d40d58ee005f09bc1f684c59eb128ca112
|
data/lib/greenjaguar/version.rb
CHANGED
data/lib/greenjaguar.rb
CHANGED
|
@@ -8,18 +8,11 @@ require 'greenjaguar/policy_builder'
|
|
|
8
8
|
require 'greenjaguar/retrier'
|
|
9
9
|
|
|
10
10
|
module Greenjaguar
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
klass.extend(ClassMethods)
|
|
11
|
+
def build_policy(&block)
|
|
12
|
+
PolicyBuilder.new(&block)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
PolicyBuilder.new(&block)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def robust_retry(policy, &block)
|
|
22
|
-
Retrier.new(policy, &block)
|
|
23
|
-
end
|
|
15
|
+
def robust_retry(policy, &block)
|
|
16
|
+
Retrier.new(policy, &block)
|
|
24
17
|
end
|
|
25
18
|
end
|
data/spec/greenjaguar_spec.rb
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
module Specs
|
|
4
|
-
include Greenjaguar
|
|
5
|
-
|
|
6
4
|
describe Greenjaguar do
|
|
7
|
-
|
|
5
|
+
class ObjectUnderTest
|
|
6
|
+
include Greenjaguar
|
|
7
|
+
end
|
|
8
8
|
|
|
9
9
|
before do
|
|
10
|
+
@object_under_test = ObjectUnderTest.new
|
|
10
11
|
@stub = stub_request(:get, "http://www.example.com").to_raise("some error")
|
|
11
12
|
end
|
|
12
13
|
|
|
@@ -15,12 +16,12 @@ module Specs
|
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
it '#run should call the passed code block 4 times' do
|
|
18
|
-
policy =
|
|
19
|
+
policy = @object_under_test.build_policy do
|
|
19
20
|
times 3
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
expect do
|
|
23
|
-
|
|
24
|
+
@object_under_test.robust_retry(policy) do
|
|
24
25
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
25
26
|
end
|
|
26
27
|
end.to raise_error
|
|
@@ -30,37 +31,37 @@ module Specs
|
|
|
30
31
|
it '#run should call the passed code block only 1 time if successful response is received' do
|
|
31
32
|
@stub = stub_request(:get, "http://www.example.com")
|
|
32
33
|
|
|
33
|
-
policy =
|
|
34
|
+
policy = @object_under_test.build_policy do
|
|
34
35
|
times 3
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
@object_under_test.robust_retry(policy) do
|
|
38
39
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
39
40
|
end
|
|
40
41
|
assert_requested :get, "http://www.example.com", :times => 1
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
it '#run should raise the error once retrying is completed' do
|
|
44
|
-
policy =
|
|
45
|
+
policy = @object_under_test.build_policy do
|
|
45
46
|
times 3
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
expect do
|
|
49
|
-
|
|
50
|
+
@object_under_test.robust_retry(policy) do
|
|
50
51
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
51
52
|
end
|
|
52
53
|
end.to raise_error
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
it '#run should call the passed code block 4 times according to fibonacci sequence' do
|
|
56
|
-
policy =
|
|
57
|
+
policy = @object_under_test.build_policy do
|
|
57
58
|
times 3
|
|
58
59
|
with_strategy :fibonacci
|
|
59
60
|
measure_time_in :ms
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
expect do
|
|
63
|
-
|
|
64
|
+
@object_under_test.robust_retry(policy) do
|
|
64
65
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
65
66
|
end
|
|
66
67
|
end.to raise_error
|
|
@@ -68,14 +69,14 @@ module Specs
|
|
|
68
69
|
end
|
|
69
70
|
|
|
70
71
|
it '#run should call the passed code block 4 times according to fixed interval strategy' do
|
|
71
|
-
policy =
|
|
72
|
+
policy = @object_under_test.build_policy do
|
|
72
73
|
times 3
|
|
73
74
|
with_strategy :fixed_interval, 2
|
|
74
75
|
measure_time_in :ms
|
|
75
76
|
end
|
|
76
77
|
|
|
77
78
|
expect do
|
|
78
|
-
|
|
79
|
+
@object_under_test.robust_retry(policy) do
|
|
79
80
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
80
81
|
end
|
|
81
82
|
end.to raise_error
|
|
@@ -83,14 +84,14 @@ module Specs
|
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
it '#run should call the passed code block 4 times according to exponential backoff sequence' do
|
|
86
|
-
policy =
|
|
87
|
+
policy = @object_under_test.build_policy do
|
|
87
88
|
times 5
|
|
88
89
|
with_strategy :exponential_backoff
|
|
89
90
|
measure_time_in :ms
|
|
90
91
|
end
|
|
91
92
|
|
|
92
93
|
expect do
|
|
93
|
-
|
|
94
|
+
@object_under_test.robust_retry(policy) do
|
|
94
95
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
95
96
|
end
|
|
96
97
|
end.to raise_error
|
|
@@ -99,14 +100,14 @@ module Specs
|
|
|
99
100
|
|
|
100
101
|
it '#run does not call the passed code block if exception is not part of allowed exception(s)' do
|
|
101
102
|
@stub = stub_request(:get, "www.example.com").to_raise(RegexpError)
|
|
102
|
-
policy =
|
|
103
|
+
policy = @object_under_test.build_policy do
|
|
103
104
|
times 5
|
|
104
105
|
with_strategy :fibonacci
|
|
105
106
|
only_on_exceptions [ZeroDivisionError]
|
|
106
107
|
end
|
|
107
108
|
|
|
108
109
|
expect do
|
|
109
|
-
|
|
110
|
+
@object_under_test.robust_retry(policy) do
|
|
110
111
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
111
112
|
end
|
|
112
113
|
end.to raise_error
|
|
@@ -116,7 +117,7 @@ module Specs
|
|
|
116
117
|
it '#run should call the passed code block if exception is part of allowed exception(s)' do
|
|
117
118
|
@stub = stub_request(:get, "http://www.example.com").to_raise(ZeroDivisionError)
|
|
118
119
|
|
|
119
|
-
policy =
|
|
120
|
+
policy = @object_under_test.build_policy do
|
|
120
121
|
times 10
|
|
121
122
|
with_strategy :fibonacci
|
|
122
123
|
measure_time_in :ms
|
|
@@ -124,7 +125,7 @@ module Specs
|
|
|
124
125
|
end
|
|
125
126
|
|
|
126
127
|
expect do
|
|
127
|
-
|
|
128
|
+
@object_under_test.robust_retry(policy) do
|
|
128
129
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
129
130
|
end
|
|
130
131
|
end.to raise_error
|
|
@@ -132,12 +133,12 @@ module Specs
|
|
|
132
133
|
end
|
|
133
134
|
|
|
134
135
|
it '#run should not raise the error if set to fail silently' do
|
|
135
|
-
policy =
|
|
136
|
+
policy = @object_under_test.build_policy do
|
|
136
137
|
times 3
|
|
137
138
|
fail_silently
|
|
138
139
|
end
|
|
139
140
|
|
|
140
|
-
|
|
141
|
+
@object_under_test.robust_retry(policy) do
|
|
141
142
|
Net::HTTP.get_response(URI.parse("http://www.example.com"))
|
|
142
143
|
end
|
|
143
144
|
end
|