Permalink
Browse files

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

  • Loading branch information...
jeremy committed Oct 13, 2012
1 parent c8fe0d5 commit 1fd89260566eae1b8d3531bf83233eb18c27ab3d
@@ -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

0 comments on commit 1fd8926

Please sign in to comment.