-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In long-running processes, allows checking the database connection by…
… pinging it, thus avoiding exceptions. Additionally, it provides the flexibility to configure the frequency of the check to be performed in the case of long-running processes.
- Loading branch information
Showing
5 changed files
with
105 additions
and
5 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Connection; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
|
||
use function sleep; | ||
|
||
class ConnectionReactivatedTest extends FunctionalTestCase | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::markConnectionWithHeartBeat(); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
if ($this->connection->getDatabasePlatform() instanceof AbstractMySQLPlatform) { | ||
return; | ||
} | ||
|
||
self::markTestSkipped('Currently only supported with MySQL'); | ||
} | ||
|
||
public function testConnectionReactivated(): void | ||
{ | ||
$this->connection->executeStatement('SET SESSION wait_timeout=1'); | ||
|
||
sleep(2); | ||
|
||
$query = $this->connection->getDatabasePlatform() | ||
->getDummySelectSQL(); | ||
|
||
$this->connection->executeQuery($query); | ||
|
||
self::assertEquals(1, $this->connection->fetchOne($query)); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -62,7 +62,7 @@ class TestUtil | |
* | ||
* @return Connection The database connection instance. | ||
*/ | ||
public static function getConnection(): Connection | ||
public static function getConnection($hasHeartBeat = false): Connection | ||
Check failure on line 65 in tests/TestUtil.php GitHub Actions / Coding Standards / Coding Standards (8.3)
Check failure on line 65 in tests/TestUtil.php GitHub Actions / Static Analysis with PHPStan (8.3)
|
||
{ | ||
$params = self::getConnectionParams(); | ||
|
||
|
@@ -75,7 +75,7 @@ public static function getConnection(): Connection | |
|
||
return DriverManager::getConnection( | ||
$params, | ||
self::createConfiguration($params['driver']), | ||
self::createConfiguration($params['driver'], $hasHeartBeat), | ||
); | ||
} | ||
|
||
|
@@ -153,7 +153,7 @@ private static function initializeDatabase(): void | |
$privConn->close(); | ||
} | ||
|
||
private static function createConfiguration(string $driver): Configuration | ||
private static function createConfiguration(string $driver, $hasHearBeat): Configuration | ||
Check failure on line 156 in tests/TestUtil.php GitHub Actions / Coding Standards / Coding Standards (8.3)
Check failure on line 156 in tests/TestUtil.php GitHub Actions / Static Analysis with PHPStan (8.3)
|
||
{ | ||
$configuration = new Configuration(); | ||
|
||
|
@@ -170,6 +170,10 @@ private static function createConfiguration(string $driver): Configuration | |
|
||
$configuration->setSchemaManagerFactory(new DefaultSchemaManagerFactory()); | ||
|
||
if ($hasHearBeat) { | ||
$configuration->setCheckConnectionTiming(1); | ||
} | ||
|
||
return $configuration; | ||
} | ||
|
||
|