2019-04-15 01:41:17 +00:00
|
|
|
# rubocop:disable RSpec/DescribeClass
|
|
|
|
|
2018-03-15 18:21:04 +00:00
|
|
|
require 'spec_helper'
|
2018-05-09 10:26:17 +00:00
|
|
|
require 'support/script_helper'
|
2018-03-15 18:21:04 +00:00
|
|
|
require 'timeout'
|
|
|
|
|
2018-05-09 10:26:17 +00:00
|
|
|
describe 'websocket-server', type: :script do
|
2018-03-15 18:21:04 +00:00
|
|
|
# Why not Rails.root.join here?
|
|
|
|
# Because it's not avaialable in this spec (no 'rails_helper' = faster start-up)
|
|
|
|
let(:app_root) { File.expand_path('../..', __dir__) }
|
|
|
|
let(:ws_server) { File.expand_path('script/websocket-server.rb', app_root) }
|
|
|
|
let(:pidfile) { File.expand_path('tmp/pids/websocket.pid', app_root) }
|
|
|
|
let(:output_log) { File.expand_path('log/websocket-server_out.log', app_root) }
|
|
|
|
let(:error_log) { File.expand_path('log/websocket-server_err.log', app_root) }
|
|
|
|
|
2018-05-09 10:26:17 +00:00
|
|
|
context 'with IPv6 bind address (via -b option)', if: has_ipv6? do
|
2018-03-15 18:21:04 +00:00
|
|
|
# This error is raised for invalid bind addresses
|
|
|
|
let(:error_msg) { "`start_tcp_server': no acceptor" }
|
|
|
|
let(:ipv6_addr) { '::1/128' }
|
2018-05-08 10:31:43 +00:00
|
|
|
# Prevent port assignment conflicts during parallel test execution
|
2018-05-09 06:10:08 +00:00
|
|
|
let(:port) { rand(60_000..65_000) }
|
2018-03-15 18:21:04 +00:00
|
|
|
|
|
|
|
# Flush logs
|
|
|
|
before do
|
|
|
|
File.write(output_log, '')
|
|
|
|
File.write(error_log, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'starts up successfully' do
|
|
|
|
begin
|
2018-05-09 08:42:32 +00:00
|
|
|
system("RAILS_ENV=test #{ws_server} start -db #{ipv6_addr} -p #{port} >/dev/null 2>&1")
|
2018-03-15 18:21:04 +00:00
|
|
|
|
|
|
|
# Wait for daemon to start
|
|
|
|
Timeout.timeout(20, Timeout::Error, 'WebSocket Server startup timed out') do
|
|
|
|
loop { break if File.size(output_log) + File.size(error_log) > 0 }
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(File.read(error_log)).not_to include(error_msg)
|
|
|
|
ensure
|
|
|
|
system("#{ws_server} stop >/dev/null 2>&1") if File.exist?(pidfile)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
|
|
# rubocop:enable RSpec/DescribeClass
|