Skip to content

Commit 3733d54

Browse files
committed
tests(acceptance): add Deployment Versioning test
1 parent 52227b0 commit 3733d54

File tree

4 files changed

+132
-6
lines changed

4 files changed

+132
-6
lines changed

src/Worker/Transport/RoadRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class RoadRunner implements HostConnectionInterface
3939
private RoadRunnerWorker $worker;
4040
private CodecInterface $codec;
4141

42-
public function __construct(RoadRunnerWorker $worker)
42+
private function __construct(RoadRunnerWorker $worker)
4343
{
4444
$this->worker = $worker;
4545
$this->codec = new JsonCodec();

testing/src/Environment.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ public function startTemporalServer(
9494
$this->systemInfo->temporalCliExecutable,
9595
"server", "start-dev",
9696
"--port", $temporalPort,
97-
'--dynamic-config-value', 'frontend.enableUpdateWorkflowExecution=true',
98-
'--dynamic-config-value', 'frontend.enableUpdateWorkflowExecutionAsyncAccepted=true',
99-
'--dynamic-config-value', 'frontend.enableExecuteMultiOperation=true',
10097
'--log-level', 'error',
10198
'--headless',
10299
...$parameters,
@@ -202,4 +199,19 @@ public function stop(): void
202199
$this->output->writeln('<info>done.</info>');
203200
}
204201
}
202+
203+
/**
204+
* @internal
205+
*/
206+
public function executeTemporalCommand(array|string $command, int $timeout = 10): void
207+
{
208+
$command = \array_merge(
209+
[$this->systemInfo->temporalCliExecutable],
210+
(array) $command,
211+
);
212+
213+
$process = new Process($command);
214+
$process->setTimeout($timeout);
215+
$process->run();
216+
}
205217
}

tests/Acceptance/App/Runtime/TemporalStarter.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Temporal\Tests\Acceptance\App\Runtime;
66

7+
use Symfony\Component\Process\Process;
78
use Temporal\Common\SearchAttributes\ValueType;
89
use Temporal\Testing\Environment;
910

@@ -49,13 +50,25 @@ public function start(): void
4950
$this->started = true;
5051
}
5152

52-
public function stop(): void
53+
public function executeTemporalCommand(array|string $command, int $timeout = 10): void
54+
{
55+
$this->environment->executeTemporalCommand(
56+
command: $command,
57+
timeout: $timeout,
58+
);
59+
}
60+
61+
/**
62+
* @return bool Returns true if the server was stopped successfully, false if it was not started.
63+
*/
64+
public function stop(): bool
5365
{
5466
if (!$this->started) {
55-
return;
67+
return false;
5668
}
5769

5870
$this->environment->stop();
5971
$this->started = false;
72+
return true;
6073
}
6174
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Temporal\Tests\Acceptance\Extra\Versioning\Deployment;
6+
7+
use PHPUnit\Framework\Attributes\Test;
8+
use Temporal\Client\WorkflowClientInterface;
9+
use Temporal\Client\WorkflowOptions;
10+
use Temporal\Tests\Acceptance\App\Attribute\Worker;
11+
use Temporal\Tests\Acceptance\App\Runtime\Feature;
12+
use Temporal\Tests\Acceptance\App\Runtime\TemporalStarter;
13+
use Temporal\Tests\Acceptance\App\TestCase;
14+
use Temporal\Worker\Versioning\VersioningBehavior;
15+
use Temporal\Worker\Versioning\WorkerDeploymentOptions;
16+
use Temporal\Worker\Versioning\WorkerDeploymentVersion;
17+
use Temporal\Worker\WorkerOptions;
18+
use Temporal\Workflow\WorkflowInterface;
19+
use Temporal\Workflow\WorkflowMethod;
20+
21+
#[Worker(options: [WorkerFactory::class, 'options'])]
22+
class DeploymentTest extends TestCase
23+
{
24+
#[Test]
25+
public function sendEmpty(
26+
TemporalStarter $starter,
27+
WorkflowClientInterface $client,
28+
Feature $feature,
29+
): 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);
38+
39+
try {
40+
# Create a Workflow stub with an execution timeout 12 seconds
41+
$stub = $client
42+
->withTimeout(10)
43+
->newUntypedWorkflowStub(
44+
'Extra_Versioning_Deployment',
45+
WorkflowOptions::new()
46+
->withTaskQueue($feature->taskQueue)
47+
->withWorkflowExecutionTimeout(20),
48+
);
49+
50+
# Start the Workflow
51+
$client->start($stub);
52+
53+
$result = $stub->getResult(timeout: 5);
54+
self::assertSame('default', $result);
55+
56+
$version = null;
57+
$behavior = null;
58+
foreach ($client->getWorkflowHistory($stub->getExecution()) as $event) {
59+
if ($event->hasWorkflowTaskCompletedEventAttributes()) {
60+
$version = $event->getWorkflowTaskCompletedEventAttributes()?->getDeploymentVersion();
61+
$behavior = $event->getWorkflowTaskCompletedEventAttributes()?->getVersioningBehavior();
62+
break;
63+
}
64+
}
65+
66+
self::assertNotNull($version);
67+
self::assertSame(WorkerFactory::DEPLOYMENT_NAME, $version->getDeploymentName());
68+
self::assertSame(WorkerFactory::BUILD_ID, $version->getBuildId());
69+
self::assertSame(VersioningBehavior::AutoUpgrade->value, $behavior);
70+
} finally {
71+
$starter->stop() and $starter->start();
72+
}
73+
}
74+
}
75+
76+
class WorkerFactory
77+
{
78+
public const DEPLOYMENT_NAME = 'foo';
79+
public const BUILD_ID = 'baz';
80+
81+
public static function options(): WorkerOptions
82+
{
83+
return WorkerOptions::new()
84+
->withDeploymentOptions(
85+
WorkerDeploymentOptions::new()
86+
->withUseVersioning(true)
87+
->withVersion(WorkerDeploymentVersion::new(self::DEPLOYMENT_NAME, self::BUILD_ID))
88+
->withDefaultVersioningBehavior(VersioningBehavior::AutoUpgrade),
89+
);
90+
}
91+
}
92+
93+
#[WorkflowInterface]
94+
class TestWorkflow
95+
{
96+
#[WorkflowMethod(name: "Extra_Versioning_Deployment")]
97+
public function handle()
98+
{
99+
return 'default';
100+
}
101+
}

0 commit comments

Comments
 (0)