diff --git a/app/jobs/inboxes/fetch_imap_emails_job.rb b/app/jobs/inboxes/fetch_imap_emails_job.rb index 74368c830..63bd9ad75 100644 --- a/app/jobs/inboxes/fetch_imap_emails_job.rb +++ b/app/jobs/inboxes/fetch_imap_emails_job.rb @@ -19,7 +19,7 @@ class Inboxes::FetchImapEmailsJob < MutexApplicationJob channel.clear_backoff! rescue Imap::AuthenticationError => e Rails.logger.error "#{channel.backoff_log_identifier} authentication error : #{e.message}" - channel.authorization_error! + channel.apply_backoff! rescue *ExceptionList::IMAP_TRANSIENT_EXCEPTIONS => e Rails.logger.error "#{channel.backoff_log_identifier} transient error : #{e.message}" channel.apply_backoff! diff --git a/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb b/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb index 1abd7450b..5cb78a6b2 100644 --- a/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb +++ b/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb @@ -89,13 +89,13 @@ RSpec.describe Inboxes::FetchImapEmailsJob do end context 'when authentication error is raised' do - it 'calls authorization_error! on the channel' do + it 'calls apply_backoff! on the channel' do allow(Imap::FetchEmailService).to receive(:new).and_raise(Imap::AuthenticationError) - allow(imap_email_channel).to receive(:authorization_error!) + allow(imap_email_channel).to receive(:apply_backoff!) described_class.perform_now(imap_email_channel) - expect(imap_email_channel).to have_received(:authorization_error!) + expect(imap_email_channel).to have_received(:apply_backoff!) end end @@ -120,7 +120,7 @@ RSpec.describe Inboxes::FetchImapEmailsJob do end context 'when IMAP OAuth errors out' do - it 'marks the connection as requiring authorization' do + it 'calls authorization_error! on the channel' do error_response = double oauth_error = OAuth2::Error.new(error_response) @@ -128,12 +128,11 @@ RSpec.describe Inboxes::FetchImapEmailsJob do .with(channel: microsoft_imap_email_channel, interval: 1) .and_raise(oauth_error) - allow(Redis::Alfred).to receive(:incr) - - expect(Redis::Alfred).to receive(:incr) - .with("AUTHORIZATION_ERROR_COUNT:channel_email:#{microsoft_imap_email_channel.id}") + allow(microsoft_imap_email_channel).to receive(:authorization_error!) described_class.perform_now(microsoft_imap_email_channel) + + expect(microsoft_imap_email_channel).to have_received(:authorization_error!) end end