diff --git a/composer.json b/composer.json index 73c535ae4..6a702664d 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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, diff --git a/testing/src/Environment.php b/testing/src/Environment.php index e4391a98f..7ca4de41c 100644 --- a/testing/src/Environment.php +++ b/testing/src/Environment.php @@ -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'); $this->output->writeln('Error starting Temporal server: ' . $this->temporalServerProcess->getErrorOutput()); exit(1); diff --git a/tests/Acceptance/App/Feature/WorkflowStubInjector.php b/tests/Acceptance/App/Feature/WorkflowStubInjector.php index cc639b7b1..01a5c06e6 100644 --- a/tests/Acceptance/App/Feature/WorkflowStubInjector.php +++ b/tests/Acceptance/App/Feature/WorkflowStubInjector.php @@ -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; diff --git a/tests/Acceptance/App/Runtime/RRStarter.php b/tests/Acceptance/App/Runtime/RRStarter.php index 5169560fc..9ab4688c7 100644 --- a/tests/Acceptance/App/Runtime/RRStarter.php +++ b/tests/Acceptance/App/Runtime/RRStarter.php @@ -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 diff --git a/tests/Acceptance/App/Runtime/TemporalStarter.php b/tests/Acceptance/App/Runtime/TemporalStarter.php index 7ef1a530b..5e3d27118 100644 --- a/tests/Acceptance/App/Runtime/TemporalStarter.php +++ b/tests/Acceptance/App/Runtime/TemporalStarter.php @@ -4,7 +4,6 @@ namespace Temporal\Tests\Acceptance\App\Runtime; -use Symfony\Component\Process\Process; use Temporal\Common\SearchAttributes\ValueType; use Temporal\Testing\Environment; @@ -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 diff --git a/tests/Acceptance/Extra/Stability/ResetWorkerTest.php b/tests/Acceptance/Extra/Stability/ResetWorkerTest.php index 583de204b..a58639583 100644 --- a/tests/Acceptance/Extra/Stability/ResetWorkerTest.php +++ b/tests/Acceptance/Extra/Stability/ResetWorkerTest.php @@ -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 @@ -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'); diff --git a/tests/Acceptance/Extra/Versioning/DeploymentTest.php b/tests/Acceptance/Extra/Versioning/DeploymentTest.php index 7662b2231..9060d3ea5 100644 --- a/tests/Acceptance/Extra/Versioning/DeploymentTest.php +++ b/tests/Acceptance/Extra/Versioning/DeploymentTest.php @@ -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); } } diff --git a/tests/Acceptance/Harness/Signal/PreventCloseTest.php b/tests/Acceptance/Harness/Signal/PreventCloseTest.php index 23128ebd7..aa6d7f826 100644 --- a/tests/Acceptance/Harness/Signal/PreventCloseTest.php +++ b/tests/Acceptance/Harness/Signal/PreventCloseTest.php @@ -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 diff --git a/tests/Acceptance/Harness/Update/TaskFailureTest.php b/tests/Acceptance/Harness/Update/TaskFailureTest.php index 8db8a912b..5b34accea 100644 --- a/tests/Acceptance/Harness/Update/TaskFailureTest.php +++ b/tests/Acceptance/Harness/Update/TaskFailureTest.php @@ -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'); diff --git a/tests/Functional/bootstrap.php b/tests/Functional/bootstrap.php index 9726420da..5737f134c 100644 --- a/tests/Functional/bootstrap.php +++ b/tests/Functional/bootstrap.php @@ -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;