File: action_cable_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (108 lines) | stat: -rw-r--r-- 2,661 bytes parent folder | download
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'ActionCable', feature_category: :redis do
  describe 'redis config_command' do
    let!(:original_config) { ::ActionCable::Server::Base.config.cable }
    let!(:custom_config) do
      {
        adapter: 'redis',
        config_command: '/opt/generate-redis-password rails',
        url: 'redis://127.0.0.1:6379',
        id: 'foobar',
        channel_prefix: 'test_'
      }
    end

    let!(:expected_args) do
      {
        url: 'redis://127.0.0.1:6379',
        password: 'custom-redis-password',
        custom: {
          instrumentation_class: 'ActionCable'
        },
        id: 'foobar'
      }
    end

    before do
      allow(Gitlab::Popen).to receive(:popen).and_return(["password: 'custom-redis-password'\n", 0])

      ActionCable.server.restart
    end

    after do
      ::ActionCable::Server::Base.config.cable = original_config
      ActionCable.server.restart
    end

    it 'uses the specified password for Redis connection' do
      expect(::Redis).to receive(:new).with(expected_args)

      ::ActionCable::Server::Base.config.cable = custom_config
      ActionCable.server.pubsub.send(:redis_connection)
    end
  end

  describe 'config' do
    before do
      stub_rails_env(rails_env) if rails_env
      stub_config_setting(relative_url_root: '/gitlab/root', url: 'example.com', https: true)

      load Rails.root.join('config/initializers/action_cable.rb')
    end

    around do |example|
      old = config.deep_dup
      Rails.application.config.action_cable.clear
      example.run
    ensure
      Rails.application.config.action_cable = old
    end

    let(:rails_env) { nil }

    subject(:config) { Rails.application.config.action_cable }

    describe 'mount_path' do
      subject { config.mount_path }

      it { is_expected.to eq('/-/cable') }
    end

    describe 'url' do
      subject { config.url }

      it { is_expected.to eq('/gitlab/root/-/cable') }
    end

    describe 'worker_pool_size' do
      subject { config.worker_pool_size }

      it { is_expected.to eq(Gitlab::ActionCable::Config.worker_pool_size) }
    end

    describe 'allow_request_origins' do
      subject { config.allowed_request_origins }

      context 'when in test' do
        let(:rails_env) { 'test' }

        it { is_expected.to eq(['example.com']) }
      end

      context 'when in development' do
        let(:rails_env) { 'development' }

        it { is_expected.to eq(['example.com']) }
      end

      context 'when in production' do
        let(:rails_env) { 'production' }

        it { is_expected.to eq(nil) }
      end
    end
  end
end