Class: ParallelCalabash::ParallelCalabashApp

Inherits:
Object
  • Object
show all
Defined in:
lib/parallel_calabash.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ParallelCalabashApp

Returns a new instance of ParallelCalabashApp.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/parallel_calabash.rb', line 15

def initialize(options)
  @options = options
  @helper = if options.has_key?(:apk_path)
              ParallelCalabash::AdbHelper.new(options[:filter])
            else
              ParallelCalabash::IosHelper.new(
                  options[:filter],
                  {
                      DEVICE_TARGET: options[:device_target],
                      DEVICE_ENDPOINT: options[:device_endpoint],
                  },
                  options[:ios_config]
              )
            end
  @runner = if options.has_key?(:apk_path)
              ParallelCalabash::AndroidRunner.new(@helper, options[:mute_output])
            else
              ParallelCalabash::IosRunner.new(@helper, options[:mute_output], options[:skip_ios_ping_check])
            end
end

Instance Method Details

#any_test_failed?(test_results) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/parallel_calabash.rb', line 70

def any_test_failed?(test_results)
  test_results.any? { |result| result[:exit_status] != 0 }
end

#number_of_processes_to_startObject



37
38
39
40
41
42
43
44
45
# File 'lib/parallel_calabash.rb', line 37

def number_of_processes_to_start
  number_of_processes = @helper.number_of_connected_devices
  raise "\n**** NO DEVICE FOUND ****\n" if number_of_processes==0
  puts '*******************************'
  puts " #{number_of_processes} DEVICES FOUND:"
  puts @helper.connected_devices_with_model_info
  puts '*******************************'
  number_of_processes
end

#report_time_takenObject



74
75
76
77
78
79
80
# File 'lib/parallel_calabash.rb', line 74

def report_time_taken
  start = Time.now
  yield
  time_in_sec = Time.now - start
  mm, ss = time_in_sec.divmod(60)
  puts "\nTook #{mm} Minutes, #{ss.round(2)} Seconds"
end

#run_tests_in_parallelObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/parallel_calabash.rb', line 47

def run_tests_in_parallel
  @runner.prepare_for_parallel_execution
  number_of_processes = number_of_processes_to_start
  test_results = nil
  report_time_taken do
    groups = FeatureGrouper.feature_groups(@options, number_of_processes)
    threads = groups.size
    puts "Running with #{threads} threads: #{groups}"
    complete = []
    test_results = Parallel.map_with_index(
        groups,
        :in_threads => threads,
        :finish => lambda { |_, i, _|  complete.push(i); print complete, "\n" }) do |group, index|
      @runner.run_tests(group, index, @options)
    end
    puts 'All threads complete'
    ResultFormatter.report_results(test_results)
  end
  @runner.prepare_for_parallel_execution
  puts 'Parallel run complete'
  Kernel.exit(1) if any_test_failed?(test_results)
end