diff options
Diffstat (limited to 'spec/lib/gitlab/mailgun/webhook_processors')
-rw-r--r-- | spec/lib/gitlab/mailgun/webhook_processors/failure_logger_spec.rb | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/spec/lib/gitlab/mailgun/webhook_processors/failure_logger_spec.rb b/spec/lib/gitlab/mailgun/webhook_processors/failure_logger_spec.rb index a2286415e96..4b9ea1c15a9 100644 --- a/spec/lib/gitlab/mailgun/webhook_processors/failure_logger_spec.rb +++ b/spec/lib/gitlab/mailgun/webhook_processors/failure_logger_spec.rb @@ -20,18 +20,43 @@ RSpec.describe Gitlab::Mailgun::WebhookProcessors::FailureLogger do context 'on permanent failure' do let(:processor) { described_class.new(base_payload.merge({ 'severity' => 'permanent' })) } - it 'logs the failure immediately' do - expect(Gitlab::ErrorTracking::Logger).to receive(:error).with( - event: 'email_delivery_failure', - mailgun_event_id: base_payload['id'], - recipient: base_payload['recipient'], - failure_type: 'permanent', - failure_reason: base_payload['reason'], - failure_code: base_payload['delivery-status']['code'], - failure_message: base_payload['delivery-status']['message'] - ) + before do + allow(Gitlab::ApplicationRateLimiter).to receive(:rate_limits) + .and_return(permanent_email_failure: { threshold: 1, interval: 1.minute }) + end - processor.execute + context 'when threshold is not exceeded' do + it 'increments counter but does not log the failure' do + expect(Gitlab::ApplicationRateLimiter).to receive(:throttled?).with( + :permanent_email_failure, scope: 'recipient@gitlab.com' + ).and_call_original + expect(Gitlab::ErrorTracking::Logger).not_to receive(:error) + + processor.execute + end + end + + context 'when threshold is exceeded' do + before do + processor.execute + end + + it 'increments counter and logs the failure' do + expect(Gitlab::ApplicationRateLimiter).to receive(:throttled?).with( + :permanent_email_failure, scope: 'recipient@gitlab.com' + ).and_call_original + expect(Gitlab::ErrorTracking::Logger).to receive(:error).with( + event: 'email_delivery_failure', + mailgun_event_id: base_payload['id'], + recipient: base_payload['recipient'], + failure_type: 'permanent', + failure_reason: base_payload['reason'], + failure_code: base_payload['delivery-status']['code'], + failure_message: base_payload['delivery-status']['message'] + ) + + processor.execute + end end end |