run_loop 2.1.9 → 2.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,19 +11,15 @@ module RunLoop
11
11
  # @!visibility private
12
12
  def install
13
13
  if File.exist?(frameworks)
14
- RunLoop.log_debug("#{frameworks} already exists; skipping install")
15
14
  return true
16
15
  end
17
16
 
18
- RunLoop.log_debug("Installing Frameworks to #{rootdir}")
19
-
20
17
  options = { :log_cmd => true }
21
18
 
22
19
  Dir.chdir(rootdir) do
23
20
  RunLoop.log_unix_cmd("cd #{rootdir}")
24
21
  shell.run_shell_command(["ditto", "-xk", File.basename(zip), "."], options)
25
22
  end
26
- RunLoop.log_debug("Installed frameworks to #{rootdir}")
27
23
  end
28
24
 
29
25
  private
@@ -76,6 +76,7 @@ but binary does not exist at that path.
76
76
  # @!visibility private
77
77
  def launch(options)
78
78
  code_sign_identity = options[:code_sign_identity]
79
+ install_timeout = options[:device_agent_install_timeout]
79
80
 
80
81
  RunLoop::DeviceAgent::Frameworks.instance.install
81
82
  cmd = RunLoop::DeviceAgent::IOSDeviceManager.ios_device_manager
@@ -84,12 +85,22 @@ but binary does not exist at that path.
84
85
  if device.simulator?
85
86
  cbxapp = RunLoop::App.new(runner.runner)
86
87
 
87
- # quits the simulator
88
- sim = CoreSimulator.new(device, cbxapp)
88
+ # Quits the simulator if CoreSimulator is not already in control of it.
89
+ sim = CoreSimulator.new(device, cbxapp, {:quit_sim_on_init => false})
89
90
  sim.install
90
91
  sim.launch_simulator
91
92
  else
92
93
 
94
+ if !install_timeout
95
+ raise ArgumentError, %Q[
96
+
97
+ Expected :device_agent_install_timeout key in options:
98
+
99
+ #{options}
100
+
101
+ ]
102
+ end
103
+
93
104
  if !code_sign_identity
94
105
  raise ArgumentError, %Q[
95
106
  Targeting a physical devices requires a code signing identity.
@@ -101,7 +112,7 @@ $ CODE_SIGN_IDENTITY="iPhone Developer: Your Name (ABCDEF1234)" cucumber
101
112
  ]
102
113
  end
103
114
 
104
- options = {:log_cmd => true}
115
+ options = {:log_cmd => true, :timeout => install_timeout}
105
116
  args = [
106
117
  cmd, "install",
107
118
  "--device-id", device.udid,
@@ -112,7 +123,6 @@ $ CODE_SIGN_IDENTITY="iPhone Developer: Your Name (ABCDEF1234)" cucumber
112
123
  start = Time.now
113
124
  hash = run_shell_command(args, options)
114
125
 
115
-
116
126
  if hash[:exit_status] != 0
117
127
  raise RuntimeError, %Q[
118
128
 
@@ -120,14 +130,12 @@ Could not install #{runner.runner}. iOSDeviceManager says:
120
130
 
121
131
  #{hash[:out]}
122
132
 
123
- ]
133
+ ]
124
134
  end
125
135
  end
126
136
 
127
137
  RunLoop::log_debug("Took #{Time.now - start} seconds to install DeviceAgent");
128
138
 
129
- cmd = RunLoop::DeviceAgent::IOSDeviceManager.ios_device_manager
130
-
131
139
  args = ["start_test", "--device-id", device.udid]
132
140
 
133
141
  log_file = IOSDeviceManager.log_file
@@ -146,11 +154,6 @@ Could not install #{runner.runner}. iOSDeviceManager says:
146
154
  pid = Process.spawn(env, cmd, *args, options)
147
155
  Process.detach(pid)
148
156
 
149
- if device.simulator?
150
- # Give it a whirl.
151
- # device.simulator_wait_for_stable_state
152
- end
153
-
154
157
  pid.to_i
155
158
  end
156
159
 
@@ -35,15 +35,11 @@ module RunLoop
35
35
 
36
36
  if device.simulator?
37
37
  # quits the simulator
38
- sim = CoreSimulator.new(device, "")
39
- sim.launch_simulator
38
+ # sim = CoreSimulator.new(device, "")
39
+ # sim.launch_simulator({:wait_for_stable => false})
40
40
  end
41
41
 
42
- start = Time.now
43
- RunLoop.log_debug("Waiting for CBX-Runner to build...")
44
- pid = xcodebuild
45
- RunLoop.log_debug("Took #{Time.now - start} seconds to build and launch CBX-Runner")
46
- pid
42
+ xcodebuild
47
43
  end
48
44
 
49
45
  # @!visibility private
@@ -104,6 +100,11 @@ Use the CBXWS environment variable to override the default.
104
100
 
105
101
  pid = Process.spawn(env, *args, options)
106
102
  Process.detach(pid)
