sauce_rspec 1.0.1 → 1.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
  SHA1:
3
- metadata.gz: e57be49a029f21900caeec78e159aa2ddab0d0ea
4
- data.tar.gz: 601f97a26625b0c99f21944394ff0f458d858610
3
+ metadata.gz: f7d1ebc7fdc156c5ea51d76d7f8526fd298e2a38
4
+ data.tar.gz: 9dd34789cebaf4884e7b3e02374b42e568a987d6
5
5
  SHA512:
6
- metadata.gz: 8f3fc22d0792b234d46a76f679234856b94dc9a3e55791817f91b55374105ae920bc03414f85b79f94257e3bc73556b48f0c37b3ea49c68bf667dd69c0775edf
7
- data.tar.gz: 6c39cfe76a888823f59dff7f93e348e5fb42b3acf65b513240857dbc5a25a2974d3ea97cd6463aebdce42ea0fa1a05f3f77719b7f83f3985489a47f68740f7af
6
+ metadata.gz: 5f58071d081f0afa8851721a5e4b68b7838024493b70640036d5da04d1668d4c62a35440265786d93420334e48980e428b3165fe8ab4f7aa93fe81d41c6e430a
7
+ data.tar.gz: 59a6c65ccd5218416238a4d61bbc1c3e2758f6ce097e400feb4794eadeabef2285f96e471a35c5d2498627c5b5a27a87807579659da074b255dab11cb42838ba
data/.rubocop.yml CHANGED
@@ -12,3 +12,9 @@ Style/RescueModifier:
12
12
  Enabled: false
13
13
  Style/SpaceAroundOperators:
14
14
  Enabled: false
15
+ Style/DoubleNegation:
16
+ Enabled: false
17
+ Metrics/CyclomaticComplexity:
18
+ Enabled: false
19
+ Metrics/PerceivedComplexity:
20
+ Enabled: false
@@ -1,6 +1,6 @@
1
1
  module SauceRSpec
2
2
  class Config
3
- attr_reader :caps
3
+ attr_reader :caps, :concurrency_timeout
4
4
  attr_accessor :opts, :user, :key, :host, :port
5
5
 
6
6
  public
@@ -18,6 +18,11 @@ module SauceRSpec
18
18
  "http://#{user}:#{key}@#{host}:#{port}/wd/hub"
19
19
  end
20
20
 
21
+ def concurrency_timeout= value
22
+ fail 'concurrency_timeout must be a numeric' unless value.is_a?(Numeric)
23
+ @concurrency_timeout = value
24
+ end
25
+
21
26
  def caps= value
22
27
  fail 'caps must be an array' unless value && value.is_a?(Array)
23
28
  @caps = value
@@ -44,7 +49,7 @@ module SauceRSpec
44
49
  # caps and opts aren't required to run on sauce because the user may
45
50
  # provide the caps outside of the SauceRSpec config.
46
51
  def sauce?
47
- @user && @key && @host && @port
52
+ !!(@user && @key && @host && @port)
48
53
  end
49
54
 
50
55
  def to_h
@@ -65,6 +70,24 @@ module SauceRSpec
65
70
  def config &block
66
71
  return @config unless block_given?
67
72
  block.call @config
73
+
74
+ # Set test-queue-split workers to the Sauce concurrency limit by default
75
+ test_queue_workers = 'TEST_QUEUE_WORKERS'
76
+ if SauceRSpec.config.sauce? && (!ENV[test_queue_workers] || ENV[test_queue_workers].empty?)
77
+ user = SauceRSpec.config.user
78
+ hurley_client = SauceRSpec.hurley_client
79
+ concurrency_url = "users/#{user}/concurrency"
80
+ concurrency_timeout = SauceRSpec.config.concurrency_timeout || 2 * 60
81
+
82
+ wait_true(concurrency_timeout) do
83
+ body = hurley_client.get(concurrency_url).body
84
+ concurrency = body['concurrency'][user]['remaining']['overall'] rescue false
85
+ ENV[test_queue_workers] = concurrency.to_s if concurrency
86
+
87
+ concurrency ? true : fail(body)
88
+ end
89
+ end
90
+
68
91
  @config
69
92
  end
70
93
  end # class << self
@@ -1,11 +1,13 @@
1
- require 'rubygems'
2
- require 'curb'
3
- require 'json'
4
-
5
1
  module SauceRSpec
6
2
  class << self
7
3
  attr_reader :driver
8
4
 
