Skip to content
Browse files

just return if server busy, no need to wait only to return (credit cyu)

  • Loading branch information...
1 parent 7097128 commit e2e56650f92b10095013f57485668e09466a3fe1 @adzap committed Dec 18, 2009
Showing with 18 additions and 44 deletions.
  1. +3 −4 lib/action_mailer/ar_sendmail.rb
  2. +15 −40 test/test_arsendmail.rb
View
7 lib/action_mailer/ar_sendmail.rb
@@ -68,7 +68,7 @@ class ActionMailer::ARSendmail
# Be verbose
attr_accessor :verbose
-
+
##
# True if only one delivery attempt will be made per call to run
@@ -363,7 +363,7 @@ def deliver(emails)
smtp_settings[:password],
smtp_settings[:authentication]
]
-
+
smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
if smtp.respond_to?(:enable_starttls_auto)
smtp.enable_starttls_auto unless smtp_settings[:tls] == false
@@ -386,8 +386,7 @@ def deliver(emails)
email.destroy
session.reset
rescue Net::SMTPServerBusy => e
- log "server too busy, sleeping #{@delay} seconds"
- sleep delay
+ log "server too busy, stopping delivery cycle"
return
rescue Net::SMTPUnknownError, Net::SMTPSyntaxError, TimeoutError => e
email.last_send_attempt = Time.now.to_i
View
55 test/test_arsendmail.rb
@@ -98,19 +98,19 @@ def test_class_parse_args_batch_size
def test_class_parse_args_chdir
argv = %w[-c /tmp]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal '/tmp', options[:Chdir]
argv = %w[--chdir /tmp]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal '/tmp', options[:Chdir]
argv = %w[-c /nonexistent]
-
+
out, err = capture_io do
assert_raises SystemExit do
ActionMailer::ARSendmail.process_args argv
@@ -120,35 +120,35 @@ def test_class_parse_args_chdir
def test_class_parse_args_daemon
argv = %w[-d]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal true, options[:Daemon]
argv = %w[--daemon]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal true, options[:Daemon]
end
-
+
def test_class_parse_args_pidfile
argv = %w[-p ./log/ar_sendmail.pid]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal './log/ar_sendmail.pid', options[:Pidfile]
argv = %w[--pidfile ./log/ar_sendmail.pid]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal './log/ar_sendmail.pid', options[:Pidfile]
end
-
+
def test_class_parse_args_delay
argv = %w[--delay 75]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal 75, options[:Delay]
@@ -158,15 +158,15 @@ def test_class_parse_args_environment
assert_equal nil, ENV['RAILS_ENV']
argv = %w[-e production]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal 'production', options[:RailsEnv]
assert_equal 'production', ENV['RAILS_ENV']
argv = %w[--environment production]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal 'production', options[:RailsEnv]
@@ -177,7 +177,7 @@ def test_class_parse_args_mailq
refute_includes options, :MailQ
argv = %w[--mailq]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal true, options[:MailQ]
@@ -209,13 +209,13 @@ def test_class_parse_args_no_config_environment
def test_class_parse_args_once
argv = %w[-o]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal true, options[:Once]
argv = %w[--once]
-
+
options = ActionMailer::ARSendmail.process_args argv
assert_equal true, options[:Once]
@@ -420,31 +420,6 @@ def test_deliver_errno_epipe
assert_equal '', err
end
- def test_deliver_server_busy
- Net::SMTP.on_send_message do
- e = Net::SMTPServerBusy.new 'try again'
- e.set_backtrace %w[one two three]
- raise e
- end
-
- now = Time.now.to_i
-
- email = Email.create :mail => 'body', :to => 'to', :from => 'from'
-
- out, err = capture_io do
- @sm.deliver [email]
- end
-
- assert_equal 0, Net::SMTP.deliveries.length
- assert_equal 1, Email.records.length
- assert_operator now, :>=, Email.records.first.last_send_attempt
- assert_equal 0, Net::SMTP.reset_called, 'Reset connection on SyntaxError'
- assert_equal [60], @sm.slept
-
- assert_equal '', out
- assert_equal "server too busy, sleeping 60 seconds\n", err
- end
-
def test_deliver_syntax_error
Net::SMTP.on_send_message do
Net::SMTP.on_send_message # clear

0 comments on commit e2e5665

Please sign in to comment.
Something went wrong with that request. Please try again.