|
| 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_OPTIONS])] |
| 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_OPTIONS = 'retryPolicy'; |
| 43 | + |
| 44 | + #[WorkflowMethod(name: "Extra_Activity_ActivityInfo")] |
| 45 | + public function handle(string $arg) |
| 46 | + { |
| 47 | + return yield match ($arg) { |
| 48 | + self::ARG_RETRY_OPTIONS => $this->getRetryOptions(), |
| 49 | + }; |
| 50 | + } |
| 51 | + |
| 52 | + private function getRetryOptions(): 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 | + ->retryOptions(); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +#[Activity\ActivityInterface(prefix: 'Extra_Activity_ActivityInfo.')] |
| 71 | +class TestActivity |
| 72 | +{ |
| 73 | + #[Activity\ActivityMethod] |
| 74 | + public function retryOptions() |
| 75 | + { |
| 76 | + return Activity::getInfo()->retryOptions; |
| 77 | + } |
| 78 | +} |
0 commit comments