summaryrefslogtreecommitdiff
path: root/php/tests
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-05-29 13:03:34 +0300
committerWolfy-J <[email protected]>2018-05-29 13:03:34 +0300
commitb8bc792b263a3891e125757a35cc563bb85f1a0b (patch)
treef7a9e6f2568220491a26f6544e4acf0ed62012bb /php/tests
parent50f820833eeef8518b3b978b33c6f20391225162 (diff)
nested observers
Diffstat (limited to 'php/tests')
-rw-r--r--php/tests/broken.php14
-rw-r--r--php/tests/client.php35
-rw-r--r--php/tests/delay.php18
-rw-r--r--php/tests/echo.php17
-rw-r--r--php/tests/error.php13
-rw-r--r--php/tests/failboot.php3
-rw-r--r--php/tests/head.php17
-rw-r--r--php/tests/pid.php17
-rw-r--r--php/tests/slow-client.php38
-rw-r--r--php/tests/stop.php25
10 files changed, 197 insertions, 0 deletions
diff --git a/php/tests/broken.php b/php/tests/broken.php
new file mode 100644
index 00000000..b1a3839e
--- /dev/null
+++ b/php/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/php/tests/client.php b/php/tests/client.php
new file mode 100644
index 00000000..31caa410
--- /dev/null
+++ b/php/tests/client.php
@@ -0,0 +1,35 @@
+<?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);
diff --git a/php/tests/delay.php b/php/tests/delay.php
new file mode 100644
index 00000000..bfde2fc4
--- /dev/null
+++ b/php/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/php/tests/echo.php b/php/tests/echo.php
new file mode 100644
index 00000000..ba58ff30
--- /dev/null
+++ b/php/tests/echo.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)$in);
+ } catch (\Throwable $e) {
+ $rr->error((string)$e);
+ }
+} \ No newline at end of file
diff --git a/php/tests/error.php b/php/tests/error.php
new file mode 100644
index 00000000..ebd3418b
--- /dev/null
+++ b/php/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/php/tests/failboot.php b/php/tests/failboot.php
new file mode 100644
index 00000000..fa8b96f6
--- /dev/null
+++ b/php/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/php/tests/head.php b/php/tests/head.php
new file mode 100644
index 00000000..4f4e4061
--- /dev/null
+++ b/php/tests/head.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)$ctx);
+ } catch (\Throwable $e) {
+ $rr->error((string)$e);
+ }
+} \ No newline at end of file
diff --git a/php/tests/pid.php b/php/tests/pid.php
new file mode 100644
index 00000000..a8cfa229
--- /dev/null
+++ b/php/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/php/tests/slow-client.php b/php/tests/slow-client.php
new file mode 100644
index 00000000..f09142b5
--- /dev/null
+++ b/php/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
diff --git a/php/tests/stop.php b/php/tests/stop.php
new file mode 100644
index 00000000..caa485d6
--- /dev/null
+++ b/php/tests/stop.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
+
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+$rr = new RoadRunner\Worker($relay);
+
+$used = false;
+while ($in = $rr->receive($ctx)) {
+ try {
+ if ($used) {
+ // kill on second attempt
+ $rr->stop();
+ continue;
+ }
+
+ $used = true;
+ $rr->send((string)getmypid());
+ } catch (\Throwable $e) {
+ $rr->error((string)$e);
+ }
+} \ No newline at end of file