Skip to content

Commit

Permalink
Attempt to debug Oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Nov 9, 2020
1 parent d671145 commit a33db9b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/LockModeSQLLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Logging\SQLLogger;

use function microtime;

class LockModeSQLLogger implements SQLLogger
{
/** @var int */
private $cid;

/** @var list<array{cid: int, time: float, sql: string}> */
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<array{cid: int, time: float, sql: string}>
*/
public function getQueries(): array
{
return $this->queries;
}
}
29 changes: 29 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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');

Expand All @@ -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);
Expand Down

0 comments on commit a33db9b

Please sign in to comment.