Serializza gli invii SMTP su una coda unica per non far chiudere Aruba.
CI / scan_js (push) Has been cancelled
CI / scan_ruby (push) Has been cancelled
CI / lint (push) Has been cancelled

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-07 12:06:23 +02:00
co-authored by Cursor
parent a9470d7e77
commit 403fe80d37
12 changed files with 423 additions and 29 deletions
+69
View File
@@ -0,0 +1,69 @@
require "test_helper"
class Mailings::SmtpGateTest < ActiveSupport::TestCase
setup do
Mailings::SmtpGate.min_gap = 0
Mailings::SmtpGate.backoff_base = 0
Mailings::SmtpGate.max_attempts = 4
Mailings::SmtpGate.reset!
end
teardown do
Mailings::SmtpGate.min_gap = 0
Mailings::SmtpGate.backoff_base = 0
Mailings::SmtpGate.max_attempts = 4
Mailings::SmtpGate.reset!
end
test "retries EOFError then succeeds" do
hits = 0
result = Mailings::SmtpGate.deliver do
hits += 1
raise EOFError, "end of file reached" if hits < 3
:sent
end
assert_equal :sent, result
assert_equal 3, hits
end
test "gives up after max attempts" do
hits = 0
error = assert_raises(EOFError) do
Mailings::SmtpGate.deliver do
hits += 1
raise EOFError, "end of file reached"
end
end
assert_equal "end of file reached", error.message
assert_equal Mailings::SmtpGate.max_attempts, hits
end
test "does not retry permanent SMTP errors" do
hits = 0
assert_raises(Net::SMTPAuthenticationError) do
Mailings::SmtpGate.deliver do
hits += 1
raise Net::SMTPAuthenticationError, "535 authentication failed"
end
end
assert_equal 1, hits
end
test "serializes concurrent deliveries" do
order = Queue.new
threads = 2.times.map do |i|
Thread.new do
Mailings::SmtpGate.deliver do
order << i
sleep 0.05
end
end
end
threads.each(&:join)
assert_equal 2, order.size
end
end