aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-07-14 10:58:46 -0500
committerPratik Naik <pratiknaik@gmail.com>2015-07-14 10:58:46 -0500
commitb75bff4225608497f23119f9fdcff34e980fb74b (patch)
treecf5f5932d1271d5d715999a0740c67358152f181 /test
parent729f57af3d3f3461d8f2b6c8421920c71ea9b03a (diff)
downloadrails-b75bff4225608497f23119f9fdcff34e980fb74b.tar.gz
rails-b75bff4225608497f23119f9fdcff34e980fb74b.tar.bz2
rails-b75bff4225608497f23119f9fdcff34e980fb74b.zip
Worker tests
Diffstat (limited to 'test')
-rw-r--r--test/test_helper.rb2
-rw-r--r--test/worker_test.rb46
2 files changed, 48 insertions, 0 deletions
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