Skip to content

Commit

Permalink
Drop reconnect: true from DB configs
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
HeyNonster committed Apr 3, 2024
1 parent 15ca49f commit 7015d7d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 23 deletions.
8 changes: 0 additions & 8 deletions test/database.yml
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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 %>
Expand All @@ -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 %>
Expand All @@ -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 %>
Expand All @@ -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 %>
Expand All @@ -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
Expand All @@ -107,4 +100,3 @@ test_pool_1_db_c:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true
2 changes: 2 additions & 0 deletions test/test_arhp.rb
Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions test/three_tier_database.yml
Expand Up @@ -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:
Expand All @@ -53,7 +52,6 @@ test:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true
replica: true

test_pool_1_db_b:
Expand All @@ -63,7 +61,6 @@ test:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true

test_pool_1_db_c:
adapter: <%= adapter %>
Expand All @@ -72,7 +69,6 @@ test:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true

test_pool_1_db_not_there:
adapter: <%= adapter %>
Expand All @@ -81,7 +77,6 @@ test:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true

test_pool_1_db_shard_a:
adapter: <%= adapter %>
Expand All @@ -90,7 +85,6 @@ test:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true

test_pool_1_db_shard_b:
adapter: <%= adapter %>
Expand All @@ -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 %>
Expand All @@ -108,7 +101,6 @@ test:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true
replica: true

test_pool_1_db_shard_c:
Expand All @@ -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 %>
Expand All @@ -127,7 +118,6 @@ test:
username: <%= mysql.user %>
password: "<%= mysql.password %>"
host: <%= mysql.host %>
reconnect: true
replica: true

test_pool_2_db_shard_d:
Expand All @@ -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 %>
Expand All @@ -148,7 +137,6 @@ test:
password: "<%= mysql.password %>"
host: <%= mysql.host %>
port: <%= mysql.port %>
reconnect: true
replica: true

test_pool_2_db_d:
Expand All @@ -159,7 +147,6 @@ test:
password: "<%= mysql.password %>"
host: <%= mysql.host %>
port: <%= mysql.port %>
reconnect: true

test_pool_2_db_e:
adapter: <%= adapter %>
Expand All @@ -169,7 +156,6 @@ test:
password: "<%= mysql.password %>"
host: <%= mysql.host %>
port: <%= mysql.port %>
reconnect: true

test_pool_3_db_e:
adapter: <%= adapter %>
Expand All @@ -179,4 +165,3 @@ test:
password:
host: <%= mysql.host %>
port: <%= mysql.port %>
reconnect: true

0 comments on commit 7015d7d

Please sign in to comment.