Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky primary key test #48473

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

eileencodes
Copy link
Member

I noticed in a build that this test was flaky and causing subsequent tests to fail with a no connection pool error. I don't entirely get why this test was failing, it's not the only one where we remove a connection. When this test fails, @automatic_reconnect is false. After spending far too much time trying to figure out the combination of tests that break this I decided to fix it by making a brand new connection that we can remove. It's also a more accurate test because we're asserting the connection is actually not connected?. Note that I had to use the connection handler to remove the connection because there is an inconsitency in remove_connection on the model. Unfortunately, NoConnection.remove_connection will cause connected? to fall back to ActiveRecord::Base which is contrary to the behavior of all other methods on the active record models. I'm going to send a PR to fix that but for now this should fix the (rare) flaky test for a primary key with no connection.

To reproduce I used this seed: SEED=29535 bundle exec rake test:mysql2

I noticed in a build that this test was flaky and causing subsequent
tests to fail with a no connection pool error. I don't entirely get why
this test was failing, it's not the only one where we remove a
connection. When this test fails, `@automatic_reconnect` is `false`.
After spending far too much time trying to figure out the combination of
tests that break this I decided to fix it by making a brand new
connection that we can remove. It's also a more accurate test because
we're asserting the connection is actually not `connected?`. Note that I
had to use the connection handler to remove the connection because there
is an inconsitency in remove_connection on the model. Unfortunately,
`NoConnection.remove_connection` will cause `connected?` to fall back to
`ActiveRecord::Base` which is contrary to the behavior of all other
methods on the active record models. I'm going to send a PR to fix that
but for now this should fix the (rare) flaky test for a primary key with
no connection.

To reproduce I used this seed: `SEED=29535 bundle exec rake test:mysql2`
@eileencodes eileencodes merged commit 87d75af into rails:main Jun 14, 2023
9 checks passed
@eileencodes eileencodes deleted the fix-flaky-primary-key-test branch June 14, 2023 17:33
eileencodes added a commit to eileencodes/rails that referenced this pull request Jun 15, 2023
This test was added in rails@b3407c8
at a time when Rails was reading the `primary_keys` off a hash stored on
`connection`. We no longer do that in Active Record so this test isn't
really necessary. I'm removing it because it was flaky. I attempted to
fix it in rails#48473 but realized today it's not testing the same thing it
was before. After discussing it with Matthew, I've decided to remove it.
zzak added a commit to zzak/rails that referenced this pull request Jul 9, 2023
This test was added in rails/rails@b3407c8
at a time when Rails was reading the `primary_keys` off a hash stored on
`connection`. We no longer do that in Active Record so this test isn't
really necessary. I'm removing it because it was flaky. I attempted to
fix it in rails#48473 but realized today it's not testing the same thing it
was before. After discussing it with Matthew, I've decided to remove it.

Co-authored-by: eileencodes <eileencodes@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant