rest 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/rest/client.rb +5 -1
- data/lib/rest/version.rb +1 -1
- data/lib/rest/wrappers/net_http_persistent_wrapper.rb +1 -0
- data/test/test_performance.rb +1 -1
- data/test/test_rest.rb +18 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/rest/client.rb
CHANGED
@@ -87,11 +87,13 @@ module Rest
|
|
87
87
|
current_retry = 0
|
88
88
|
current_follow = 0
|
89
89
|
success = false
|
90
|
+
tries = 0
|
90
91
|
res = nil
|
91
92
|
while current_retry < max_retries && current_follow < max_follows do
|
93
|
+
tries += 1
|
92
94
|
begin
|
93
95
|
res = yield blk
|
94
|
-
res.tries =
|
96
|
+
res.tries = tries
|
95
97
|
if res.code >= 300 && res.code < 400
|
96
98
|
# try new location
|
97
99
|
#p res.headers
|
@@ -113,6 +115,8 @@ module Rest
|
|
113
115
|
break
|
114
116
|
rescue Rest::HttpError => ex
|
115
117
|
if ex.code == 503
|
118
|
+
raise ex if current_retry == max_retries - 1
|
119
|
+
|
116
120
|
pow = (4 ** (current_retry)) * 100 # milliseconds
|
117
121
|
#puts 'pow=' + pow.to_s
|
118
122
|
s = Random.rand * pow
|
data/lib/rest/version.rb
CHANGED
data/test/test_performance.rb
CHANGED
data/test/test_rest.rb
CHANGED
@@ -25,9 +25,25 @@ class TestRest < TestBase
|
|
25
25
|
response = @rest.get("http://rest-test.iron.io/code/503?switch_after=3&switch_to=200")
|
26
26
|
p response
|
27
27
|
p response.code
|
28
|
-
|
28
|
+
assert response.tries == 3
|
29
29
|
assert response.code == 200
|
30
30
|
|
31
|
+
# Now let's try to error out
|
32
|
+
begin
|
33
|
+
response = @rest.get("http://rest-test.iron.io/code/503")
|
34
|
+
assert false, "shouldn't get here"
|
35
|
+
rescue Rest::HttpError => ex
|
36
|
+
puts "EX: " + ex.inspect
|
37
|
+
p ex.backtrace
|
38
|
+
assert ex.is_a?(Rest::HttpError)
|
39
|
+
assert ex.response
|
40
|
+
assert ex.response.body
|
41
|
+
assert ex.code == 503
|
42
|
+
#assert ex.response.tries == 5 # the default max
|
43
|
+
assert ex.response.body.include?("503")
|
44
|
+
assert ex.to_s.include?("503")
|
45
|
+
end
|
46
|
+
|
31
47
|
end
|
32
48
|
|
33
49
|
def test_gets
|
@@ -98,6 +114,7 @@ class TestRest < TestBase
|
|
98
114
|
end
|
99
115
|
end
|
100
116
|
|
117
|
+
|
101
118
|
def test_post_with_headers
|
102
119
|
|
103
120
|
@token = "abctoken"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|