2015-07-12 11:07:31 -04:00
|
|
|
require 'test_helper'
|
|
|
|
require 'stubs/test_connection'
|
2015-07-13 11:43:52 -04:00
|
|
|
require 'stubs/room'
|
2015-07-12 11:07:31 -04:00
|
|
|
|
|
|
|
class ActionCable::Channel::PeriodicTimersTest < ActiveSupport::TestCase
|
|
|
|
class ChatChannel < ActionCable::Channel::Base
|
|
|
|
periodically -> { ping }, every: 5
|
|
|
|
periodically :send_updates, every: 1
|
|
|
|
|
|
|
|
private
|
|
|
|
def ping
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
@connection = TestConnection.new
|
|
|
|
end
|
|
|
|
|
|
|
|
test "periodic timers definition" do
|
|
|
|
timers = ChatChannel.periodic_timers
|
|
|
|
|
|
|
|
assert_equal 2, timers.size
|
|
|
|
|
|
|
|
first_timer = timers[0]
|
|
|
|
assert_kind_of Proc, first_timer[0]
|
|
|
|
assert_equal 5, first_timer[1][:every]
|
|
|
|
|
|
|
|
second_timer = timers[1]
|
|
|
|
assert_equal :send_updates, second_timer[0]
|
|
|
|
assert_equal 1, second_timer[1][:every]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "timer start and stop" do
|
2016-01-27 08:33:15 -05:00
|
|
|
EventMachine::PeriodicTimer.expects(:new).times(2).returns(true)
|
2015-07-12 11:07:31 -04:00
|
|
|
channel = ChatChannel.new @connection, "{id: 1}", { id: 1 }
|
|
|
|
|
|
|
|
channel.expects(:stop_periodic_timers).once
|
|
|
|
channel.unsubscribe_from_channel
|
|
|
|
end
|
|
|
|
end
|