From dfc1c2ee0be150770a37cfeea55a904d21a10d0b Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 13 Feb 2024 22:51:20 +0400 Subject: [PATCH 1/2] Add local-activity tests --- .../src/Activity/JustLocalActivity.php | 25 ++++++++++++ .../src/Workflow/LocalActivityWorkflow.php | 30 +++++++++++++++ tests/Functional/SimpleWorkflowTestCase.php | 38 ++++++++++++++++--- 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 tests/Fixtures/src/Activity/JustLocalActivity.php create mode 100644 tests/Fixtures/src/Workflow/LocalActivityWorkflow.php diff --git a/tests/Fixtures/src/Activity/JustLocalActivity.php b/tests/Fixtures/src/Activity/JustLocalActivity.php new file mode 100644 index 00000000..28ff2fe5 --- /dev/null +++ b/tests/Fixtures/src/Activity/JustLocalActivity.php @@ -0,0 +1,25 @@ +withStartToCloseTimeout('10 seconds'), + )->echo('test'); + } +} diff --git a/tests/Functional/SimpleWorkflowTestCase.php b/tests/Functional/SimpleWorkflowTestCase.php index c32a7890..6f0795d0 100644 --- a/tests/Functional/SimpleWorkflowTestCase.php +++ b/tests/Functional/SimpleWorkflowTestCase.php @@ -60,11 +60,11 @@ public function testCancelSignaledChildWorkflow(): void $status = $workflow->getStatus(); $this->assertSame([ - "start", - "child started", - "child signaled", - "scope canceled", - "process done", + "start", + "child started", + "child signaled", + "scope canceled", + "process done", ], $status); $this->assertContainsEvent( @@ -73,6 +73,34 @@ public function testCancelSignaledChildWorkflow(): void ); } + public function testLocalActivity(): void + { + $workflow = $this->workflowClient + ->newWorkflowStub( + \Temporal\Tests\Workflow\LocalActivityWorkflow::class, + WorkflowOptions::new()->withWorkflowRunTimeout('10 seconds') + ); + $run = $this->workflowClient->start($workflow); + + $run->getResult(null, 5); + + $history = $this->workflowClient->getWorkflowHistory( + $run->getExecution(), + pageSize: 50, + ); + foreach ($history as $item) { + if ($item->getEventType() === EventType::EVENT_TYPE_MARKER_RECORDED && + $item->getMarkerRecordedEventAttributes()->getMarkerName() === 'LocalActivity' + ) { + // LocalActivity found + $this->assertTrue(true); + return; + } + } + + $this->fail('LocalActivity not found in history'); + } + private function assertContainsEvent(WorkflowExecution $execution, int $event): void { $history = $this->workflowClient->getWorkflowHistory( From fe1eff8e709515092b17327ab269f42275922fe8 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 13 Feb 2024 22:52:47 +0400 Subject: [PATCH 2/2] Fix local-activity run --- src/Internal/Client/WorkflowRun.php | 3 +-- src/Internal/Workflow/ActivityProxy.php | 2 +- src/Internal/Workflow/WorkflowContext.php | 2 +- tests/bootstrap.php | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Internal/Client/WorkflowRun.php b/src/Internal/Client/WorkflowRun.php index c2bfc281..63676010 100644 --- a/src/Internal/Client/WorkflowRun.php +++ b/src/Internal/Client/WorkflowRun.php @@ -25,8 +25,7 @@ final class WorkflowRun implements WorkflowRunInterface public function __construct( private WorkflowStubInterface $stub, private $returnType = null, - ) - { + ) { } /** diff --git a/src/Internal/Workflow/ActivityProxy.php b/src/Internal/Workflow/ActivityProxy.php index cb7f96d5..3405e3a7 100644 --- a/src/Internal/Workflow/ActivityProxy.php +++ b/src/Internal/Workflow/ActivityProxy.php @@ -88,7 +88,7 @@ public function __call(string $method, array $args = []): PromiseInterface ? $this->callsInterceptor->with( fn(ExecuteLocalActivityInput $input): PromiseInterface => $this->ctx ->newUntypedActivityStub($input->options) - ->execute($input->type, $input->args, $input->returnType), + ->execute($input->type, $input->args, $input->returnType, true), /** @see WorkflowOutboundCallsInterceptor::executeLocalActivity() */ 'executeLocalActivity', )( diff --git a/src/Internal/Workflow/WorkflowContext.php b/src/Internal/Workflow/WorkflowContext.php index 7b6205cf..b79b9e29 100644 --- a/src/Internal/Workflow/WorkflowContext.php +++ b/src/Internal/Workflow/WorkflowContext.php @@ -430,7 +430,7 @@ public function executeActivity( ? $this->callsInterceptor->with( fn(ExecuteLocalActivityInput $input): PromiseInterface => $this ->newUntypedActivityStub($input->options) - ->execute($input->type, $input->args, $input->returnType), + ->execute($input->type, $input->args, $input->returnType, true), /** @see WorkflowOutboundCallsInterceptor::executeLocalActivity() */ 'executeLocalActivity', )(new ExecuteLocalActivityInput($type, $args, $options, $returnType)) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 36bd7035..86fc4324 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,4 +14,3 @@ $environment->startRoadRunner('./rr serve -c .rr.silent.yaml -w tests'); register_shutdown_function(fn() => $environment->stop()); } -