websocket_server_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. # rubocop:disable RSpec/DescribeClass
  3. require 'spec_helper'
  4. require 'support/script_helper'
  5. require 'timeout'
  6. describe 'websocket-server', type: :script do
  7. # Why not Rails.root.join here?
  8. # Because it's not avaialable in this spec (no 'rails_helper' = faster start-up)
  9. let(:app_root) { File.expand_path('../..', __dir__) }
  10. let(:ws_server) { File.expand_path('script/websocket-server.rb', app_root) }
  11. let(:pidfile) { File.expand_path('tmp/pids/websocket.pid', app_root) }
  12. let(:output_log) { File.expand_path('log/websocket-server_out.log', app_root) }
  13. let(:error_log) { File.expand_path('log/websocket-server_err.log', app_root) }
  14. context 'with IPv6 bind address (via -b option)', if: has_ipv6? do
  15. # This error is raised for invalid bind addresses
  16. let(:error_msg) { "`start_tcp_server': no acceptor" }
  17. let(:ipv6_addr) { '::1/128' }
  18. # Prevent port assignment conflicts during parallel test execution
  19. let(:port) { rand(60_000..65_000) } # rubocop:disable Zammad/ForbidRand
  20. # Flush logs
  21. before do
  22. File.write(output_log, '')
  23. File.write(error_log, '')
  24. end
  25. it 'starts up successfully' do
  26. system("RAILS_ENV=test #{ws_server} start -db #{ipv6_addr} -p #{port} >/dev/null 2>&1")
  27. # Wait for daemon to start
  28. Timeout.timeout(20, Timeout::Error, 'WebSocket Server startup timed out') do
  29. loop { break if File.size(output_log) + File.size(error_log) > 0 }
  30. end
  31. expect(File.read(error_log)).not_to include(error_msg)
  32. ensure
  33. system("#{ws_server} stop >/dev/null 2>&1") if File.exist?(pidfile)
  34. end
  35. end
  36. end
  37. # rubocop:enable RSpec/DescribeClass