4 $ARV_API_SERVER_DIR = File.expand_path('../..', __FILE__)
6 s = TCPServer.new('0.0.0.0', 0)
7 WEBSOCKET_PORT = s.addr[1]
9 SERVER_PID_PATH = "tmp/pids/passenger.#{WEBSOCKET_PORT}.pid"
11 class WebsocketTestRunner < MiniTest::Unit
13 Bundler.with_clean_env do
14 if not system({'ARVADOS_WEBSOCKETS' => 'ws-only', 'RAILS_ENV' => 'test'}, *cmd)
15 raise RuntimeError, "Command failed with exit status #{$?}: #{cmd.inspect}"
21 server_pid = Dir.chdir($ARV_API_SERVER_DIR) do |apidir|
22 # Only passenger seems to be able to run the websockets server successfully.
23 _system('passenger', 'start', '-d', "-p#{WEBSOCKET_PORT}")
24 timeout = Time.now.tv_sec + 10
28 server_pid = IO.read(SERVER_PID_PATH).to_i
29 good_pid = (server_pid > 0) and (Process.kill(0, pid) rescue false)
33 end while (not good_pid) and (Time.now.tv_sec < timeout)
35 raise RuntimeError, "could not find API server Rails pid"
42 Dir.chdir($ARV_API_SERVER_DIR) do
43 _system('passenger', 'stop', "-p#{WEBSOCKET_PORT}")
45 # DatabaseCleaner leaves the database empty. Prefer to leave it full.
46 dc = DatabaseController.new
47 dc.define_singleton_method :render do |*args| end
53 MiniTest::Unit.runner = WebsocketTestRunner.new