Skip to content

Commit

Permalink
Add typed SA parameter into startTemporalServer() method
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Feb 4, 2025
1 parent 3a61fca commit 7ac4f6c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
35 changes: 33 additions & 2 deletions testing/src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Process\Process;
use Temporal\Common\SearchAttributes\ValueType;

final class Environment
{
Expand Down Expand Up @@ -52,11 +53,41 @@ public function start(?string $rrCommand = null, int $commandTimeout = 10, array

/**
* @param list<non-empty-string> $parameters
* @param array<non-empty-string, ValueType|non-empty-string> $searchAttributes Key is the name of the search
* attribute, value is the type of the search attribute. Expected values from {@see ValueType}.
*/
public function startTemporalServer(int $commandTimeout = 10, array $parameters = []): void
{
public function startTemporalServer(
int $commandTimeout = 10,
array $parameters = [],
array $searchAttributes = [],
): void {
$temporalPort = \parse_url(\getenv('TEMPORAL_ADDRESS') ?: '127.0.0.1:7233', PHP_URL_PORT);

// Add search attributes
foreach ($searchAttributes as $name => $type) {
$type = \is_string($type) ? ValueType::tryFrom($type) : $type;
if (!$type instanceof ValueType) {
\trigger_error('Invalid search attribute type: ' . \get_debug_type($type), E_USER_WARNING);
continue;
}

if (\preg_match('/^[a-zA-Z0-9_-]+$/', $name) !== 1) {
\trigger_error('Invalid search attribute name: ' . $name, E_USER_WARNING);
continue;
}

$parameters[] = '--search-attribute';
$parameters[] = $name . '=' . match ($type) {
ValueType::Bool => 'bool',
ValueType::Float => 'double',
ValueType::Int => 'int',
ValueType::Keyword => 'keyword',
ValueType::KeywordList => 'keywordList',
ValueType::String => 'text',
ValueType::Datetime => 'datetime',
};
}

$this->output->write('Starting Temporal test server... ');
$this->temporalServerProcess = new Process(
[
Expand Down
21 changes: 11 additions & 10 deletions tests/Acceptance/App/Runtime/TemporalStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Temporal\Tests\Acceptance\App\Runtime;

use Temporal\Common\SearchAttributes\ValueType;
use Temporal\Testing\Environment;

final class TemporalStarter
Expand All @@ -23,16 +24,16 @@ public function start(): void
return;
}

$this->environment->startTemporalServer(parameters: [
'--search-attribute', 'foo=text',
'--search-attribute', 'bar=int',
'--search-attribute', 'testBool=bool',
'--search-attribute', 'testInt=int',
'--search-attribute', 'testFloat=double',
'--search-attribute', 'testString=text',
'--search-attribute', 'testKeyword=keyword',
'--search-attribute', 'testKeywordList=keywordList',
'--search-attribute', 'testDatetime=datetime',
$this->environment->startTemporalServer(searchAttributes: [
'foo' => ValueType::String->value,
'bar' => ValueType::Int->value,
'testBool' => ValueType::Bool,
'testInt' => ValueType::Int,
'testFloat' => ValueType::Float,
'testString' => ValueType::String,
'testKeyword' => ValueType::Keyword,
'testKeywordList' => ValueType::KeywordList,
'testDatetime' => ValueType::Datetime,
]);
$this->started = true;
}
Expand Down

0 comments on commit 7ac4f6c

Please sign in to comment.