class LibyuiClient::LocalProcess
Constants
- DEFAULT_TIMEOUT_PROCESS
default timeout for process
Public Instance Methods
kill_app()
click to toggle source
kill the process if it is still running after finishing a scenario
# File lib/libyui_client/local_process.rb, line 27 def kill_app return unless @app_pid Process.waitpid(@app_pid, Process::WNOHANG) LibyuiClient.logger.debug("Sending KILL signal for PID #{@app_pid}") Process.kill('-KILL', @app_pid) rescue Errno::ECHILD, Errno::ESRCH # the process has already exited @app_pid = nil end
start_app(application)
click to toggle source
start the application in background @param application [String] the command to start
# File lib/libyui_client/local_process.rb, line 11 def start_app(application) @app_host = 'localhost' @app_port = port # another app already running? raise "The port #{@app_host}:#{@app_port} is already open!" if port_open?(@app_host, @app_port) LibyuiClient.logger.debug("Starting #{application}...") # create a new process group so easily we will be able # to kill all its sub-processes @app_pid = spawn(application, pgroup: true) wait_for_port(@app_host, @app_port) LibyuiClient.logger.debug("App started: '#{application}'") end
Private Instance Methods
add_step_delay()
click to toggle source
optionally allow a short delay between the steps to watch the UI changes
# File lib/libyui_client/local_process.rb, line 68 def add_step_delay delay = ENV['STEP_DELAY'].to_f sleep(delay) if delay.positive? end
port()
click to toggle source
set the application introspection port for communication
# File lib/libyui_client/local_process.rb, line 41 def port ENV['YUI_HTTP_PORT'] ||= '9999' end
port_open?(host, port)
click to toggle source
is the target port open? @param host [String] the host to connect to @param port [Integer] the port number @return [Boolean] true if the port is open, false otherwise
# File lib/libyui_client/local_process.rb, line 49 def port_open?(host, port) TCPSocket.new(host, port).close true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH false end
wait_for_port(host, port)
click to toggle source
wait until the specified port is open or until the timeout is reached @param host [String] the host to connect to @param port [Integer] the port number @raise LibyuiClient::Error::TimeoutError
if the port is not opened in time
# File lib/libyui_client/local_process.rb, line 60 def wait_for_port(host, port) Wait.until(timeout: LibyuiClient.timeout, interval: LibyuiClient.interval) do LibyuiClient.logger.debug("Waiting for #{host}:#{port}...") port_open?(host, port) end end