-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathWorkflowInfoTest.php
More file actions
144 lines (132 loc) · 4.8 KB
/
Copy pathWorkflowInfoTest.php
File metadata and controls
144 lines (132 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
namespace Temporal\Tests\Acceptance\Extra\Workflow\WorkflowInfo;
use PHPUnit\Framework\Attributes\Test;
use Temporal\Client\WorkflowStubInterface;
use Temporal\Tests\Acceptance\App\Attribute\RetryOptions;
use Temporal\Tests\Acceptance\App\Attribute\Stub;
use Temporal\Tests\Acceptance\App\TestCase;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;
class WorkflowInfoTest extends TestCase
{
#[Test]
public static function rootWorkflowExecution(
#[Stub('Extra_Workflow_WorkflowInfo', args: [[MainWorkflow::ARG_ROOT_EXECUTION]])]
WorkflowStubInterface $stub,
): void {
$result = $stub->getResult(type: 'array');
self::assertSame([
'id' => $stub->getExecution()->getID(),
'runID' => $stub->getExecution()->getRunID(),
], $result['rootExecution']);
}
#[Test]
public static function continueAsNewExecution(
#[Stub('Extra_Workflow_WorkflowInfo', args: [[
MainWorkflow::ARG_CONTINUE_AS_NEW,
MainWorkflow::ARG_DUMP,
]])]
WorkflowStubInterface $stub,
): void {
$result = $stub->getResult(type: 'array');
self::assertNotEmpty($result['continuedExecutionRunId']);
self::assertSame($result['firstExecutionRunId'], $result['continuedExecutionRunId']);
self::assertNotSame($result['firstExecutionRunId'], $result['originalExecutionRunId']);
}
#[Test]
public static function continueAsNewExecutionChild(
#[Stub('Extra_Workflow_WorkflowInfo', args: [[
MainWorkflow::ARG_CONTINUE_AS_NEW,
MainWorkflow::ARG_RUN_MAIN_AS_CHILD,
MainWorkflow::ARG_DUMP,
]])]
WorkflowStubInterface $stub,
): void {
$result = $stub->getResult(type: 'array');
/**
* There is no information about continued execution in child workflows.
*/
self::assertEmpty($result['continuedExecutionRunId']);
self::assertIsString($result['continuedExecutionRunId']);
self::assertSame($result['firstExecutionRunId'], $result['originalExecutionRunId']);
}
#[Test]
public static function retryOptions(
#[Stub(
'Extra_Workflow_WorkflowInfo',
args: [[MainWorkflow::ARG_RETRY_OPTIONS]],
retryOptions: new RetryOptions(
backoffCoefficient: 3.0,
maximumInterval: '2 minutes',
maximumAttempts: 10,
),
)]
WorkflowStubInterface $stub,
): void {
$result = $stub->getResult(type: 'array');
self::assertEquals([
"initial_interval" => ['seconds' => 1, 'nanos' => 0],
"backoff_coefficient" => 3,
"maximum_interval" => ['seconds' => 120, 'nanos' => 0],
"maximum_attempts" => 10,
"non_retryable_error_types" => [],
], $result);
}
}
#[WorkflowInterface]
class MainWorkflow
{
public const ARG_RETRY_OPTIONS = 'retryPolicy';
public const ARG_ROOT_EXECUTION = 'rootExecution';
public const ARG_CONTINUE_AS_NEW = 'continueAsNew';
public const ARG_DUMP = 'dump';
public const ARG_RUN_MAIN_AS_CHILD = 'runMainAsChild';
#[WorkflowMethod('Extra_Workflow_WorkflowInfo')]
public function run(array $actions)
{
$action = \array_shift($actions);
return yield match ($action) {
self::ARG_ROOT_EXECUTION => Workflow::newChildWorkflowStub(ChildWorkflow::class)->run(),
self::ARG_RETRY_OPTIONS => Workflow::getInfo()->retryOptions,
self::ARG_CONTINUE_AS_NEW => Workflow::continueAsNew('Extra_Workflow_WorkflowInfo', args: [$actions]),
self::ARG_RUN_MAIN_AS_CHILD => Workflow::newChildWorkflowStub(MainWorkflow::class)->run($actions),
self::ARG_DUMP => Helper::dumpWorkflow(),
};
}
}
#[WorkflowInterface]
class ChildWorkflow
{
#[WorkflowMethod('Extra_Workflow_WorkflowInfo_Child')]
public function run()
{
return yield Workflow::newChildWorkflowStub(ChildWorkflow2::class)->run();
}
}
#[WorkflowInterface]
class ChildWorkflow2
{
#[WorkflowMethod('Extra_Workflow_WorkflowInfo_Child2')]
public function run()
{
return Helper::dumpWorkflow();
}
}
class Helper
{
public static function dumpWorkflow(): array
{
$workflowInfo = Workflow::getInfo();
return [
'rootExecution' => [
'id' => $workflowInfo->rootExecution?->getID(),
'runID' => $workflowInfo->rootExecution?->getRunID(),
],
'firstExecutionRunId' => $workflowInfo->firstExecutionRunId,
'continuedExecutionRunId' => $workflowInfo->continuedExecutionRunId,
'originalExecutionRunId' => $workflowInfo->originalExecutionRunId,
];
}
}