Commit 348a6648 authored by Aleksei Lipniagov's avatar Aleksei Lipniagov Committed by Adam Hegyi

Fix stuck transaction in spec

It seems that the connection we obtained was reused, even though we
expected to have a separate one for the initial lock. It may be related
to the changes how ActiveRecordSecond is being set up in Ruby3.
parent d71f1b02
...@@ -37,22 +37,20 @@ RSpec.describe Gitlab::Database::WithLockRetriesOutsideTransaction do ...@@ -37,22 +37,20 @@ RSpec.describe Gitlab::Database::WithLockRetriesOutsideTransaction do
context 'when lock retry is enabled' do context 'when lock retry is enabled' do
let(:lock_fiber) do let(:lock_fiber) do
Fiber.new do Fiber.new do
configuration = ActiveRecordSecond.configurations.find_db_config(Rails.env).configuration_hash # Initiating a separate DB connection for the lock
conn = ActiveRecord::Base.connection_pool.checkout
# Initiating a second DB connection for the lock
conn = ActiveRecordSecond.establish_connection(configuration).connection
conn.transaction do conn.transaction do
conn.execute("LOCK TABLE #{Project.table_name} in exclusive mode") conn.execute("LOCK TABLE #{Project.table_name} in exclusive mode")
Fiber.yield Fiber.yield
end end
ActiveRecordSecond.remove_connection # force disconnect # Releasing the connection we requested
ActiveRecord::Base.connection_pool.checkin(conn)
end end
end end
before do before do
stub_const('ActiveRecordSecond', Class.new(ActiveRecord::Base))
lock_fiber.resume # start the transaction and lock the table lock_fiber.resume # start the transaction and lock the table
end end
......
...@@ -37,22 +37,19 @@ RSpec.describe Gitlab::Database::WithLockRetries do ...@@ -37,22 +37,19 @@ RSpec.describe Gitlab::Database::WithLockRetries do
context 'when lock retry is enabled' do context 'when lock retry is enabled' do
let(:lock_fiber) do let(:lock_fiber) do
Fiber.new do Fiber.new do
configuration = ActiveRecordSecond.configurations.find_db_config(Rails.env).configuration_hash # Initiating a separate DB connection for the lock
conn = ActiveRecord::Base.connection_pool.checkout
# Initiating a second DB connection for the lock
conn = ActiveRecordSecond.establish_connection(configuration).connection
conn.transaction do conn.transaction do
conn.execute("LOCK TABLE #{Project.table_name} in exclusive mode") conn.execute("LOCK TABLE #{Project.table_name} in exclusive mode")
Fiber.yield Fiber.yield
end end
ActiveRecordSecond.remove_connection # force disconnect # Releasing the connection we requested
ActiveRecord::Base.connection_pool.checkin(conn)
end end
end end
before do before do
stub_const('ActiveRecordSecond', Class.new(ActiveRecord::Base))
lock_fiber.resume # start the transaction and lock the table lock_fiber.resume # start the transaction and lock the table
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