1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-04 02:17:44 +01:00
postgres/test/AggregatePoolTest.php
Aaron Piotrowski 88808aa654
Add isAlive() method to connection handles
Used in pool to drop dead connections from the pool automatically.
2017-11-05 15:38:17 -06:00

50 lines
1.6 KiB
PHP

<?php
namespace Amp\Postgres\Test;
use Amp\Postgres\AggregatePool;
class AggregatePoolTest extends AbstractPoolTest {
/**
* @param array $connections
*
* @return \Amp\Postgres\Pool
*/
protected function createPool(array $connections) {
$mock = $this->getMockBuilder(AggregatePool::class)
->setConstructorArgs(['', 0, count($connections)])
->setMethods(['createConnection'])
->getMock();
$mock->method('createConnection')
->will($this->returnCallback(function () {
$this->fail('The createConnection() method should not be called.');
}));
foreach ($connections as $connection) {
$mock->addConnection($connection);
}
return $mock;
}
public function testGetMaxConnections() {
$pool = $this->createPool([$this->createConnection()]);
$this->assertSame(1, $pool->getMaxConnections());
$pool->addConnection($this->createConnection());
$this->assertSame(2, $pool->getMaxConnections());
}
public function testGetConnectionCount() {
$pool = $this->createPool([$this->createConnection(), $this->createConnection()]);
$this->assertSame(2, $pool->getConnectionCount());
}
public function testGetIdleConnectionCount() {
$pool = $this->createPool([$this->createConnection(), $this->createConnection()]);
$this->assertSame(2, $pool->getIdleConnectionCount());
$promise = $pool->query("SELECT 1");
$this->assertSame(1, $pool->getIdleConnectionCount());
}
}