Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
For fixtures share the connection pool when there are multiple handlers #34773
This PR "fixes" the fixtures so that when there are 2 connections (primary & replica) to a database the tests can see data inserted during the test run on the primary connections. We can't actually use replica connections in tests because Rails keeps a transaction open in order to rollback. I've explained in detail below.
This is kind of hacky but I'm not sure there's a better way to make sure the replica connections can see data inserted on the primary connections.
In an application that has a primary and replica database the data
In a test like this:
The home inserted in the beginning of the test can't be read by the
Because the data isn't actually committed to the database the replica
I considered a couple ways to fix this. I could have written a database
In GitHub we solve this by sharing the connection pool for the replicas
In this PR the code loops through the handlers. If the handler doesn't
Then in enlist_fixture_connections it maps all the connections for the
The test uses a temporary connection pool so we can test this with
changed the title
Share the connection pool when there are multiple handlers
Dec 21, 2018
I fixed the sqlite memory tests by creating a temporary connection pool. This isn't necessary for the other adapters but the sqlite memory ones break if I create new connection handlers and connections while running. I didn't want to skip sqlite memory for this because it's kind of hacky and I'd like all adapters to be testing it. The temp connection pool is the same method the query cache tests use.
Jan 4, 2019
How this works in a multi-tenant environment? The two connections needs to have different data. In the tenant 1, user A should exist but in the tenant 2, only user B should exists.
Does the solution here makes harder to implement a multi-tenant approach to fixtures like #34246?
A multi-tenant environment would have different specification names for tenant 1 and tenant 2 right? This only ties a primary and replica together if they have the same connection specification name.
So a case where we need multiple directories for fixtures is still broken but this at least fixes the fact that a replica can't see a primary in tests.