diff options
Diffstat (limited to 'railties/test/queueing/test_queue_test.rb')
-rw-r--r-- | railties/test/queueing/test_queue_test.rb | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/railties/test/queueing/test_queue_test.rb b/railties/test/queueing/test_queue_test.rb index de30e8cffd..78c6c617fe 100644 --- a/railties/test/queueing/test_queue_test.rb +++ b/railties/test/queueing/test_queue_test.rb @@ -3,9 +3,7 @@ require 'rails/queueing' class TestQueueTest < ActiveSupport::TestCase class Job - attr_reader :id - def initialize(id, &block) - @id = id + def initialize(&block) @block = block end @@ -18,18 +16,43 @@ class TestQueueTest < ActiveSupport::TestCase @queue = Rails::Queueing::TestQueue.new end + def test_drain_raises + @queue.push Job.new { raise } + assert_raises(RuntimeError) { @queue.drain } + end + + def test_jobs + @queue.push 1 + @queue.push 2 + assert_equal [1,2], @queue.jobs + end + def test_contents - assert_equal [], @queue.contents - job = Job.new(1) + assert @queue.empty? + job = Job.new @queue.push job - assert_equal [job], @queue.contents + refute @queue.empty? + assert_equal job, @queue.pop + end + + def test_order + processed = [] + + job1 = Job.new { processed << 1 } + job2 = Job.new { processed << 2 } + + @queue.push job1 + @queue.push job2 + @queue.drain + + assert_equal [1,2], processed end def test_drain t = nil ran = false - job = Job.new(1) do + job = Job.new do ran = true t = Thread.current end @@ -37,7 +60,7 @@ class TestQueueTest < ActiveSupport::TestCase @queue.push job @queue.drain - assert_equal [], @queue.contents + assert @queue.empty? assert ran, "The job runs synchronously when the queue is drained" assert_not_equal t, Thread.current end |