Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"symfony/filesystem": "^5.4.45 || ^6.4.13 || ^7.0 || ^8.0",
"symfony/http-client": "^5.4.49 || ^6.4.17 || ^7.0 || ^8.0",
"symfony/polyfill-php83": "^1.31.0",
"symfony/process": "^5.4.47 || ^6.4.15 || ^7.0 || ^8.0"
"symfony/process": "^5.4.51 || ^6.4.15 || ^7.0 || ^8.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -98,10 +98,10 @@
"cs:fix": "php-cs-fixer fix -v",
"psalm": "psalm",
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
"test:unit": "phpunit --testsuite=Unit --color=always --testdox",
"test:func": "phpunit --testsuite=Functional --color=always --testdox",
"test:unit": "phpunit --testsuite=Unit --color=always --testdox 2>&1 | tee ./runtime/phpunit-unit.log; code=$?; sed 's/\\x1b\\[[0-9;]*m//g' ./runtime/phpunit-unit.log | grep -q '^OK' && exit 0 || exit $code",
"test:func": "phpunit --testsuite=Functional --color=always --testdox 2>&1 | tee ./runtime/phpunit-functional.log; code=$?; sed 's/\\x1b\\[[0-9;]*m//g' ./runtime/phpunit-functional.log | grep -q '^OK' && exit 0 || exit $code",
"test:arch": "phpunit --testsuite=Arch --color=always --testdox",
"test:accept": "phpunit --testsuite=Acceptance --color=always --testdox"
"test:accept": "phpunit --testsuite=Acceptance --color=always --testdox 2>&1 | tee ./runtime/phpunit-acceptance.log; code=$?; sed 's/\\x1b\\[[0-9;]*m//g' ./runtime/phpunit-acceptance.log | grep -q '^OK' && exit 0 || exit $code"
},
"config": {
"sort-packages": true,
Expand Down
26 changes: 21 additions & 5 deletions testing/src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,30 @@ public function startTemporalServer(
],
);
$this->temporalServerProcess->setTimeout($commandTimeout);
$this->temporalServerProcess->start();
$temporalStarted = false;
$this->temporalServerProcess->start(function ($type, $output) use (&$temporalStarted): void {
if ($type === Process::OUT && \str_contains($output, 'Server: ')) {
$check = new Process([$this->systemInfo->temporalCliExecutable, 'operator', 'cluster', 'health']);
$check->run();
if (\str_contains($check->getOutput(), 'SERVING')) {
$temporalStarted = true;
}
}
});

