Commit b2681e0f authored by Stan Hu's avatar Stan Hu

Optimize Geo specs by using truncation strategy for DB cleaner only when necessary

Closes #4259
parent 5722f7b7
require 'spec_helper' require 'spec_helper'
# Disable transactions via :truncate method because a foreign table describe Geo::AttachmentRegistryFinder, :geo do
# can't see changes inside a transaction of a different connection.
describe Geo::AttachmentRegistryFinder, :geo, :truncate do
include ::EE::GeoHelpers include ::EE::GeoHelpers
let(:secondary) { create(:geo_node) } let(:secondary) { create(:geo_node) }
...@@ -28,7 +26,9 @@ describe Geo::AttachmentRegistryFinder, :geo, :truncate do ...@@ -28,7 +26,9 @@ describe Geo::AttachmentRegistryFinder, :geo, :truncate do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
end end
context 'FDW' do # Disable transactions via :truncate method because a foreign table
# can't see changes inside a transaction of a different connection.
context 'FDW', :truncate do
before do before do
skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo.fdw? skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo.fdw?
end end
......
require 'spec_helper' require 'spec_helper'
# Disable transactions via :truncate method because a foreign table describe Geo::ExpireUploadsFinder, :geo do
# can't see changes inside a transaction of a different connection.
describe Geo::ExpireUploadsFinder, :geo, :truncate do
let(:project) { create(:project) } let(:project) { create(:project) }
context 'FDW' do # Disable transactions via :truncate method because a foreign table
# can't see changes inside a transaction of a different connection.
context 'FDW', :truncate do
before do before do
skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo.fdw? skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo.fdw?
end end
......
require 'spec_helper' require 'spec_helper'
# Disable transactions via :truncate method because a foreign table describe Geo::ProjectRegistryFinder, :geo do
# can't see changes inside a transaction of a different connection.
describe Geo::ProjectRegistryFinder, :geo, :truncate do
include ::EE::GeoHelpers include ::EE::GeoHelpers
let(:secondary) { create(:geo_node) } let(:secondary) { create(:geo_node) }
...@@ -154,7 +152,9 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do ...@@ -154,7 +152,9 @@ describe Geo::ProjectRegistryFinder, :geo, :truncate do
end end
end end
context 'FDW' do # Disable transactions via :truncate method because a foreign table
# can't see changes inside a transaction of a different connection.
context 'FDW', :truncate do
before do before do
skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo.fdw? skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo.fdw?
end end
......
require 'spec_helper' require 'spec_helper'
# Disable transactions via :truncate method because a foreign table describe GeoNodeStatus, :geo do
# can't see changes inside a transaction of a different connection.
describe GeoNodeStatus, :geo, :truncate do
include ::EE::GeoHelpers include ::EE::GeoHelpers
let!(:primary) { create(:geo_node, :primary) } let!(:primary) { create(:geo_node, :primary) }
...@@ -52,7 +50,9 @@ describe GeoNodeStatus, :geo, :truncate do ...@@ -52,7 +50,9 @@ describe GeoNodeStatus, :geo, :truncate do
end end
end end
describe '#attachments_synced_count' do # Disable transactions via :truncate method because a foreign table
# can't see changes inside a transaction of a different connection.
describe '#attachments_synced_count', :truncate do
it 'only counts successful syncs' do it 'only counts successful syncs' do
create_list(:user, 3, avatar: fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png')) create_list(:user, 3, avatar: fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/png'))
uploads = Upload.all.pluck(:id) uploads = Upload.all.pluck(:id)
...@@ -95,7 +95,7 @@ describe GeoNodeStatus, :geo, :truncate do ...@@ -95,7 +95,7 @@ describe GeoNodeStatus, :geo, :truncate do
end end
end end
describe '#attachments_failed_count' do describe '#attachments_failed_count', :truncate do
it 'counts failed avatars, attachment, personal snippets and files' do it 'counts failed avatars, attachment, personal snippets and files' do
# These two should be ignored # These two should be ignored
create(:geo_file_registry, :lfs, :with_file, success: false) create(:geo_file_registry, :lfs, :with_file, success: false)
...@@ -110,7 +110,7 @@ describe GeoNodeStatus, :geo, :truncate do ...@@ -110,7 +110,7 @@ describe GeoNodeStatus, :geo, :truncate do
end end
end end
describe '#attachments_synced_in_percentage' do describe '#attachments_synced_in_percentage', :truncate do
let(:avatar) { fixture_file_upload(Rails.root.join('spec/fixtures/dk.png')) } let(:avatar) { fixture_file_upload(Rails.root.join('spec/fixtures/dk.png')) }
let(:upload_1) { create(:upload, model: group, path: avatar) } let(:upload_1) { create(:upload, model: group, path: avatar) }
let(:upload_2) { create(:upload, model: project_1, path: avatar) } let(:upload_2) { create(:upload, model: project_1, path: avatar) }
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
# Disable transactions via :truncate method because a foreign table # Disable transactions via :truncate method because a foreign table
# can't see changes inside a transaction of a different connection. # can't see changes inside a transaction of a different connection.
describe Geo::FileDownloadDispatchWorker, :geo, :truncate do describe Geo::FileDownloadDispatchWorker, :geo do
include ::EE::GeoHelpers include ::EE::GeoHelpers
let(:primary) { create(:geo_node, :primary, host: 'primary-geo-node') } let(:primary) { create(:geo_node, :primary, host: 'primary-geo-node') }
...@@ -171,7 +171,7 @@ describe Geo::FileDownloadDispatchWorker, :geo, :truncate do ...@@ -171,7 +171,7 @@ describe Geo::FileDownloadDispatchWorker, :geo, :truncate do
end end
end end
describe 'when PostgreSQL FDW is available', :geo do describe 'when PostgreSQL FDW is available', :geo, :truncate do
# Skip if FDW isn't activated on this database # Skip if FDW isn't activated on this database
it_behaves_like '#perform', Gitlab::Database.postgresql? && !Gitlab::Geo.fdw? it_behaves_like '#perform', Gitlab::Database.postgresql? && !Gitlab::Geo.fdw?
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