summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-01-23 19:51:15 -0500
committerWolfy-J <[email protected]>2018-01-23 19:51:15 -0500
commit78a42de837928cf7d10a1ae04d7e82e56d66e1e2 (patch)
tree8882b9a051bcc9c42328df583c0bb8c39a89591e /tests
parentfa4bd78d9f7c5f74e8445374370927c742fc4e78 (diff)
API update
Diffstat (limited to 'tests')
-rw-r--r--tests/broken-client.php17
-rw-r--r--tests/broken.php14
-rw-r--r--tests/client.php36
-rw-r--r--tests/delay.php18
-rw-r--r--tests/echo.php (renamed from tests/echo-client.php)11
-rw-r--r--tests/error-client.php16
-rw-r--r--tests/error.php13
-rw-r--r--tests/failboot.php3
-rw-r--r--tests/pid.php17
-rw-r--r--tests/slow-client.php38
10 files changed, 143 insertions, 40 deletions
diff --git a/tests/broken-client.php b/tests/broken-client.php
deleted file mode 100644
index ed5bde20..00000000
--- a/tests/broken-client.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-
-use Spiral\Goridge;
-use Spiral\RoadRunner;
-
-/**
- * echo client over pipes.
- */
-ini_set('display_errors', 'stderr');
-require "vendor/autoload.php";
-
-$rr = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
-
-while ($in = $rr->receive($ctx)) {
- echo undefined_function();
- $rr->send((string)$in);
-} \ No newline at end of file
diff --git a/tests/broken.php b/tests/broken.php
new file mode 100644
index 00000000..b1a3839e
--- /dev/null
+++ b/tests/broken.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
+
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+$rr = new RoadRunner\Worker($relay);
+
+while ($in = $rr->receive($ctx)) {
+ echo undefined_function();
+ $rr->send((string)$in);
+} \ No newline at end of file
diff --git a/tests/client.php b/tests/client.php
new file mode 100644
index 00000000..1f1d21b1
--- /dev/null
+++ b/tests/client.php
@@ -0,0 +1,36 @@
+<?php
+
+use Spiral\Goridge;
+
+ini_set('display_errors', 'stderr');
+require dirname(__DIR__) . "/vendor/autoload.php";
+
+if (count($argv) < 3) {
+ die("need 2 arguments");
+}
+
+list($test, $goridge) = [$argv[1], $argv[2]];
+
+switch ($goridge) {
+ case "pipes":
+ $relay = new Goridge\StreamRelay(STDIN, STDOUT);
+ break;
+
+ case "tcp":
+ $relay = new Goridge\SocketRelay("localhost", 9007);
+ break;
+
+ case "unix":
+ $relay = new Goridge\SocketRelay(
+ "sock.unix",
+ null,
+ Goridge\SocketRelay::SOCK_UNIX
+ );
+
+ break;
+
+ default:
+ die("invalid protocol selection");
+}
+
+require_once sprintf("%s/%s.php", __DIR__, $test); \ No newline at end of file
diff --git a/tests/delay.php b/tests/delay.php
new file mode 100644
index 00000000..bfde2fc4
--- /dev/null
+++ b/tests/delay.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
+
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+$rr = new RoadRunner\Worker($relay);
+
+while ($in = $rr->receive($ctx)) {
+ try {
+ usleep($in * 1000);
+ $rr->send('');
+ } catch (\Throwable $e) {
+ $rr->error((string)$e);
+ }
+} \ No newline at end of file
diff --git a/tests/echo-client.php b/tests/echo.php
index 22761862..ba58ff30 100644
--- a/tests/echo-client.php
+++ b/tests/echo.php
@@ -1,15 +1,12 @@
<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
use Spiral\Goridge;
use Spiral\RoadRunner;
-/**
- * echo client over pipes.
- */
-ini_set('display_errors', 'stderr');
-require "vendor/autoload.php";
-
-$rr = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
+$rr = new RoadRunner\Worker($relay);
while ($in = $rr->receive($ctx)) {
try {
diff --git a/tests/error-client.php b/tests/error-client.php
deleted file mode 100644
index 113d1197..00000000
--- a/tests/error-client.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-use Spiral\Goridge;
-use Spiral\RoadRunner;
-
-/**
- * echo client over pipes.
- */
-ini_set('display_errors', 'stderr');
-require "vendor/autoload.php";
-
-$rr = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
-
-while ($in = $rr->receive($ctx)) {
- $rr->error((string)$in);
-} \ No newline at end of file
diff --git a/tests/error.php b/tests/error.php
new file mode 100644
index 00000000..ebd3418b
--- /dev/null
+++ b/tests/error.php
@@ -0,0 +1,13 @@
+<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
+
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+$rr = new RoadRunner\Worker($relay);
+
+while ($in = $rr->receive($ctx)) {
+ $rr->error((string)$in);
+} \ No newline at end of file
diff --git a/tests/failboot.php b/tests/failboot.php
new file mode 100644
index 00000000..fa8b96f6
--- /dev/null
+++ b/tests/failboot.php
@@ -0,0 +1,3 @@
+<?php
+ini_set('display_errors', 'stderr');
+throw new Error("failboot error"); \ No newline at end of file
diff --git a/tests/pid.php b/tests/pid.php
new file mode 100644
index 00000000..a8cfa229
--- /dev/null
+++ b/tests/pid.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
+
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+$rr = new RoadRunner\Worker($relay);
+
+while ($in = $rr->receive($ctx)) {
+ try {
+ $rr->send((string)getmypid());
+ } catch (\Throwable $e) {
+ $rr->error((string)$e);
+ }
+} \ No newline at end of file
diff --git a/tests/slow-client.php b/tests/slow-client.php
new file mode 100644
index 00000000..f09142b5
--- /dev/null
+++ b/tests/slow-client.php
@@ -0,0 +1,38 @@
+<?php
+
+use Spiral\Goridge;
+
+ini_set('display_errors', 'stderr');
+require dirname(__DIR__) . "/vendor/autoload.php";
+
+if (count($argv) < 3) {
+ die("need 2 arguments");
+}
+
+list($test, $goridge, $bootDelay, $shutdownDelay) = [$argv[1], $argv[2], $argv[3], $argv[4]];
+
+switch ($goridge) {
+ case "pipes":
+ $relay = new Goridge\StreamRelay(STDIN, STDOUT);
+ break;
+
+ case "tcp":
+ $relay = new Goridge\SocketRelay("localhost", 9007);
+ break;
+
+ case "unix":
+ $relay = new Goridge\SocketRelay(
+ "sock.unix",
+ null,
+ Goridge\SocketRelay::SOCK_UNIX
+ );
+
+ break;
+
+ default:
+ die("invalid protocol selection");
+}
+
+usleep($bootDelay * 1000);
+require_once sprintf("%s/%s.php", __DIR__, $test);
+usleep($shutdownDelay * 1000); \ No newline at end of file