Module: Applitools::Connectivity::UniversalServer

Extended by:
UniversalServer
Included in:
UniversalServer
Defined in:
lib/applitools/universal_sdk/universal_server.rb

Constant Summary collapse

DEFAULT_SERVER_IP =
'127.0.0.1'
DEFAULT_SERVER_PORT =
21077

Instance Method Summary collapse

Instance Method Details

#check_or_run(ip = DEFAULT_SERVER_IP, port = DEFAULT_SERVER_PORT) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/applitools/universal_sdk/universal_server.rb', line 27

def check_or_run(ip = DEFAULT_SERVER_IP, port = DEFAULT_SERVER_PORT)
  server_uri = "#{ip}:#{port}"
  socket_uri = "ws://#{server_uri}/eyes"
  begin
    socket = TCPSocket.new(ip, port)
    msg = "Connect to #{server_uri}"
  rescue Errno::ECONNREFUSED
    run
    socket = confirm_is_up(ip, port)
    msg = "Connect to #{server_libname} : #{filename}"
  end

  Applitools::EyesLogger.logger.debug(msg) if ENV['APPLITOOLS_SHOW_LOGS']
  socket_uri
  socket
end

#confirm_is_up(ip, port, attempt = 1) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/applitools/universal_sdk/universal_server.rb', line 16

def confirm_is_up(ip, port, attempt = 1)
  raise 'Universal server unavailable' if (attempt === 16)
  begin
    socket = TCPSocket.new(ip, port)
  rescue Errno::ECONNREFUSED
    sleep 1
    socket = confirm_is_up(ip, port, attempt + 1)
  end
  socket
end

#runObject



10
11
12
13
14
# File 'lib/applitools/universal_sdk/universal_server.rb', line 10

def run
  raise 'Universal server unrecognized' unless find_server_file?
  pid = spawn(filepath, '--singleton --lazy', [:out, :err] => ["log", 'w'])
  Process.detach(pid)
end