aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/kernel_test.rb
diff options
context:
space:
mode:
authorMario Visic <mario@mariovisic.com>2013-10-29 13:04:04 +1100
committerMario Visic <mario@mariovisic.com>2013-12-06 10:24:06 +1100
commitffe99774bb0b64644dc419ba83d131218854d404 (patch)
tree8886f4bd9a889d828410d1bf8d43f0fed2afa4db /activesupport/test/core_ext/kernel_test.rb
parentdbdbda9a4a5cb9cd22e7a5a5625caa84edae6d5d (diff)
downloadrails-ffe99774bb0b64644dc419ba83d131218854d404.tar.gz
rails-ffe99774bb0b64644dc419ba83d131218854d404.tar.bz2
rails-ffe99774bb0b64644dc419ba83d131218854d404.zip
Fix issue with Kernel#silence_stream leaking file descriptors
Calling Kernel#silence_stream creates a new file descriptor which isn't closed after it is used. As a result calling silence_stream multiple times leads to a build up of loose file descriptors and can cause issues in environments where garbage collection isn't run often.
Diffstat (limited to 'activesupport/test/core_ext/kernel_test.rb')
-rw-r--r--activesupport/test/core_ext/kernel_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb
index b8951de402..18b251173f 100644
--- a/activesupport/test/core_ext/kernel_test.rb
+++ b/activesupport/test/core_ext/kernel_test.rb
@@ -38,6 +38,22 @@ class KernelTest < ActiveSupport::TestCase
# Skip if we can't STDERR.tell
end
+ def test_silence_stream
+ old_stream_position = STDOUT.tell
+ silence_stream(STDOUT) { STDOUT.puts 'hello world' }
+ assert_equal old_stream_position, STDOUT.tell
+ rescue Errno::ESPIPE
+ # Skip if we can't stream.tell
+ end
+
+ def test_silence_stream_closes_file_descriptors
+ stream = StringIO.new
+ dup_stream = StringIO.new
+ stream.stubs(:dup).returns(dup_stream)
+ dup_stream.expects(:close)
+ silence_stream(stream) { stream.puts 'hello world' }
+ end
+
def test_quietly
old_stdout_position, old_stderr_position = STDOUT.tell, STDERR.tell
quietly do