Skip to content

Commit

Permalink
Add test that start a workflow with bad arguments; improve behavior: …
Browse files Browse the repository at this point in the history
…decoder exceptions must be skipped in signal methods only
  • Loading branch information
roxblnfk committed Jul 21, 2023
1 parent 2d63521 commit 9f962fd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/Internal/Workflow/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use JetBrains\PhpStorm\Pure;
use Temporal\DataConverter\ValuesInterface;
use Temporal\Exception\DestructMemorizedInstanceException;
use Temporal\Exception\InvalidArgumentException;
use Temporal\Internal\Declaration\WorkflowInstanceInterface;
use Temporal\Internal\ServiceContainer;
use Temporal\Internal\Workflow\WorkflowContext;
Expand Down Expand Up @@ -44,11 +43,7 @@ function (?\Throwable $error): void {
}
);

try {
$scope->start($handler);
} catch (InvalidArgumentException $e) {
// invalid signal invocation, destroy the scope with no traces
}
$scope->startSignal($handler);
}
);

Expand Down
37 changes: 36 additions & 1 deletion src/Internal/Workflow/Process/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ public function start(callable $handler, ValuesInterface $values = null): void
$this->next();
}

/**
* @param callable $handler
*/
public function startSignal(callable $handler): void
{
// Create a coroutine generator
$this->coroutine = $this->callSignalHandler($handler);
$this->context->resolveConditions();
$this->next();
}

/**
* @param \Generator $generator
* @return self
Expand Down Expand Up @@ -323,11 +334,35 @@ function () use ($cancelID): void {
* @return \Generator
*/
protected function call(callable $handler, ValuesInterface $values): \Generator
{
try {
$this->makeCurrent();
$result = $handler($values);

if ($result instanceof \Generator) {
yield from $result;

return $result->getReturn();
}

return $result;
} catch (\Throwable $e) {
$this->onException($e);
}
}

/**
* Call a Signal method. In this case deserialization errors are skipped.
*
* @param callable $handler
* @return \Generator
*/
protected function callSignalHandler(callable $handler): \Generator
{
try {
$this->makeCurrent();
try {
$result = $handler($values);
$result = $handler();
} catch (InvalidArgumentException) {
// Skip deserialization errors
return null;
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Client/FailureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testSignalThatThrowsCustomError()

try {
// The next
sleep(1);
sleep(2);
$wf->exit();
$this->fail('Signal must fail');
} catch (AssertionFailedError $e) {
Expand Down Expand Up @@ -148,7 +148,7 @@ public function testSignalThatThrowsInternalException()
$run = $client->startWithSignal($wf, 'failActivity', ['foo']);

try {
sleep(5);
sleep(8);
$wf->failActivity('foo');
$this->fail('Signal must fail');
} catch (AssertionFailedError $e) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Functional/Client/UntypedWorkflowStubTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public function testUntypedStartAndWaitResult()
$this->assertSame('HELLO WORLD', $simple->getResult());
}

public function testUntypedStartWithWrongData()
{
$client = $this->createClient();
$simple = $client->newUntypedWorkflowStub('SimpleWorkflow');
$client->start($simple, ['hello world']);

$this->expectException(WorkflowFailedException::class);
$simple->getResult();
}

public function testUntypedStartViaClient()
{
$client = $this->createClient();
Expand Down

0 comments on commit 9f962fd

Please sign in to comment.