This reverts commit 7acd239c70 to further
debug upstream issues.
This commit is contained in:
@@ -38,14 +38,6 @@ RSpec.describe Inboxes::FetchImapEmailsJob do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when channel is in backoff' do
|
||||
it 'does not fetch emails' do
|
||||
allow(imap_email_channel).to receive(:in_backoff?).and_return(true)
|
||||
expect(Imap::FetchEmailService).not_to receive(:new)
|
||||
described_class.perform_now(imap_email_channel)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the channel is regular imap' do
|
||||
it 'calls the imap fetch service' do
|
||||
fetch_service = double
|
||||
@@ -64,17 +56,6 @@ RSpec.describe Inboxes::FetchImapEmailsJob do
|
||||
described_class.perform_now(imap_email_channel, 4)
|
||||
expect(fetch_service).to have_received(:perform)
|
||||
end
|
||||
|
||||
it 'clears backoff after successful fetch' do
|
||||
fetch_service = double
|
||||
allow(Imap::FetchEmailService).to receive(:new).and_return(fetch_service)
|
||||
allow(fetch_service).to receive(:perform).and_return([])
|
||||
allow(imap_email_channel).to receive(:clear_backoff!)
|
||||
|
||||
described_class.perform_now(imap_email_channel)
|
||||
|
||||
expect(imap_email_channel).to have_received(:clear_backoff!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the channel is Microsoft' do
|
||||
@@ -88,37 +69,6 @@ RSpec.describe Inboxes::FetchImapEmailsJob do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when authentication error is raised' do
|
||||
it 'calls authorization_error! on the channel' do
|
||||
allow(Imap::FetchEmailService).to receive(:new).and_raise(Imap::AuthenticationError)
|
||||
allow(imap_email_channel).to receive(:authorization_error!)
|
||||
|
||||
described_class.perform_now(imap_email_channel)
|
||||
|
||||
expect(imap_email_channel).to have_received(:authorization_error!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a transient IMAP error is raised' do
|
||||
it 'calls apply_backoff! on the channel' do
|
||||
allow(Imap::FetchEmailService).to receive(:new).and_raise(EOFError)
|
||||
allow(imap_email_channel).to receive(:apply_backoff!)
|
||||
|
||||
described_class.perform_now(imap_email_channel)
|
||||
|
||||
expect(imap_email_channel).to have_received(:apply_backoff!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when lock acquisition fails' do
|
||||
it 'does not raise an error' do
|
||||
lock_manager = instance_double(Redis::LockManager, lock: false)
|
||||
allow(Redis::LockManager).to receive(:new).and_return(lock_manager)
|
||||
|
||||
expect { described_class.perform_now(imap_email_channel) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'when IMAP OAuth errors out' do
|
||||
it 'marks the connection as requiring authorization' do
|
||||
error_response = double
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
|
||||
require 'rails_helper'
|
||||
require Rails.root.join 'spec/models/concerns/reauthorizable_shared.rb'
|
||||
require Rails.root.join 'spec/models/concerns/backoffable_shared.rb'
|
||||
|
||||
RSpec.describe Channel::Email do
|
||||
let(:channel) { create(:channel_email) }
|
||||
|
||||
describe 'concerns' do
|
||||
it_behaves_like 'reauthorizable'
|
||||
it_behaves_like 'backoffable'
|
||||
|
||||
context 'when prompt_reauthorization!' do
|
||||
it 'calls channel notifier mail for email' do
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
require 'rails_helper'
|
||||
|
||||
shared_examples_for 'backoffable' do
|
||||
let(:obj) { FactoryBot.create(described_class.to_s.underscore.tr('/', '_').to_sym) }
|
||||
|
||||
before do
|
||||
allow(GlobalConfigService).to receive(:load).with('BACKOFF_MAX_INTERVAL_MINUTES', 5).and_return(2)
|
||||
allow(GlobalConfigService).to receive(:load).with('BACKOFF_MAX_INTERVAL_COUNT', 10).and_return(3)
|
||||
# max_interval=2, max_retries=(2-1)+3=4; exhausts on 5th apply_backoff!
|
||||
end
|
||||
|
||||
it 'starts with no backoff' do
|
||||
expect(obj.in_backoff?).to be false
|
||||
expect(obj.backoff_retry_count).to eq 0
|
||||
end
|
||||
|
||||
it 'ramps backoff on each failure' do
|
||||
obj.apply_backoff!
|
||||
expect(obj.backoff_retry_count).to eq 1
|
||||
expect(obj.in_backoff?).to be true
|
||||
end
|
||||
|
||||
it 'caps wait time at max interval' do
|
||||
4.times { obj.apply_backoff! }
|
||||
expect(obj.backoff_retry_count).to eq 4
|
||||
expect(obj.in_backoff?).to be true
|
||||
end
|
||||
|
||||
it 'exhausts backoff and calls prompt_reauthorization! after max retries' do
|
||||
allow(obj).to receive(:prompt_reauthorization!)
|
||||
5.times { obj.apply_backoff! }
|
||||
expect(obj).to have_received(:prompt_reauthorization!)
|
||||
expect(obj.backoff_retry_count).to eq 0
|
||||
expect(obj.in_backoff?).to be false
|
||||
end
|
||||
|
||||
it 'clear_backoff! resets retry count and backoff window' do
|
||||
obj.apply_backoff!
|
||||
obj.clear_backoff!
|
||||
expect(obj.in_backoff?).to be false
|
||||
expect(obj.backoff_retry_count).to eq 0
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user