103
+
104
+ sleep_for = 15
105
+ RunLoop.log_debug("Waiting #{sleep_for} seconds for DeviceAgent to build...")
106
+ sleep(sleep_for)
107
+
107
108
  pid.to_i
108
109
  end
109
110
 
@@ -5,7 +5,7 @@ module RunLoop
5
5
  # An HTTP client that retries its connection on errors and can time out.
6
6
  # @!visibility private
7
7
  class RetriableClient
8
- attr_reader :client
8
+ attr_reader :client, :retries, :timeout, :interval
9
9
 
10
10
  # @!visibility private
11
11
  RETRY_ON =
@@ -49,22 +49,14 @@ module RunLoop
49
49
  # @option options [Number] :interval (0.5) How long to sleep between
50
50
  # retries.
51
51
  def initialize(server, options = {})
52
- @client = options[:client] || ::HTTPClient.new
53
52
  @server = server
54
53
  @retries = options.fetch(:retries, 5)
55
54
  @timeout = options.fetch(:timeout, 5)
56
55
  @interval = options.fetch(:interval, 0.5)
57
- @on_error = {}
58
- end
59
56
 
60
- # @!visibility private
61
- def on_error(type, &block)
62
- @on_error[type] = block
63
- end
64
-
65
- # @!visibility private
66
- def change_server(new_server)
67
- @server = new_server
57
+ # Call after setting the attr.
58
+ # Yes, it is redundant to set @client, but it makes testing easier.
59
+ @client = new_client!
68
60
  end
69
61
 
70
62
  # Make an HTTP get request.
@@ -101,12 +93,37 @@ module RunLoop
101
93
  request(request, :post, options)
102
94
  end
103
95
 
96
+ # There is bug in HTTPClient so this method does work.
97
+ # https://xamarin.atlassian.net/browse/TCFW-255
98
+ # httpclient is unable to send a valid DELETE
104
99
  def delete(request, options={})
105
100
  request(request, :delete, options)
106
101
  end
107
102
 
103
+ # Call HTTPClient#reset_all
104
+ def reset_all!
105
+ if @client
106
+ @client.reset_all
107
+ @client = nil
108
+ end
109
+ end
110
+
108
111
  private
109
112
 
113
+ def new_client!
114
+ reset_all!
115
+
116
+ # Assumes ::HTTPClient has these defaults:
117
+ # send_timeout = 120
118
+ # There is an rspec test for this so we will know if they change.
119
+
120
+ new_client = HTTPClient.new
121
+ new_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
122
+ new_client.connect_timeout = 15
123
+ new_client.receive_timeout = timeout
124
+ @client = new_client
125
+ end
126
+
110
127
  def request(request, request_method, options={})
111
128
  retries = options.fetch(:retries, @retries)
112
129
  timeout = options.fetch(:timeout, @timeout)
@@ -121,14 +138,16 @@ module RunLoop
121
138
  RunLoop.log_debug("HTTP: #{request_method} #{@server.endpoint + request.route} #{http_options}")
122
139
  end
123
140
 
141
+ if !client
142
+ raise RuntimeError, "This RetriableClient is not attached to client"
143
+ end
144
+
124
145
  start_time = Time.now
125
146
  last_error = nil
126
147
 
127
- client = @client.dup
128
148
  client.receive_timeout = timeout
129
149
 
130
- retries.times do |i|
131
- first_try = i == 0
150
+ retries.times do |_|
132
151
 
133
152
  # Subtract the aggregate time we've spent thus far to make sure we're
134
153
  # not exceeding the request timeout across retries.
@@ -141,17 +160,11 @@ module RunLoop
141
160
  client.receive_timeout = [time_diff, client.receive_timeout].min
142
161
 
143
162
  begin
144
- return client.send(request_method, @server.endpoint + request.route,
145
- request.params, header)
163
+ return send_request(client, request_method,
164
+ @server.endpoint + request.route,
165
+ request.params, header)
146
166
  rescue *RETRY_ON => e
147
- #RunLoop.log_debug("Rescued http error: #{e}")
148
-
149
- if first_try
150
- if @on_error[e.class]
151
- @on_error[e.class].call(@server)
152
- end
153
- end
154
-
167
+ new_client!
155
168
  last_error = e
156
169
  sleep interval
157
170
  end
@@ -166,7 +179,10 @@ module RunLoop
166
179
 
167
180
  raise HTTP::Error, last_error
168
181
  end
182
+
183
+ def send_request(client, request_method, endpoint, parameters, header)
184
+ client.send(request_method, endpoint, parameters, header)
185
+ end
169
186
  end
170
187
  end
171
188
  end
172
-
@@ -1,5 +1,5 @@
1
1
  module RunLoop
2
- VERSION = "2.1.9"
2
+ VERSION = "2.1.10"
3
3
 
4
4
  # A model of a software release version that can be used to compare two versions.
5
5
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_loop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.9
4
+ version: 2.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Krukow
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-03 00:00:00.000000000 Z
12
+ date: 2016-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json