aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/test/cases/mysql_rake_test.rb4
-rw-r--r--activesupport/lib/active_support/notifications.rb38
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb11
-rw-r--r--activesupport/test/clean_backtrace_test.rb11
4 files changed, 39 insertions, 25 deletions
diff --git a/activerecord/test/cases/mysql_rake_test.rb b/activerecord/test/cases/mysql_rake_test.rb
index 8255fe3aa5..7da63de282 100644
--- a/activerecord/test/cases/mysql_rake_test.rb
+++ b/activerecord/test/cases/mysql_rake_test.rb
@@ -129,7 +129,7 @@ module ActiveRecord
ActiveRecord::Base.stubs(:establish_connection).returns(true)
end
- def test_establishes_connection_to_postgresql_database
+ def test_establishes_connection_to_mysql_database
ActiveRecord::Base.expects(:establish_connection).with @configuration
ActiveRecord::Tasks::DatabaseTasks.drop @configuration
@@ -142,7 +142,7 @@ module ActiveRecord
end
end
- class MySQLTestPurge < ActiveRecord::TestCase
+ class MySQLPurgeTest < ActiveRecord::TestCase
def setup
@connection = stub(:recreate_database => true)
@configuration = {
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index e3d8cf48ce..55041ea2af 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -135,17 +135,30 @@ module ActiveSupport
# to log subscribers in a thread. You can use any queue implementation you want.
#
module Notifications
- @instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) }
+ class Registry # :nodoc:
+ def self.instance
+ Thread.current[name] ||= new
+ end
- class << self
- attr_accessor :notifier
+ attr_reader :notifier, :instrumenter
+
+ def initialize
+ self.notifier = Fanout.new
+ end
+
+ def notifier=(notifier)
+ @notifier = notifier
+ @instrumenter = Instrumenter.new(notifier)
+ end
+ end
+ class << self
def publish(name, *args)
notifier.publish(name, *args)
end
def instrument(name, payload = {})
- if @instrumenters[name]
+ if notifier.listening?(name)
instrumenter.instrument(name, payload) { yield payload if block_given? }
else
yield payload if block_given?
@@ -153,9 +166,7 @@ module ActiveSupport
end
def subscribe(*args, &block)
- notifier.subscribe(*args, &block).tap do
- @instrumenters.clear
- end
+ notifier.subscribe(*args, &block)
end
def subscribed(callback, *args, &block)
@@ -167,14 +178,19 @@ module ActiveSupport
def unsubscribe(args)
notifier.unsubscribe(args)
- @instrumenters.clear
end
def instrumenter
- Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
+ Registry.instance.instrumenter
end
- end
- self.notifier = Fanout.new
+ def notifier
+ Registry.instance.notifier
+ end
+
+ def notifier=(notifier)
+ Registry.instance.notifier = notifier
+ end
+ end
end
end
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index 17c99089c1..3a2ccf1489 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -2,6 +2,9 @@ module ActiveSupport
module Notifications
# This is a default queue implementation that ships with Notifications.
# It just pushes events to all registered log subscribers.
+ #
+ # Only one of these objects should instantiated per thread. Concurrent
+ # access to this class is not allowed.
class Fanout
def initialize
@subscribers = []
@@ -85,9 +88,7 @@ module ActiveSupport
class Timed < Evented
def initialize(pattern, delegate)
- @timestack = Hash.new { |h,id|
- h[id] = Hash.new { |ids,name| ids[name] = [] }
- }
+ @timestack = []
super
end
@@ -96,11 +97,11 @@ module ActiveSupport
end
def start(name, id, payload)
- @timestack[id][name].push Time.now
+ @timestack.push Time.now
end
def finish(name, id, payload)
- started = @timestack[id][name].pop
+ started = @timestack.pop
@delegate.call(name, started, Time.now, id, payload)
end
end
diff --git a/activesupport/test/clean_backtrace_test.rb b/activesupport/test/clean_backtrace_test.rb
index 32e346bb48..b14950acb3 100644
--- a/activesupport/test/clean_backtrace_test.rb
+++ b/activesupport/test/clean_backtrace_test.rb
@@ -6,8 +6,10 @@ class BacktraceCleanerFilterTest < ActiveSupport::TestCase
@bc.add_filter { |line| line.gsub("/my/prefix", '') }
end
- test "backtrace should not contain prefix when it has been filtered out" do
- assert_equal "/my/class.rb", @bc.clean([ "/my/prefix/my/class.rb" ]).first
+ test "backtrace should filter all lines in a backtrace, removing prefixes" do
+ assert_equal \
+ ["/my/class.rb", "/my/module.rb"],
+ @bc.clean(["/my/prefix/my/class.rb", "/my/prefix/my/module.rb"])
end
test "backtrace cleaner should allow removing filters" do
@@ -19,11 +21,6 @@ class BacktraceCleanerFilterTest < ActiveSupport::TestCase
assert_equal "/my/other_prefix/my/class.rb", @bc.clean([ "/my/other_prefix/my/class.rb" ]).first
end
- test "backtrace should filter all lines in a backtrace" do
- assert_equal \
- ["/my/class.rb", "/my/module.rb"],
- @bc.clean([ "/my/prefix/my/class.rb", "/my/prefix/my/module.rb" ])
- end
end
class BacktraceCleanerSilencerTest < ActiveSupport::TestCase