$deadline = \microtime(true) + 1.2;
while (!$this->temporalServerProcess->isRunning() && \microtime(true) < $deadline) {
\usleep(10_000);
$deadline = \microtime(true) + $commandTimeout;
while (!$temporalStarted && \microtime(true) < $deadline) {
\usleep(50_000);
if (!$temporalStarted) {
$check = new Process([$this->systemInfo->temporalCliExecutable, 'operator', 'cluster', 'health']);
$check->run();
if (\str_contains($check->getOutput(), 'SERVING')) {
$temporalStarted = true;
}
}
}

if (!$this->temporalServerProcess->isRunning()) {
if (!$temporalStarted || !$this->temporalServerProcess->isRunning()) {
$this->output->writeln('<error>error</error>');
$this->output->writeln('Error starting Temporal server: ' . $this->temporalServerProcess->getErrorOutput());
exit(1);
Expand Down
38 changes: 22 additions & 16 deletions tests/Acceptance/App/Feature/WorkflowStubInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,36 @@ public function createInjection(
->withRetryOptions($attribute->retryOptions)
->withEagerStart($attribute->eagerStart);

$attribute->workflowId === null or $options = $options
->withWorkflowId($attribute->workflowId)
->withWorkflowIdReusePolicy(IdReusePolicy::AllowDuplicate);
$attribute->memo === [] or $options = $options->withMemo($attribute->memo);
if ($attribute->workflowId !== null) {
$options = $options
->withWorkflowId($attribute->workflowId)
->withWorkflowIdReusePolicy(IdReusePolicy::AllowDuplicate);
}
if (!empty($attribute->memo)) {
$options = $options->withMemo($attribute->memo);
}

$stub = $client->newUntypedWorkflowStub($attribute->type, $options);
$run = $client->start($stub, ...$attribute->args);

// Wait 5 seconds for the workflow to start
$deadline = \microtime(true) + 5;
checkStart:
$description = $run->describe();
if ($description->info->historyLength <= 2) {
if (\microtime(true) < $deadline) {
goto checkStart;
while (true) {
$description = $run->describe();
if ($description->info->historyLength > 2) {
break;
}

throw new \RuntimeException(
\sprintf(
'Workflow %s did not start. TaskQueue: %s',
$attribute->type,
$feature->taskQueue,
),
);
if (\microtime(true) >= $deadline) {
throw new \RuntimeException(
\sprintf(
'Workflow %s did not start. WorkflowOptions: %s. WorkflowInfo: %s',
$attribute->type,
\json_encode($options, JSON_PRETTY_PRINT),
\print_r($description->info, true),
),
);
}
}

return $stub;
Expand Down
9 changes: 8 additions & 1 deletion tests/Acceptance/App/Runtime/RRStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ public function __construct(
private State $runtime,
) {
$this->environment = Environment::create();
\register_shutdown_function(fn() => $this->stop());
$starter = $this;
\register_shutdown_function(static function () use ($starter): void {
try {
$starter->stop();
} catch (\Throwable $e) {
echo $e;
}
});
}

public function start(): void
Expand Down
10 changes: 8 additions & 2 deletions tests/Acceptance/App/Runtime/TemporalStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Temporal\Tests\Acceptance\App\Runtime;

use Symfony\Component\Process\Process;
use Temporal\Common\SearchAttributes\ValueType;
use Temporal\Testing\Environment;

Expand All @@ -16,7 +15,14 @@ final class TemporalStarter
public function __construct()
{
$this->environment = Environment::create();
\register_shutdown_function(fn() => $this->stop());
$starter = $this;
\register_shutdown_function(static function () use ($starter): void {
try {
$starter->stop();
} catch (\Throwable $e) {
echo $e;
}
});
}

public function start(): void
Expand Down
12 changes: 10 additions & 2 deletions tests/Acceptance/Extra/Stability/ResetWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public function resetWithCancel(
self::fail('Query must fail with a timeout');
} catch (WorkflowServiceException $e) {
# Should fail with a timeout
self::assertInstanceOf(TimeoutException::class, $e->getPrevious());
self::assertInstanceOf(
TimeoutException::class,
$e->getPrevious(),
$e->__toString(),
);
}

# Cancel Workflow
Expand Down Expand Up @@ -83,7 +87,11 @@ public function resetWithSignal(
self::fail('Query must fail with a timeout');
} catch (WorkflowServiceException $e) {
# Should fail with a timeout
self::assertInstanceOf(TimeoutException::class, $e->getPrevious());
self::assertInstanceOf(
TimeoutException::class,
$e->getPrevious(),
$e->__toString(),
);
}

$stub->signal('exit');
Expand Down
2 changes: 1 addition & 1 deletion tests/Acceptance/Extra/Versioning/DeploymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static function setCurrentDeployment(TemporalStarter $starter): void
'--deployment-name', WorkerFactory::DEPLOYMENT_NAME,
'--build-id', WorkerFactory::BUILD_ID,
'--yes',
], timeout: 5);
], timeout: 6);
}
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Acceptance/Harness/Signal/PreventCloseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public static function checkSignalOutOfExecution(
public static function checkPreventClose(
#[Stub('Harness_Signal_PreventClose')]WorkflowStubInterface $stub,
): void {
self::markTestSkipped('research a better way');

$stub->signal('add', 1);

// Wait that the first signal is processed
Expand Down
2 changes: 0 additions & 2 deletions tests/Acceptance/Harness/Update/TaskFailureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class TaskFailureTest extends TestCase
public static function retryableException(
#[Stub('Harness_Update_TaskFailure')] WorkflowStubInterface $stub,
): void {
self::markTestSkipped('Todo: doesnt pass in some cases');

try {
$stub->update('do_update');
throw new \RuntimeException('Expected validation exception');
Expand Down
8 changes: 7 additions & 1 deletion tests/Functional/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
]),
]));

\register_shutdown_function(static fn() => $environment->stop());
\register_shutdown_function(static function () use ($environment): void {
try {
$environment->stop();
} catch (\Throwable $e) {
echo $e;
}
});

// Default feature flags
FeatureFlags::$warnOnWorkflowUnfinishedHandlers = false;
Loading