X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/df9955d76e3103e747360d2c27914d79b97fdf6f..27b18bf9b168319660bdde4632ac4c3f359666d6:/services/api/test/integration/websocket_test.rb diff --git a/services/api/test/integration/websocket_test.rb b/services/api/test/integration/websocket_test.rb index 9179acd680..25e7592c39 100644 --- a/services/api/test/integration/websocket_test.rb +++ b/services/api/test/integration/websocket_test.rb @@ -31,7 +31,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest ws.on :open do |event| opened = true if timeout - EM::Timer.new 4 do + EM::Timer.new 8 do too_long = true if close_status.nil? EM.stop_event_loop end @@ -56,7 +56,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest ws_helper do |ws| ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data status = d["status"] ws.close end @@ -75,7 +75,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data status = d["status"] ws.close end @@ -84,7 +84,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest assert_equal 200, status end - test "connect, subscribe, get event" do + def subscribe_test state = 1 spec = nil ev_uuid = nil @@ -97,7 +97,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -115,6 +115,10 @@ class WebsocketTest < ActionDispatch::IntegrationTest assert_equal spec.uuid, ev_uuid end + test "connect, subscribe, get event" do + subscribe_test() + end + test "connect, subscribe, get two events" do state = 1 spec = nil @@ -130,7 +134,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -170,7 +174,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -209,7 +213,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -253,7 +257,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -293,7 +297,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -319,6 +323,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end test "connect, subscribe, get event, unsubscribe" do + slow_test state = 1 spec = nil spec_ev_uuid = nil @@ -338,7 +343,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -368,6 +373,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end test "connect, subscribe, get event, unsubscribe with filter" do + slow_test state = 1 spec = nil spec_ev_uuid = nil @@ -386,7 +392,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -417,6 +423,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest test "connect, subscribe, get event, try to unsubscribe with bogus filter" do + slow_test state = 1 spec = nil spec_ev_uuid = nil @@ -431,7 +438,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -469,6 +476,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest test "connected, not subscribed, no event" do + slow_test authorize_with :admin ws_helper :admin, false do |ws| @@ -489,6 +497,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end test "connected, not authorized to see event" do + slow_test state = 1 authorize_with :admin @@ -503,7 +512,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -527,7 +536,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data status = d["status"] ws.close end @@ -545,7 +554,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data status = d["status"] ws.close end @@ -563,7 +572,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data status = d["status"] ws.close end @@ -586,12 +595,12 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state - when (1..EventBus::MAX_FILTERS) + when (1..Rails.configuration.websocket_max_filters) assert_equal 200, d["status"] state += 1 - when (EventBus::MAX_FILTERS+1) + when (Rails.configuration.websocket_max_filters+1) assert_equal 403, d["status"] ws.close end @@ -599,11 +608,12 @@ class WebsocketTest < ActionDispatch::IntegrationTest end - assert_equal 17, state + assert_equal Rails.configuration.websocket_max_filters+1, state end test "connect, subscribe, lots of events" do + slow_test state = 1 event_count = 0 log_start = Log.order(:id).last.id @@ -621,7 +631,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest end ws.on :message do |event| - d = Oj.load event.data + d = Oj.strict_load event.data case state when 1 assert_equal 200, d["status"] @@ -646,4 +656,45 @@ class WebsocketTest < ActionDispatch::IntegrationTest end + test "connect, subscribe with invalid filter" do + state = 1 + human = nil + human_ev_uuid = nil + + authorize_with :admin + + ws_helper :admin do |ws| + ws.on :open do |event| + # test that #6451 is fixed (invalid filter crashes websockets) + ws.send ({method: 'subscribe', filters: [['object_blarg', 'is_a', 'arvados#human']]}.to_json) + end + + ws.on :message do |event| + d = Oj.strict_load event.data + case state + when 1 + assert_equal 200, d["status"] + Specimen.create + human = Human.create + state = 2 + when 2 + assert_equal 500, d["status"] + state = 3 + ws.close + when 3 + assert false, "Should not get any more events" + end + end + + end + + assert_equal 3, state + + # Try connecting again, ensure that websockets server is still running and + # didn't crash per #6451 + subscribe_test() + + end + + end