-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Convert driver exceptions when starting transactions #6812
base: 4.2.x
Are you sure you want to change the base?
Convert driver exceptions when starting transactions #6812
Conversation
Let's get it integration-tested. Even though the unit test passes, and the code works as expected on MySQL, we want to be sure that it works the same on other platforms as well or at least know that it doesn't. |
This optimises how this test is executed by leveraging two connections and killing the one executing the tests. It also aims at making the whole conversion process available to other platforms. Signed-off-by: Luís Cobucci <[email protected]>
For long-running processes, it's possible that the wrapped connection is no longer valid and starting a transaction will lead to driver exceptions. DBAL Connection wasn't converting these, leaking internal details of the platform and not providing a consistent API (all other methods would throw a `ConnectionLost` exception for the scenario above). This ensures we do have the expected behaviour for this edge-case. Signed-off-by: Luís Cobucci <[email protected]>
5fa77a9
to
5c1255f
Compare
default => self::markTestSkipped('Unsupported test platform.'), | ||
}; | ||
|
||
$privilegedConnection = TestUtil::getPrivilegedConnection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using priviledged connection here, assuming that's a requirement for other platforms (maybe oracle or SQL server?)
|
||
use const E_WARNING; | ||
|
||
class TransactionTest extends FunctionalTestCase | ||
{ | ||
public function testCommitFailure(): void | ||
{ | ||
$this->markConnectionNotReusable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking as not reusable as I didn't want for a failure in one test to leak into the other
if ( | ||
$exception->getSQLState() === 'HY000' | ||
&& str_contains($exception->getMessage(), 'server closed the connection') | ||
) { | ||
return new ConnectionLost($exception, $query); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might only be applicable for recent PGSQL versions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah... only PDO has the SQL State set for this error :)
Ooohh I missed working with DBAL 😅
75ced17
to
6e47746
Compare
This extends the functional test for connection loss detection to verify the behaviour against Postgres and ensures the ExceptionConverter for that API behaves as expected. Signed-off-by: Luís Cobucci <[email protected]>
This is required because the MySQLi API only returns a boolean result that we were simply not using. Signed-off-by: Luís Cobucci <[email protected]>
6e47746
to
432b89d
Compare
Summary
The wrapped connection may no longer be valid for long-running processes, and starting a transaction will cause driver exceptions.
DBAL Connection wasn't converting these, leaking internal details of the platform and not providing a consistent API (all other methods would throw a
ConnectionLost
exception for the scenario above).This ensures we do have the expected behaviour for this edge case.