diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-04-27 10:30:03 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-04-27 10:30:03 +0100 |
commit | 4ed6167e985ed41311d979371813f22fcb0143b7 (patch) | |
tree | ee82a44517f747576a55ba0fc363e1e62182a3b3 /railties/test/queueing/threaded_consumer_test.rb | |
parent | cf1a83c8816edeacd209725ae6c90846e9c6b4fc (diff) | |
parent | 7d1a42a0b17028662e24967a32c6a36849e48068 (diff) | |
download | rails-4ed6167e985ed41311d979371813f22fcb0143b7.tar.gz rails-4ed6167e985ed41311d979371813f22fcb0143b7.tar.bz2 rails-4ed6167e985ed41311d979371813f22fcb0143b7.zip |
Merge branch 'master' of github.com:rails/rails
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 |