Skip to content

Commit d63c0f7

Browse files
committed
test: Test RetryPolicy in Activity context
1 parent bd95a63 commit d63c0f7

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Temporal\Tests\Acceptance\Extra\Activity\ActivityInfo;
6+
7+
use PHPUnit\Framework\Attributes\Test;
8+
use React\Promise\PromiseInterface;
9+
use Temporal\Activity;
10+
use Temporal\Client\WorkflowStubInterface;
11+
use Temporal\Common\RetryOptions;
12+
use Temporal\Tests\Acceptance\App\Attribute\Stub;
13+
use Temporal\Tests\Acceptance\App\TestCase;
14+
use Temporal\Workflow;
15+
use Temporal\Workflow\WorkflowInterface;
16+
use Temporal\Workflow\WorkflowMethod;
17+
18+
class ActivityInfoTest extends TestCase
19+
{
20+
#[Test]
21+
public static function retryPolicy(
22+
#[Stub('Extra_Activity_ActivityInfo', args: [TestWorkflow::ARG_RETRY_POLICY])]
23+
WorkflowStubInterface $stub,
24+
): void {
25+
self::markTestSkipped('See https://github.com/temporalio/sdk-php/issues/602');
26+
27+
$result = $stub->getResult(type: 'array');
28+
self::assertSame([
29+
"initial_interval" => ['seconds' => 1, 'nanos' => 0],
30+
"backoff_coefficient" => 3,
31+
"maximum_interval" => ['seconds' => 120, 'nanos' => 0],
32+
"maximum_attempts" => 20,
33+
"non_retryable_error_types" => [],
34+
], $result);
35+
}
36+
}
37+
38+
39+
#[WorkflowInterface]
40+
class TestWorkflow
41+
{
42+
public const ARG_RETRY_POLICY = 'retryPolicy';
43+
44+
#[WorkflowMethod(name: "Extra_Activity_ActivityInfo")]
45+
public function handle(string $arg)
46+
{
47+
return yield match ($arg) {
48+
self::ARG_RETRY_POLICY => $this->getRetryPolicy(),
49+
};
50+
}
51+
52+
private function getRetryPolicy(): PromiseInterface
53+
{
54+
return Workflow::newActivityStub(
55+
TestActivity::class,
56+
Activity\ActivityOptions::new()
57+
->withRetryOptions(
58+
RetryOptions::new()
59+
->withMaximumAttempts(20)
60+
->withBackoffCoefficient(3.0)
61+
->withInitialInterval('1 second')
62+
->withMaximumInterval('2 minutes'),
63+
)
64+
->withScheduleToCloseTimeout(10),
65+
)
66+
->retryPolicy();
67+
}
68+
}
69+
70+
#[Activity\ActivityInterface(prefix: 'Extra_Activity_ActivityInfo.')]
71+
class TestActivity
72+
{
73+
#[Activity\ActivityMethod]
74+
public function retryPolicy()
75+
{
76+
return Activity::getInfo()->retryPolicy;
77+
}
78+
}

0 commit comments

Comments
 (0)