Skip to content

Commit 0ccd250

Browse files
committed
🔇 Add silence_thread_safety_deprecation_warnings
This is provided as a temporary workaround, until dependant projects can update their usage. A future release will remove this backwards compatibility, but no sooner than one year after the release that contains this deprecation warning.
1 parent f4d665a commit 0ccd250

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/net/imap.rb

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

772+
self.silence_thread_safety_deprecation_warnings = false
773+
764774
# Returns the initial greeting the server, an UntaggedResponse.
765775
attr_reader :greeting
766776

@@ -2501,7 +2511,9 @@ def responses(type = nil)
25012511
elsif type
25022512
raise ArgumentError, "Pass a block or use #clear_responses"
25032513
else
2504-
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
2514+
unless IMAP.silence_thread_safety_deprecation_warnings
2515+
warn("DEPRECATED: pass a block or use #clear_responses", uplevel: 1)
2516+
end
25052517
@responses
25062518
end
25072519
end

test/net/imap/test_imap.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ def test_enable
10911091

10921092
def test_responses
10931093
with_fake_server do |server, imap|
1094+
original_silence = Net::IMAP.silence_thread_safety_deprecation_warnings
1095+
Net::IMAP.silence_thread_safety_deprecation_warnings = false
10941096
# responses available before SELECT/EXAMINE
10951097
assert_equal(%w[IMAP4REV1 NAMESPACE MOVE IDLE UTF8=ACCEPT],
10961098
imap.responses("CAPABILITY", &:last))
@@ -1108,6 +1110,15 @@ def test_responses
11081110
assert_equal(%i[Answered Flagged Deleted Seen Draft],
11091111
imap.responses["FLAGS"]&.last)
11101112
end
1113+
Net::IMAP.silence_thread_safety_deprecation_warnings = true
1114+
# TODO: assert_no_warn?
1115+
stderr = EnvUtil.verbose_warning {
1116+
assert_equal(%i[Answered Flagged Deleted Seen Draft],
1117+
imap.responses["FLAGS"]&.last)
1118+
}
1119+
assert_empty stderr
1120+
ensure
1121+
Net::IMAP.silence_thread_safety_deprecation_warnings = original_silence
11111122
end
11121123
end
11131124

0 commit comments

Comments
 (0)