summaryrefslogtreecommitdiff
path: root/spec/services/web_hooks
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/web_hooks')
-rw-r--r--spec/services/web_hooks/log_execution_service_spec.rb43
1 files changed, 14 insertions, 29 deletions
diff --git a/spec/services/web_hooks/log_execution_service_spec.rb b/spec/services/web_hooks/log_execution_service_spec.rb
index 1967a8368fb..1b8ff9f2a05 100644
--- a/spec/services/web_hooks/log_execution_service_spec.rb
+++ b/spec/services/web_hooks/log_execution_service_spec.rb
@@ -41,12 +41,21 @@ RSpec.describe WebHooks::LogExecutionService do
service.execute
end
+ it 'does not update the last failure when the feature flag is disabled' do
+ stub_feature_flags(web_hooks_disable_failed: false)
+
+ expect(project_hook).not_to receive(:update_last_failure)
+
+ service.execute
+ end
+
context 'obtaining an exclusive lease' do
let(:lease_key) { "web_hooks:update_hook_failure_state:#{project_hook.id}" }
it 'updates failure state using a lease that ensures fresh state is written' do
service = described_class.new(hook: project_hook, log_data: data, response_category: :error)
- WebHook.find(project_hook.id).update!(backoff_count: 1)
+ # Write state somewhere else, so that the hook is out-of-date
+ WebHook.find(project_hook.id).update!(recent_failures: 5, disabled_until: 10.minutes.from_now, backoff_count: 1)
lease = stub_exclusive_lease(lease_key, timeout: described_class::LOCK_TTL)
@@ -69,6 +78,8 @@ RSpec.describe WebHooks::LogExecutionService do
subject(:service) { described_class.new(hook: project_hook, log_data: data, response_category: response_category) }
before do
+ # stub LOCK_RETRY to be 0 in order for tests to run quicker
+ stub_const("#{described_class.name}::LOCK_RETRY", 0)
stub_exclusive_lease_taken(lease_key, timeout: described_class::LOCK_TTL)
allow(project_hook).to receive(:executable?).and_return(executable)
end
@@ -146,36 +157,10 @@ RSpec.describe WebHooks::LogExecutionService do
data[:response_status] = '500'
end
- it 'does not increment the failure count' do
- expect { service.execute }.not_to change(project_hook, :recent_failures)
- end
-
it 'backs off' do
- expect { service.execute }.to change(project_hook, :disabled_until)
- end
-
- it 'increases the backoff count' do
- expect { service.execute }.to change(project_hook, :backoff_count).by(1)
- end
-
- context 'when the previous cool-off was near the maximum' do
- before do
- project_hook.update!(disabled_until: 5.minutes.ago, backoff_count: 8)
- end
+ expect(project_hook).to receive(:backoff!)
- it 'sets the disabled_until attribute' do
- expect { service.execute }.to change(project_hook, :disabled_until).to(1.day.from_now)
- end
- end
-
- context 'when we have backed-off many many times' do
- before do
- project_hook.update!(disabled_until: 5.minutes.ago, backoff_count: 365)
- end
-
- it 'sets the disabled_until attribute' do
- expect { service.execute }.to change(project_hook, :disabled_until).to(1.day.from_now)
- end
+ service.execute
end
end
end