diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/broken.php | 4 | ||||
-rw-r--r-- | tests/client.php | 2 | ||||
-rw-r--r-- | tests/composer.json | 13 | ||||
-rw-r--r-- | tests/delay.php | 4 | ||||
-rw-r--r-- | tests/echo.php | 4 | ||||
-rw-r--r-- | tests/error.php | 4 | ||||
-rw-r--r-- | tests/head.php | 4 | ||||
-rw-r--r-- | tests/http/client.php | 14 | ||||
-rw-r--r-- | tests/http/slow-client.php | 18 | ||||
-rw-r--r-- | tests/http/upload.php | 2 | ||||
-rw-r--r-- | tests/memleak.php | 15 | ||||
-rw-r--r-- | tests/pid.php | 2 | ||||
-rw-r--r-- | tests/psr-worker-bench.php | 28 | ||||
-rw-r--r-- | tests/psr-worker.php | 28 | ||||
-rw-r--r-- | tests/sleep.php | 15 | ||||
-rw-r--r-- | tests/slow-client.php | 2 | ||||
-rw-r--r-- | tests/slow-destroy.php | 2 | ||||
-rw-r--r-- | tests/slow-pid.php | 2 | ||||
-rw-r--r-- | tests/stop.php | 2 |
19 files changed, 138 insertions, 27 deletions
diff --git a/tests/broken.php b/tests/broken.php index 42b4e7c2..1f869b2d 100644 --- a/tests/broken.php +++ b/tests/broken.php @@ -8,7 +8,7 @@ use Spiral\RoadRunner; $rr = new RoadRunner\Worker($relay); -while ($in = $rr->receive($ctx)) { +while ($in = $rr->waitPayload()) { echo undefined_function(); - $rr->send((string)$in); + $rr->send((string)$in->body, null); } diff --git a/tests/client.php b/tests/client.php index 835b1c6c..c00cece1 100644 --- a/tests/client.php +++ b/tests/client.php @@ -3,7 +3,7 @@ use Spiral\Goridge; ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/vendor_php/autoload.php"; +require __DIR__ . "/vendor/autoload.php"; if (count($argv) < 3) { die("need 2 arguments"); diff --git a/tests/composer.json b/tests/composer.json new file mode 100644 index 00000000..d4f32be5 --- /dev/null +++ b/tests/composer.json @@ -0,0 +1,13 @@ +{ + "minimum-stability": "beta", + "require": { + "nyholm/psr7": "^1.3", + "spiral/roadrunner": "^2.0", + "spiral/roadrunner-http": "^2.0" + }, + "autoload": { + "psr-4": { + "Spiral\\RoadRunner\\": "src/" + } + } +} diff --git a/tests/delay.php b/tests/delay.php index bf9ecc12..f0435b05 100644 --- a/tests/delay.php +++ b/tests/delay.php @@ -8,9 +8,9 @@ use Spiral\RoadRunner; $rr = new RoadRunner\Worker($relay); -while ($in = $rr->receive($ctx)) { +while ($in = $rr->waitPayload()) { try { - usleep($in * 1000); + usleep($in->body * 1000); $rr->send(''); } catch (\Throwable $e) { $rr->error((string)$e); diff --git a/tests/echo.php b/tests/echo.php index 1570e3df..83eec92e 100644 --- a/tests/echo.php +++ b/tests/echo.php @@ -8,9 +8,9 @@ use Spiral\RoadRunner; $rr = new RoadRunner\Worker($relay); -while ($in = $rr->receive($ctx)) { +while ($in = $rr->waitPayload()) { try { - $rr->send((string)$in); + $rr->send((string)$in->body); } catch (\Throwable $e) { $rr->error((string)$e); } diff --git a/tests/error.php b/tests/error.php index 8e1c8d0d..c77e6817 100644 --- a/tests/error.php +++ b/tests/error.php @@ -8,6 +8,6 @@ use Spiral\RoadRunner; $rr = new RoadRunner\Worker($relay); -while ($in = $rr->receive($ctx)) { - $rr->error((string)$in); +while ($in = $rr->waitPayload()) { + $rr->error((string)$in->body); } diff --git a/tests/head.php b/tests/head.php index 88ebd3f2..3c57258f 100644 --- a/tests/head.php +++ b/tests/head.php @@ -8,9 +8,9 @@ use Spiral\RoadRunner; $rr = new RoadRunner\Worker($relay); -while ($in = $rr->receive($ctx)) { +while ($in = $rr->waitPayload()) { try { - $rr->send("", (string)$ctx); + $rr->send("", (string)$in->header); } catch (\Throwable $e) { $rr->error((string)$e); } diff --git a/tests/http/client.php b/tests/http/client.php index 9f21b273..ad5cce24 100644 --- a/tests/http/client.php +++ b/tests/http/client.php @@ -4,7 +4,7 @@ use Spiral\Goridge; use Spiral\RoadRunner; ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/../vendor_php/autoload.php"; +require dirname(__DIR__) . "/vendor/autoload.php"; if (count($argv) < 3) { die("need 2 arguments"); @@ -33,12 +33,18 @@ switch ($goridge) { die("invalid protocol selection"); } -$psr7 = new RoadRunner\PSR7Client(new RoadRunner\Worker($relay)); +$psr7 = new RoadRunner\Http\PSR7Worker( + new RoadRunner\Worker($relay), + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory() +); + require_once sprintf("%s/%s.php", __DIR__, $test); -while ($req = $psr7->acceptRequest()) { +while ($req = $psr7->waitRequest()) { try { - $psr7->respond(handleRequest($req, new \Zend\Diactoros\Response())); + $psr7->respond(handleRequest($req, new \Nyholm\Psr7\Response())); } catch (\Throwable $e) { $psr7->getWorker()->error((string)$e); } diff --git a/tests/http/slow-client.php b/tests/http/slow-client.php index 4d3963d7..731232f7 100644 --- a/tests/http/slow-client.php +++ b/tests/http/slow-client.php @@ -4,13 +4,13 @@ use Spiral\Goridge; use Spiral\RoadRunner; ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/../vendor_php/autoload.php"; +require dirname(__DIR__) . "/vendor/autoload.php"; if (count($argv) < 3) { die("need 2 arguments"); } -list($test, $goridge, $bootDelay) = [$argv[1], $argv[2], $argv[3]]; +[$test, $goridge, $bootDelay] = [$argv[1], $argv[2], $argv[3]]; usleep($bootDelay * 1000); switch ($goridge) { @@ -34,13 +34,19 @@ switch ($goridge) { die("invalid protocol selection"); } -$psr7 = new RoadRunner\PSR7Client(new RoadRunner\Worker($relay)); +$psr7 = new RoadRunner\Http\PSR7Worker( + new RoadRunner\Worker($relay), + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory() +); + require_once sprintf("%s/%s.php", __DIR__, $test); -while ($req = $psr7->acceptRequest()) { +while ($req = $psr7->waitRequest()) { try { - $psr7->respond(handleRequest($req, new \Zend\Diactoros\Response())); + $psr7->respond(handleRequest($req, new \Nyholm\Psr7\Response())); } catch (\Throwable $e) { - $psr7->getWorker()->error((string)$e); + $psr7->getWorker()->error((string) $e); } } diff --git a/tests/http/upload.php b/tests/http/upload.php index bb4af766..57526246 100644 --- a/tests/http/upload.php +++ b/tests/http/upload.php @@ -24,7 +24,7 @@ function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): Re 'size' => $v->getSize(), 'mime' => $v->getClientMediaType(), 'error' => $v->getError(), - 'md5' => md5($v->getStream()->__toString()), + 'sha512' => hash('sha512', $v->getStream()->__toString()), ]; } }); diff --git a/tests/memleak.php b/tests/memleak.php new file mode 100644 index 00000000..9a5376f0 --- /dev/null +++ b/tests/memleak.php @@ -0,0 +1,15 @@ +<?php + +declare(strict_types=1); + +use Spiral\Goridge\StreamRelay; +use Spiral\RoadRunner\Worker as RoadRunner; + +require __DIR__ . "/vendor/autoload.php"; + +$rr = new RoadRunner(new StreamRelay(\STDIN, \STDOUT)); +$mem = ''; +while($rr->waitPayload()){ + $mem .= str_repeat(" ", 1024*1024); + $rr->send(""); +} diff --git a/tests/pid.php b/tests/pid.php index bf10a025..f8b2515d 100644 --- a/tests/pid.php +++ b/tests/pid.php @@ -8,7 +8,7 @@ $rr = new RoadRunner\Worker($relay); - while ($in = $rr->receive($ctx)) { + while ($in = $rr->waitPayload()) { try { $rr->send((string)getmypid()); } catch (\Throwable $e) { diff --git a/tests/psr-worker-bench.php b/tests/psr-worker-bench.php new file mode 100644 index 00000000..e6df81ad --- /dev/null +++ b/tests/psr-worker-bench.php @@ -0,0 +1,28 @@ +<?php +/** + * @var Goridge\RelayInterface $relay + */ +use Spiral\Goridge; +use Spiral\RoadRunner; + +ini_set('display_errors', 'stderr'); +require __DIR__ . "/vendor/autoload.php"; + +$worker = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT)); +$psr7 = new RoadRunner\Http\PSR7Worker( + $worker, + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory() +); + +while ($req = $psr7->waitRequest()) { + try { + $resp = new \Nyholm\Psr7\Response(); + $resp->getBody()->write("hello world"); + + $psr7->respond($resp); + } catch (\Throwable $e) { + $psr7->getWorker()->error((string)$e); + } +} diff --git a/tests/psr-worker.php b/tests/psr-worker.php new file mode 100644 index 00000000..db53eee2 --- /dev/null +++ b/tests/psr-worker.php @@ -0,0 +1,28 @@ +<?php +/** + * @var Goridge\RelayInterface $relay + */ +use Spiral\Goridge; +use Spiral\RoadRunner; + +ini_set('display_errors', 'stderr'); +require __DIR__ . "/vendor/autoload.php"; + +$worker = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT)); +$psr7 = new RoadRunner\Http\PSR7Worker( + $worker, + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory(), + new \Nyholm\Psr7\Factory\Psr17Factory() +); + +while ($req = $psr7->waitRequest()) { + try { + $resp = new \Nyholm\Psr7\Response(); + $resp->getBody()->write(str_repeat("hello world", 1000)); + + $psr7->respond($resp); + } catch (\Throwable $e) { + $psr7->getWorker()->error((string)$e); + } +} diff --git a/tests/sleep.php b/tests/sleep.php new file mode 100644 index 00000000..e34a6834 --- /dev/null +++ b/tests/sleep.php @@ -0,0 +1,15 @@ +<?php + +declare(strict_types=1); + +use Spiral\Goridge\StreamRelay; +use Spiral\RoadRunner\Worker as RoadRunner; + +require __DIR__ . "/vendor/autoload.php"; + +$rr = new RoadRunner(new StreamRelay(\STDIN, \STDOUT)); + +while($rr->waitPayload()){ + sleep(3); + $rr->send(""); +} diff --git a/tests/slow-client.php b/tests/slow-client.php index ece0a439..7737f0b1 100644 --- a/tests/slow-client.php +++ b/tests/slow-client.php @@ -3,7 +3,7 @@ use Spiral\Goridge; ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/vendor_php/autoload.php"; +require __DIR__ . "/vendor/autoload.php"; if (count($argv) < 3) { die("need 2 arguments"); diff --git a/tests/slow-destroy.php b/tests/slow-destroy.php index e2a01af2..900bb68a 100644 --- a/tests/slow-destroy.php +++ b/tests/slow-destroy.php @@ -3,7 +3,7 @@ use Spiral\Goridge; ini_set('display_errors', 'stderr'); -require dirname(__DIR__) . "/vendor_php/autoload.php"; +require __DIR__ . "/vendor/autoload.php"; if (count($argv) < 3) { die("need 2 arguments"); diff --git a/tests/slow-pid.php b/tests/slow-pid.php index 747e7e86..3660cb40 100644 --- a/tests/slow-pid.php +++ b/tests/slow-pid.php @@ -8,7 +8,7 @@ $rr = new RoadRunner\Worker($relay); - while ($in = $rr->receive($ctx)) { + while ($in = $rr->waitPayload()) { try { sleep(1); $rr->send((string)getmypid()); diff --git a/tests/stop.php b/tests/stop.php index 0100ad0f..f83d3f29 100644 --- a/tests/stop.php +++ b/tests/stop.php @@ -9,7 +9,7 @@ use Spiral\RoadRunner; $rr = new RoadRunner\Worker($relay); $used = false; -while ($in = $rr->receive($ctx)) { +while ($in = $rr->waitPayload()) { try { if ($used) { // kill on second attempt |