From 854949b7e63e8bacb04c4c3829cab5dd0e48d3ad Mon Sep 17 00:00:00 2001 From: Fabio Pitino Date: Fri, 10 Jun 2022 07:47:16 +0100 Subject: [PATCH] Fix Sidekiq warning in Gitlab::EventStore --- lib/gitlab/event_store/subscription.rb | 3 +-- spec/lib/gitlab/event_store/store_spec.rb | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/gitlab/event_store/subscription.rb b/lib/gitlab/event_store/subscription.rb index e5c92ab969f9be..01986355d2d805 100644 --- a/lib/gitlab/event_store/subscription.rb +++ b/lib/gitlab/event_store/subscription.rb @@ -13,8 +13,7 @@ def initialize(worker, condition) def consume_event(event) return unless condition_met?(event) - worker.perform_async(event.class.name, event.data) - # TODO: Log dispatching of events to subscriber + worker.perform_async(event.class.name, event.data.deep_stringify_keys) # We rescue and track any exceptions here because we don't want to # impact other subscribers if one is faulty. diff --git a/spec/lib/gitlab/event_store/store_spec.rb b/spec/lib/gitlab/event_store/store_spec.rb index 94e8f0ff2ffa5d..bbdfecc897aded 100644 --- a/spec/lib/gitlab/event_store/store_spec.rb +++ b/spec/lib/gitlab/event_store/store_spec.rb @@ -134,6 +134,7 @@ def schema describe '#publish' do let(:data) { { name: 'Bob', id: 123 } } + let(:serialized_data) { data.deep_stringify_keys } context 'when event has a subscribed worker' do let(:store) do @@ -144,12 +145,21 @@ def schema end it 'dispatches the event to the subscribed worker' do - expect(worker).to receive(:perform_async).with('TestEvent', data) + expect(worker).to receive(:perform_async).with('TestEvent', serialized_data) expect(another_worker).not_to receive(:perform_async) store.publish(event) end + it 'does not raise any Sidekiq warning' do + logger = double(:logger, info: nil) + allow(Sidekiq).to receive(:logger).and_return(logger) + expect(logger).not_to receive(:warn).with(/do not serialize to JSON safely/) + expect(worker).to receive(:perform_async).with('TestEvent', serialized_data).and_call_original + + store.publish(event) + end + context 'when other workers subscribe to the same event' do let(:store) do described_class.new do |store| @@ -160,8 +170,8 @@ def schema end it 'dispatches the event to each subscribed worker' do - expect(worker).to receive(:perform_async).with('TestEvent', data) - expect(another_worker).to receive(:perform_async).with('TestEvent', data) + expect(worker).to receive(:perform_async).with('TestEvent', serialized_data) + expect(another_worker).to receive(:perform_async).with('TestEvent', serialized_data) expect(unrelated_worker).not_to receive(:perform_async) store.publish(event) @@ -215,7 +225,7 @@ def schema let(:event) { event_klass.new(data: data) } it 'dispatches the event to the workers satisfying the condition' do - expect(worker).to receive(:perform_async).with('TestEvent', data) + expect(worker).to receive(:perform_async).with('TestEvent', serialized_data) expect(another_worker).not_to receive(:perform_async) store.publish(event) -- GitLab