From 4fe672034a740836e930733d741017d07f6ffa0c Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 10 Oct 2014 08:52:27 -0400 Subject: [PATCH] 3692: Fixed test, and fixed the actual bug --- services/api/lib/eventbus.rb | 16 +++++---- .../api/test/integration/websocket_test.rb | 36 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/services/api/lib/eventbus.rb b/services/api/lib/eventbus.rb index 50400ee86b..9f74b5db84 100644 --- a/services/api/lib/eventbus.rb +++ b/services/api/lib/eventbus.rb @@ -73,13 +73,15 @@ class EventBus param_out = [] ws.filters.each do |filter| ft = record_filters filter.filters, Log - cond_out += ft[:cond_out] - param_out += ft[:param_out] + if ft[:cond_out].any? + cond_out << "(#{ft[:cond_out].join ') AND ('})" + param_out += ft[:param_out] + end end # Add filters to query if cond_out.any? - logs = logs.where('(' + cond_out.join(') OR (') + ')', *param_out) + logs = logs.where("(#{cond_out.join ') OR ('})", *param_out) end # Finally execute query and actually send the matching log rows @@ -92,8 +94,8 @@ class EventBus ws.last_log_id = id.to_i end rescue Exception => e - puts "Error publishing event: #{$!}" - puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" + Rails.logger.warn "Error publishing event: #{$!}" + Rails.logger.warn "Backtrace:\n\t#{e.backtrace.join("\n\t")}" ws.send ({status: 500, message: 'error'}.to_json) ws.close end @@ -143,8 +145,8 @@ class EventBus rescue Oj::Error => e ws.send ({status: 400, message: "malformed request"}.to_json) rescue Exception => e - puts "Error handling message: #{$!}" - puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" + Rails.logger.warn "Error handling message: #{$!}" + Rails.logger.warn "Backtrace:\n\t#{e.backtrace.join("\n\t")}" ws.send ({status: 500, message: 'error'}.to_json) ws.close end diff --git a/services/api/test/integration/websocket_test.rb b/services/api/test/integration/websocket_test.rb index 925d879906..fbc18c50c7 100644 --- a/services/api/test/integration/websocket_test.rb +++ b/services/api/test/integration/websocket_test.rb @@ -240,6 +240,42 @@ class WebsocketTest < ActionDispatch::IntegrationTest assert_equal human.uuid, human_ev_uuid end + + test "connect, subscribe, compound filter" do + state = 1 + t1 = nil + + authorize_with :admin + + ws_helper :admin do |ws| + ws.on :open do |event| + ws.send ({method: 'subscribe', filters: [['object_uuid', 'is_a', 'arvados#trait'], ['event_type', '=', 'update']]}.to_json) + end + + ws.on :message do |event| + d = Oj.load event.data + case state + when 1 + assert_equal 200, d["status"] + t1 = Trait.create("name" => "foo") + t1.name = "bar" + t1.save! + state = 2 + when 2 + assert_equal 'update', d['event_type'] + state = 3 + ws.close + when 3 + assert false, "Should not get any more events" + end + end + + end + + assert_equal 3, state + assert_not_nil t1 + end + test "connect, subscribe, ask events starting at seq num" do state = 1 human = nil -- 2.39.5