1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Avoid mutating global STDOUT & STDERR (#1837)

This commit is contained in:
Montana Low 2019-07-25 12:09:51 -07:00 committed by Nate Berkopec
parent f89f194dcb
commit 70b28bb5dd
3 changed files with 14 additions and 5 deletions

View file

@ -29,8 +29,8 @@ module Puma
#
def initialize(stdout, stderr)
@formatter = DefaultFormatter.new
@stdout = stdout
@stderr = stderr
@stdout = stdout.dup
@stderr = stderr.dup
@stdout.sync = true
@stderr.sync = true

View file

@ -6,7 +6,6 @@ class TestEvents < Minitest::Test
assert_instance_of Puma::NullIO, events.stdout
assert_instance_of Puma::NullIO, events.stderr
assert_equal events.stdout, events.stderr
end
def test_strings
@ -19,8 +18,17 @@ class TestEvents < Minitest::Test
def test_stdio
events = Puma::Events.stdio
assert_equal STDOUT, events.stdout
assert_equal STDERR, events.stderr
# events.stdout is a dup, so same file handle, different ruby object, but inspect should show the same file handle
assert_equal STDOUT.inspect, events.stdout.inspect
assert_equal STDERR.inspect, events.stderr.inspect
end
def test_stdio_respects_sync
STDOUT.sync = false
events = Puma::Events.stdio
assert !STDOUT.sync
assert events.stdout.sync
end
def test_register_callback_with_block

View file

@ -18,6 +18,7 @@ class TestTCPLogger < Minitest::Test
# in lib/puma/launcher.rb:85
# Puma::Events is default tcp_logger for cluster mode
logger = Puma::Events.new(STDOUT, STDERR)
logger.instance_variable_set(:@stdout, $stdout) # ensure capture_process_io has access to the loggers output
out, err = capture_subprocess_io do
Puma::TCPLogger.new(logger, @server.app).call({}, @socket)
end