aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-21 13:05:30 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-21 13:09:12 +0100
commit378464a2e47bb849f3351cb8c87366554b7ce74d (patch)
tree98a0aeb321ae4005f45e9c9d4147da1fbef0f7d5
parentdcb8b64975832ac75d92104da3c95876e56eec66 (diff)
downloadrails-378464a2e47bb849f3351cb8c87366554b7ce74d.tar.gz
rails-378464a2e47bb849f3351cb8c87366554b7ce74d.tar.bz2
rails-378464a2e47bb849f3351cb8c87366554b7ce74d.zip
Default to sync instrumentation.
-rw-r--r--actionmailer/test/subscriber_test.rb13
-rw-r--r--actionpack/lib/action_dispatch.rb1
-rw-r--r--actionpack/lib/action_dispatch/middleware/notifications.rb32
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb3
-rw-r--r--actionpack/lib/action_dispatch/railties/subscriber.rb17
-rw-r--r--actionpack/test/activerecord/controller_runtime_test.rb19
-rw-r--r--actionpack/test/controller/subscriber_test.rb18
-rw-r--r--actionpack/test/dispatch/subscriber_test.rb111
-rw-r--r--actionpack/test/template/subscriber_test.rb13
-rw-r--r--activerecord/test/cases/subscriber_test.rb13
-rw-r--r--activeresource/test/cases/subscriber_test.rb13
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb36
-rw-r--r--activesupport/test/notifications_test.rb18
-rw-r--r--railties/lib/rails/commands/server.rb11
-rw-r--r--railties/lib/rails/configuration.rb12
-rw-r--r--railties/lib/rails/rack.rb1
-rw-r--r--railties/lib/rails/rack/logger.rb38
-rw-r--r--railties/lib/rails/subscriber.rb7
-rw-r--r--railties/lib/rails/subscriber/test_helper.rb26
-rw-r--r--railties/test/application/middleware_test.rb2
-rw-r--r--railties/test/subscriber_test.rb45
21 files changed, 80 insertions, 369 deletions
diff --git a/actionmailer/test/subscriber_test.rb b/actionmailer/test/subscriber_test.rb
index 01a71f481d..aed5d2ca7e 100644
--- a/actionmailer/test/subscriber_test.rb
+++ b/actionmailer/test/subscriber_test.rb
@@ -2,7 +2,8 @@ require "abstract_unit"
require "rails/subscriber/test_helper"
require "action_mailer/railties/subscriber"
-module SubscriberTest
+class AMSubscriberTest < ActionMailer::TestCase
+ include Rails::Subscriber::TestHelper
Rails::Subscriber.add(:action_mailer, ActionMailer::Railties::Subscriber.new)
class TestMailer < ActionMailer::Base
@@ -40,14 +41,4 @@ module SubscriberTest
assert_equal 1, @logger.logged(:debug).size
assert_match /Jamis/, @logger.logged(:debug).first
end
-
- class SyncSubscriberTest < ActionMailer::TestCase
- include Rails::Subscriber::SyncTestHelper
- include SubscriberTest
- end
-
- class AsyncSubscriberTest < ActionMailer::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include SubscriberTest
- end
end \ No newline at end of file
diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb
index 42ff9ca2e4..f0490a5619 100644
--- a/actionpack/lib/action_dispatch.rb
+++ b/actionpack/lib/action_dispatch.rb
@@ -46,7 +46,6 @@ module ActionDispatch
autoload :Cookies
autoload :Flash
autoload :Head
- autoload :Notifications
autoload :ParamsParser
autoload :Rescue
autoload :ShowExceptions
diff --git a/actionpack/lib/action_dispatch/middleware/notifications.rb b/actionpack/lib/action_dispatch/middleware/notifications.rb
deleted file mode 100644
index 65409f57fd..0000000000
--- a/actionpack/lib/action_dispatch/middleware/notifications.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module ActionDispatch
- # Provide notifications in the middleware stack. Notice that for the before_dispatch
- # and after_dispatch notifications, we just send the original env, so we don't pile
- # up large env hashes in the queue. However, in exception cases, the whole env hash
- # is actually useful, so we send it all.
- class Notifications
- def initialize(app)
- @app = app
- end
-
- def call(env)
- request = Request.new(env)
- payload = retrieve_payload_from_env(request.filtered_env)
-
- ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", payload)
-
- ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", payload) do
- @app.call(env)
- end
- rescue Exception => exception
- ActiveSupport::Notifications.instrument('action_dispatch.exception',
- :env => env, :exception => exception)
- raise exception
- end
-
- protected
- # Remove any rack related constants from the env, like rack.input.
- def retrieve_payload_from_env(env)
- Hash[:env => env.except(*env.keys.select { |k| k.to_s.index("rack.") == 0 })]
- end
- end
-end
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index 18978bfb39..e4bd143e78 100644
--- a/actionpack/lib/action_dispatch/railtie.rb
+++ b/actionpack/lib/action_dispatch/railtie.rb
@@ -5,9 +5,6 @@ module ActionDispatch
class Railtie < Rails::Railtie
plugin_name :action_dispatch
- require "action_dispatch/railties/subscriber"
- subscriber ActionDispatch::Railties::Subscriber.new
-
# Prepare dispatcher callbacks and run 'prepare' callbacks
initializer "action_dispatch.prepare_dispatcher" do |app|
# TODO: This used to say unless defined?(Dispatcher). Find out why and fix.
diff --git a/actionpack/lib/action_dispatch/railties/subscriber.rb b/actionpack/lib/action_dispatch/railties/subscriber.rb
deleted file mode 100644
index cdb1162eac..0000000000
--- a/actionpack/lib/action_dispatch/railties/subscriber.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-module ActionDispatch
- module Railties
- class Subscriber < Rails::Subscriber
- def before_dispatch(event)
- request = Request.new(event.payload[:env])
- path = request.request_uri.inspect rescue "unknown"
-
- info "\n\nStarted #{request.method.to_s.upcase} #{path} " <<
- "for #{request.remote_ip} at #{event.time.to_s(:db)}"
- end
-
- def logger
- ActionController::Base.logger
- end
- end
- end
-end \ No newline at end of file
diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb
index 37c7738301..ed8e324938 100644
--- a/actionpack/test/activerecord/controller_runtime_test.rb
+++ b/actionpack/test/activerecord/controller_runtime_test.rb
@@ -6,16 +6,15 @@ require 'action_controller/railties/subscriber'
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
-module ControllerRuntimeSubscriberTest
+class ControllerRuntimeSubscriberTest < ActionController::TestCase
class SubscriberController < ActionController::Base
def show
render :inline => "<%= Project.all %>"
end
end
-
- def self.included(base)
- base.tests SubscriberController
- end
+
+ include Rails::Subscriber::TestHelper
+ tests SubscriberController
def setup
@old_logger = ActionController::Base.logger
@@ -40,14 +39,4 @@ module ControllerRuntimeSubscriberTest
assert_equal 2, @logger.logged(:info).size
assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1]
end
-
- class SyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::SyncTestHelper
- include ControllerRuntimeSubscriberTest
- end
-
- class AsyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include ControllerRuntimeSubscriberTest
- end
end \ No newline at end of file
diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/subscriber_test.rb
index 52434426f7..bd0c83413c 100644
--- a/actionpack/test/controller/subscriber_test.rb
+++ b/actionpack/test/controller/subscriber_test.rb
@@ -35,11 +35,9 @@ module Another
end
end
-module ActionControllerSubscriberTest
-
- def self.included(base)
- base.tests Another::SubscribersController
- end
+class ACSubscriberTest < ActionController::TestCase
+ tests Another::SubscribersController
+ include Rails::Subscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@@ -174,14 +172,4 @@ module ActionControllerSubscriberTest
def logs
@logs ||= @logger.logged(:info)
end
-
- class SyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::SyncTestHelper
- include ActionControllerSubscriberTest
- end
-
- class AsyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include ActionControllerSubscriberTest
- end
end
diff --git a/actionpack/test/dispatch/subscriber_test.rb b/actionpack/test/dispatch/subscriber_test.rb
deleted file mode 100644
index 3096c132e7..0000000000
--- a/actionpack/test/dispatch/subscriber_test.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_dispatch/railties/subscriber"
-
-module DispatcherSubscriberTest
- Boomer = lambda do |env|
- req = ActionDispatch::Request.new(env)
- case req.path
- when "/"
- [200, {}, []]
- else
- raise "puke!"
- end
- end
-
- App = ActionDispatch::Notifications.new(Boomer)
-
- def setup
- Rails::Subscriber.add(:action_dispatch, ActionDispatch::Railties::Subscriber.new)
- @app = App
- super
-
- @events = []
- ActiveSupport::Notifications.subscribe do |*args|
- @events << args
- end
- end
-
- def set_logger(logger)
- ActionController::Base.logger = logger
- end
-
- def test_publishes_notifications
- get "/"
- wait
-
- assert_equal 2, @events.size
- before, after = @events
-
- assert_equal 'action_dispatch.before_dispatch', before[0]
- assert_kind_of Hash, before[4][:env]
- assert_equal 'GET', before[4][:env]["REQUEST_METHOD"]
-
- assert_equal 'action_dispatch.after_dispatch', after[0]
- assert_kind_of Hash, after[4][:env]
- assert_equal 'GET', after[4][:env]["REQUEST_METHOD"]
- end
-
- def test_publishes_notifications_even_on_failures
- begin
- get "/puke"
- rescue
- end
-
- wait
-
- assert_equal 3, @events.size
- before, after, exception = @events
-
- assert_equal 'action_dispatch.before_dispatch', before[0]
- assert_kind_of Hash, before[4][:env]
- assert_equal 'GET', before[4][:env]["REQUEST_METHOD"]
-
- assert_equal 'action_dispatch.after_dispatch', after[0]
- assert_kind_of Hash, after[4][:env]
- assert_equal 'GET', after[4][:env]["REQUEST_METHOD"]
-
- assert_equal 'action_dispatch.exception', exception[0]
- assert_kind_of Hash, exception[4][:env]
- assert_equal 'GET', exception[4][:env]["REQUEST_METHOD"]
- assert_kind_of RuntimeError, exception[4][:exception]
- end
-
- def test_subscriber_logs_notifications
- get "/"
- wait
-
- log = @logger.logged(:info).first
- assert_equal 1, @logger.logged(:info).size
-
- assert_match %r{^Started GET "/"}, log
- assert_match %r{for 127\.0\.0\.1}, log
- end
-
- def test_subscriber_has_its_logged_flushed_after_request
- assert_equal 0, @logger.flush_count
- get "/"
- wait
- assert_equal 1, @logger.flush_count
- end
-
- def test_subscriber_has_its_logged_flushed_even_after_busted_requests
- assert_equal 0, @logger.flush_count
- begin
- get "/puke"
- rescue
- end
- wait
- assert_equal 1, @logger.flush_count
- end
-
- class SyncSubscriberTest < ActionController::IntegrationTest
- include Rails::Subscriber::SyncTestHelper
- include DispatcherSubscriberTest
- end
-
- class AsyncSubscriberTest < ActionController::IntegrationTest
- include Rails::Subscriber::AsyncTestHelper
- include DispatcherSubscriberTest
- end
-end \ No newline at end of file
diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb
index af0b3102cf..5db2b16ac1 100644
--- a/actionpack/test/template/subscriber_test.rb
+++ b/actionpack/test/template/subscriber_test.rb
@@ -3,7 +3,8 @@ require "rails/subscriber/test_helper"
require "action_view/railties/subscriber"
require "controller/fake_models"
-module ActionViewSubscriberTest
+class AVSubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@@ -89,14 +90,4 @@ module ActionViewSubscriberTest
assert_equal 1, @logger.logged(:info).size
assert_match /Rendered collection/, @logger.logged(:info).last
end
-
- class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::SyncTestHelper
- include ActionViewSubscriberTest
- end
-
- class AsyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include ActionViewSubscriberTest
- end
end \ No newline at end of file
diff --git a/activerecord/test/cases/subscriber_test.rb b/activerecord/test/cases/subscriber_test.rb
index ce91d9385d..5328d4468b 100644
--- a/activerecord/test/cases/subscriber_test.rb
+++ b/activerecord/test/cases/subscriber_test.rb
@@ -3,7 +3,8 @@ require "models/developer"
require "rails/subscriber/test_helper"
require "active_record/railties/subscriber"
-module SubscriberTest
+class SubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::TestHelper
Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
def setup
@@ -38,14 +39,4 @@ module SubscriberTest
assert_match /CACHE/, @logger.logged(:debug).last
assert_match /SELECT .*?FROM .?developers.?/, @logger.logged(:debug).last
end
-
- class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::SyncTestHelper
- include SubscriberTest
- end
-
- class AsyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include SubscriberTest
- end
end \ No newline at end of file
diff --git a/activeresource/test/cases/subscriber_test.rb b/activeresource/test/cases/subscriber_test.rb
index 7100b02872..3556fbf7cb 100644
--- a/activeresource/test/cases/subscriber_test.rb
+++ b/activeresource/test/cases/subscriber_test.rb
@@ -3,7 +3,8 @@ require "fixtures/person"
require "rails/subscriber/test_helper"
require "active_resource/railties/subscriber"
-module SubscriberTest
+class SubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::TestHelper
Rails::Subscriber.add(:active_resource, ActiveResource::Railties::Subscriber.new)
def setup
@@ -26,14 +27,4 @@ module SubscriberTest
assert_equal "GET http://somewhere.else:80/people/1.xml", @logger.logged(:info)[0]
assert_match /\-\-\> 200 200 106/, @logger.logged(:info)[1]
end
-
- class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::SyncTestHelper
- include SubscriberTest
- end
-
- class AsyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include SubscriberTest
- end
end \ No newline at end of file
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index bb07e4765c..ac482a2ec8 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -3,11 +3,9 @@ require 'thread'
module ActiveSupport
module Notifications
# This is a default queue implementation that ships with Notifications. It
- # consumes events in a thread and publish them to all registered subscribers.
- #
+ # just pushes events to all registered subscribers.
class Fanout
- def initialize(sync = false)
- @subscriber_klass = sync ? Subscriber : AsyncSubscriber
+ def initialize
@subscribers = []
end
@@ -16,7 +14,7 @@ module ActiveSupport
end
def subscribe(pattern = nil, &block)
- @subscribers << @subscriber_klass.new(pattern, &block)
+ @subscribers << Subscriber.new(pattern, &block)
end
def publish(*args)
@@ -68,34 +66,6 @@ module ActiveSupport
@block.call(*args)
end
end
-
- # Used for internal implementation only.
- class AsyncSubscriber < Subscriber #:nodoc:
- def initialize(pattern, &block)
- super
- @events = Queue.new
- start_consumer
- end
-
- def drained?
- @events.empty?
- end
-
- private
- def start_consumer
- Thread.new { consume }
- end
-
- def consume
- while args = @events.shift
- @block.call(*args)
- end
- end
-
- def push(*args)
- @events << args
- end
- end
end
end
end
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index c41d81fe7e..d3af535c26 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -3,18 +3,12 @@ require 'abstract_unit'
module Notifications
class TestCase < ActiveSupport::TestCase
def setup
- Thread.abort_on_exception = true
-
ActiveSupport::Notifications.notifier = nil
@notifier = ActiveSupport::Notifications.notifier
@events = []
@notifier.subscribe { |*args| @events << event(*args) }
end
- def teardown
- Thread.abort_on_exception = false
- end
-
private
def event(*args)
ActiveSupport::Notifications::Event.new(*args)
@@ -25,7 +19,7 @@ module Notifications
end
end
- class PubSubTest < TestCase
+ class SyncPubSubTest < TestCase
def test_events_are_published_to_a_listener
@notifier.publish :foo
@notifier.wait
@@ -72,16 +66,6 @@ module Notifications
end
end
- class SyncPubSubTest < PubSubTest
- def setup
- Thread.abort_on_exception = true
-
- @notifier = ActiveSupport::Notifications::Notifier.new(ActiveSupport::Notifications::Fanout.new(true))
- @events = []
- @notifier.subscribe { |*args| @events << event(*args) }
- end
- end
-
class InstrumentationTest < TestCase
delegate :instrument, :instrument!, :to => ActiveSupport::Notifications
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index 115499db05..b21ae2a17b 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -46,7 +46,6 @@ module Rails
trap(:INT) { exit }
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
- initialize_log_tailer! unless options[:daemonize]
super
ensure
puts 'Exiting' unless options[:daemonize]
@@ -54,6 +53,7 @@ module Rails
def middleware
middlewares = []
+ middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize]
middlewares << [Rails::Rack::Debugger] if options[:debugger]
Hash.new(middlewares)
end
@@ -71,14 +71,5 @@ module Rails
:pid => "tmp/pids/server.pid"
})
end
-
- protected
-
- # LogTailer should not be used as a middleware since the logging happens
- # async in a request and the middleware calls are sync. So we send it
- # to subscriber which will be responsible for calling tail! in the log tailer.
- def initialize_log_tailer!
- Rails::Subscriber.log_tailer = Rails::Rack::LogTailer.new(nil, log_path)
- end
end
end
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index a9586b6e9e..c7331f79c5 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -10,15 +10,15 @@ module Rails
def self.default_middleware_stack
ActionDispatch::MiddlewareStack.new.tap do |middleware|
- middleware.use('ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets })
+ middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets })
middleware.use('::Rack::Lock', :if => lambda { !ActionController::Base.allow_concurrency })
middleware.use('::Rack::Runtime')
- middleware.use('ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local })
- middleware.use('ActionDispatch::Notifications')
- middleware.use('ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes })
- middleware.use('ActionDispatch::Cookies')
+ middleware.use('::Rails::Rack::Logger')
+ middleware.use('::ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local })
+ middleware.use('::ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes })
+ middleware.use('::ActionDispatch::Cookies')
middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
- middleware.use('ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store })
+ middleware.use('::ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store })
middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.paths.app.metals.to_a, Rails.application.config.metals) })
middleware.use('ActionDispatch::ParamsParser')
middleware.use('::Rack::MethodOverride')
diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb
index 36945a6b0f..4bc0c2c88b 100644
--- a/railties/lib/rails/rack.rb
+++ b/railties/lib/rails/rack.rb
@@ -1,6 +1,7 @@
module Rails
module Rack
autoload :Debugger, "rails/rack/debugger"
+ autoload :Logger, "rails/rack/logger"
autoload :LogTailer, "rails/rack/log_tailer"
autoload :Metal, "rails/rack/metal"
autoload :Static, "rails/rack/static"
diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb
new file mode 100644
index 0000000000..91a613092f
--- /dev/null
+++ b/railties/lib/rails/rack/logger.rb
@@ -0,0 +1,38 @@
+require 'rails/subscriber'
+
+module Rails
+ module Rack
+ # Log the request started and flush all loggers after it.
+ class Logger < Rails::Subscriber
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ @env = env
+ before_dispatch
+ result = @app.call(@env)
+ after_dispatch
+ result
+ end
+
+ protected
+
+ def request
+ @request ||= ActionDispatch::Request.new(@env)
+ end
+
+ def before_dispatch
+ path = request.request_uri.inspect rescue "unknown"
+
+ info "\n\nStarted #{request.method.to_s.upcase} #{path} " <<
+ "for #{request.remote_ip} at #{Time.now.to_s(:db)}"
+ end
+
+ def after_dispatch
+ Rails::Subscriber.flush_all!
+ end
+
+ end
+ end
+end
diff --git a/railties/lib/rails/subscriber.rb b/railties/lib/rails/subscriber.rb
index 9965786d86..8c62f562d9 100644
--- a/railties/lib/rails/subscriber.rb
+++ b/railties/lib/rails/subscriber.rb
@@ -33,7 +33,7 @@ module Rails
# Subscriber also has some helpers to deal with logging and automatically flushes
# all logs when the request finishes (via action_dispatch.callback notification).
class Subscriber
- mattr_accessor :colorize_logging, :log_tailer
+ mattr_accessor :colorize_logging
self.colorize_logging = true
# Embed in a String to clear all previous ANSI sequences.
@@ -69,11 +69,6 @@ module Rails
Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
end
end
-
- if args[0] == "action_dispatch.after_dispatch" && !subscribers.empty?
- flush_all!
- log_tailer.tail! if log_tailer
- end
end
# Flush all subscribers' logger.
diff --git a/railties/lib/rails/subscriber/test_helper.rb b/railties/lib/rails/subscriber/test_helper.rb
index 1464767ed9..39b4117372 100644
--- a/railties/lib/rails/subscriber/test_helper.rb
+++ b/railties/lib/rails/subscriber/test_helper.rb
@@ -1,12 +1,12 @@
require 'rails/subscriber'
-require 'active_support/notifications'
module Rails
class Subscriber
# Provides some helpers to deal with testing subscribers by setting up
# notifications. Take for instance ActiveRecord subscriber tests:
#
- # module SubscriberTest
+ # class SyncSubscriberTest < ActiveSupport::TestCase
+ # include Rails::Subscriber::TestHelper
# Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
#
# def test_basic_query_logging
@@ -39,8 +39,6 @@ module Rails
#
module TestHelper
def setup
- Thread.abort_on_exception = true
-
@logger = MockLogger.new
@notifier = ActiveSupport::Notifications::Notifier.new(queue)
@@ -54,7 +52,6 @@ module Rails
def teardown
set_logger(nil)
ActiveSupport::Notifications.notifier = nil
- Thread.abort_on_exception = false
end
class MockLogger
@@ -92,26 +89,9 @@ module Rails
def set_logger(logger)
Rails.logger = logger
end
- end
-
- module SyncTestHelper
- include TestHelper
-
- def queue
- ActiveSupport::Notifications::Fanout.new(true)
- end
- end
-
- module AsyncTestHelper
- include TestHelper
def queue
- ActiveSupport::Notifications::Fanout.new(false)
- end
-
- def wait
- sleep(0.01)
- super
+ ActiveSupport::Notifications::Fanout.new
end
end
end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 1c5cc62ecd..8c4247e840 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -17,8 +17,8 @@ module ApplicationTests
"ActionDispatch::Static",
"Rack::Lock",
"Rack::Runtime",
+ "Rails::Rack::Logger",
"ActionDispatch::ShowExceptions",
- "ActionDispatch::Notifications",
"ActionDispatch::Callbacks",
"ActionDispatch::Cookies",
"ActionDispatch::Session::CookieStore",
diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb
index 724e8a75d6..f6c895093f 100644
--- a/railties/test/subscriber_test.rb
+++ b/railties/test/subscriber_test.rb
@@ -24,7 +24,9 @@ class MySubscriber < Rails::Subscriber
end
end
-module SubscriberTest
+class SyncSubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::TestHelper
+
def setup
super
@subscriber = MySubscriber.new
@@ -94,51 +96,24 @@ module SubscriberTest
assert_equal 1, @logger.flush_count
end
- def test_flushes_loggers_when_action_dispatch_callback_is_received
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "action_dispatch.after_dispatch"
- wait
- assert_equal 1, @logger.flush_count
- end
-
def test_flushes_the_same_logger_just_once
Rails::Subscriber.add :my_subscriber, @subscriber
Rails::Subscriber.add :another, @subscriber
- instrument "action_dispatch.after_dispatch"
+ Rails::Subscriber.flush_all!
wait
assert_equal 1, @logger.flush_count
end
- def test_logging_thread_does_not_die_on_failures
+ def test_logging_does_not_die_on_failures
Rails::Subscriber.add :my_subscriber, @subscriber
instrument "my_subscriber.puke"
- instrument "action_dispatch.after_dispatch"
- wait
- assert_equal 1, @logger.flush_count
- assert_equal 1, @logger.logged(:error).size
- assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
- end
-
- def test_tails_logs_when_action_dispatch_callback_is_received
- log_tailer = mock()
- log_tailer.expects(:tail!)
- Rails::Subscriber.log_tailer = log_tailer
-
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "action_dispatch.after_dispatch"
+ instrument "my_subscriber.some_event"
wait
- ensure
- Rails::Subscriber.log_tailer = nil
- end
- class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::SyncTestHelper
- include SubscriberTest
- end
+ assert_equal 1, @logger.logged(:info).size
+ assert_equal 'my_subscriber.some_event', @logger.logged(:info).last
- class AsyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include SubscriberTest
+ assert_equal 1, @logger.logged(:error).size
+ assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
end
-
end \ No newline at end of file