5

I am experiencing a problem that when running the first test of mailers when it makes the first call to the ActionMailer::Base#mail method the test hangs and takes about 10min. Has anyone ever experienced this?

CircleCi image: image: circleci/ruby:2.4.3-node

My test

class Notifier::AccountMailer < NotifierMailer
  def welcome(user_id)
    @user = User.find user_id

    mail(to: @user.email, subject: t('subject.welcome'))
  end
end

RSpec.describe Notifier::AccountMailer, type: :mailer do
 describe '.welcome' do
   let(:user) { build_stubbed(:user) }
   let(:mail) { described_class.welcome(1) }
   before { allow(User).to receive(:find).and_return(user) }

   it 'Send from <notify@my-server.me>' do
     expect(mail.from).to eq(['notify@my-server.me'])
   end

   it 'Send to account e-mail' do
     expect(mail.to).to eq([user.email])
   end
 end
end

The slowness happens only in the first call of the mail method, after everything works normal.

  • I have no idea, but it sounds like it must be doing something like starting up a mail server or similar... OOC what are your mail settings in your test env? Have you changed them from the default? – Taryn East May 04 '18 at 01:43
  • 1
    My environment test is: `config.action_mailer.delivery_method = :test` `config.action_mailer.asset_host = "http://example.com"` `config.action_mailer.default_url_options = { host: 'example.com', port: 3000 }` `config.action_mailer.default charset: "utf-8"` `config.active_job.queue_adapter = :inline` – Leandro Nunes May 04 '18 at 12:34
  • Did you ever find an answer? I am seeing the same when I run specs locally even - over 10 minutes for the first test to actually call a mailer (to call #mail). That is with everything set to :test as you'd expect or want. – Warren Wright Nov 18 '19 at 14:31

0 Answers0