diff --git a/lib/run_loop/core_simulator.rb b/lib/run_loop/core_simulator.rb index a0cd2d09..e5d85f49 100644 --- a/lib/run_loop/core_simulator.rb +++ b/lib/run_loop/core_simulator.rb @@ -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 @@ -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 = @@ -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 diff --git a/spec/lib/core_simulator_spec.rb b/spec/lib/core_simulator_spec.rb index 218d56f1..40c3b107 100644 --- a/spec/lib/core_simulator_spec.rb +++ b/spec/lib/core_simulator_spec.rb @@ -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 @@ -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)