Fix UDG test failure
@@ -14,23 +14,20 @@ use Swow\Socket;
use Swow\Sync\WaitReference;
use const Swow\Errno\ECANCELED;
-if (PHP_OS_FAMILY === 'Linux') {
+// TODO: test both file and abstract name
+if (PHP_OS_FAMILY === 'Linux' && mt_rand(0, 1)) {
/* linux abstract name */
- if (mt_rand(0, 1)) {
- define('SERVER_SOCK', '');
- define('CLIENT_SOCK', '');
- } else {
define('SERVER_SOCK', "\0swow_server_" . getRandomBytes(8));
define('CLIENT_SOCK', "\0swow_client_" . getRandomBytes(8));
- }
} else {
define('SERVER_SOCK', '/tmp/swow_server_' . getRandomBytes(8) . '.sock');
define('CLIENT_SOCK', '/tmp/swow_client_' . getRandomBytes(8) . '.sock');
}
foreach ([false, true] as $useConnect) {
+ $wrs = new WaitReference();
$server = new Socket(Socket::TYPE_UDG);
- Coroutine::run(function () use ($server) {
+ Coroutine::run(function () use ($server, $wrs) {
$server->bind(SERVER_SOCK);
try {
while (true) {
@@ -71,9 +68,11 @@ foreach ([false, true] as $useConnect) {
}
}
- WaitReference::wait($wr);
+ WaitReference::wait($wr); /* wait read done */
$client->close();
+
$server->close();
+ WaitReference::wait($wrs); /* wait server closed */
}
echo 'Done' . PHP_LF;
