Class: TestCenter::Helper::MultiScanManager::SimulatorHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SimulatorHelper

Returns a new instance of SimulatorHelper.



5
6
7
8
9
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 5

def initialize(options)
  @options = options
  # TODO: add byebug to make sure we're mocking this
  @all_simulators = FastlaneCore::DeviceManager.simulators('iOS') 
end

Class Method Details

.call_simulator_started_callback(options, devices) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 101

def self.call_simulator_started_callback(options, devices)
  return unless options[:simulator_started_callback]
  return unless options[:platform] == :ios_simulator

  devices.each do |device|
    options[:simulator_started_callback].call(device.udid)
  end
end

Instance Method Details

#clone_destination_simulators(remaining_desired_simulators) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 64

def clone_destination_simulators(remaining_desired_simulators)
  cloned_simulators = []

  run_count = remaining_desired_simulators
  destinations = Scan.config[:destination].clone
  original_simulators = @all_simulators.find_all do |simulator|
    found_simulator = destinations.find do |destination|
      simulator_matches_destination(simulator, destination)
    end
    if found_simulator
      destinations.delete(found_simulator)
    end

    !found_simulator.nil?
  end
  original_simulators.each(&:shutdown)
  (0...run_count).each do |batch_index|
    cloned_simulators << []
    original_simulators.each do |simulator|
      cloned_simulator = simulator.clone
      new_first_name = simulator.name.sub(/( ?\(.*| ?$)/, " Clone #{batch_index + 1}")
      FastlaneCore::UI.verbose("Cloned simulator #{simulator.name} to (name=#{new_first_name}, udid=#{cloned_simulator.udid}, OS=#{cloned_simulator.ios_version})")
      new_last_name = "#{self.class.name}<#{self.object_id}>"
      cloned_simulator.rename("#{new_first_name} #{new_last_name}")

      cloned_simulators.last << cloned_simulator
    end
  end
  cloned_simulators
end

#delete_multi_scan_cloned_simulatorsObject



95
96
97
98
99
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 95

def delete_multi_scan_cloned_simulators
  FastlaneCore::DeviceManager.simulators('iOS').each do |simulator|
    simulator.delete if /#{self.class.name}<\d+>/ =~ simulator.name
  end
end

#find_matching_destination_simulators(remaining_desired_simulators) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 35

def find_matching_destination_simulators(remaining_desired_simulators)
  destination = Scan.config[:destination].clone.first

  desired_device = @all_simulators.find do |simulator|
    match = destination.match(/id=(?<udid>[^,]+)/) 
    match && match[:udid] == simulator.udid
  end

  matching_simulators = @all_simulators.find_all do |simulator|
    desired_device.os_version == simulator.os_version && simulator.name =~ /#{Regexp.escape(desired_device.name)} Clone \d #{self.class.name}<[^>]+>/ 
  end
  matching_simulators.first(remaining_desired_simulators)
end

#parallel_destination_simulatorsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 17

def parallel_destination_simulators
  remaining_desired_simulators = @options[:parallel_testrun_count] || 0

  simulators = []
  if @options[:reuse_simulators_for_parallel_testruns]
    matching_simulators = find_matching_destination_simulators(remaining_desired_simulators)
    remaining_desired_simulators -= matching_simulators.size
    (0...matching_simulators.size).each do |s|
      simulators << [matching_simulators[s]]
    end
  end

  if remaining_desired_simulators > 0
    simulators.concat(clone_destination_simulators(remaining_desired_simulators))
  end
  simulators
end

#setupObject



11
12
13
14
15
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 11

def setup
  if @options[:parallel_testrun_count] > 1 && @options.fetch(:pre_delete_cloned_simulators, true)
    delete_multi_scan_cloned_simulators
  end
end

#simulator_matches_destination(simulator, destination) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/simulator_helper.rb', line 49

def simulator_matches_destination(simulator, destination)
  match = destination.match(/id=(?<udid>[^,]+)/)
  if match
    found_match = (match[:udid] == simulator.udid)
  else
    match = destination.match(/name=(?<name>[^,]+)/)
    name = match[:name] || ''
    match = destination.match(/OS=(?<os_version>[^,]+)/)
    os_version = match[:os_version] || ''

    found_match = (name == simulator.name && os_version == simulator.os_version)
  end
  found_match
end