summaryrefslogtreecommitdiff
path: root/tests/psr-worker-bench.php
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-25 22:47:02 +0300
committerValery Piashchynski <[email protected]>2021-01-25 22:47:02 +0300
commit43071e43a0743ff8c7913bba7819952962124355 (patch)
treee3b61113d3c0d28f972c71592af8b2f708994167 /tests/psr-worker-bench.php
parent5fd1168c687040ca7d72f4727ee1aec753d3f258 (diff)
Initial commit of the Temporal plugins set
Diffstat (limited to 'tests/psr-worker-bench.php')
-rw-r--r--tests/psr-worker-bench.php62
1 files changed, 48 insertions, 14 deletions
diff --git a/tests/psr-worker-bench.php b/tests/psr-worker-bench.php
index d382098a..ef741a61 100644
--- a/tests/psr-worker-bench.php
+++ b/tests/psr-worker-bench.php
@@ -1,24 +1,58 @@
<?php
+declare(strict_types=1);
+
use Spiral\RoadRunner;
use Nyholm\Psr7\Factory;
ini_set('display_errors', 'stderr');
include "vendor/autoload.php";
-$worker = new RoadRunner\Http\PSR7Worker(
- RoadRunner\Worker::create(),
- new Factory\Psr17Factory(),
- new Factory\Psr17Factory(),
- new Factory\Psr17Factory()
-);
-
-while ($req = $worker->waitRequest()) {
- try {
- $rsp = new \Nyholm\Psr7\Response();
- $rsp->getBody()->write("hello world");
- $worker->respond($rsp);
- } catch (\Throwable $e) {
- $worker->getWorker()->error((string)$e);
+$env = \Spiral\RoadRunner\Environment::fromGlobals();
+
+if ($env->getMode() === 'http') {
+ $worker = new RoadRunner\Http\PSR7Worker(
+ RoadRunner\Worker::create(),
+ new Factory\Psr17Factory(),
+ new Factory\Psr17Factory(),
+ new Factory\Psr17Factory()
+ );
+
+ while ($req = $worker->waitRequest()) {
+ try {
+ $rsp = new \Nyholm\Psr7\Response();
+ $rsp->getBody()->write("hello world");
+ $worker->respond($rsp);
+ } catch (\Throwable $e) {
+ $worker->getWorker()->error((string)$e);
+ }
}
+} else {
+ /**
+ * @param string $dir
+ * @return array<string>
+ */
+ $getClasses = static function (string $dir): iterable {
+ $files = glob($dir . '/*.php');
+
+ foreach ($files as $file) {
+ yield substr(basename($file), 0, -4);
+ }
+ };
+
+ $factory = \Temporal\WorkerFactory::create();
+
+ $worker = $factory->newWorker('default');
+
+ // register all workflows
+ foreach ($getClasses(__DIR__ . '/../temporal/Workflow') as $name) {
+ $worker->registerWorkflowType('Temporal\\Tests\\Workflow\\' . $name);
+ }
+
+ // register all activity
+ foreach ($getClasses(__DIR__ . '/../temporal/Activity') as $name) {
+ $worker->registerActivityType('Temporal\\Tests\\Activity\\' . $name);
+ }
+
+ $factory->run();
} \ No newline at end of file