X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0862d7206c66e8cc435de1d379c1a3ed389c1c87..21006cfaf6d4d0ac3884a72803a8723bc4bb76fb:/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 7780ccb87c..c4d6d5eb7e 100644 --- a/services/api/test/integration/websocket_test.rb +++ b/services/api/test/integration/websocket_test.rb @@ -3,7 +3,7 @@ require 'websocket_runner' require 'oj' require 'database_cleaner' -DatabaseCleaner.strategy = :truncation +DatabaseCleaner.strategy = :deletion class WebsocketTest < ActionDispatch::IntegrationTest self.use_transactional_fixtures = false @@ -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 @@ -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 @@ -283,7 +287,7 @@ class WebsocketTest < ActionDispatch::IntegrationTest authorize_with :admin - lastid = logs(:log3).id + lastid = logs(:admin_changes_specimen).id l1 = nil l2 = nil @@ -311,11 +315,11 @@ class WebsocketTest < ActionDispatch::IntegrationTest assert false, "Should not get any more events" end end - end - assert_equal logs(:log4).object_uuid, l1 - assert_equal logs(:log5).object_uuid, l2 + expect_next_logs = Log.where('id > ?', lastid).order('id asc') + assert_equal expect_next_logs[0].object_uuid, l1 + assert_equal expect_next_logs[1].object_uuid, l2 end test "connect, subscribe, get event, unsubscribe" do @@ -646,4 +650,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.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