2019-07-25 05:21:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-07 10:30:10 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::Database do
|
2017-03-17 13:16:47 +00:00
|
|
|
before do
|
|
|
|
stub_const('MigrationTest', Class.new { include Gitlab::Database })
|
|
|
|
end
|
|
|
|
|
2020-06-25 00:09:26 +00:00
|
|
|
describe 'EXTRA_SCHEMAS' do
|
|
|
|
it 'contains only schemas starting with gitlab_ prefix' do
|
|
|
|
described_class::EXTRA_SCHEMAS.each do |schema|
|
|
|
|
expect(schema.to_s).to start_with('gitlab_')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-09 15:09:24 +00:00
|
|
|
describe '.default_pool_size' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Runtime).to receive(:max_threads).and_return(7)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the max thread size plus a fixed headroom of 10' do
|
|
|
|
expect(described_class.default_pool_size).to eq(17)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the max thread size plus a DB_POOL_HEADROOM if this env var is present' do
|
|
|
|
stub_env('DB_POOL_HEADROOM', '7')
|
|
|
|
|
|
|
|
expect(described_class.default_pool_size).to eq(14)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-28 21:10:13 +00:00
|
|
|
describe '.has_config?' do
|
|
|
|
context 'two tier database config' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Application).to receive_message_chain(:config, :database_configuration, :[]).with(Rails.env)
|
|
|
|
.and_return({ "adapter" => "postgresql", "database" => "gitlabhq_test" })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for primary' do
|
|
|
|
expect(described_class.has_config?(:primary)).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for ci' do
|
|
|
|
expect(described_class.has_config?(:ci)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'three tier database config' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Application).to receive_message_chain(:config, :database_configuration, :[]).with(Rails.env)
|
|
|
|
.and_return({
|
|
|
|
"primary" => { "adapter" => "postgresql", "database" => "gitlabhq_test" },
|
|
|
|
"ci" => { "adapter" => "postgresql", "database" => "gitlabhq_test_ci" }
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true for primary' do
|
|
|
|
expect(described_class.has_config?(:primary)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true for ci' do
|
|
|
|
expect(described_class.has_config?(:ci)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for non-existent' do
|
|
|
|
expect(described_class.has_config?(:nonexistent)).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-15 18:14:39 +00:00
|
|
|
describe '.check_for_non_superuser' do
|
|
|
|
subject { described_class.check_for_non_superuser }
|
|
|
|
|
|
|
|
let(:non_superuser) { Gitlab::Database::PgUser.new(usename: 'foo', usesuper: false ) }
|
|
|
|
let(:superuser) { Gitlab::Database::PgUser.new(usename: 'bar', usesuper: true) }
|
|
|
|
|
|
|
|
it 'prints user details if not superuser' do
|
|
|
|
allow(Gitlab::Database::PgUser).to receive(:find_by).with('usename = CURRENT_USER').and_return(non_superuser)
|
|
|
|
|
|
|
|
expect(Gitlab::AppLogger).to receive(:info).with("Account details: User: \"foo\", UseSuper: (false)")
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an exception if superuser' do
|
|
|
|
allow(Gitlab::Database::PgUser).to receive(:find_by).with('usename = CURRENT_USER').and_return(superuser)
|
|
|
|
|
|
|
|
expect(Gitlab::AppLogger).to receive(:info).with("Account details: User: \"bar\", UseSuper: (true)")
|
|
|
|
expect { subject }.to raise_error('Error: detected superuser')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'catches exception if find_by fails' do
|
|
|
|
allow(Gitlab::Database::PgUser).to receive(:find_by).with('usename = CURRENT_USER').and_raise(ActiveRecord::StatementInvalid)
|
|
|
|
|
|
|
|
expect { subject }.to raise_error('User CURRENT_USER not found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-07 03:09:32 +00:00
|
|
|
describe '.check_postgres_version_and_print_warning' do
|
2021-11-15 15:10:57 +00:00
|
|
|
let(:reflect) { instance_spy(Gitlab::Database::Reflection) }
|
|
|
|
|
2020-07-07 03:09:32 +00:00
|
|
|
subject { described_class.check_postgres_version_and_print_warning }
|
|
|
|
|
2021-11-15 15:10:57 +00:00
|
|
|
before do
|
|
|
|
allow(Gitlab::Database::Reflection)
|
|
|
|
.to receive(:new)
|
|
|
|
.and_return(reflect)
|
|
|
|
end
|
|
|
|
|
2020-07-07 03:09:32 +00:00
|
|
|
it 'prints a warning if not compliant with minimum postgres version' do
|
2021-11-15 15:10:57 +00:00
|
|
|
allow(reflect).to receive(:postgresql_minimum_supported_version?).and_return(false)
|
2020-07-07 03:09:32 +00:00
|
|
|
|
2021-11-15 15:10:57 +00:00
|
|
|
expect(Kernel)
|
|
|
|
.to receive(:warn)
|
|
|
|
.with(/You are using PostgreSQL/)
|
|
|
|
.exactly(Gitlab::Database.database_base_models.length)
|
|
|
|
.times
|
2020-07-07 03:09:32 +00:00
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'doesnt print a warning if compliant with minimum postgres version' do
|
2021-11-15 15:10:57 +00:00
|
|
|
allow(reflect).to receive(:postgresql_minimum_supported_version?).and_return(true)
|
2020-07-07 03:09:32 +00:00
|
|
|
|
|
|
|
expect(Kernel).not_to receive(:warn).with(/You are using PostgreSQL/)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'doesnt print a warning in Rails runner environment' do
|
2021-11-15 15:10:57 +00:00
|
|
|
allow(reflect).to receive(:postgresql_minimum_supported_version?).and_return(false)
|
2020-07-07 03:09:32 +00:00
|
|
|
allow(Gitlab::Runtime).to receive(:rails_runner?).and_return(true)
|
|
|
|
|
|
|
|
expect(Kernel).not_to receive(:warn).with(/You are using PostgreSQL/)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores ActiveRecord errors' do
|
2021-11-15 15:10:57 +00:00
|
|
|
allow(reflect).to receive(:postgresql_minimum_supported_version?).and_raise(ActiveRecord::ActiveRecordError)
|
2020-07-07 03:09:32 +00:00
|
|
|
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'ignores Postgres errors' do
|
2021-11-15 15:10:57 +00:00
|
|
|
allow(reflect).to receive(:postgresql_minimum_supported_version?).and_raise(PG::Error)
|
2020-07-07 03:09:32 +00:00
|
|
|
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-15 12:11:13 +00:00
|
|
|
describe '.db_config_for_connection' do
|
|
|
|
context 'when the regular connection is used' do
|
|
|
|
it 'returns db_config' do
|
|
|
|
connection = ActiveRecord::Base.retrieve_connection
|
2021-06-22 00:07:53 +00:00
|
|
|
|
2021-09-15 12:11:13 +00:00
|
|
|
expect(described_class.db_config_for_connection(connection)).to eq(connection.pool.db_config)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-24 18:09:18 +00:00
|
|
|
context 'when the connection is LoadBalancing::ConnectionProxy', :database_replica do
|
|
|
|
it 'returns primary db config even if ambiguous queries default to replica' do
|
|
|
|
Gitlab::Database::LoadBalancing::Session.current.use_primary!
|
|
|
|
primary_config = described_class.db_config_for_connection(ActiveRecord::Base.connection)
|
|
|
|
|
|
|
|
Gitlab::Database::LoadBalancing::Session.clear_session
|
|
|
|
Gitlab::Database::LoadBalancing::Session.current.fallback_to_replicas_for_ambiguous_queries do
|
|
|
|
expect(described_class.db_config_for_connection(ActiveRecord::Base.connection)).to eq(primary_config)
|
|
|
|
end
|
2021-09-15 12:11:13 +00:00
|
|
|
end
|
2021-06-22 00:07:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the pool is a NullPool' do
|
2021-09-15 12:11:13 +00:00
|
|
|
it 'returns nil' do
|
2021-06-22 00:07:53 +00:00
|
|
|
connection = double(:active_record_connection, pool: ActiveRecord::ConnectionAdapters::NullPool.new)
|
|
|
|
|
2021-09-15 12:11:13 +00:00
|
|
|
expect(described_class.db_config_for_connection(connection)).to be_nil
|
2021-06-22 00:07:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-15 12:11:13 +00:00
|
|
|
describe '.db_config_name' do
|
|
|
|
it 'returns the db_config name for the connection' do
|
2021-09-21 18:11:18 +00:00
|
|
|
model = ActiveRecord::Base
|
2021-09-15 12:11:13 +00:00
|
|
|
|
2021-09-21 18:11:18 +00:00
|
|
|
# This is a ConnectionProxy
|
|
|
|
expect(described_class.db_config_name(model.connection))
|
2022-03-16 18:08:16 +00:00
|
|
|
.to eq('main')
|
2021-09-21 18:11:18 +00:00
|
|
|
|
|
|
|
# This is an actual connection
|
|
|
|
expect(described_class.db_config_name(model.retrieve_connection))
|
|
|
|
.to eq('main')
|
|
|
|
end
|
|
|
|
|
2021-10-11 15:13:01 +00:00
|
|
|
context 'when replicas are configured', :database_replica do
|
2021-09-21 18:11:18 +00:00
|
|
|
it 'returns the name for a replica' do
|
2021-11-09 06:13:00 +00:00
|
|
|
replica = ActiveRecord::Base.load_balancer.host
|
2021-09-21 18:11:18 +00:00
|
|
|
|
|
|
|
expect(described_class.db_config_name(replica)).to eq('main_replica')
|
|
|
|
end
|
2021-09-15 12:11:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-19 18:09:14 +00:00
|
|
|
describe '.db_config_names' do
|
|
|
|
let(:expected) { %w[foo bar] }
|
|
|
|
|
|
|
|
it 'includes only main by default' do
|
|
|
|
allow(::ActiveRecord::Base).to receive(:configurations).and_return(
|
|
|
|
double(configs_for: %w[foo bar].map { |x| double(name: x) })
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(described_class.db_config_names).to eq(expected)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'excludes geo when that is included' do
|
|
|
|
allow(::ActiveRecord::Base).to receive(:configurations).and_return(
|
|
|
|
double(configs_for: %w[foo bar geo].map { |x| double(name: x) })
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(described_class.db_config_names).to eq(expected)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-16 18:08:16 +00:00
|
|
|
describe '.gitlab_schemas_for_connection' do
|
|
|
|
it 'does return a valid schema depending on a base model used', :request_store do
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Project.connection)).to include(:gitlab_main, :gitlab_shared)
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).to include(:gitlab_ci, :gitlab_shared)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does return gitlab_ci when a ActiveRecord::Base is using CI connection' do
|
|
|
|
with_reestablished_active_record_base do
|
|
|
|
reconfigure_db_connection(model: ActiveRecord::Base, config_model: Ci::Build)
|
|
|
|
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(ActiveRecord::Base.connection)).to include(:gitlab_ci, :gitlab_shared)
|
|
|
|
end
|
|
|
|
end
|
2022-04-08 06:08:32 +00:00
|
|
|
|
|
|
|
context "when there's CI connection", :request_store do
|
|
|
|
before do
|
|
|
|
skip_if_multiple_databases_not_setup
|
|
|
|
|
|
|
|
# FF due to lib/gitlab/database/load_balancing/configuration.rb:92
|
|
|
|
# Requires usage of `:request_store`
|
|
|
|
stub_feature_flags(force_no_sharing_primary_model: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when CI uses database_tasks: false does indicate that ci: is subset of main:' do
|
|
|
|
before do
|
|
|
|
allow(Ci::ApplicationRecord.connection_db_config).to receive(:database_tasks?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does return gitlab_ci when accessing via main: connection' do
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Project.connection)).to include(:gitlab_ci, :gitlab_main, :gitlab_shared)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return gitlab_main when accessing via ci: connection' do
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).to include(:gitlab_ci, :gitlab_shared)
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).not_to include(:gitlab_main)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when CI uses database_tasks: true does indicate that ci: has own database' do
|
|
|
|
before do
|
|
|
|
allow(Ci::ApplicationRecord.connection_db_config).to receive(:database_tasks?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return gitlab_ci when accessing via main: connection' do
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Project.connection)).to include(:gitlab_main, :gitlab_shared)
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Project.connection)).not_to include(:gitlab_ci)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return gitlab_main when accessing via ci: connection' do
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).to include(:gitlab_ci, :gitlab_shared)
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(Ci::Build.connection)).not_to include(:gitlab_main)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-05-20 18:07:48 +00:00
|
|
|
|
|
|
|
it 'does return empty for non-adopted connections' do
|
|
|
|
new_connection = ActiveRecord::Base.postgresql_connection(
|
|
|
|
ActiveRecord::Base.connection_db_config.configuration_hash)
|
|
|
|
|
|
|
|
expect(described_class.gitlab_schemas_for_connection(new_connection)).to be_nil
|
|
|
|
ensure
|
|
|
|
new_connection&.disconnect!
|
|
|
|
end
|
2022-03-16 18:08:16 +00:00
|
|
|
end
|
|
|
|
|
2016-02-15 19:13:47 +00:00
|
|
|
describe '#true_value' do
|
2019-06-13 13:12:28 +00:00
|
|
|
it 'returns correct value' do
|
2017-04-10 10:23:28 +00:00
|
|
|
expect(described_class.true_value).to eq "'t'"
|
2016-02-15 19:13:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#false_value' do
|
2019-06-13 13:12:28 +00:00
|
|
|
it 'returns correct value' do
|
2017-04-10 10:23:28 +00:00
|
|
|
expect(described_class.false_value).to eq "'f'"
|
2016-02-15 19:13:47 +00:00
|
|
|
end
|
|
|
|
end
|
2017-10-30 23:21:56 +00:00
|
|
|
|
|
|
|
describe '#sanitize_timestamp' do
|
|
|
|
let(:max_timestamp) { Time.at((1 << 31) - 1) }
|
|
|
|
|
|
|
|
subject { described_class.sanitize_timestamp(timestamp) }
|
|
|
|
|
|
|
|
context 'with a timestamp smaller than MAX_TIMESTAMP_VALUE' do
|
|
|
|
let(:timestamp) { max_timestamp - 10.years }
|
|
|
|
|
|
|
|
it 'returns the given timestamp' do
|
|
|
|
expect(subject).to eq(timestamp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a timestamp larger than MAX_TIMESTAMP_VALUE' do
|
|
|
|
let(:timestamp) { max_timestamp + 1.second }
|
|
|
|
|
|
|
|
it 'returns MAX_TIMESTAMP_VALUE' do
|
|
|
|
expect(subject).to eq(max_timestamp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-10 15:09:11 +00:00
|
|
|
|
2022-03-08 12:20:17 +00:00
|
|
|
describe '.all_uncached' do
|
|
|
|
let(:base_model) do
|
|
|
|
Class.new do
|
|
|
|
def self.uncached
|
|
|
|
@uncached = true
|
|
|
|
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:model1) { Class.new(base_model) }
|
|
|
|
let(:model2) { Class.new(base_model) }
|
|
|
|
|
|
|
|
before do
|
2022-07-19 06:10:05 +00:00
|
|
|
allow(described_class).to receive(:database_base_models_using_load_balancing)
|
2022-03-08 12:20:17 +00:00
|
|
|
.and_return({ model1: model1, model2: model2 }.with_indifferent_access)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'wraps the given block in uncached calls for each primary connection', :aggregate_failures do
|
|
|
|
expect(model1.instance_variable_get(:@uncached)).to be_nil
|
|
|
|
expect(model2.instance_variable_get(:@uncached)).to be_nil
|
|
|
|
|
|
|
|
expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_primary).and_yield
|
|
|
|
|
|
|
|
expect(model2).to receive(:uncached).and_call_original
|
|
|
|
expect(model1).to receive(:uncached).and_call_original
|
|
|
|
|
|
|
|
yielded_to_block = false
|
|
|
|
described_class.all_uncached do
|
|
|
|
expect(model1.instance_variable_get(:@uncached)).to be(true)
|
|
|
|
expect(model2.instance_variable_get(:@uncached)).to be(true)
|
|
|
|
|
|
|
|
yielded_to_block = true
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(yielded_to_block).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-02 09:10:09 +00:00
|
|
|
describe '.read_only?' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(described_class.read_only?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.read_write' do
|
|
|
|
it 'returns true' do
|
|
|
|
expect(described_class.read_write?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-10 15:09:11 +00:00
|
|
|
describe 'ActiveRecordBaseTransactionMetrics' do
|
|
|
|
def subscribe_events
|
|
|
|
events = []
|
|
|
|
|
|
|
|
begin
|
|
|
|
subscriber = ActiveSupport::Notifications.subscribe('transaction.active_record') do |e|
|
|
|
|
events << e
|
|
|
|
end
|
|
|
|
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
|
|
|
|
end
|
|
|
|
|
|
|
|
events
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a transaction block' do
|
|
|
|
it 'does not publish a transaction event' do
|
|
|
|
events = subscribe_events do
|
|
|
|
User.first
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(events).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'within a transaction block' do
|
|
|
|
it 'publishes a transaction event' do
|
|
|
|
events = subscribe_events do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
User.first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(events.length).to be(1)
|
|
|
|
|
|
|
|
event = events.first
|
|
|
|
expect(event).not_to be_nil
|
|
|
|
expect(event.duration).to be > 0.0
|
|
|
|
expect(event.payload).to a_hash_including(
|
2021-09-21 18:11:18 +00:00
|
|
|
connection: be_a(Gitlab::Database::LoadBalancing::ConnectionProxy)
|
2021-03-10 15:09:11 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'within an empty transaction block' do
|
|
|
|
it 'publishes a transaction event' do
|
|
|
|
events = subscribe_events do
|
|
|
|
ActiveRecord::Base.transaction {}
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(events.length).to be(1)
|
|
|
|
|
|
|
|
event = events.first
|
|
|
|
expect(event).not_to be_nil
|
|
|
|
expect(event.duration).to be > 0.0
|
|
|
|
expect(event.payload).to a_hash_including(
|
2021-09-21 18:11:18 +00:00
|
|
|
connection: be_a(Gitlab::Database::LoadBalancing::ConnectionProxy)
|
2021-03-10 15:09:11 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'within a nested transaction block' do
|
|
|
|
it 'publishes multiple transaction events' do
|
|
|
|
events = subscribe_events do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
User.first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(events.length).to be(3)
|
|
|
|
|
|
|
|
events.each do |event|
|
|
|
|
expect(event).not_to be_nil
|
|
|
|
expect(event.duration).to be > 0.0
|
|
|
|
expect(event.payload).to a_hash_including(
|
2021-09-21 18:11:18 +00:00
|
|
|
connection: be_a(Gitlab::Database::LoadBalancing::ConnectionProxy)
|
2021-03-10 15:09:11 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'within a cancelled transaction block' do
|
|
|
|
it 'publishes multiple transaction events' do
|
|
|
|
events = subscribe_events do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
User.first
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(events.length).to be(1)
|
|
|
|
|
|
|
|
event = events.first
|
|
|
|
expect(event).not_to be_nil
|
|
|
|
expect(event.duration).to be > 0.0
|
|
|
|
expect(event.payload).to a_hash_including(
|
2021-09-21 18:11:18 +00:00
|
|
|
connection: be_a(Gitlab::Database::LoadBalancing::ConnectionProxy)
|
2021-03-10 15:09:11 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-07 10:30:10 +00:00
|
|
|
end
|