Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
DevZer0x00 committed Mar 1, 2024
1 parent 68ace75 commit 7f56fe0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/unit/Database/PDOPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Swoole\Coroutine;
use Swoole\Coroutine\WaitGroup;
use Swoole\Exception\TimeoutException;
use Swoole\Tests\HookFlagsTrait;

use function Swoole\Coroutine\go;
Expand Down Expand Up @@ -216,4 +217,39 @@ public function testSqlite(): void
self::restoreHookFlags();
});
}

public function testTimeoutException()
{
self::saveHookFlags();
self::setHookFlags(SWOOLE_HOOK_ALL);
run(function () use (&$timeoutOccured) {
$config = (new PDOConfig())
->withHost(MYSQL_SERVER_HOST)
->withPort(MYSQL_SERVER_PORT)
->withDbName(MYSQL_SERVER_DB)
->withCharset('utf8mb4')
->withUsername(MYSQL_SERVER_USER)
->withPassword(MYSQL_SERVER_PWD)
;

$pool = new PDOPool($config, 1);
$timeoutOccured = false;
go(function () use ($pool, &$timeoutOccured) {
try {
$pool->get(2);
} catch (TimeoutException) {
$timeoutOccured = true;
}
});

go(function () use ($pool) {
$pdo = $pool->get(1);
$pdo->exec('SELECT SLEEP(2)');
});
});

$this->assertTrue($timeoutOccured);

self::restoreHookFlags();
}
}

0 comments on commit 7f56fe0

Please sign in to comment.