Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local activities starting #397

Merged
merged 2 commits into from Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Internal/Client/WorkflowRun.php
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
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
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
@@ -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
@@ -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
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
Expand Up @@ -14,4 +14,3 @@
$environment->startRoadRunner('./rr serve -c .rr.silent.yaml -w tests');
register_shutdown_function(fn() => $environment->stop());
}