aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/test/subscription_adapter/evented_redis_test.rb
blob: e3e0a0c72afeea13dcb012013c818f52c7be4758 (plain) (blame)
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
# frozen_string_literal: true

require "test_helper"
require_relative "common"
require_relative "channel_prefix"

class EventedRedisAdapterTest < ActionCable::TestCase
  include CommonSubscriptionAdapterTest
  include ChannelPrefixTest

  def setup
    assert_deprecated do
      super
    end

    # em-hiredis is warning-rich
    @previous_verbose, $VERBOSE = $VERBOSE, nil
  end

  def teardown
    super

    # Ensure EM is shut down before we re-enable warnings
    EventMachine.reactor_thread.tap do |thread|
      EventMachine.stop
      thread.join
    end

    $VERBOSE = @previous_verbose
  end

  def test_slow_eventmachine
    require "eventmachine"
    require "thread"

    lock = Mutex.new

    EventMachine.singleton_class.class_eval do
      alias_method :delayed_initialize_event_machine, :initialize_event_machine
      define_method(:initialize_event_machine) do
        lock.synchronize do
          sleep 0.5
          delayed_initialize_event_machine
        end
      end
    end

    test_basic_broadcast
  ensure
    lock.synchronize do
      EventMachine.singleton_class.class_eval do
        alias_method :initialize_event_machine, :delayed_initialize_event_machine
        remove_method :delayed_initialize_event_machine
      end
    end
  end

  def cable_config
    { adapter: "evented_redis", url: "redis://:password@127.0.0.1:6379/12" }
  end
end