Skip to content

Commit

Permalink
add pgsql test
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Dec 25, 2024
1 parent 25837a8 commit c7a95d4
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/swoole_pdo_pgsql/long_running_pgsql_test.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
swoole_pdo_pgsql: long running pgsql test
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
require __DIR__ . '/pdo_pgsql.inc';

use Swoole\Coroutine;
use Swoole\Coroutine\WaitGroup;
use Swoole\Coroutine\Channel;
use function Swoole\Coroutine\run;

Coroutine::set(['hook_flags' => SWOOLE_HOOK_PDO_PGSQL]);
run(function() {
$waitGroup = new WaitGroup();
$channel = new Channel(1);
Coroutine::create(function() use ($waitGroup, $channel) {
$waitGroup->add();
$pdo = pdo_pgsql_test_inc::create();
$pdo->query("SELECT pg_sleep(5);");
$waitGroup->done();
echo 'DONE' . PHP_EOL;
});

Coroutine::create(function() use ($waitGroup, $channel) {
$waitGroup->add();
$result = $channel->pop(2);
if (!$result) {
echo 'channel pop timeout' . PHP_EOL;
}
$waitGroup->done();
});

var_dump(1);
Coroutine::sleep(1);
var_dump(2);
$waitGroup->wait();
});
?>
--EXPECTF--
int(1)
int(2)
channel pop timeout
DONE

0 comments on commit c7a95d4

Please sign in to comment.