-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case where workflow fails with react/promise v3
- Loading branch information
Showing
4 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
tests/Fixtures/src/Workflow/CancelSignaledChildWorkflow.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Tests\Workflow; | ||
|
||
use React\Promise\Deferred; | ||
use Temporal\Workflow; | ||
use Temporal\Workflow\WorkflowMethod; | ||
|
||
#[Workflow\WorkflowInterface] | ||
class CancelSignaledChildWorkflow | ||
{ | ||
private array $status = []; | ||
|
||
#[Workflow\QueryMethod(name: 'getStatus')] | ||
public function getStatus(): array | ||
{ | ||
return $this->status; | ||
} | ||
|
||
#[WorkflowMethod(name: 'CancelSignaledChildWorkflow')] | ||
public function handler() | ||
{ | ||
// typed stub | ||
$simple = Workflow::newChildWorkflowStub(SimpleSignaledWorkflow::class); | ||
|
||
$waitSignaled = new Deferred(); | ||
|
||
$this->status[] = 'start'; | ||
|
||
// start execution | ||
$scope = Workflow::async( | ||
function () use ($simple, $waitSignaled) { | ||
$call = $simple->handler(); | ||
$this->status[] = 'child started'; | ||
|
||
yield $simple->add(8); | ||
$this->status[] = 'child signaled'; | ||
$waitSignaled->resolve(); | ||
|
||
return yield $call; | ||
} | ||
); | ||
|
||
// only cancel scope when signal dispatched | ||
yield $waitSignaled; | ||
$scope->cancel(); | ||
$this->status[] = 'scope canceled'; | ||
|
||
try { | ||
return yield $scope; | ||
} catch (\Throwable $e) { | ||
$this->status[] = 'process done'; | ||
|
||
return 'canceled ok'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Tests\Workflow; | ||
|
||
use Temporal\Workflow; | ||
use Temporal\Workflow\WorkflowMethod; | ||
|
||
#[Workflow\WorkflowInterface] | ||
class SimpleSignaledWorkflow | ||
{ | ||
private $counter = 0; | ||
|
||
#[Workflow\SignalMethod(name: "add")] | ||
public function add( | ||
int $value | ||
) { | ||
$this->counter += $value; | ||
} | ||
|
||
#[WorkflowMethod(name: 'SimpleSignaledWorkflow')] | ||
public function handler(): iterable | ||
{ | ||
// collect signals during one second | ||
yield Workflow::timer(1); | ||
|
||
return $this->counter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters