Skip to content

Commit 19acde7

Browse files
committed
test(acceptance): add Versioning test with Pinned behavior
1 parent 118beeb commit 19acde7

File tree

1 file changed

+79
-12
lines changed

1 file changed

+79
-12
lines changed

tests/Acceptance/Extra/Versioning/DeploymentTest.php

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,26 @@
1717
use Temporal\Worker\WorkerOptions;
1818
use Temporal\Workflow\WorkflowInterface;
1919
use Temporal\Workflow\WorkflowMethod;
20+
use Temporal\Workflow\WorkflowVersioningBehavior;
2021

2122
#[Worker(options: [WorkerFactory::class, 'options'])]
2223
class DeploymentTest extends TestCase
2324
{
2425
#[Test]
25-
public function sendEmpty(
26+
public function defaultBehaviorAuto(
2627
TemporalStarter $starter,
2728
WorkflowClientInterface $client,
2829
Feature $feature,
2930
): void {
30-
$starter->executeTemporalCommand([
31-
'worker',
32-
'deployment',
33-
'set-current-version',
34-
'--deployment-name', WorkerFactory::DEPLOYMENT_NAME,
35-
'--build-id', WorkerFactory::BUILD_ID,
36-
'--yes',
37-
], timeout: 5);
31+
WorkerFactory::setCurrentDeployment($starter);
3832

3933
try {
4034
# Create a Workflow stub with an execution timeout 12 seconds
4135
$stub = $client
4236
->withTimeout(10)
4337
->newUntypedWorkflowStub(
44-
'Extra_Versioning_Deployment',
38+
/** @see PinnedWorkflow */
39+
'Extra_Versioning_Deployment_Default',
4540
WorkflowOptions::new()
4641
->withTaskQueue($feature->taskQueue)
4742
->withWorkflowExecutionTimeout(20),
@@ -50,9 +45,11 @@ public function sendEmpty(
5045
# Start the Workflow
5146
$client->start($stub);
5247

48+
# Check the result
5349
$result = $stub->getResult(timeout: 5);
5450
self::assertSame('default', $result);
5551

52+
# Check the Workflow History
5653
$version = null;
5754
$behavior = null;
5855
foreach ($client->getWorkflowHistory($stub->getExecution()) as $event) {
@@ -71,6 +68,53 @@ public function sendEmpty(
7168
$starter->stop() and $starter->start();
7269
}
7370
}
71+
72+
#[Test]
73+
public function customBehaviorPinned(
74+
TemporalStarter $starter,
75+
WorkflowClientInterface $client,
76+
Feature $feature,
77+
): void {
78+
WorkerFactory::setCurrentDeployment($starter);
79+
80+
try {
81+
# Create a Workflow stub with an execution timeout 12 seconds
82+
$stub = $client
83+
->withTimeout(10)
84+
->newUntypedWorkflowStub(
85+
/** @see DefaultWorkflow */
86+
'Extra_Versioning_Deployment_Pinned',
87+
WorkflowOptions::new()
88+
->withTaskQueue($feature->taskQueue)
89+
->withWorkflowExecutionTimeout(20),
90+
);
91+
92+
# Start the Workflow
93+
$client->start($stub);
94+
95+
# Check the result
96+
$result = $stub->getResult(timeout: 5);
97+
self::assertSame('pinned', $result);
98+
99+
# Check the Workflow History
100+
$version = null;
101+
$behavior = null;
102+
foreach ($client->getWorkflowHistory($stub->getExecution()) as $event) {
103+
if ($event->hasWorkflowTaskCompletedEventAttributes()) {
104+
$version = $event->getWorkflowTaskCompletedEventAttributes()?->getDeploymentVersion();
105+
$behavior = $event->getWorkflowTaskCompletedEventAttributes()?->getVersioningBehavior();
106+
break;
107+
}
108+
}
109+
110+
self::assertNotNull($version);
111+
self::assertSame(WorkerFactory::DEPLOYMENT_NAME, $version->getDeploymentName());
112+
self::assertSame(WorkerFactory::BUILD_ID, $version->getBuildId());
113+
self::assertSame(VersioningBehavior::Pinned->value, $behavior);
114+
} finally {
115+
$starter->stop() and $starter->start();
116+
}
117+
}
74118
}
75119

76120
class WorkerFactory
@@ -88,14 +132,37 @@ public static function options(): WorkerOptions
88132
->withDefaultVersioningBehavior(VersioningBehavior::AutoUpgrade),
89133
);
90134
}
135+
136+
public static function setCurrentDeployment(TemporalStarter $starter): void
137+
{
138+
$starter->executeTemporalCommand([
139+
'worker',
140+
'deployment',
141+
'set-current-version',
142+
'--deployment-name', WorkerFactory::DEPLOYMENT_NAME,
143+
'--build-id', WorkerFactory::BUILD_ID,
144+
'--yes',
145+
], timeout: 5);
146+
}
91147
}
92148

93149
#[WorkflowInterface]
94-
class TestWorkflow
150+
class DefaultWorkflow
95151
{
96-
#[WorkflowMethod(name: "Extra_Versioning_Deployment")]
152+
#[WorkflowMethod(name: "Extra_Versioning_Deployment_Default")]
97153
public function handle()
98154
{
99155
return 'default';
100156
}
101157
}
158+
159+
#[WorkflowInterface]
160+
class PinnedWorkflow
161+
{
162+
#[WorkflowMethod(name: "Extra_Versioning_Deployment_Pinned")]
163+
#[WorkflowVersioningBehavior(VersioningBehavior::Pinned)]
164+
public function handle()
165+
{
166+
return 'pinned';
167+
}
168+
}

0 commit comments

Comments
 (0)