[ARVADOS] created: c36840670ed16bc74a260e1c047ed70f03dc5696

Git user git at public.curoverse.com
Thu Jun 30 18:04:41 EDT 2016


        at  c36840670ed16bc74a260e1c047ed70f03dc5696 (commit)


commit c36840670ed16bc74a260e1c047ed70f03dc5696
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Jun 30 17:58:14 2016 -0400

    4753: Select an available port for the passenger server when testing websockets.
    
    This makes it possible to run API tests concurrently (in different
    working dirs on the same host) without fighting over port 3002.

diff --git a/services/api/test/integration/websocket_test.rb b/services/api/test/integration/websocket_test.rb
index 98ae103..0c99fcc 100644
--- a/services/api/test/integration/websocket_test.rb
+++ b/services/api/test/integration/websocket_test.rb
@@ -23,9 +23,9 @@ class WebsocketTest < ActionDispatch::IntegrationTest
 
     EM.run {
       if token
-        ws = Faye::WebSocket::Client.new("ws://localhost:3002/websocket?api_token=#{api_client_authorizations(token).api_token}")
+        ws = Faye::WebSocket::Client.new("ws://localhost:#{WEBSOCKET_PORT}/websocket?api_token=#{api_client_authorizations(token).api_token}")
       else
-        ws = Faye::WebSocket::Client.new("ws://localhost:3002/websocket")
+        ws = Faye::WebSocket::Client.new("ws://localhost:#{WEBSOCKET_PORT}/websocket")
       end
 
       ws.on :open do |event|
diff --git a/services/api/test/websocket_runner.rb b/services/api/test/websocket_runner.rb
index 65af8ce..be32a0f 100644
--- a/services/api/test/websocket_runner.rb
+++ b/services/api/test/websocket_runner.rb
@@ -1,7 +1,12 @@
 require 'bundler'
+require 'socket'
 
 $ARV_API_SERVER_DIR = File.expand_path('../..', __FILE__)
-SERVER_PID_PATH = 'tmp/pids/passenger.3002.pid'
+
+s = TCPServer.new('0.0.0.0', 0)
+WEBSOCKET_PORT = s.addr[1]
+s.close
+SERVER_PID_PATH = "tmp/pids/passenger.#{WEBSOCKET_PORT}.pid"
 
 class WebsocketTestRunner < MiniTest::Unit
   def _system(*cmd)
@@ -15,7 +20,7 @@ class WebsocketTestRunner < MiniTest::Unit
   def _run(args=[])
     server_pid = Dir.chdir($ARV_API_SERVER_DIR) do |apidir|
       # Only passenger seems to be able to run the websockets server successfully.
-      _system('passenger', 'start', '-d', '-p3002')
+      _system('passenger', 'start', '-d', "-p#{WEBSOCKET_PORT}")
       timeout = Time.now.tv_sec + 10
       begin
         sleep 0.2
@@ -35,7 +40,7 @@ class WebsocketTestRunner < MiniTest::Unit
       super(args)
     ensure
       Dir.chdir($ARV_API_SERVER_DIR) do
-        _system('passenger', 'stop', '-p3002')
+        _system('passenger', 'stop', "-p#{WEBSOCKET_PORT}")
       end
       # DatabaseCleaner leaves the database empty. Prefer to leave it full.
       dc = DatabaseController.new

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list