Skip to content

Commit

Permalink
Merge pull request #397: fix starting for local activities
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Feb 13, 2024
2 parents e726dda + fe1eff8 commit ce3a461
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/Internal/Client/WorkflowRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ final class WorkflowRun implements WorkflowRunInterface
public function __construct(
private WorkflowStubInterface $stub,
private $returnType = null,
)
{
) {
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Workflow/ActivityProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)(
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Workflow/WorkflowContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
25 changes: 25 additions & 0 deletions tests/Fixtures/src/Activity/JustLocalActivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Temporal\Tests\Activity;

use Temporal\Activity;

#[Activity\LocalActivityInterface(prefix: "JustLocalActivity.")]
class JustLocalActivity
{
#[Activity\ActivityMethod]
public function echo(
string $input
): string {
return strtoupper($input);
}
}
30 changes: 30 additions & 0 deletions tests/Fixtures/src/Workflow/LocalActivityWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Temporal\Tests\Workflow;

use Temporal\Activity\LocalActivityOptions;
use Temporal\Tests\Activity\JustLocalActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class LocalActivityWorkflow
{
#[WorkflowMethod(name: 'LocalActivityWorkflow')]
public function handler()
{
yield Workflow::newActivityStub(
JustLocalActivity::class,
LocalActivityOptions::new()->withStartToCloseTimeout('10 seconds'),
)->echo('test');
}
}
38 changes: 33 additions & 5 deletions tests/Functional/SimpleWorkflowTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
$environment->startRoadRunner('./rr serve -c .rr.silent.yaml -w tests');
register_shutdown_function(fn() => $environment->stop());
}

0 comments on commit ce3a461

Please sign in to comment.