diff options
author | Oscar Del Ben <info@oscardelben.com> | 2012-04-28 11:45:15 +0200 |
---|---|---|
committer | Oscar Del Ben <info@oscardelben.com> | 2012-04-28 11:45:15 +0200 |
commit | 4e69a1579ea74fe2823f6fb2f055db97480492e5 (patch) | |
tree | d8a5834a0ed5a372969f26db753a30785777a5c2 /railties/test/queueing/threaded_consumer_test.rb | |
parent | 943410197cca4235212ca0fc409820378a40890c (diff) | |
parent | 0297e8e4ddc034bcb8ed477efff91d8fe104cb39 (diff) | |
download | rails-4e69a1579ea74fe2823f6fb2f055db97480492e5.tar.gz rails-4e69a1579ea74fe2823f6fb2f055db97480492e5.tar.bz2 rails-4e69a1579ea74fe2823f6fb2f055db97480492e5.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'railties/test/queueing/threaded_consumer_test.rb')
-rw-r--r-- | railties/test/queueing/threaded_consumer_test.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/railties/test/queueing/threaded_consumer_test.rb b/railties/test/queueing/threaded_consumer_test.rb new file mode 100644 index 0000000000..d00a67d511 --- /dev/null +++ b/railties/test/queueing/threaded_consumer_test.rb @@ -0,0 +1,65 @@ +require 'abstract_unit' +require 'rails/queueing' + +class TestThreadConsumer < ActiveSupport::TestCase + class Job + attr_reader :id + def initialize(id, &block) + @id = id + @block = block + end + + def run + @block.call if @block + end + end + + def setup + @queue = Queue.new + @consumer = Rails::Queueing::ThreadedConsumer.start(@queue) + end + + def teardown + @queue.push nil + end + + test "the jobs are executed" do + ran = false + + job = Job.new(1) do + ran = true + end + + @queue.push job + sleep 0.1 + assert_equal true, ran + end + + test "the jobs are not executed synchronously" do + ran = false + + job = Job.new(1) do + sleep 0.1 + ran = true + end + + @queue.push job + assert_equal false, ran + end + + test "shutting down the queue synchronously drains the jobs" do + ran = false + + job = Job.new(1) do + sleep 0.1 + ran = true + end + + @queue.push job + assert_equal false, ran + + @consumer.shutdown + + assert_equal true, ran + end +end |