diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/lib/gitlab/metrics/subscribers/action_cable_spec.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) | |
download | gitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/lib/gitlab/metrics/subscribers/action_cable_spec.rb')
-rw-r--r-- | spec/lib/gitlab/metrics/subscribers/action_cable_spec.rb | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/subscribers/action_cable_spec.rb b/spec/lib/gitlab/metrics/subscribers/action_cable_spec.rb new file mode 100644 index 00000000000..153cf43be0a --- /dev/null +++ b/spec/lib/gitlab/metrics/subscribers/action_cable_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Metrics::Subscribers::ActionCable, :request_store do + let(:subscriber) { described_class.new } + let(:counter) { double(:counter) } + let(:data) { { data: { event: 'updated' } } } + let(:channel_class) { 'IssuesChannel' } + let(:event) do + double( + :event, + name: name, + payload: payload + ) + end + + describe '#transmit' do + let(:name) { 'transmit.action_cable' } + let(:via) { 'streamed from issues:Z2lkOi8vZs2l0bGFiL0lzc3VlLzQ0Ng' } + let(:payload) do + { + channel_class: channel_class, + via: via, + data: data + } + end + + it 'tracks the transmit event' do + allow(::Gitlab::Metrics).to receive(:counter).with( + :action_cable_single_client_transmissions_total, /transmit/ + ).and_return(counter) + + expect(counter).to receive(:increment) + + subscriber.transmit(event) + end + end + + describe '#broadcast' do + let(:name) { 'broadcast.action_cable' } + let(:coder) { ActiveSupport::JSON } + let(:message) do + { event: :updated } + end + + let(:broadcasting) { 'issues:Z2lkOi8vZ2l0bGFiL0lzc3VlLzQ0Ng' } + let(:payload) do + { + broadcasting: broadcasting, + message: message, + coder: coder + } + end + + it 'tracks the broadcast event' do + allow(::Gitlab::Metrics).to receive(:counter).with( + :action_cable_broadcasts_total, /broadcast/ + ).and_return(counter) + + expect(counter).to receive(:increment) + + subscriber.broadcast(event) + end + end + + describe '#transmit_subscription_confirmation' do + let(:name) { 'transmit_subscription_confirmation.action_cable' } + let(:channel_class) { 'IssuesChannel' } + let(:payload) do + { + channel_class: channel_class + } + end + + it 'tracks the subscription confirmation event' do + allow(::Gitlab::Metrics).to receive(:counter).with( + :action_cable_subscription_confirmations_total, /confirm/ + ).and_return(counter) + + expect(counter).to receive(:increment) + + subscriber.transmit_subscription_confirmation(event) + end + end + + describe '#transmit_subscription_rejection' do + let(:name) { 'transmit_subscription_rejection.action_cable' } + let(:channel_class) { 'IssuesChannel' } + let(:payload) do + { + channel_class: channel_class + } + end + + it 'tracks the subscription rejection event' do + allow(::Gitlab::Metrics).to receive(:counter).with( + :action_cable_subscription_rejections_total, /reject/ + ).and_return(counter) + + expect(counter).to receive(:increment) + + subscriber.transmit_subscription_rejection(event) + end + end +end |