websocket_server.rb 621 B

12345678910111213141516171819202122232425262728
  1. RSpec.configure do |config|
  2. config.around(:each, type: :system) do |example|
  3. server_required = example.metadata.fetch(:websocket, true)
  4. if server_required
  5. websocket_server = Thread.new do
  6. WebsocketServer.run(
  7. p: ENV['WS_PORT'] || 6042,
  8. b: '0.0.0.0',
  9. s: false,
  10. v: false,
  11. d: false,
  12. )
  13. end
  14. end
  15. example.run
  16. next if !server_required
  17. # returns immediately and thread may be still shutting down
  18. EventMachine.stop_event_loop
  19. # give thread time to terminate
  20. sleep 0.01 while websocket_server.status
  21. end
  22. end