5
+ MUTEX = Mutex.new
6
+ # from: https://github.com/lostisland/hurley/blob/b61f4c96bcfa4fcd51c6718bc05f13e1c2ba01e6/lib/hurley.rb#L17
7
+ def mutex
8
+ MUTEX.synchronize(&Proc.new)
9
+ end
10
+
9
11
  # Fully initialized Selenium Webdriver.
10
12
  def driver= driver
11
13
  fail 'Driver must not be nil' unless driver
@@ -57,44 +59,51 @@ module SauceRSpec
57
59
  caps
58
60
  end
59
61
 
60
- private
62
+ def hurley_client
63
+ mutex do
64
+ return @hurley_client if @hurley_client
65
+ client = @hurley_client = Hurley::Client.new 'https://saucelabs.com/rest/v1/'
66
+ client.header[:content_type] = 'application/json'
67
+ client.request_options.timeout = 2 * 60
68
+ client.request_options.open_timeout = 2 * 60
69
+
70
+ config = SauceRSpec.config
71
+ client.url.user = config.user
72
+ client.url.password = config.key
73
+
74
+ # Ensure body JSON string is parsed into a hash
75
+ # Detect errors and fail so wait_true will retry the request
76
+ client.after_call do |response|
77
+ response.body = Oj.load(response.body) rescue {}
78
+
79
+ client_server_error = %i(client_error server_error).include? response.status_type
80
+ body_error = response.body['error']
81
+
82
+ if client_server_error || body_error
83
+ response_error = body_error || ''
84
+ fail(::Errno::ECONNREFUSED, response_error)
85
+ end
86
+ end
61
87
 
62
- attr_reader :update_job
88
+ @hurley_client
89
+ end
90
+ end
91
+
92
+ private
63
93
 
64
94
  # @param timeout <Integer> timeout in seconds to wait for sauce labs response
65
95
  def update_job_status_on_sauce timeout
96
+ # PUT https://saucelabs.com/rest/v1/:username/jobs/:job_id
66
97
  # https://docs.saucelabs.com/reference/rest-api/#update-job
67
- # https://saucelabs.com/rest/v1/:username/jobs/:job_id
68
- config = SauceRSpec.config
69
- user = config.user
70
- unless update_job
71
- key = config.key
72
-
73
- request = Curl::Easy.new('')
74
- request.http_auth_types = :basic
75
- request.username = user
76
- request.password = key
77
-
78
- @update_job = request
79
- end
80
-
81
- passed = RSpec.current_example.exception.nil?
82
- passed = { passed: passed }
83
- url = "https://saucelabs.com/rest/v1/#{user}/jobs/#{driver.session_id}"
84
-
85
- update_job.url = url
98
+ user = SauceRSpec.config.user
99
+ passed = RSpec.current_example.exception.nil?
100
+ passed = { passed: passed }
101
+ passed_json = Oj.dump(passed)
102
+ update_job_url = "#{user}/jobs/#{driver.session_id}"
86
103
 
87
104
  wait_true(timeout) do
88
- update_job.http_put passed.to_json
89
- response = JSON.parse(update_job.body_str) rescue {}
90
- response_passed = response['passed']
91
- response_error = response['error'] || ''
92
-
93
- if response_error.include? 'Not authorized'
94
- fail(::Errno::ECONNREFUSED, response_error)
95
- end
96
-
97
- response_passed == passed[:passed] ? true : fail(response)
105
+ body = hurley_client.put(update_job_url, passed_json).body
106
+ body['passed'] == passed[:passed] ? true : fail(body)
98
107
  end
99
108
  end
100
109
 
@@ -1,4 +1,4 @@
1
1
  module SauceRSpec
2
- VERSION = '1.0.1' unless defined? ::SauceRSpec::VERSION
3
- DATE = '2015-10-08' unless defined? ::SauceRSpec::DATE
2
+ VERSION = '1.0.2' unless defined? ::SauceRSpec::VERSION
3
+ DATE = '2015-10-12' unless defined? ::SauceRSpec::DATE
4
4
  end
data/lib/sauce_rspec.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  require 'rubygems'
2
+ require 'oj'
3
+ # Ensure Hash symbols are serialized as JSON strings
4
+ # {:passed=>true} => "{\"passed\":true}" not "{\":passed\":true}"
5
+ Oj.default_options = { mode: :compat }
6
+
2
7
  require 'webdriver_utils'
8
+ require 'addressable/uri'
9
+ require 'hurley'
10
+ require 'hurley/addressable'
3
11
 
