From a33db9b3b785577d947068039c63e725ae75e4d9 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Mon, 9 Nov 2020 10:06:34 +0100 Subject: [PATCH] Attempt to debug Oracle --- .../DBAL/Functional/LockModeSQLLogger.php | 47 +++++++++++++++++++ .../Tests/DBAL/Functional/LockModeTest.php | 29 ++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/LockModeSQLLogger.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/LockModeSQLLogger.php b/tests/Doctrine/Tests/DBAL/Functional/LockModeSQLLogger.php new file mode 100644 index 00000000000..812b8791977 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/LockModeSQLLogger.php @@ -0,0 +1,47 @@ + */ + private $queries = []; + + public function __construct(int $cid) + { + $this->cid = $cid; + } + + /** + * @inheritDoc + */ + public function startQuery($sql, ?array $params = null, ?array $types = null): void + { + $this->queries[] = [ + 'cid' => $this->cid, + 'time' => microtime(true), + 'sql' => $sql, + ]; + } + + public function stopQuery(): void + { + } + + /** + * @return list + */ + public function getQueries(): array + { + return $this->queries; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php b/tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php index e4bcbe449ef..53c9132eed7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php @@ -13,6 +13,9 @@ use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\TestUtil; +use function array_merge; +use function usort; + class LockModeTest extends DbalTestCase { /** @var Connection */ @@ -21,11 +24,20 @@ class LockModeTest extends DbalTestCase /** @var Connection */ private $c2; + /** @var LockModeSQLLogger */ + private $c1Logger; + + /** @var LockModeSQLLogger */ + private $c2Logger; + public function setUp(): void { $this->c1 = TestUtil::getConnection(); $this->c2 = TestUtil::getConnection(); + $this->c1->getConfiguration()->setSQLLogger($this->c1Logger = new LockModeSQLLogger(1)); + $this->c2->getConfiguration()->setSQLLogger($this->c2Logger = new LockModeSQLLogger(2)); + $table = new Table('users'); $table->addColumn('id', 'integer'); @@ -48,10 +60,27 @@ public function tearDown(): void $this->c1->close(); $this->c2->close(); + + $queries = array_merge( + $this->c1Logger->getQueries(), + $this->c2Logger->getQueries() + ); + + usort($queries, static function (array $a, array $b) { + return $a['time'] - $b['time']; + }); + + echo "\n"; + + foreach ($queries as $query) { + echo 'C' . $query['cid'] . ': ' . $query['sql'] . "\n"; + } } public function testLockModeNoneDoesNotBreakTransactionIsolation(): void { + $this->c1->getConfiguration()->setSQLLogger(); + try { $this->c1->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED); $this->c2->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);