Class: LibyuiClient::LocalProcess

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

Constant Summary collapse

DEFAULT_TIMEOUT_PROCESS =

default timeout for process

2

Instance Method Summary collapse

Instance Method Details

#kill_appObject

kill the process if it is still running after finishing a scenario



27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object

start the application in background

Parameters:

  • application (String)

    the command to start



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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