Skip to content

Commit a87cc46

Browse files
authored
Merge pull request rails#55397 from skipkayhil/hm-vnpxkwrpuvlmylmy
Assert connection id changes when reconnecting
2 parents 480faf6 + 1121091 commit a87cc46

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

activerecord/test/cases/adapter_test.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,13 @@ def teardown
882882
end
883883

884884
test "#execute is retryable" do
885-
kill_connection_from_server
885+
initial_connection_id = connection_id_from_server
886+
887+
kill_connection_from_server(initial_connection_id)
886888

887889
@connection.execute("SELECT 1", allow_retry: true)
890+
891+
assert_not_equal initial_connection_id, connection_id_from_server
888892
end
889893

890894
test "disconnect and recover on #configure_connection failure" do
@@ -975,14 +979,23 @@ def remote_disconnect(connection)
975979
end
976980
end
977981

978-
def kill_connection_from_server
982+
def connection_id_from_server
983+
case @connection.adapter_name
984+
when "Mysql2", "Trilogy"
985+
@connection.execute("SELECT CONNECTION_ID()").to_a[0][0]
986+
when "PostgreSQL"
987+
@connection.execute("SELECT pg_backend_pid()").to_a[0]["pg_backend_pid"]
988+
else
989+
skip("connection_id_from_server unsupported")
990+
end
991+
end
992+
993+
def kill_connection_from_server(connection_id)
979994
conn = @connection.pool.checkout
980995
case conn.adapter_name
981996
when "Mysql2", "Trilogy"
982-
connection_id = @connection.execute("SELECT CONNECTION_ID()").to_a[0][0]
983997
conn.execute("KILL #{connection_id}")
984998
when "PostgreSQL"
985-
connection_id = @connection.execute("SELECT pg_backend_pid()").to_a[0]["pg_backend_pid"]
986999
conn.execute("SELECT pg_terminate_backend(#{connection_id})")
9871000
else
9881001
skip("kill_connection_from_server unsupported")

0 commit comments

Comments
 (0)