Skip to content

Commit 40a15db

Browse files
committed
🔇 Add silence_thread_safety_deprecation_warnings
This is provided as a temporary workaround, until dependant projects can update their usage.
1 parent 197a44f commit 40a15db

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/net/imap.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,18 @@ class << self
763763
alias default_imap_port default_port
764764
alias default_imaps_port default_tls_port
765765
alias default_ssl_port default_tls_port
766+
767+
# Set to true to silence deprecation warnings, e.g. from #responses.
768+
# Defaults to false.
769+
#
770+
# These warnings are concerning thread-safety issues, so it is recommended
771+
# to update other code and leave this value. Deprecated usage will
772+
# become errors regardless of this setting, so use this only temporarily.
773+
attr_accessor :silence_thread_safety_deprecation_warnings
766774
end
767775

776+
self.silence_thread_safety_deprecation_warnings = false
777+
768778
def client_thread # :nodoc:
769779
warn "Net::IMAP#client_thread is deprecated and will be removed soon."
770780
@client_thread
@@ -2091,7 +2101,9 @@ def responses(type = nil)
20912101
elsif type
20922102
raise ArgumentError, "Pass a block or use #clear_responses"
20932103
else
2094-
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
2104+
unless IMAP.silence_thread_safety_deprecation_warnings
2105+
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
2106+
end
20952107
@responses
20962108
end
20972109
end

test/net/imap/test_imap.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ def test_responses
959959
end
960960
sock.getcmd # waits for logout command
961961
end
962+
original_silence = Net::IMAP.silence_thread_safety_deprecation_warnings
963+
Net::IMAP.silence_thread_safety_deprecation_warnings = false
962964
begin
963965
imap = Net::IMAP.new(server_addr, port: port)
964966
# responses available before SELECT/EXAMINE
@@ -978,8 +980,16 @@ def test_responses
978980
assert_equal(%i[Answered Flagged Deleted Seen Draft],
979981
imap.responses["FLAGS"]&.last)
980982
end
983+
Net::IMAP.silence_thread_safety_deprecation_warnings = true
984+
# TODO: assert_no_warn?
985+
stderr = EnvUtil.verbose_warning {
986+
assert_equal(%i[Answered Flagged Deleted Seen Draft],
987+
imap.responses["FLAGS"]&.last)
988+
}
989+
assert_empty stderr
981990
imap.logout
982991
ensure
992+
Net::IMAP.silence_thread_safety_deprecation_warnings = original_silence
983993
imap.disconnect if imap
984994
end
985995
end

0 commit comments

Comments
 (0)