-
-
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
Open
lcobucci
wants to merge
4
commits into
doctrine:4.2.x
Choose a base branch
from
lcobucci:convert-exceptions-on-begin-transaction
base: 4.2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−15
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
db13704
Kill connection instead of waiting for idle timeout
lcobucci c175a8f
Convert driver exceptions when starting transactions
lcobucci 056546e
Ensure connection lost detection is available for PGSQL
lcobucci 432b89d
Propagate mysqli errors when starting transactions
lcobucci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,43 +9,40 @@ | |
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Tests\TestUtil; | ||
use Doctrine\DBAL\Types\Types; | ||
|
||
use function func_get_args; | ||
use function restore_error_handler; | ||
use function set_error_handler; | ||
use function sleep; | ||
use function sprintf; | ||
|
||
use const E_WARNING; | ||
|
||
class TransactionTest extends FunctionalTestCase | ||
{ | ||
public function testCommitFailure(): void | ||
{ | ||
$this->markConnectionNotReusable(); | ||
|
||
$this->expectConnectionLoss(static function (Connection $connection): void { | ||
$connection->commit(); | ||
}); | ||
} | ||
|
||
public function testRollbackFailure(): void | ||
{ | ||
$this->markConnectionNotReusable(); | ||
|
||
$this->expectConnectionLoss(static function (Connection $connection): void { | ||
$connection->rollBack(); | ||
}); | ||
} | ||
|
||
private function expectConnectionLoss(callable $scenario): void | ||
{ | ||
if (! $this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { | ||
self::markTestSkipped('Restricted to MySQL.'); | ||
} | ||
|
||
$this->connection->executeStatement('SET SESSION wait_timeout=1'); | ||
$this->connection->beginTransaction(); | ||
|
||
// during the sleep MySQL will close the connection | ||
sleep(2); | ||
|
||
$this->killCurrentSession(); | ||
$this->expectException(ConnectionLost::class); | ||
|
||
// prevent the PHPUnit error handler from handling the "MySQL server has gone away" warning | ||
|
@@ -65,6 +62,24 @@ private function expectConnectionLoss(callable $scenario): void | |
} | ||
} | ||
|
||
private function killCurrentSession(): void | ||
{ | ||
$databasePlatform = $this->connection->getDatabasePlatform(); | ||
|
||
[$currentProcessQuery, $killProcessStatement] = match (true) { | ||
$databasePlatform instanceof AbstractMySqlPlatform => ['SELECT CONNECTION_ID()', 'KILL %s'], | ||
default => self::markTestSkipped('Unsupported test platform.'), | ||
}; | ||
|
||
$privilegedConnection = TestUtil::getPrivilegedConnection(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?) |
||
$privilegedConnection->executeStatement( | ||
sprintf( | ||
$killProcessStatement, | ||
$this->connection->executeQuery($currentProcessQuery)->fetchOne(), | ||
), | ||
); | ||
} | ||
|
||
public function testNestedTransactionWalkthrough(): void | ||
{ | ||
if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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