1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

View file

@ -44,7 +44,7 @@ module Rails
@autoflush_log = true @autoflush_log = true
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new @log_formatter = ActiveSupport::Logger::SimpleFormatter.new
@queue = ActiveSupport::SynchronousQueue.new @queue = ActiveSupport::SynchronousQueue.new
@queue_consumer = ActiveSupport::ThreadedQueueConsumer @queue_consumer = nil
@eager_load = nil @eager_load = nil
@assets = ActiveSupport::OrderedOptions.new @assets = ActiveSupport::OrderedOptions.new

View file

@ -98,7 +98,8 @@ module Rails
initializer :activate_queue_consumer do |app| initializer :activate_queue_consumer do |app|
if config.queue.class == ActiveSupport::Queue 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 } at_exit { app.queue_consumer.shutdown }
end end
end end

View file

@ -69,6 +69,17 @@ module ApplicationTests
refute job.ran_in_different_thread?, "Expected job to run in the same thread" refute job.ran_in_different_thread?, "Expected job to run in the same thread"
end 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 test "attempting to marshal a queue will raise an exception" do
app("test") app("test")
assert_raises TypeError do assert_raises TypeError do
@ -123,7 +134,6 @@ module ApplicationTests
def start def start
@started = true @started = true
self
end end
end end
RUBY RUBY