eyes_core 3.6.9 → 3.6.10

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
  SHA1:
3
- metadata.gz: 4718e711226f2377be5c702dacc4649c522fd68a
4
- data.tar.gz: 77928e6bdbd3581d89714f9bcc10f2a5b13f258c
3
+ metadata.gz: d15c919b0a3855dd876f5c97f1c663b4e26f7eb8
4
+ data.tar.gz: 65015d063f2996ce8704e88b6761b63c12297e8a
5
5
  SHA512:
6
- metadata.gz: 09f163b46bac2faed9f9f6a0e1a0dc5122fd6c18745c56c4b1144f620232c049bd816fc840f4d0248057d2552120962f1cb42901eef0422a38eb8fc9c84a30ed
7
- data.tar.gz: 81350a849282adcbe61224befa6649b97ba72cf2eb33b95e1dd6032a2c0b1b666cdc5ced6cea104672ad4ef6bee4abb0d6fc712d20ac921aab16b28adf2135ca
6
+ metadata.gz: c15f4b873889c51b17d02550f40e99905975ec228ab3b4a4d89de9e68f15499aa53b4e2942cb40f665a293e085788c7c8d5fbd4561bebc11f2d8f0a1afa42d74
7
+ data.tar.gz: 9208a20ae00ec92b16858cd44cffc4d6ec1abf4a7067f98759045087b71cc6d0cd4ace920fd056f574ee64b21b861a4fce26ce6440463fdcb36a5d922e511491
@@ -16,7 +16,9 @@ module Applitools::Connectivity
16
16
 
17
17
  HTTP_STATUS_CODES = {
18
18
  created: 201,
19
- accepted: 202
19
+ accepted: 202,
20
+ ok: 200,
21
+ gone: 410
20
22
  }.freeze
21
23
 
22
24
  attr_accessor :server_url, :api_key
@@ -55,18 +57,34 @@ module Applitools::Connectivity
55
57
  body = [json_data.length].pack('L>') + json_data + data.screenshot
56
58
  Applitools::EyesLogger.debug 'Sending match data...'
57
59
  # Applitools::EyesLogger.debug json_data
58
- res = post(URI.join(endpoint_url, session.id.to_s), content_type: 'application/octet-stream', body: body)
60
+ res = long_post(URI.join(endpoint_url, session.id.to_s), content_type: 'application/octet-stream', body: body)
59
61
  raise Applitools::EyesError.new("Request failed: #{res.status} #{res.headers}") unless res.success?
60
62
  Applitools::MatchResult.new Oj.load(res.body)
61
63
  end
62
64
 
65
+ RETRY_DELAY = 0.5
66
+ RETRY_STEP_FACTOR = 1.5
67
+ RETRY_MAX_DELAY = 5
68
+
63
69
  def match_single_window(data)
64
70
  # Notice that this does not include the screenshot.
65
71
  json_data = Oj.dump(data.to_hash).force_encoding('BINARY')
66
72
  body = [json_data.length].pack('L>') + json_data + data.screenshot
67
73
  # Applitools::EyesLogger.debug json_data
68
- Applitools::EyesLogger.debug 'Sending match data...'
69
- res = post(@single_check_endpoint_url, content_type: 'application/octet-stream', body: body)
74
+ begin
75
+ Applitools::EyesLogger.debug 'Sending match data...'
76
+ res = long_post(@single_check_endpoint_url, content_type: 'application/octet-stream', body: body)
77
+ rescue Errno::EWOULDBLOCK, Faraday::ConnectionFailed
78
+ @delays ||= request_delay(RETRY_DELAY, RETRY_STEP_FACTOR, RETRY_MAX_DELAY)
79
+ begin
80
+ sleep @delays.next
81
+ rescue StopIteration
82
+ raise Applitools::UnknownNetworkStackError.new('Unknown network stack error')
83
+ end
84
+ res = match_single_window(data)
85
+ ensure
86
+ @delays = nil
87
+ end
70
88
  raise Applitools::EyesError.new("Request failed: #{res.status} #{res.headers} #{res.body}") unless res.success?
71
89
  Applitools::TestResults.new Oj.load(res.body)
72
90
  end
@@ -104,8 +122,21 @@ module Applitools::Connectivity
104
122
  request(url, method, options)
105
123
  end
106
124
 
