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 Aug 5, 2023
1 parent 3f7ff98 commit bbaa32a
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -720,8 +720,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 @@ -2130,7 +2140,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
11 changes: 11 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@ def test_enable
end

def test_responses
original_silence = Net::IMAP.silence_thread_safety_deprecation_warnings
Net::IMAP.silence_thread_safety_deprecation_warnings = false
with_fake_server do |server, imap|
# responses available before SELECT/EXAMINE
assert_equal(%w[IMAP4REV1 NAMESPACE MOVE IDLE UTF8=ACCEPT],
Expand All @@ -981,7 +983,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
end
ensure
Net::IMAP.silence_thread_safety_deprecation_warnings = original_silence
end

def test_clear_responses
Expand Down

0 comments on commit bbaa32a

Please sign in to comment.