aboutsummaryrefslogtreecommitdiffstats
path: root/test/worker_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/worker_test.rb')
-rw-r--r--test/worker_test.rb46
1 files changed, 46 insertions, 0 deletions
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