run_loop 1.1.1.pre6 → 1.1.1.pre7

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: d9b31f9972e25c59de2b72ab0afbc80b9b466e38
4
- data.tar.gz: e6f49c6b0685ccc5278bbd132a86cd224810ae3d
3
+ metadata.gz: 1420a614a1d2f74b9cbb6e7bf376fd1521eebd01
4
+ data.tar.gz: 26965697486e6081811a4f876e333d0d77f4750e
5
5
  SHA512:
6
- metadata.gz: 61340a659acd2465aac81330d51fb4b8ccd09e9123d02204f5356152743ef4c742a505e10864aed55c4c57776725ca8d85f5448a084fc8d398afdf4f8540ff47
7
- data.tar.gz: 7d07874bd804d87ceab4b1db43d129c71d2077cc8c42b8c2ebf7e6d48ca6ec8256fcd17d8226a7c54d172b95b6d1f9fcfa0c652144d0ac9c8125447f22d9e02d
6
+ metadata.gz: 805cfd4180e6566a36e4b518c102a10dd5ce93f2e405d14db8d13904e9ef6425aeaf2b64d316b963b718492250cf1582b8dc4f82bc487fe6124dc40689151d7f
7
+ data.tar.gz: a43ef171976bb68f1ed6b19a582a29b1fec64dcfe6cbdaf3a710c229a941bf6c18ff091948aabdc74a2af21fcee7f984a01fe7ba180a9a9bbf39aa814b019921
data/lib/run_loop/core.rb CHANGED
@@ -721,21 +721,64 @@ module RunLoop
721
721
  Core.run_with_options(options)
722
722
  end
723
723
 
724
- def self.send_command(run_loop, cmd, timeout=60)
724
+ def self.send_command(run_loop, cmd, options={timeout: 60}, num_retries=0, last_error=nil)
725
+ if num_retries > 3
726
+ if last_error
727
+ raise last_error
728
+ else
729
+ raise "Max retries exceeded #{num_retries} > 3. No error recorded."
730
+ end
731
+ end
732
+
733
+ if options.is_a?(Numeric)
734
+ options = {timeout: options}
735
+ end
725
736
 
726
737
  if not cmd.is_a?(String)
727
738
  raise "Illegal command #{cmd} (must be a string)"
728
739
  end
729
740
 
741
+ if not options.is_a?(Hash)
742
+ raise "Illegal options #{options} (must be a Hash (or number for compatibility))"
743
+ end
744
+
745
+ timeout = options[:timeout] || 60
746
+ logger = options[:logger]
747
+ interrupt_retry_timeout = options[:interrupt_retry_timeout] || 25
730
748
 
731
- expected_index = Core.write_request(run_loop, cmd)
749
+ expected_index = run_loop[:index]
732
750
  result = nil
751
+ begin
752
+ expected_index = Core.write_request(run_loop, cmd)
753
+ rescue Errno::EINTR => intr_error
754
+ # Attempt recover from interrupt by attempting to read result (assuming write went OK)
755
+ # or retry if attempted read result fails
756
+ run_loop[:index] = expected_index # restore expected index in case it changed
757
+ log_info(logger, "Core.write_request was interrupted: #{intr_error}. Attempting recovery...")
758
+ sleep(1) # Arbitrary wait in hope that the system condition causing the interrupt passes
759
+ if intr_error && intr_error.backtrace
760
+ log_info(logger, "backtrace: #{intr_error.backtrace.join("\n")}")
761
+ end
762
+ log_info(logger, "Attempting read in case the request was received... Please wait (#{interrupt_retry_timeout})...")
763
+ begin
764
+ Timeout::timeout(interrupt_retry_timeout, TimeoutError) do
765
+ result = Core.read_response(run_loop, expected_index)
766
+ end
767
+ # Update run_loop expected index since we succeeded in reading the index
768
+ run_loop[:index] = expected_index + 1
769
+ log_info(logger, "Did read response for interrupted request of index #{expected_index}... Proceeding.")
770
+ return result
771
+ rescue TimeoutError => _
772
+ log_info(logger, "Read did not result in a response for index #{expected_index}... Retrying send_command...")
773
+ return send_command(run_loop, cmd, options, num_retries+1, intr_error)
774
+ end
775
+ end
776
+
733
777
 
734
778
  begin
735
779
  Timeout::timeout(timeout, TimeoutError) do
736
780
  result = Core.read_response(run_loop, expected_index)
737
781
  end
738
-
739
782
  rescue TimeoutError => _
740
783
  raise TimeoutError, "Time out waiting for UIAutomation run-loop for command #{cmd}. Waiting for index:#{expected_index}"
741
784
  end
@@ -776,4 +819,12 @@ module RunLoop
776
819
  script
777
820
  end
778
821
 
822
+ def self.log_info(device_logger, message)
823
+ msg = "#{Time.now}: #{message}"
824
+ if device_logger && device_logger.respond_to?(:info)
825
+ logger.info(msg)
826
+ else
827
+ puts msg if ENV['DEBUG'] == '1'
828
+ end
829
+ end
779
830
  end
@@ -1,5 +1,5 @@
1
1
  module RunLoop
2
- VERSION = '1.1.1.pre6'
2
+ VERSION = '1.1.1.pre7'
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: 1.1.1.pre6
4
+ version: 1.1.1.pre7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Krukow