1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actioncable/test/subscription_adapter/evented_redis_test.rb
Matthew Draper 162e889f16 Prevent race condition when launching EventMachine reactor
reactor_running? will be true just after the thread enters
EventMachine.run; reactor_thread only gets set after the internal
initialize_event_machine method has been called, the C extension is set
up, and it is entering its run loop.
2016-11-30 22:55:04 +10:30

55 lines
1.2 KiB
Ruby

require "test_helper"
require_relative "./common"
class EventedRedisAdapterTest < ActionCable::TestCase
include CommonSubscriptionAdapterTest
def setup
super
# 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://127.0.0.1:6379/12" }
end
end