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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a88cabf223f1d717cc86375818e02d37627da2193c4b0fe1406f60515d4db8b
4
- data.tar.gz: 2f8eeba9710b0d07f588b6a8c3c64b4b94ad99f6acc0040b510d740819485f86
3
+ metadata.gz: cb32f605c7e39943ceeebc882d52885339e064be73030eb027f3d749934a57b8
4
+ data.tar.gz: b01052119256ca5704ae42f4f05b32124c1a86877398fe596b8b1e2e0f8d220f
5
5
  SHA512:
6
- metadata.gz: ef1d3c5a7641e276b4c044750cef300bb2ede4716cb4f9d2a8e9d0a52b0445c585c8f92e0429f11814f025e9b0b9705cf39a9d5f2de28f4da0ddbdf7a63b000d
7
- data.tar.gz: f1897c81a9d3762f41878a2a55fbd77a19e4828ef3270773e25f5add2698514a51e259b5654474d4341992e767974a83a260ec9207b09417bcfffea0caa9494c
6
+ metadata.gz: 4f9970b7e41b709a81fb6739190ffc60d9e37152f285a745749c4e9e10b526e919e687db7c2d501bb138bd1875d46cf6baac9ef78f1f83f5b256ac4516d4ab34
7
+ data.tar.gz: 614d24dbb43c4e5a26840889b0444ed634c393bcee7ad90c032f01251197a5974c550f6ba66c1bb18401d442afe76711f7c5c0dbfe70236b63b4a300804de873
@@ -8,7 +8,6 @@ addons:
8
8
  - libgmp-dev
9
9
  cache: bundler
10
10
  rvm:
11
- - ruby-2.2.6
12
11
  - ruby-2.3.3
13
12
  - ruby-2.4.0
14
13
  - ruby-2.5.0
@@ -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:
@@ -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::HttpError => e
74
- # Retry on 502 errors.
75
- if e.status == 502 && (retries -= 1) >= 0
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
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '2.0.1'.freeze
3
+ VERSION = '2.0.2'.freeze
4
4
  end
5
5
  end
@@ -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', '~> 1.7'
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 502 errors' do
55
- stub_request(:get, uri)
56
- .to_return(body: {foo: true}.to_json, status: 502)
57
- .then.to_return(body: {foo: true}.to_json, status: 200)
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
- expect(response).to eq('foo' => true)
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
- stub_request(:post, uri)
135
- .to_return(body: {foo: true}.to_json, status: 500)
136
- .then.to_return(body: {foo: true}.to_json, status: 200)
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
- expect(response).to eq('foo' => true)
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.1
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: 2018-10-19 00:00:00.000000000 Z
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: '1.7'
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: '1.7'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement