diff options
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab')
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/event_store_shared_examples.rb | 18 | ||||
-rw-r--r-- | spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb | 3 |
2 files changed, 20 insertions, 1 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/event_store_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/event_store_shared_examples.rb new file mode 100644 index 00000000000..4fc15cacab4 --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/event_store_shared_examples.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'subscribes to event' do + include AfterNextHelpers + + it 'consumes the published event', :sidekiq_inline do + expect_next(described_class) + .to receive(:handle_event) + .with(instance_of(event.class)) + .and_call_original + + ::Gitlab::EventStore.publish(event) + end +end + +def consume_event(subscriber:, event:) + subscriber.new.perform(event.class.name, event.data) +end diff --git a/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb index 4b956c2b566..b5d93aec1bf 100644 --- a/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/usage_data_counters/issuable_activity_shared_examples.rb @@ -5,7 +5,7 @@ RSpec.shared_examples 'a daily tracked issuable event' do stub_application_setting(usage_ping_enabled: true) end - def count_unique(date_from:, date_to:) + def count_unique(date_from: 1.minute.ago, date_to: 1.minute.from_now) Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: action, start_date: date_from, end_date: date_to) end @@ -14,6 +14,7 @@ RSpec.shared_examples 'a daily tracked issuable event' do expect(track_action(author: user1)).to be_truthy expect(track_action(author: user1)).to be_truthy expect(track_action(author: user2)).to be_truthy + expect(count_unique).to eq(2) end end |