Merge branch 'master' into 9998-unsigned_manifest
[arvados.git] / services / api / test / integration / websocket_test.rb
index 2f950a3ae21308570a6611f65cc4498420ce406c..a9993b2fc318b4abe6ca0669f64a614250608733 100644 (file)
@@ -19,17 +19,20 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     s = TCPServer.new('0.0.0.0', 0)
     @@port = s.addr[1]
     s.close
-    pidfile = "tmp/pids/passenger.#{@@port}.pid"
+    @@pidfile = "tmp/pids/passenger.#{@@port}.pid"
     DatabaseCleaner.start
     Dir.chdir(Rails.root) do |apidir|
       # Only passenger seems to be able to run the websockets server
       # successfully.
-      _system('passenger', 'start', '-d', "-p#{@@port}")
+      _system('passenger', 'start', '-d',
+              "-p#{@@port}",
+              "--log-file", "/dev/stderr",
+              "--pid-file", @@pidfile)
       timeout = Time.now.tv_sec + 10
       begin
         sleep 0.2
         begin
-          server_pid = IO.read(pidfile).to_i
+          server_pid = IO.read(@@pidfile).to_i
           good_pid = (server_pid > 0) and (Process.kill(0, pid) rescue false)
         rescue Errno::ENOENT
           good_pid = false
@@ -44,7 +47,8 @@ class WebsocketTest < ActionDispatch::IntegrationTest
 
   def self.shutdown
     Dir.chdir(Rails.root) do
-      _system('passenger', 'stop', "-p#{@@port}")
+      _system('passenger', 'stop', "-p#{@@port}",
+              "--pid-file", @@pidfile)
     end
     # DatabaseCleaner leaves the database empty. Prefer to leave it full.
     dc = DatabaseController.new
@@ -333,8 +337,6 @@ class WebsocketTest < ActionDispatch::IntegrationTest
 
   test "connect, subscribe, ask events starting at seq num" do
     state = 1
-    human = nil
-    human_ev_uuid = nil
 
     authorize_with :active
 
@@ -373,12 +375,10 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     assert_equal expect_next_logs[1].object_uuid, l2
   end
 
-  test "connect, subscribe, get event, unsubscribe" do
-    slow_test
+  slow_test "connect, subscribe, get event, unsubscribe" do
     state = 1
     spec = nil
     spec_ev_uuid = nil
-    filter_id = nil
 
     authorize_with :active
 
@@ -423,8 +423,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     assert_equal spec.uuid, spec_ev_uuid
   end
 
-  test "connect, subscribe, get event, unsubscribe with filter" do
-    slow_test
+  slow_test "connect, subscribe, get event, unsubscribe with filter" do
     state = 1
     spec = nil
     spec_ev_uuid = nil
@@ -473,8 +472,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
   end
 
 
-  test "connect, subscribe, get event, try to unsubscribe with bogus filter" do
-    slow_test
+  slow_test "connect, subscribe, get event, try to unsubscribe with bogus filter" do
     state = 1
     spec = nil
     spec_ev_uuid = nil
@@ -524,10 +522,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     assert_equal human.uuid, human_ev_uuid
   end
 
-
-
-  test "connected, not subscribed, no event" do
-    slow_test
+  slow_test "connected, not subscribed, no event" do
     authorize_with :active
 
     ws_helper(token: :active, timeout: false) do |ws|
@@ -547,8 +542,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
     end
   end
 
-  test "connected, not authorized to see event" do
-    slow_test
+  slow_test "connected, not authorized to see event" do
     state = 1
 
     authorize_with :admin
@@ -663,8 +657,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
 
   end
 
-  test "connect, subscribe, lots of events" do
-    slow_test
+  slow_test "connect, subscribe, lots of events" do
     state = 1
     event_count = 0
     log_start = Log.order(:id).last.id
@@ -688,7 +681,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
           assert_equal 200, d["status"]
           ActiveRecord::Base.transaction do
             (1..202).each do
-              spec = Specimen.create
+              Specimen.create
             end
           end
           state = 2
@@ -709,8 +702,6 @@ class WebsocketTest < ActionDispatch::IntegrationTest
 
   test "connect, subscribe with invalid filter" do
     state = 1
-    human = nil
-    human_ev_uuid = nil
 
     authorize_with :active
 
@@ -726,7 +717,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest
         when 1
           assert_equal 200, d["status"]
           Specimen.create
-          human = Human.create
+          Human.create
           state = 2
         when 2
           assert_equal 500, d["status"]