4
12
  require_relative 'sauce_rspec/version'
5
13
  require_relative 'sauce_rspec/config'
6
- require_relative 'sauce_rspec/jenkins'
14
+ require_relative 'sauce_rspec/sauce_rspec'
data/release_notes.md CHANGED
@@ -1,3 +1,14 @@
1
+ #### v1.0.2 2015-10-12
2
+
3
+ - [21b3df0](https://github.com/bootstraponline/sauce_rspec/commit/21b3df0b6042fc93a2426522213b0bfdd4902db7) Release 1.0.2
4
+ - [d21bd01](https://github.com/bootstraponline/sauce_rspec/commit/d21bd01bafff4cfd8a87469094ad7b53998b9130) Fix thor cop and thor spec
5
+ - [25504d1](https://github.com/bootstraponline/sauce_rspec/commit/25504d1d13d3da96445e80c4009083ee43ae34d1) Fix Oj.dump
6
+ - [780496e](https://github.com/bootstraponline/sauce_rspec/commit/780496e1547bad10fe55e3bdba7624cfb0f6183a) Use hurely for HTTP instead of curb
7
+ - [3ac6a7c](https://github.com/bootstraponline/sauce_rspec/commit/3ac6a7c106bedd8669be4b9b730280c3b9e9fd77) Create a new Curl::Easy object each time
8
+ - [03ddc81](https://github.com/bootstraponline/sauce_rspec/commit/03ddc81a6a0a1d5d3b36a61f34210e3ebfcb5d6f) Clean up Sauce API code
9
+ - [7bc7a24](https://github.com/bootstraponline/sauce_rspec/commit/7bc7a24a06c60ee874b8f360b87598544d0fe891) Add concurrency detection. Fix 401 check
10
+
11
+
1
12
  #### v1.0.1 2015-10-08
2
13
 
3
14
  - [52bcf9f](https://github.com/bootstraponline/sauce_rspec/commit/52bcf9fd9dc970122a42fb7eb407de2a9ff37db5) Release 1.0.1
data/sauce_rspec.gemspec CHANGED
@@ -21,7 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'webdriver_utils', '~> 1.0.2'
22
22
  # Recommended way of doing parallel execution
23
23
  spec.add_runtime_dependency 'test-queue-split', '~> 0.3.2'
24
- spec.add_runtime_dependency 'curb', '~> 0.8.8'
24
+ spec.add_runtime_dependency 'hurley', '~> 0.2'
25
+ spec.add_runtime_dependency 'addressable', '~> 2.3.8'
26
+ spec.add_runtime_dependency 'oj', '~> 2.12.14'
25
27
 
26
28
  spec.add_development_dependency 'webmock', '~> 1.21.0'
27
29
  spec.add_development_dependency 'appium_thor', '~> 1.0.1'
@@ -31,4 +33,5 @@ Gem::Specification.new do |spec|
31
33
  spec.add_development_dependency 'bundler', '~> 1.10.6'
32
34
  spec.add_development_dependency 'rake', '~> 10.4.2'
33
35
  spec.add_development_dependency 'rubocop', '~> 0.34.2'
36
+ spec.add_development_dependency 'trace_files', '~> 1.0.0'
34
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sauce_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - code@bootstraponline.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-08 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -53,19 +53,47 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.3.2
55
55
  - !ruby/object:Gem::Dependency
56
- name: curb
56
+ name: hurley
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.8
61
+ version: '0.2'
62
62
  type: :runtime
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: 0.8.8
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.8
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.8
83
+ - !ruby/object:Gem::Dependency
84
+ name: oj
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.12.14
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.12.14
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: webmock
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +206,20 @@ dependencies:
178
206
  - - "~>"
179
207
  - !ruby/object:Gem::Version
180
208
  version: 0.34.2
209
+ - !ruby/object:Gem::Dependency
210
+ name: trace_files
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 1.0.0
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 1.0.0
181
223
  description: Sauce rspec integration.
182
224
  email:
183
225
  - code@bootstraponline.com
@@ -194,8 +236,8 @@ files:
194
236
  - Thorfile
195
237
  - lib/sauce_rspec.rb
196
238
  - lib/sauce_rspec/config.rb
197
- - lib/sauce_rspec/jenkins.rb
198
239
  - lib/sauce_rspec/rspec.rb
240
+ - lib/sauce_rspec/sauce_rspec.rb
199
241
  - lib/sauce_rspec/version.rb
200
242
  - release_notes.md
201
243
  - sauce_rspec.gemspec