percy-client 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/appveyor.yml +1 -2
- data/lib/percy/client.rb +6 -0
- data/lib/percy/client/connection.rb +8 -3
- data/lib/percy/client/version.rb +1 -1
- data/percy-client.gemspec +1 -1
- data/spec/lib/percy/client/connection_spec.rb +18 -9
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb32f605c7e39943ceeebc882d52885339e064be73030eb027f3d749934a57b8
|
4
|
+
data.tar.gz: b01052119256ca5704ae42f4f05b32124c1a86877398fe596b8b1e2e0f8d220f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f9970b7e41b709a81fb6739190ffc60d9e37152f285a745749c4e9e10b526e919e687db7c2d501bb138bd1875d46cf6baac9ef78f1f83f5b256ac4516d4ab34
|
7
|
+
data.tar.gz: 614d24dbb43c4e5a26840889b0444ed634c393bcee7ad90c032f01251197a5974c550f6ba66c1bb18401d442afe76711f7c5c0dbfe70236b63b4a300804de873
|
data/.travis.yml
CHANGED
data/appveyor.yml
CHANGED
@@ -3,12 +3,11 @@ environment:
|
|
3
3
|
- RUBY_VERSION: 25
|
4
4
|
- RUBY_VERSION: 24
|
5
5
|
- RUBY_VERSION: 23
|
6
|
-
- RUBY_VERSION: 22
|
7
|
-
- RUBY_VERSION: 21
|
8
6
|
|
9
7
|
# Install scripts. (runs after repo cloning)
|
10
8
|
install:
|
11
9
|
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
|
10
|
+
- gem install bundler
|
12
11
|
- bundle install
|
13
12
|
|
14
13
|
before_test:
|
data/lib/percy/client.rb
CHANGED
@@ -65,6 +65,12 @@ module Percy
|
|
65
65
|
# 503
|
66
66
|
class ServiceUnavailableError < ServerError; end
|
67
67
|
|
68
|
+
# 504
|
69
|
+
class GatewayTimeoutError < ServerError; end
|
70
|
+
|
71
|
+
# 520..530.
|
72
|
+
class CloudflareError < ServerError; end
|
73
|
+
|
68
74
|
attr_reader :config, :client_info, :environment_info
|
69
75
|
|
70
76
|
def initialize(options = {})
|
@@ -30,6 +30,10 @@ module Percy
|
|
30
30
|
error_class = Percy::Client::BadGatewayError
|
31
31
|
when 503
|
32
32
|
error_class = Percy::Client::ServiceUnavailableError
|
33
|
+
when 504
|
34
|
+
error_class = Percy::Client::GatewayTimeoutError
|
35
|
+
when 520..530
|
36
|
+
error_class = Percy::Client::CloudflareError
|
33
37
|
when CLIENT_ERROR_STATUS_RANGE # Catchall.
|
34
38
|
error_class = Percy::Client::HttpError
|
35
39
|
end
|
@@ -70,9 +74,9 @@ module Percy
|
|
70
74
|
raise Percy::Client::TimeoutError
|
71
75
|
rescue Faraday::ConnectionFailed
|
72
76
|
raise Percy::Client::ConnectionFailed
|
73
|
-
rescue Percy::Client::
|
74
|
-
# Retry on
|
75
|
-
if
|
77
|
+
rescue Percy::Client::ServerError => e
|
78
|
+
# Retry on 5XX errors.
|
79
|
+
if (retries -= 1) >= 0
|
76
80
|
sleep(rand(1..3))
|
77
81
|
retry
|
78
82
|
end
|
@@ -98,6 +102,7 @@ module Percy
|
|
98
102
|
rescue Faraday::ConnectionFailed
|
99
103
|
raise Percy::Client::ConnectionFailed
|
100
104
|
rescue Percy::Client::ServerError => e
|
105
|
+
# Retry on 5XX errors.
|
101
106
|
if (retries -= 1) >= 0
|
102
107
|
sleep(rand(1..3))
|
103
108
|
retry
|
data/lib/percy/client/version.rb
CHANGED
data/percy-client.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'excon'
|
24
24
|
spec.add_dependency 'addressable'
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bundler', '~>
|
26
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
29
29
|
spec.add_development_dependency 'vcr'
|
@@ -12,6 +12,8 @@ RSpec.describe Percy::Client::Connection do
|
|
12
12
|
let(:ci_version) { '8.14.3-ee' }
|
13
13
|
let(:uri) { "#{Percy.config.api_url}/test" }
|
14
14
|
|
15
|
+
SERVER_ERROR_CODES = ((500..504).to_a + (520..530).to_a).freeze
|
16
|
+
|
15
17
|
shared_examples_for 'a connection that sets headers with HTTP method' do |http_method|
|
16
18
|
it 'sets headers' do
|
17
19
|
stub_request(http_method, uri)
|
@@ -51,12 +53,14 @@ RSpec.describe Percy::Client::Connection do
|
|
51
53
|
expect { response }.to raise_error(Percy::Client::ConnectionFailed)
|
52
54
|
end
|
53
55
|
|
54
|
-
it 'retries on
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
it 'retries on 5XX errors' do
|
57
|
+
SERVER_ERROR_CODES.each do |error_code|
|
58
|
+
stub_request(:get, uri)
|
59
|
+
.to_return(body: {foo: true}.to_json, status: error_code)
|
60
|
+
.then.to_return(body: {foo: true}.to_json, status: 200)
|
58
61
|
|
59
|
-
|
62
|
+
expect(response).to eq('foo' => true)
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
66
|
it 'raises error after 3 retries' do
|
@@ -124,6 +128,9 @@ RSpec.describe Percy::Client::Connection do
|
|
124
128
|
'500' => Percy::Client::InternalServerError,
|
125
129
|
'502' => Percy::Client::BadGatewayError,
|
126
130
|
'503' => Percy::Client::ServiceUnavailableError,
|
131
|
+
'504' => Percy::Client::GatewayTimeoutError,
|
132
|
+
'520' => Percy::Client::CloudflareError,
|
133
|
+
'530' => Percy::Client::CloudflareError,
|
127
134
|
}
|
128
135
|
|
129
136
|
http_errors.each do |http_status, error_class|
|
@@ -131,11 +138,13 @@ RSpec.describe Percy::Client::Connection do
|
|
131
138
|
end
|
132
139
|
|
133
140
|
it 'retries on server errors' do
|
134
|
-
|
135
|
-
|
136
|
-
|
141
|
+
SERVER_ERROR_CODES.each do |error_code|
|
142
|
+
stub_request(:post, uri)
|
143
|
+
.to_return(body: {foo: true}.to_json, status: 500)
|
144
|
+
.then.to_return(body: {foo: true}.to_json, status: 200)
|
137
145
|
|
138
|
-
|
146
|
+
expect(response).to eq('foo' => true)
|
147
|
+
end
|
139
148
|
end
|
140
149
|
|
141
150
|
it 'raises error after 3 retries' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|