Fix dead lock test sporadic failures
@@ -13,21 +13,48 @@ skip_if_function_not_exist('posix_kill');
<?php
require __DIR__ . '/../include/bootstrap.php';
+use Swow\Signal;
+use Swow\Socket;
+
+$pipePath = getRandomPipePath();
+$syncServer = new Socket(Socket::TYPE_PIPE);
+$syncServer->bind($pipePath)->listen();
+// TODO: new sync component?
+$syncClientNew = function () use ($pipePath) {
+ return new class($pipePath) extends Socket {
+ public function __construct(string $pipePath)
+ {
+ parent::__construct(Socket::TYPE_PIPE);
+ $this->connect($pipePath);
+ }
+
+ public function notify(): void
+ {
+ $this->sendString('x');
+ }
+ };
+};
+
foreach (
[
[
- 'function' => function () {
+ 'function' => function () use ($syncClientNew) {
+ $syncClient = $syncClientNew();
+ $syncClient->notify();
Swow\Coroutine::yield();
echo 'Never here' . PHP_LF;
},
- 'expect_status' => SIGTERM
+ 'expect_status' => Signal::TERM
],
[
- 'function' => function () {
+ 'function' => function () use ($syncClientNew) {
+ $syncClient = $syncClientNew();
+ $syncClient->notify();
Swow\Coroutine::run(function () {
Swow\Coroutine::yield();
echo 'Never here' . PHP_LF;
});
+ $syncClient->notify();
},
'expect_status' => 0
]
@@ -40,9 +67,11 @@ foreach (
if ($child === 0) {
return $item['function']();
} else {
- switchProcess();
- posix_kill($child, SIGTERM);
- switchProcess();
+ $syncConnection = $syncServer->accept();
+ Assert::same($syncConnection->readString(1), 'x'); // wait()
+ if ($item['expect_status'] === Signal::TERM) {
+ Signal::kill($child, Signal::TERM);
+ }
pcntl_wait($status);
Assert::same($status, $item['expect_status']);
}
