Commit f7debee7 authored by Stan Hu's avatar Stan Hu

Make Geo DB tracking database work with let_it_be

Geo tracking atabase entries created in specs with `let_it_be` and
`before_all` would not be cleaned up between test runs. By default,
let_it_be uses an adapter that only cleans records created via
`ActiveRecord::Base`. We fix this by introducing a custom adapter that
cleans the Geo tracking database and the main database.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/232749
parent 3d51a0b3
...@@ -14,7 +14,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do ...@@ -14,7 +14,7 @@ RSpec.describe Geo::BlobVerificationSecondaryService, :geo do
describe '#execute' do describe '#execute' do
let_it_be(:package_file) { create(:conan_package_file, :conan_recipe_file, verification_checksum: '62fc1ec4ce60') } let_it_be(:package_file) { create(:conan_package_file, :conan_recipe_file, verification_checksum: '62fc1ec4ce60') }
let_it_be(:registry) { create(:geo_package_file_registry, :synced, package_file: package_file) } let!(:registry) { create(:geo_package_file_registry, :synced, package_file: package_file) }
subject(:service) { described_class.new(package_file.replicator) } subject(:service) { described_class.new(package_file.replicator) }
......
# frozen_string_literal: true
module EE
class BeforeAllAdapter
def self.begin_transaction
TestProf::BeforeAll::Adapters::ActiveRecord.begin_transaction
::Geo::BaseRegistry.connection.begin_transaction
end
def self.rollback_transaction
TestProf::BeforeAll::Adapters::ActiveRecord.rollback_transaction
::Geo::BaseRegistry.connection.rollback_transaction
end
end
end
...@@ -13,6 +13,7 @@ module EE ...@@ -13,6 +13,7 @@ module EE
def setup_database_cleaner def setup_database_cleaner
if ::Gitlab::Geo.geo_database_configured? if ::Gitlab::Geo.geo_database_configured?
::DatabaseCleaner[:active_record, { connection: ::Geo::BaseRegistry }] ::DatabaseCleaner[:active_record, { connection: ::Geo::BaseRegistry }]
TestProf::BeforeAll.adapter = ::EE::BeforeAllAdapter
end end
super super
......
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