Class: CrateRuby::TestServer

Inherits:
Object
  • Object
show all
Defined in:
lib/crate_ruby/utils.rb

Constant Summary collapse

STARTUP_TIMEOUT =
30

Instance Method Summary collapse

Constructor Details

#initialize(name, http_port) ⇒ TestServer

Returns a new instance of TestServer.



57
58
59
60
61
62
63
64
65
66
# File 'lib/crate_ruby/utils.rb', line 57

def initialize(name, http_port)
  @node_name = name
  @http_port = http_port

  @crate_bin = File.join('parts', 'crate', 'bin', 'crate')
  if !File.file?(@crate_bin)
    puts "Crate is not available. Please run 'bundle exec ruby spec/bootstrap.rb' first."
    exit 1
  end
end

Instance Method Details

#startObject



68
69
70
71
72
73
# File 'lib/crate_ruby/utils.rb', line 68

def start
  cmd = "sh #{@crate_bin} #{start_params}"
  @pid = spawn(cmd)
  wait_for
  Process.detach(@pid)
end

#stopObject



92
93
94
# File 'lib/crate_ruby/utils.rb', line 92

def stop
  Process.kill('HUP', @pid)
end

#wait_forObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/crate_ruby/utils.rb', line 75

def wait_for
  time_slept = 0
  interval = 1
  while true
    if !alive? and time_slept > STARTUP_TIMEOUT
      puts "Crate hasn't started for #{STARTUP_TIMEOUT} seconds. Giving up now..."
      exit 1
    end
    if alive?
      break
    else
      sleep(interval)
      time_slept += interval
    end
  end
end