107
- define_method "long_#{method}" do |url, options = {}|
108
- long_request(url, method, options)
125
+ define_method "long_#{method}" do |url, options = {}, request_delay = LONG_REQUEST_DELAY|
126
+ long_request(url, method, request_delay, options)
127
+ end
128
+
129
+ private method, "long_#{method}"
130
+ end
131
+
132
+ def request_delay(first_delay, step_factor, max_delay)
133
+ Enumerator.new do |y|
134
+ delay = first_delay
135
+ loop do
136
+ y << delay
137
+ delay *= step_factor
138
+ break if delay > max_delay
139
+ end
109
140
  end
110
141
  end
111
142
 
@@ -123,22 +154,29 @@ module Applitools::Connectivity
123
154
  end
124
155
  end
125
156
 
126
- def long_request(url, method, options = {})
127
- delay = LONG_REQUEST_DELAY
128
- (options[:headers] ||= {})['Eyes-Expect'] = '202-accepted'
129
-
130
- loop do
131
- # Date should be in RFC 1123 format.
132
- options[:headers]['Eyes-Date'] = Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
133
-
134
- res = request(url, method, options)
135
- return res unless res.status == HTTP_STATUS_CODES[:accepted]
136
-
137
- Applitools::EyesLogger.debug "Still running... retrying in #{delay}s"
138
- sleep delay
139
-
157
+ def long_request(url, method, request_delay, options = {})
158
+ delay = request_delay
159
+ options = { headers: {
160
+ 'Eyes-Expect' => '202+location',
161
+ 'Eyes-Date' => Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
162
+ } }.merge! options
163
+ res = request(url, method, options)
164
+ return res if res.status == HTTP_STATUS_CODES[:ok]
165
+
166
+ if res.status == HTTP_STATUS_CODES[:accepted]
167
+ second_step_url = res.headers[:location]
140
168
  delay = [MAX_LONG_REQUEST_DELAY, (delay * LONG_REQUEST_DELAY_MULTIPLICATIVE_INCREASE_FACTOR).round].min
169
+ loop do
170
+ Applitools::EyesLogger.debug "Still running... retrying in #{delay}s"
171
+ sleep delay
172
+ res = request(second_step_url, :get)
173
+ break unless res.status == HTTP_STATUS_CODES[:ok]
174
+ end
141
175
  end
176
+
177
+ raise Applitools::EyesError.new('The server task has gone.') if res.status == HTTP_STATUS_CODES[:gone]
178
+ return request(second_step_url, :delete) if res.status == HTTP_STATUS_CODES[:created]
179
+ raise Applitools::EyesError.new('Unknown error processing long request')
142
180
  end
143
181
  end
144
182
  end
@@ -8,7 +8,7 @@ module Applitools
8
8
  end
9
9
 
10
10
  def scale_image(image)
11
- Applitools::Utils::ImageUtils.scale!(image, scale_method, scale_ratio)
11
+ Applitools::Utils::ImageUtils.scale!(image, scale_ratio)
12
12
  end
13
13
  end
14
14
  end
@@ -154,9 +154,11 @@ module Applitools
154
154
  end
155
155
 
156
156
  def to_hash
157
- raise Applitools::EyesError.new(
158
- 'You should convert coordinates for ignored_regions!'
159
- ) if @need_convert_ignored_regions_coordinates
157
+ if @need_convert_ignored_regions_coordinates
158
+ raise Applitools::EyesError.new(
159
+ 'You should convert coordinates for ignored_regions!'
160
+ )
161
+ end
160
162
  current_data.dup
161
163
  end
162
164
 
@@ -1,3 +1,3 @@
1
1
  module Applitools
2
- VERSION = '3.6.9'.freeze
2
+ VERSION = '3.6.10'.freeze
3
3
  end
data/lib/eyes_core.rb CHANGED
@@ -29,6 +29,8 @@ module Applitools
29
29
  class EyesNotOpenException < EyesError; end
30
30
  # @!visibility private
31
31
  class EyesCoordinateTypeConversionException < EyesError; end
32
+ # @!visibility private
33
+ class UnknownNetworkStackError < EyesError; end
32
34
 
33
35
  # @!visibility private
34
36
  class AbstractMethodCalled < EyesError
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eyes_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.9
4
+ version: 3.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Applitools Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oily_png