Skip to content

Commit

Permalink
Merge pull request #340 from calabash/feature/export-CoreSim-wait-for…
Browse files Browse the repository at this point in the history
…-state-option-to-public-API

CoreSim: expose :wait_for_state_timeout option
  • Loading branch information
jmoody committed Nov 25, 2015
2 parents 8f8e102 + 35676ea commit 70183d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
18 changes: 9 additions & 9 deletions lib/run_loop/core_simulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ class RunLoop::CoreSimulator
# value may need to be higher. 120 is the default for CI.
:install_app_timeout => RunLoop::Environment.ci? ? 120 : 30,
:uninstall_app_timeout => RunLoop::Environment.ci? ? 120 : 30,
:launch_app_timeout => RunLoop::Environment.ci? ? 120 : 30
:launch_app_timeout => RunLoop::Environment.ci? ? 120 : 30,
:wait_for_state_timeout => RunLoop::Environment.ci? ? 120 : 30
}

# @!visibility private
# This should not be overridden
WAIT_FOR_SIMULATOR_STATE_INTERVAL = 0.1

# @!visibility private
@@simulator_pid = nil

Expand All @@ -45,11 +50,6 @@ class RunLoop::CoreSimulator
# @!visibility private
CORE_SIMULATOR_DEVICE_DIR = File.expand_path('~/Library/Developer/CoreSimulator/Devices')

# @!visibility private
WAIT_FOR_DEVICE_STATE_OPTS = {
interval: 0.1,
timeout: 5
}

# @!visibility private
MANAGED_PROCESSES =
Expand Down Expand Up @@ -142,14 +142,14 @@ def self.quit_simulator
# @param [String] target_state the state to wait for
def self.wait_for_simulator_state(simulator, target_state)
now = Time.now
timeout = WAIT_FOR_DEVICE_STATE_OPTS[:timeout]
timeout = DEFAULT_OPTIONS[:wait_for_state_timeout]
poll_until = now + timeout
delay = WAIT_FOR_DEVICE_STATE_OPTS[:interval]
delay = WAIT_FOR_SIMULATOR_STATE_INTERVAL
in_state = false
while Time.now < poll_until
in_state = simulator.update_simulator_state == target_state
break if in_state
sleep delay
sleep delay if delay != 0
end

elapsed = Time.now - now
Expand Down
18 changes: 7 additions & 11 deletions spec/lib/core_simulator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,14 @@
end

describe '.wait_for_simulator_state' do
it 'times out if state is never reached' do
if Resources.shared.travis_ci?
options = { :timeout => 0.2, :interval => 0.01 }
else
options = { :timeout => 0.02, :interval => 0.01 }
end
before do
stub_const("RunLoop::CoreSimulator::WAIT_FOR_SIMULATOR_STATE_INTERVAL", 0)

stub_const('RunLoop::CoreSimulator::WAIT_FOR_DEVICE_STATE_OPTS',
options)
options = { :wait_for_state_timeout => 0.2 }
stub_const('RunLoop::CoreSimulator::DEFAULT_OPTIONS', options)
end

it 'times out if state is never reached' do
expect(device).to receive(:update_simulator_state).at_least(:once).and_return 'Undesired'

expect do
Expand All @@ -680,9 +679,6 @@
end

it 'waits for a state' do
options = { :timeout => 0.1, :interval => 0.01 }
stub_const('RunLoop::CoreSimulator::WAIT_FOR_DEVICE_STATE_OPTS',
options)
values = ['Undesired', 'Undesired', 'Desired']
expect(device).to receive(:update_simulator_state).at_least(:once).and_return(*values)

Expand Down

0 comments on commit 70183d7

Please sign in to comment.