Commit adffe5c2 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'fix-phase4-specs-v4' into 'master'

Fix/acknowledge various cross-DB modifications

See merge request gitlab-org/gitlab!78098
parents 0c3b6bf0 e432845e
...@@ -41,7 +41,9 @@ module Clusters ...@@ -41,7 +41,9 @@ module Clusters
end end
def prepare_uninstall def prepare_uninstall
runner&.update!(active: false) ::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/350180') do
runner&.update!(active: false)
end
end end
def post_uninstall def post_uninstall
......
...@@ -12,9 +12,7 @@ module Ci ...@@ -12,9 +12,7 @@ module Ci
# Ci::Pipeline#destroy triggers `use_fast_destroy :job_artifacts` and # Ci::Pipeline#destroy triggers `use_fast_destroy :job_artifacts` and
# ci_builds has ON DELETE CASCADE to ci_pipelines. The pipeline, the builds, # ci_builds has ON DELETE CASCADE to ci_pipelines. The pipeline, the builds,
# job and pipeline artifacts all get destroyed here. # job and pipeline artifacts all get destroyed here.
::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/345664') do pipeline.reset.destroy!
pipeline.reset.destroy!
end
ServiceResponse.success(message: 'Pipeline not found') ServiceResponse.success(message: 'Pipeline not found')
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
......
...@@ -10,7 +10,9 @@ module EE ...@@ -10,7 +10,9 @@ module EE
override :destroy_related_records override :destroy_related_records
def destroy_related_records(artifacts) def destroy_related_records(artifacts)
destroy_security_findings(artifacts) ::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/346236') do
destroy_security_findings(artifacts)
end
end end
override :after_batch_destroy_hook override :after_batch_destroy_hook
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Geo::TerraformStateVersionReplicator do RSpec.describe Geo::TerraformStateVersionReplicator do
let(:model_record) { build(:terraform_state_version, terraform_state: create(:terraform_state)) } let_it_be(:ci_build) { create(:ci_build) }
let_it_be(:terraform_state) { create(:terraform_state, project: ci_build.project) }
let(:model_record) { build(:terraform_state_version, build: ci_build, terraform_state: terraform_state) }
include_examples 'a blob replicator' include_examples 'a blob replicator'
include_examples 'a verifiable replicator' include_examples 'a verifiable replicator'
......
...@@ -118,7 +118,6 @@ FactoryBot.define do ...@@ -118,7 +118,6 @@ FactoryBot.define do
end end
factory :clusters_applications_runner, class: 'Clusters::Applications::Runner' do factory :clusters_applications_runner, class: 'Clusters::Applications::Runner' do
runner factory: %i(ci_runner)
cluster factory: %i(cluster with_installed_helm provided_by_gcp) cluster factory: %i(cluster with_installed_helm provided_by_gcp)
end end
......
...@@ -7,7 +7,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Create do ...@@ -7,7 +7,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Create do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:pipeline) do let(:pipeline) do
build(:ci_empty_pipeline, project: project, ref: 'master') build(:ci_empty_pipeline, project: project, ref: 'master', user: user)
end end
let(:command) do let(:command) do
...@@ -59,7 +59,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Create do ...@@ -59,7 +59,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Create do
context 'tags persistence' do context 'tags persistence' do
let(:stage) do let(:stage) do
build(:ci_stage_entity, pipeline: pipeline) build(:ci_stage_entity, pipeline: pipeline, project: project)
end end
let(:job) do let(:job) do
......
...@@ -49,9 +49,9 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git ...@@ -49,9 +49,9 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git
end end
context 'FastDestroyAll' do context 'FastDestroyAll' do
let(:parent) { create(:project) } let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, project: parent) } let(:pipeline) { create(:ci_pipeline, project: project) }
let!(:build) { create(:ci_build, :running, :trace_live, pipeline: pipeline, project: parent) } let!(:build) { create(:ci_build, :running, :trace_live, pipeline: pipeline, project: project) }
let(:subjects) { build.trace_chunks } let(:subjects) { build.trace_chunks }
describe 'Forbid #destroy and #destroy_all' do describe 'Forbid #destroy and #destroy_all' do
...@@ -84,7 +84,13 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git ...@@ -84,7 +84,13 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git
expect(external_data_counter).to be > 0 expect(external_data_counter).to be > 0
expect(subjects.count).to be > 0 expect(subjects.count).to be > 0
expect { parent.destroy! }.not_to raise_error ::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/350185') do
# This should use to prevent cross-DB modification
# but due to https://gitlab.com/gitlab-org/gitlab/-/issues/350185
# the build trace chunks are not destroyed by Projects::DestroyService
# Change to: expect { Projects::DestroyService.new(project, project.owner).execute }.to eq(true)
expect { project.destroy! }.not_to raise_error
end
expect(subjects.count).to eq(0) expect(subjects.count).to eq(0)
expect(external_data_counter).to eq(0) expect(external_data_counter).to eq(0)
...@@ -830,7 +836,7 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git ...@@ -830,7 +836,7 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git
expect(described_class.count).to eq(3) expect(described_class.count).to eq(3)
subject expect(subject).to be_truthy
expect(described_class.count).to eq(0) expect(described_class.count).to eq(0)
...@@ -852,7 +858,13 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git ...@@ -852,7 +858,13 @@ RSpec.describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state, :clean_git
context 'when project is destroyed' do context 'when project is destroyed' do
let(:subject) do let(:subject) do
project.destroy! ::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/350185') do
# This should use to prevent cross-DB modification
# but due to https://gitlab.com/gitlab-org/gitlab/-/issues/350185
# the build trace chunks are not destroyed by Projects::DestroyService
# Change to: Projects::DestroyService.new(project, project.owner).execute
project.destroy!
end
end end
it_behaves_like 'deletes all build_trace_chunk and data in redis' it_behaves_like 'deletes all build_trace_chunk and data in redis'
......
...@@ -1056,9 +1056,7 @@ RSpec.describe API::Commits do ...@@ -1056,9 +1056,7 @@ RSpec.describe API::Commits do
shared_examples_for 'ref with pipeline' do shared_examples_for 'ref with pipeline' do
let!(:pipeline) do let!(:pipeline) do
project create(:ci_empty_pipeline, project: project, status: :created, source: :push, ref: 'master', sha: commit.sha, protected: false)
.ci_pipelines
.create!(source: :push, ref: 'master', sha: commit.sha, protected: false)
end end
it 'includes status as "created" and a last_pipeline object' do it 'includes status as "created" and a last_pipeline object' do
...@@ -1090,9 +1088,7 @@ RSpec.describe API::Commits do ...@@ -1090,9 +1088,7 @@ RSpec.describe API::Commits do
shared_examples_for 'ref with unaccessible pipeline' do shared_examples_for 'ref with unaccessible pipeline' do
let!(:pipeline) do let!(:pipeline) do
project create(:ci_empty_pipeline, project: project, status: :created, source: :push, ref: 'master', sha: commit.sha, protected: false)
.ci_pipelines
.create!(source: :push, ref: 'master', sha: commit.sha, protected: false)
end end
it 'does not include last_pipeline' do it 'does not include last_pipeline' do
......
...@@ -371,6 +371,14 @@ RSpec.describe Ci::RetryBuildService do ...@@ -371,6 +371,14 @@ RSpec.describe Ci::RetryBuildService do
it_behaves_like 'when build with dynamic environment is retried' it_behaves_like 'when build with dynamic environment is retried'
context 'when create_deployment_in_separate_transaction feature flag is disabled' do context 'when create_deployment_in_separate_transaction feature flag is disabled' do
let(:new_build) do
travel_to(1.second.from_now) do
::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/345668') do
service.clone!(build)
end
end
end
before do before do
stub_feature_flags(create_deployment_in_separate_transaction: false) stub_feature_flags(create_deployment_in_separate_transaction: false)
end end
......
- "./ee/spec/replicators/geo/terraform_state_version_replicator_spec.rb" []
- "./spec/features/issues/issue_detail_spec.rb"
- "./spec/features/projects/pipelines/pipeline_spec.rb"
- "./spec/features/signed_commits_spec.rb"
- "./spec/lib/gitlab/ci/pipeline/chain/create_spec.rb"
- "./spec/models/ci/build_trace_chunk_spec.rb"
- "./spec/models/ci/job_artifact_spec.rb"
- "./spec/models/clusters/applications/runner_spec.rb"
- "./spec/requests/api/commits_spec.rb"
- "./spec/services/ci/retry_build_service_spec.rb"
...@@ -115,16 +115,14 @@ RSpec.shared_examples 'UpdateProjectStatistics' do |with_counter_attribute| ...@@ -115,16 +115,14 @@ RSpec.shared_examples 'UpdateProjectStatistics' do |with_counter_attribute|
expect(ProjectStatistics) expect(ProjectStatistics)
.not_to receive(:increment_statistic) .not_to receive(:increment_statistic)
project.update!(pending_delete: true) expect(Projects::DestroyService.new(project, project.owner).execute).to eq(true)
project.destroy!
end end
it 'does not schedule a namespace statistics worker' do it 'does not schedule a namespace statistics worker' do
expect(Namespaces::ScheduleAggregationWorker) expect(Namespaces::ScheduleAggregationWorker)
.not_to receive(:perform_async) .not_to receive(:perform_async)
project.update!(pending_delete: true) expect(Projects::DestroyService.new(project, project.owner).execute).to eq(true)
project.destroy!
end end
end end
end end
......
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