diff options
author | José Valim <jose.valim@gmail.com> | 2011-10-21 12:29:14 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-10-21 12:29:14 -0700 |
commit | b838570bd69ff13d677fb43e79f10d6f3168c696 (patch) | |
tree | 6d9d581e6dde04c2356714fd45c6cf367b4b10b9 /activesupport/test | |
parent | e2aaae16292640f2314be205d7782f6eaf2b1cf5 (diff) | |
parent | d565fda5f27abf0097adf7b3e232a52f7ae5c1e9 (diff) | |
download | rails-b838570bd69ff13d677fb43e79f10d6f3168c696.tar.gz rails-b838570bd69ff13d677fb43e79f10d6f3168c696.tar.bz2 rails-b838570bd69ff13d677fb43e79f10d6f3168c696.zip |
Merge pull request #3394 from bdurand/buffered_logger_threads
Fix threading issues with BufferedLogger.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 21049d685b..8699862d9e 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -198,4 +198,57 @@ class BufferedLoggerTest < Test::Unit::TestCase end assert byte_string.include?(BYTE_STRING) end + + def test_silence_only_current_thread + @logger.auto_flushing = true + run_thread_a = false + + a = Thread.new do + while !run_thread_a do + sleep(0.001) + end + @logger.info("x") + run_thread_a = false + end + + @logger.silence do + run_thread_a = true + @logger.info("a") + while run_thread_a do + sleep(0.001) + end + end + + a.join + + assert @output.string.include?("x") + assert !@output.string.include?("a") + end + + def test_flush_dead_buffers + @logger.auto_flushing = false + + a = Thread.new do + @logger.info("a") + end + + keep_running = true + b = Thread.new do + @logger.info("b") + while keep_running + sleep(0.001) + end + end + + @logger.info("x") + a.join + @logger.flush + + + assert @output.string.include?("x") + assert @output.string.include?("a") + assert !@output.string.include?("b") + + keep_running = false + end end |