aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/tagged_logging_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-10-19 22:26:56 +0200
committerJosé Valim <jose.valim@gmail.com>2011-10-19 22:26:56 +0200
commit6c126015a676c376f1646713fbb739049a783238 (patch)
treeeab5e9279c9710b308ebdc8998856ff397866d92 /activesupport/test/tagged_logging_test.rb
parent4ef74536940ea4c8c7f8c2cb0252bfe5f0db6fdf (diff)
downloadrails-6c126015a676c376f1646713fbb739049a783238.tar.gz
rails-6c126015a676c376f1646713fbb739049a783238.tar.bz2
rails-6c126015a676c376f1646713fbb739049a783238.zip
Ensure TaggegLogging is thread safe.
Diffstat (limited to 'activesupport/test/tagged_logging_test.rb')
-rw-r--r--activesupport/test/tagged_logging_test.rb30
1 files changed, 29 insertions, 1 deletions
diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb
index a1504c6ce4..b12b12f32c 100644
--- a/activesupport/test/tagged_logging_test.rb
+++ b/activesupport/test/tagged_logging_test.rb
@@ -3,9 +3,15 @@ require 'active_support/core_ext/logger'
require 'active_support/tagged_logging'
class TaggedLoggingTest < ActiveSupport::TestCase
+ class MyLogger < ::Logger
+ def flush(*)
+ info "[FLUSHED]"
+ end
+ end
+
setup do
@output = StringIO.new
- @logger = ActiveSupport::TaggedLogging.new(Logger.new(@output))
+ @logger = ActiveSupport::TaggedLogging.new(MyLogger.new(@output))
end
test "tagged once" do
@@ -23,6 +29,28 @@ class TaggedLoggingTest < ActiveSupport::TestCase
assert_equal "[BCX] [Jason] [New] Funky time\n", @output.string
end
+ test "keeps each tag in their own thread" do
+ @logger.tagged("BCX") do
+ Thread.new do
+ @logger.tagged("OMG") { @logger.info "Cool story bro" }
+ end.join
+ @logger.info "Funky time"
+ end
+ assert_equal "[OMG] Cool story bro\n[BCX] Funky time\n", @output.string
+ end
+
+ test "cleans up the taggings on flush" do
+ @logger.tagged("BCX") do
+ Thread.new do
+ @logger.tagged("OMG") do
+ @logger.flush
+ @logger.info "Cool story bro"
+ end
+ end.join
+ end
+ assert_equal "[FLUSHED]\nCool story bro\n", @output.string
+ end
+
test "mixed levels of tagging" do
@logger.tagged("BCX") do
@logger.tagged("Jason") { @logger.info "Funky time" }