Skip to content

Commit

Permalink
🔇 Add silence_thread_safety_deprecation_warnings
Browse files Browse the repository at this point in the history
This is provided as a temporary workaround, until dependant projects can
update their usage.
  • Loading branch information
nevans committed Jun 12, 2023
1 parent 197a44f commit 40a15db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,18 @@ class << self
alias default_imap_port default_port
alias default_imaps_port default_tls_port
alias default_ssl_port default_tls_port

# Set to true to silence deprecation warnings, e.g. from #responses.
# Defaults to false.
#
# These warnings are concerning thread-safety issues, so it is recommended
# to update other code and leave this value. Deprecated usage will
# become errors regardless of this setting, so use this only temporarily.
attr_accessor :silence_thread_safety_deprecation_warnings
end

self.silence_thread_safety_deprecation_warnings = false

def client_thread # :nodoc:
warn "Net::IMAP#client_thread is deprecated and will be removed soon."
@client_thread
Expand Down Expand Up @@ -2091,7 +2101,9 @@ def responses(type = nil)
elsif type
raise ArgumentError, "Pass a block or use #clear_responses"
else
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
unless IMAP.silence_thread_safety_deprecation_warnings
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
end
@responses
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,8 @@ def test_responses
end
sock.getcmd # waits for logout command
end
original_silence = Net::IMAP.silence_thread_safety_deprecation_warnings
Net::IMAP.silence_thread_safety_deprecation_warnings = false
begin
imap = Net::IMAP.new(server_addr, port: port)
# responses available before SELECT/EXAMINE
Expand All @@ -978,8 +980,16 @@ def test_responses
assert_equal(%i[Answered Flagged Deleted Seen Draft],
imap.responses["FLAGS"]&.last)
end
Net::IMAP.silence_thread_safety_deprecation_warnings = true
# TODO: assert_no_warn?
stderr = EnvUtil.verbose_warning {
assert_equal(%i[Answered Flagged Deleted Seen Draft],
imap.responses["FLAGS"]&.last)
}
assert_empty stderr
imap.logout
ensure
Net::IMAP.silence_thread_safety_deprecation_warnings = original_silence
imap.disconnect if imap
end
end
Expand Down

0 comments on commit 40a15db

Please sign in to comment.