-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from ionutf6s/database_connection_not_released
Fix issue with connection not released in specific scenario
- Loading branch information
Showing
2 changed files
with
58 additions
and
9 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
47 changes: 47 additions & 0 deletions
47
test/integration/Adapter/Driver/Pdo/Mysql/TableGatewayAndAdapterTest.php
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,47 @@ | ||
<?php | ||
|
||
namespace LaminasIntegrationTest\Db\Adapter\Driver\Pdo\Mysql; | ||
|
||
use Laminas\Db\TableGateway\TableGateway; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
use function array_fill; | ||
|
||
/** | ||
* Usually mysql has 151 max connections by default. | ||
* Set up a test where executed Laminas\Db\Adapter\Adapter::query and then using table gateway to fetch a row | ||
* On tear down disconnected from the database and set the driver adapter on null | ||
* Running many tests ended up in consuming all mysql connections and not releasing them | ||
*/ | ||
class TableGatewayAndAdapterTest extends TestCase | ||
{ | ||
use AdapterTrait; | ||
|
||
/** | ||
* @dataProvider connections | ||
*/ | ||
public function testGetOutOfConnections(): void | ||
{ | ||
$this->adapter->query('SELECT VERSION();'); | ||
$table = new TableGateway( | ||
'test', | ||
$this->adapter | ||
); | ||
$select = $table->getSql()->select()->where(['name' => 'foo']); | ||
$result = $table->selectWith($select); | ||
self::assertCount(3, $result->current()); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
if ($this->adapter->getDriver()->getConnection()->isConnected()) { | ||
$this->adapter->getDriver()->getConnection()->disconnect(); | ||
} | ||
$this->adapter = null; | ||
} | ||
|
||
public function connections(): array | ||
{ | ||
return array_fill(0, 200, []); | ||
} | ||
} |