Commit e725aab2 authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Add more database load balancing testss

parent bf2670a1
...@@ -583,6 +583,29 @@ RSpec.describe Gitlab::Database::LoadBalancing do ...@@ -583,6 +583,29 @@ RSpec.describe Gitlab::Database::LoadBalancing do
false, [:replica, :replica] false, [:replica, :replica]
], ],
# A custom read query inside use_replica_if_possible
[
-> {
::Gitlab::Database::LoadBalancing::Session.current.use_replica_if_possible do
model.connection.exec_query("SELECT 1")
end
},
false, [:replica]
],
# A custom read query inside a transaction use_replica_if_possible
[
-> {
::Gitlab::Database::LoadBalancing::Session.current.use_replica_if_possible do
model.transaction do
model.connection.exec_query("SET LOCAL statement_timeout = 5000")
model.count
end
end
},
true, [:replica, :replica, :replica, :replica]
],
# use_replica_if_possible after a write # use_replica_if_possible after a write
[ [
-> { -> {
......
...@@ -120,7 +120,7 @@ RSpec.describe ApplicationRecord do ...@@ -120,7 +120,7 @@ RSpec.describe ApplicationRecord do
# other way to test the timeout for sure, 10ms of waiting seems to be # other way to test the timeout for sure, 10ms of waiting seems to be
# reasonable! # reasonable!
context 'when the query runs longer than configured timeout' do context 'when the query runs longer than configured timeout' do
it 'cancels the query and raiss an exception' do it 'cancels the query and raises an exception' do
expect do expect do
described_class.with_fast_read_statement_timeout(10) do described_class.with_fast_read_statement_timeout(10) do
described_class.connection.exec_query('SELECT pg_sleep(0.1)') described_class.connection.exec_query('SELECT pg_sleep(0.1)')
......
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