Test that a Rails.queue consumer is automatically started in production

This commit is contained in:
Jeremy Kemper 2012-10-13 09:54:34 -07:00
parent c8fe0d58bc
commit 1fd8926056
3 changed files with 14 additions and 3 deletions

@ -44,7 +44,7 @@ def initialize(*)
@autoflush_log = true
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
@queue = ActiveSupport::SynchronousQueue.new
@queue_consumer = ActiveSupport::ThreadedQueueConsumer
@queue_consumer = nil
@eager_load = nil
@assets = ActiveSupport::OrderedOptions.new

@ -98,7 +98,8 @@ module Finisher
initializer :activate_queue_consumer do |app|
if config.queue.class == ActiveSupport::Queue
app.queue_consumer = config.queue_consumer.start
app.queue_consumer = config.queue_consumer || config.queue.consumer
app.queue_consumer.start
at_exit { app.queue_consumer.shutdown }
end
end

@ -69,6 +69,17 @@ def ran?
refute job.ran_in_different_thread?, "Expected job to run in the same thread"
end
test "in production, automatically spawn a queue consumer in a background thread" do
add_to_env_config "production", <<-RUBY
config.queue = ActiveSupport::Queue.new
RUBY
app("production")
assert_nil Rails.application.config.queue_consumer
assert_kind_of ActiveSupport::ThreadedQueueConsumer, Rails.application.queue_consumer
end
test "attempting to marshal a queue will raise an exception" do
app("test")
assert_raises TypeError do
@ -123,7 +134,6 @@ class MyQueueConsumer
def start
@started = true
self
end
end
RUBY