-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Deprecate reporting methods for silencing output as they aren't thread safe #13392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate reporting methods for silencing output as they aren't thread safe #13392
Conversation
There are some test failures, and a lot of deprecations in our own test suite 😢. If I got it right, we would keep using that in our own tests, but deprecate as public API, right? So we'll have to cleanup the deprecations in our own tests somehow. @tommeier mind taking a look at the failures? Maybe we would need to copy these to a test helper or something like that to use on our tests, and leave the public ones deprecated. |
Happy to do so @carlosantoniodasilva :) All the failures are just the additional output including deprecation warnings. Where would be a good spot for a test_helper? Considering that we'd want to use the methods in railties and active support (for example), is there a good shared spot? |
Merged at 1fbb5c1...3121412 |
Is there going to be something to replace this? Some of this code is also duplicated elsewhere in the codebase without the deprecation. I'm not sure why e.g. Also, wouldn't the below be thread-safe due to how it uses pipes and threads? (untested assertion). silencing would just be a matter of not returning the captured output. # From episode 029 of Ruby Tapas by Avdi
# https://rubytapas.dpdcart.com/subscriber/post?id=88
def capture_output(stream=STDOUT, &block)
old_stdout = stream.clone
pipe_r, pipe_w = IO.pipe
pipe_r.sync = true
output = ""
reader = Thread.new do
begin
loop do
output << pipe_r.readpartial(1024)
end
rescue EOFError
end
end
stream.reopen(pipe_w)
yield
ensure
stream.reopen(old_stdout)
pipe_w.close
reader.join
pipe_r.close
return output
end or e.g. https://github.com/rubygems/rubygems/blob/dd7ca9b2c321f7/lib/rubygems/util.rb#L74 NULL_DEVICE = defined?(IO::NULL) ? IO::NULL : Gem.win_platform? ? 'NUL' : '/dev/null'
def self.silent_system(null_device=NULL_DEVICE,&block)
require 'thread'
@silent_mutex ||= Mutex.new
@silent_mutex.synchronize do
begin
stdout = STDOUT.dup
stderr = STDERR.dup
STDOUT.reopen null_device, 'w'
STDERR.reopen null_device, 'w'
return yield
ensure
STDOUT.reopen stdout
STDERR.reopen stderr
stdout.close
stderr.close
end
end
end |
No.
Yes, it is duplicated because the framework still need these methods but we don't want to make them available for the users. |
Thanks :) |
@bf4 I have extracted the silence stream functionality into a standalone gem called |
The old implementation has been removed from Rails because it was not thread safe. This commit replaces the old `silence_stream` implementation with the new one that we can actually find in Active Support. Refs: - rails/rails@481e49c - rails/rails#13392
The old implementation of `silence_stream` has been removed from Rails. This commit replaces the old `silence_stream` implementation with the new one that we can actually find in Active Support. Refs: - rails/rails@481e49c - rails/rails#13392
As per #13139, this is the deprecation warning methods for these thread unsafe methods.