Welcome to mirror list, hosted at ThFree Co, Russian Federation.

action_cable_redis_listener_spec.rb « patch « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 14f556ff348edffdb533c6da9ad73479e325bb2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Patch::ActionCableRedisListener do
  let(:adapter) { instance_double('ActionCable::SubscriptionAdapter::Redis') }
  let(:connection) { instance_double('Redis') }
  let(:listener) { ActionCable::SubscriptionAdapter::Redis::Listener.new(adapter, nil) }

  before do
    allow(Thread).to receive(:new).and_yield
    allow(adapter).to receive(:redis_connection_for_subscriptions).and_return(connection)
  end

  it 'catches Redis connection errors and restarts Action Cable' do
    expect(connection).to receive(:without_reconnect).and_raise Redis::ConnectionError
    expect(ActionCable).to receive_message_chain(:server, :restart)

    expect { listener.add_channel('test_channel', nil) }.not_to raise_error
  end

  it 're-raises other exceptions' do
    expect(connection).to receive(:without_reconnect).and_raise StandardError
    expect(ActionCable).not_to receive(:server)

    expect { listener.add_channel('test_channel', nil) }.to raise_error(StandardError)
  end
end