From 7015d7da65c22ab84a7cd778ccad66fe302a4528 Mon Sep 17 00:00:00 2001 From: Nony Dutton Date: Wed, 3 Apr 2024 11:31:20 +0200 Subject: [PATCH] Drop `reconnect: true` from DB configs We get flooded with these errors in tests: ``` WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version. ``` `reconnect: true` allows for automatic reconnection to the server in the event that the server disconnects the client. One way that happens is if the connection sits unused long enough to exceed the session timeout. ARHP doesn't manage reconnection on its own so we can remove this. This did require manually adding a `connection.reconnect!` to a test where we tell the server to kill the connection. In that test we're testing that calling `reconnect!` doesn't cause us to switch to the wrong database, not the specific behavior of `reconnect: true`. --- test/database.yml | 8 -------- test/test_arhp.rb | 2 ++ test/three_tier_database.yml | 15 --------------- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/test/database.yml b/test/database.yml index e8f529e1..dd810b1f 100644 --- a/test/database.yml +++ b/test/database.yml @@ -36,7 +36,6 @@ test_pool_1_db_a: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true # Mimic configurations as read by active_record_shards/ar_flexmaster test_pool_1_db_a_replica: @@ -46,7 +45,6 @@ test_pool_1_db_a_replica: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true slave: true test_pool_1_db_b: @@ -56,7 +54,6 @@ test_pool_1_db_b: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_1_db_not_there: adapter: <%= adapter %> @@ -65,7 +62,6 @@ test_pool_1_db_not_there: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_2_db_d: adapter: <%= adapter %> @@ -75,7 +71,6 @@ test_pool_2_db_d: password: "<%= mysql.password %>" host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true test_pool_2_db_e: adapter: <%= adapter %> @@ -85,7 +80,6 @@ test_pool_2_db_e: password: "<%= mysql.password %>" host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true test_pool_3_db_e: adapter: <%= adapter %> @@ -95,7 +89,6 @@ test_pool_3_db_e: password: host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true # test_pool_1_db_c needs to be the last database defined in the file # otherwise the test_models_with_matching_hosts_and_non_matching_databases_issue_exists_without_arhp_patch @@ -107,4 +100,3 @@ test_pool_1_db_c: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true diff --git a/test/test_arhp.rb b/test/test_arhp.rb index 0b4c5707..bb4f621d 100644 --- a/test/test_arhp.rb +++ b/test/test_arhp.rb @@ -186,6 +186,8 @@ def test_underlying_assumption_about_test_db Pool2DbD.connection.execute("KILL #{thread_id}") end + switch_to_klass.connection.reconnect! + # and finally, did mysql reconnect correctly? puts "\nAnd now we end up on #{current_database(switch_to_klass)}" if debug_me assert_equal expected_database, current_database(switch_to_klass) diff --git a/test/three_tier_database.yml b/test/three_tier_database.yml index 44ab0db8..9a5ae4ba 100644 --- a/test/three_tier_database.yml +++ b/test/three_tier_database.yml @@ -43,7 +43,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true # Mimic configurations as read by active_record_shards/ar_flexmaster test_pool_1_db_a_replica: @@ -53,7 +52,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true replica: true test_pool_1_db_b: @@ -63,7 +61,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_1_db_c: adapter: <%= adapter %> @@ -72,7 +69,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_1_db_not_there: adapter: <%= adapter %> @@ -81,7 +77,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_1_db_shard_a: adapter: <%= adapter %> @@ -90,7 +85,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_1_db_shard_b: adapter: <%= adapter %> @@ -99,7 +93,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_1_db_shard_b_replica: adapter: <%= adapter %> @@ -108,7 +101,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true replica: true test_pool_1_db_shard_c: @@ -118,7 +110,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true test_pool_1_db_shard_c_replica: adapter: <%= adapter %> @@ -127,7 +118,6 @@ test: username: <%= mysql.user %> password: "<%= mysql.password %>" host: <%= mysql.host %> - reconnect: true replica: true test_pool_2_db_shard_d: @@ -138,7 +128,6 @@ test: password: "<%= mysql.password %>" host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true test_pool_2_db_shard_d_replica: adapter: <%= adapter %> @@ -148,7 +137,6 @@ test: password: "<%= mysql.password %>" host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true replica: true test_pool_2_db_d: @@ -159,7 +147,6 @@ test: password: "<%= mysql.password %>" host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true test_pool_2_db_e: adapter: <%= adapter %> @@ -169,7 +156,6 @@ test: password: "<%= mysql.password %>" host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true test_pool_3_db_e: adapter: <%= adapter %> @@ -179,4 +165,3 @@ test: password: host: <%= mysql.host %> port: <%= mysql.port %> - reconnect: true