Skip to content

Commit

Permalink
Merge pull request #335: Fix potential issue when signal coroutine wo…
Browse files Browse the repository at this point in the history
…n't trigger await due to failed activity call

Fixes potential issue when signal coroutine won't trigger await due to failed activity call
  • Loading branch information
roxblnfk authored Jul 27, 2023
2 parents 42b6f9e + 23c5549 commit f3e2a6e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Internal/Workflow/Process/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ protected function next(): void
}

$current = $this->coroutine->current();
$this->context->resolveConditions();

switch (true) {
case $current instanceof PromiseInterface:
Expand Down
38 changes: 38 additions & 0 deletions tests/Fixtures/src/Workflow/Case335Workflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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.
*/

namespace Temporal\Tests\Workflow;

use Temporal\Workflow;
use Temporal\Workflow\SignalMethod;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class Case335Workflow
{
private bool $exit = false;
private bool $timerRun = false;

#[SignalMethod('signal')]
public function signal()
{
$this->exit = true;

yield Workflow::timer(1);

$this->timerRun = true;
}

#[WorkflowMethod('case335_workflow')]
public function run()
{
yield Workflow::await(fn() => $this->exit);
return $this->timerRun;
}
}
12 changes: 12 additions & 0 deletions tests/Functional/Client/TypedStubTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Temporal\Tests\DTO\User;
use Temporal\Tests\Unit\Declaration\Fixture\WorkflowWithoutHandler;
use Temporal\Tests\Workflow\ActivityReturnTypeWorkflow;
use Temporal\Tests\Workflow\Case335Workflow;
use Temporal\Tests\Workflow\GeneratorWorkflow;
use Temporal\Tests\Workflow\QueryWorkflow;
use Temporal\Tests\Workflow\SignalledWorkflowReusable;
Expand Down Expand Up @@ -159,4 +160,15 @@ public function testSignalRunningWorkflowWithInheritedSignalViaParentInterface()
$result = $workflowRun->getResult();
$this->assertEquals(['test1'], $result);
}

public function testSignalResolvesCondidtionsBeforePromiseRun()
{
$client = $this->createClient();

$workflow = $client->newWorkflowStub(Case335Workflow::class);
$workflowRun = $client->startWithSignal($workflow, 'signal');

$result = $workflowRun->getResult('bool', 5);
$this->assertFalse($result);
}
}

0 comments on commit f3e2a6e

Please sign in to comment.