From b75bff4225608497f23119f9fdcff34e980fb74b Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 14 Jul 2015 10:58:46 -0500 Subject: Worker tests --- test/test_helper.rb | 2 ++ test/worker_test.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/worker_test.rb (limited to 'test') diff --git a/test/test_helper.rb b/test/test_helper.rb index 4b8e66b569..759ea18524 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,3 +15,5 @@ ActiveSupport.test_order = :sorted # Require all the stubs and models Dir[File.dirname(__FILE__) + '/stubs/*.rb'].each {|file| require file } + +Celluloid.logger = Logger.new(StringIO.new) diff --git a/test/worker_test.rb b/test/worker_test.rb new file mode 100644 index 0000000000..e1fa6f561b --- /dev/null +++ b/test/worker_test.rb @@ -0,0 +1,46 @@ +require 'test_helper' + +class WorkerTest < ActiveSupport::TestCase + class Receiver + attr_accessor :last_action + + def run + @last_action = :run + end + + def process(message) + @last_action = [ :process, message ] + end + end + + setup do + Celluloid.boot + + @worker = ActionCable::Server::Worker.new + @receiver = Receiver.new + end + + teardown do + @receiver.last_action = nil + end + + test "invoke" do + @worker.invoke @receiver, :run + assert_equal :run, @receiver.last_action + end + + test "invoke with arguments" do + @worker.invoke @receiver, :process, "Hello" + assert_equal [ :process, "Hello" ], @receiver.last_action + end + + test "running periodic timers with a proc" do + @worker.run_periodic_timer @receiver, @receiver.method(:run) + assert_equal :run, @receiver.last_action + end + + test "running periodic timers with a method" do + @worker.run_periodic_timer @receiver, :run + assert_equal :run, @receiver.last_action + end +end -- cgit v1.2.3