class Hive::Worker::Android
Attributes
device[RW]
Public Class Methods
new(device)
click to toggle source
Calls superclass method
# File lib/hive/worker/android.rb, line 22 def initialize(device) @serial = device['serial'] @queue_prefix = device['queue_prefix'].to_s == '' ? '' : "#{device['queue_prefix']}-" @model = device['model'].downcase.gsub(/\s/, '_') @brand = device['brand'].downcase.gsub(/\s/, '_') @os_version = device['os_version'] @worker_ports = PortReserver.new begin device.merge!({"device_api" => DeviceAPI::Android.device(@serial)}) rescue DeviceAPI::DeviceNotFound Hive.logger.info("Device '#{@serial}' disconnected during initialization") rescue DeviceAPI::UnauthorizedDevice Hive.logger.info("Device '#{@serial}' is unauthorized") rescue DeviceAPI::Android::ADBCommandError Hive.logger.info("Device disconnected during worker initialization") rescue => e Hive.logger.warn("Error with connected device: #{e.message}") end set_device_status('happy') self.device = device super(device) end
Public Instance Methods
adb_port()
click to toggle source
# File lib/hive/worker/android.rb, line 45 def adb_port # Assign adb port for this worker return @adb_port unless @adb_port.nil? @adb_port = @port_allocator.allocate_port end
autogenerated_queues()
click to toggle source
def set_device_status(status)
# TODO Report to Hive Mind
end
# File lib/hive/worker/android.rb, line 102 def autogenerated_queues @log.info("Autogenerating queues") [ "#{@queue_prefix}#{@model}", "#{@queue_prefix}#{@brand}", "#{@queue_prefix}android", "#{@queue_prefix}android-#{@os_version}", "#{@queue_prefix}android-#{@os_version}-#{@model}" ] end
hive_mind_device_identifiers()
click to toggle source
# File lib/hive/worker/android.rb, line 113 def hive_mind_device_identifiers { serial: @serial, device_type: 'Mobile' } end
job_message_klass()
click to toggle source
# File lib/hive/worker/android.rb, line 82 def job_message_klass Hive::Messages::AndroidJob end
post_script(job, file_system, script)
click to toggle source
# File lib/hive/worker/android.rb, line 86 def post_script(job, file_system, script) @log.info('Post script') @worker_ports.ports.each do |name, port| @port_allocator.release_port(port) end set_device_status('happy') end
pre_script(job, file_system, script)
click to toggle source
# File lib/hive/worker/android.rb, line 51 def pre_script(job, file_system, script) set_device_status('busy') script.set_env "TEST_SERVER_PORT", adb_port # TODO: Allow the scheduler to specify the ports to use script.set_env "CHARLES_PROXY_PORT", @worker_ports.reserve(queue_name: 'Charles') { @port_allocator.allocate_port } script.set_env "APPIUM_PORT", @worker_ports.reserve(queue_name: 'Appium') { @port_allocator.allocate_port } script.set_env "BOOTSTRAP_PORT", @worker_ports.reserve(queue_name: 'Bootstrap') { @port_allocator.allocate_port } script.set_env "CHROMEDRIVER_PORT", @worker_ports.reserve(queue_name: 'Chromedriver') { @port_allocator.allocate_port } script.set_env 'ADB_DEVICE_ARG', self.device['serial'] FileUtils.mkdir(file_system.home_path + '/build') apk_path = file_system.home_path + '/build/' + 'build.apk' script.set_env "APK_PATH", apk_path if job.build @log.debug("Fetching build") file_system.fetch_build(job.build, apk_path) @log.debug("Re-signing APK: #{job.resign}") if job.resign DeviceAPI::Android::Signing.sign_apk({apk: apk_path, resign: true}) @log.debug("Signing done") end end DeviceAPI::Android.device(device['serial']).unlock "#{self.device['serial']} #{@worker_ports.ports['Appium']} #{apk_path} #{file_system.results_path}" end