Closed prohalexey closed 5 months ago
How exactly does your doctrine dbal config look like for the test environment?
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(DATABASE_URL)%'
server_version: "8.0.31"
use_savepoints: true
options:
# some TLS settings
master:
url: '%env(MASTER_DATABASE_URL)%'
server_version: "8.0.31"
use_savepoints: true
options:
# some TLS settings
replicas:
replica1:
url: '%env(DATABASE_URL)%'
mapping_types:
enum: string
You mentioned
For the tests I want to have 1 connection to two local databases without replication
But that is not what you have configured? You have
default
with env(DATABASE_URL)
master
with primay env(MASTER_DATABASE_URL)
and replica env(DATABASE_URL)
So the default and read replica connection are using the exact same database? Interesting setup :thinking:
Production: Code reads and writes to the LOCAL DB and MASTER GLOBAL SERVER and read from REPLICA DB FROM MASTER
--- |----MASTER GLOBAL SERVER---| ---
| | A data center | |
|--------LOCAL SERVER--------| |--------LOCAL SERVER--------|
| B data center | | C data center |
| 1. LOCAL DB | | 1. LOCAL DB |
| 2. REPLICA DB FROM MASTER | | 2. REPLICA DB FROM MASTER |
Test: 2 connections with the same connection params to the 1 database
In the end this is related to https://github.com/dmaicher/doctrine-test-bundle/issues/289
I'm not sure how to fix this properly yet. I don't see StaticDriver
as an extension point really :confused:
Now I wrote a copy of your StaticDriver with changes in param hash and did
class ConnectionIsolationBreakerMiddleware implements Middleware
{
public function wrap(Driver $driver): Driver
{
return new ExtendedStaticDriver($driver);
}
}
And add into services_test.yaml
# Removing isolation between default and master connections
doctrine.logging.middleware.connection_isolation_breaker:
class: Tests\ConnectionIsolationBreakerMiddleware
And set keep static connection to the true in the bootstrap.php(phpunit)
ExtendedStaticDriver::setKeepStaticConnections(true);
But this is not the best way, because I have to rewrite this every time you release :))
See https://github.com/dmaicher/doctrine-test-bundle/issues/289#issuecomment-2079076089
I think this should solve such problems
@dmaicher Yes, closing this PR.
Hi! I use this package to run tests, but have some troubles with it.
I have 2 connections to different databases in the production. Master server had one database and local servers that have their own databases and database replicated from master server. Doctrine have 2 connections. For the tests I want to have 1 connection to two local databases without replication. But they have different SHA hash string, and I cannot see transactions that I made with first database on the second connenction.
With this changes I will be able to extend StaticDriver and get hash from only a few parameters, for example: