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:
parent
c8fe0d58bc
commit
1fd8926056
3 changed files with 14 additions and 3 deletions
|
@ -44,7 +44,7 @@ module Rails
|
|||
@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 Rails
|
|||
|
||||
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 @@ module ApplicationTests
|
|||
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 @@ module ApplicationTests
|
|||
|
||||
def start
|
||||
@started = true
|
||||
self
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
|
Loading…
Reference in a new issue