-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WorkflowUpdateRPCTimeoutOrCanceledException; add a test case
- Loading branch information
Showing
8 changed files
with
131 additions
and
13 deletions.
There are no files selected for viewing
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
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
29 changes: 29 additions & 0 deletions
29
src/Exception/Client/WorkflowUpdateRPCTimeoutOrCanceledException.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,29 @@ | ||
<?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\Exception\Client; | ||
|
||
/** | ||
* Occurs when an update call times out or is cancelled. | ||
* | ||
* @note this is not related to any general concept of timing out or cancelling a running update, | ||
* this is only related to the client call itself. | ||
*/ | ||
class WorkflowUpdateRPCTimeoutOrCanceledException extends TimeoutException { | ||
public static function fromTimeoutException(TimeoutException $exception): self | ||
{ | ||
return new self( | ||
$exception->getMessage(), | ||
$exception->getCode(), | ||
$exception->getPrevious(), | ||
); | ||
} | ||
} |
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
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Tests\Acceptance\Extra\Update\TimeoutTest; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Temporal\Client\WorkflowClientInterface; | ||
use Temporal\Client\WorkflowOptions; | ||
use Temporal\Client\WorkflowStubInterface; | ||
use Temporal\Exception\Client\WorkflowUpdateRPCTimeoutOrCanceledException; | ||
use Temporal\Tests\Acceptance\App\Attribute\Client; | ||
use Temporal\Tests\Acceptance\App\Attribute\Stub; | ||
use Temporal\Tests\Acceptance\App\TestCase; | ||
use Temporal\Workflow; | ||
use Temporal\Workflow\WorkflowInterface; | ||
use Temporal\Workflow\WorkflowMethod; | ||
|
||
class TimeoutTest extends TestCase | ||
{ | ||
#[Test] | ||
public function getUpdateResultFromHandler( | ||
#[Stub('Extra_Timeout_WorkflowUpdate')] | ||
WorkflowStubInterface $stub, | ||
): void { | ||
/** @see TestWorkflow::sleep */ | ||
$handle = $stub->startUpdate('sleep', '1 second'); | ||
|
||
$this->expectException(WorkflowUpdateRPCTimeoutOrCanceledException::class); | ||
|
||
$handle->getResult(0.2); | ||
} | ||
|
||
#[Test] | ||
public function doUpdateWithTimeout( | ||
#[Stub('Extra_Timeout_WorkflowUpdate')] | ||
#[Client(timeout: 1.2)] | ||
WorkflowStubInterface $stub, | ||
): void { | ||
$this->expectException(WorkflowUpdateRPCTimeoutOrCanceledException::class); | ||
|
||
/** @see TestWorkflow::sleep */ | ||
$stub->update('sleep', '2 second'); | ||
} | ||
|
||
#[Test] | ||
public function withoutRunningWorker(WorkflowClientInterface $client): void | ||
{ | ||
$client = $client->withTimeout(1.2); | ||
$wf = $client->newUntypedWorkflowStub('Extra_Timeout_WorkflowUpdate', WorkflowOptions::new() | ||
->withTaskQueue('not-existing-task-queue')); | ||
$client->start($wf); | ||
|
||
$this->expectException(WorkflowUpdateRPCTimeoutOrCanceledException::class); | ||
|
||
/** @see TestWorkflow::sleep */ | ||
$wf->update('sleep', '2 second'); | ||
} | ||
} | ||
|
||
#[WorkflowInterface] | ||
class TestWorkflow | ||
{ | ||
#[WorkflowMethod(name: "Extra_Timeout_WorkflowUpdate")] | ||
public function handle() | ||
{ | ||
yield Workflow::await(static fn() => false); | ||
} | ||
|
||
#[Workflow\UpdateMethod(name: 'sleep')] | ||
public function sleep(string $sleep): mixed | ||
{ | ||
yield Workflow::timer(\DateInterval::createFromDateString($sleep)); | ||
} | ||
} |