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

railtie: Fix connection pools #72

Merged
merged 1 commit into from
Jan 25, 2024
Merged

Conversation

ethan-readyset
Copy link
Contributor

Previously, the readyset.connection_pool railtie was setting up the connection pool for the gem by calling
ConnectionHandler.establish_connection, which was resulting in the connection pool's database key being set to that of the primary database instead of "readyset". This commit resolves the issue by relying directly on ActiveRecord::Base.establish_connection to set up the connection pool. It also adds unit test converage to ensure the connection pool is set up as expected.

Previously, the `readyset.connection_pool` railtie was setting up the
connection pool for the gem by calling
`ConnectionHandler.establish_connection`, which was resulting in the
connection pool's database key being set to that of the primary database
instead of "readyset". This commit resolves the issue by relying
directly on `ActiveRecord::Base.establish_connection` to set up the
connection pool. It also adds unit test converage to ensure the
connection pool is set up as expected.
pools = ActiveRecord::Base.connection_handler.connection_pools
readyset_pool = pools.find { |pool| pool.shard == Readyset.config.shard }

expect(readyset_pool).not_to be_nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is the nil expectation here just in-case the bottom two expectations turn up nil? 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to make explicit that a connection pool for Readyset should exist at that point

@helpotters helpotters added this pull request to the merge queue Jan 25, 2024
Merged via the queue into main with commit 59a6a1a Jan 25, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants