Commit f6e06d4d authored by David Kim's avatar David Kim

Merge branch '300105-remove-integrations_test_webhook_optimizations-feature-flag' into 'master'

Enable optimal webhook queries feature [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!53676
parents 8c3f309e 2c585877
...@@ -8,16 +8,8 @@ module Integrations ...@@ -8,16 +8,8 @@ module Integrations
Gitlab::DataBuilder::Push.build_sample(project, current_user) Gitlab::DataBuilder::Push.build_sample(project, current_user)
end end
def use_optimal_query?
Feature.enabled?(:integrations_test_webhook_optimizations, project)
end
def note_events_data def note_events_data
note = if use_optimal_query? note = NotesFinder.new(current_user, project: project, target: project).execute.reorder(nil).last # rubocop: disable CodeReuse/ActiveRecord
NotesFinder.new(current_user, project: project, target: project).execute.reorder(nil).last # rubocop: disable CodeReuse/ActiveRecord
else
project.notes.first
end
return { error: s_('TestHooks|Ensure the project has notes.') } unless note.present? return { error: s_('TestHooks|Ensure the project has notes.') } unless note.present?
...@@ -25,11 +17,7 @@ module Integrations ...@@ -25,11 +17,7 @@ module Integrations
end end
def issues_events_data def issues_events_data
issue = if use_optimal_query? issue = IssuesFinder.new(current_user, project_id: project.id, sort: 'created_desc').execute.first
IssuesFinder.new(current_user, project_id: project.id, sort: 'created_desc').execute.first
else
project.issues.first
end
return { error: s_('TestHooks|Ensure the project has issues.') } unless issue.present? return { error: s_('TestHooks|Ensure the project has issues.') } unless issue.present?
...@@ -37,11 +25,7 @@ module Integrations ...@@ -37,11 +25,7 @@ module Integrations
end end
def merge_requests_events_data def merge_requests_events_data
merge_request = if use_optimal_query? merge_request = MergeRequestsFinder.new(current_user, project_id: project.id, sort: 'created_desc').execute.first
MergeRequestsFinder.new(current_user, project_id: project.id, sort: 'created_desc').execute.first
else
project.merge_requests.first
end
return { error: s_('TestHooks|Ensure the project has merge requests.') } unless merge_request.present? return { error: s_('TestHooks|Ensure the project has merge requests.') } unless merge_request.present?
......
---
title: Fix timeouts affecting certain test webhooks
merge_request: 53676
author:
type: fixed
---
name: integrations_test_webhook_optimizations
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52646
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/300105
milestone: '13.9'
type: development
group: group::ecosystem
default_enabled: false
...@@ -79,21 +79,6 @@ RSpec.describe Integrations::Test::ProjectService do ...@@ -79,21 +79,6 @@ RSpec.describe Integrations::Test::ProjectService do
expect(integration).to receive(:test).with(sample_data).and_return(success_result) expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result) expect(subject).to eq(success_result)
end end
context 'when the query optimization feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_optimizations: false)
end
it 'executes the old query' do
allow(Gitlab::DataBuilder::Note).to receive(:build).and_return(sample_data)
expect(NotesFinder).not_to receive(:new)
expect(project).to receive(:notes).and_return([Note.new])
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
end end
shared_examples_for 'a test of an integration that operates on issues' do shared_examples_for 'a test of an integration that operates on issues' do
...@@ -114,21 +99,6 @@ RSpec.describe Integrations::Test::ProjectService do ...@@ -114,21 +99,6 @@ RSpec.describe Integrations::Test::ProjectService do
expect(integration).to receive(:test).with(sample_data).and_return(success_result) expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result) expect(subject).to eq(success_result)
end end
context 'when the query optimization feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_optimizations: false)
end
it 'executes the old query' do
allow(issue).to receive(:to_hook_data).and_return(sample_data)
expect(IssuesFinder).not_to receive(:new)
expect(project).to receive(:issues).and_return([issue])
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
end end
context 'issue' do context 'issue' do
...@@ -161,22 +131,6 @@ RSpec.describe Integrations::Test::ProjectService do ...@@ -161,22 +131,6 @@ RSpec.describe Integrations::Test::ProjectService do
expect(integration).to receive(:test).with(sample_data).and_return(success_result) expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to include(success_result) expect(subject).to include(success_result)
end end
context 'when the query optimization feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_optimizations: false)
end
it 'executes the old query' do
expect(MergeRequestsFinder).not_to receive(:new)
expect(project).to receive(:merge_requests).and_return([merge_request])
allow(merge_request).to receive(:to_hook_data).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
end end
context 'deployment' do context 'deployment' do
......
...@@ -71,21 +71,6 @@ RSpec.describe TestHooks::ProjectService do ...@@ -71,21 +71,6 @@ RSpec.describe TestHooks::ProjectService do
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
context 'when the query optimization feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_optimizations: false)
end
it 'executes the old query' do
allow(Gitlab::DataBuilder::Note).to receive(:build).and_return(sample_data)
expect(NotesFinder).not_to receive(:new)
expect(project).to receive(:notes).and_return([Note.new])
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end end
shared_examples_for 'a test webhook that operates on issues' do shared_examples_for 'a test webhook that operates on issues' do
...@@ -105,21 +90,6 @@ RSpec.describe TestHooks::ProjectService do ...@@ -105,21 +90,6 @@ RSpec.describe TestHooks::ProjectService do
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
context 'when the query optimization feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_optimizations: false)
end
it 'executes the old query' do
allow(issue).to receive(:to_hook_data).and_return(sample_data)
expect(IssuesFinder).not_to receive(:new)
expect(project).to receive(:issues).and_return([issue])
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end end
context 'issues_events' do context 'issues_events' do
...@@ -155,21 +125,6 @@ RSpec.describe TestHooks::ProjectService do ...@@ -155,21 +125,6 @@ RSpec.describe TestHooks::ProjectService do
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
context 'when the query optimization feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_optimizations: false)
end
it 'executes the old query' do
allow(merge_request).to receive(:to_hook_data).and_return(sample_data)
expect(MergeRequestsFinder).not_to receive(:new)
expect(project).to receive(:merge_requests).and_return([merge_request])
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end end
context 'job_events' do context 'job_events' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment