Skip to content

Commit

Permalink
fix: don't fail on null workflow result history (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
seregazhuk authored Aug 1, 2022
1 parent 40ef9c5 commit f10d8d5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Internal/Client/WorkflowStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ private function getCloseEvent(int $timeout = null): HistoryEvent
}
}

if ($response->getHistory() === null) {
continue;
}

if ($response->getHistory()->getEvents()->count() === 0) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace Temporal\Tests\Unit\Internal\Client;

use Temporal\Api\Common\V1\Payload;
use Temporal\Api\Common\V1\Payloads;
use Temporal\Api\Enums\V1\EventType;
use Temporal\Api\History\V1\History;
use Temporal\Api\History\V1\HistoryEvent;
use Temporal\Api\History\V1\WorkflowExecutionCompletedEventAttributes;
use Temporal\Api\Workflowservice\V1\GetWorkflowExecutionHistoryResponse;
use Temporal\Client\ClientOptions;
use Temporal\Client\GRPC\ServiceClientInterface;
use Temporal\Client\GRPC\StatusCode;
Expand All @@ -21,7 +28,7 @@
*
* @covers \Temporal\Internal\Client\WorkflowStub
*/
final class WorkflowStubTest extends TestCase
final class WorkflowStubTestCase extends TestCase
{
private WorkflowStub $workflowStub;
/** @var MockObject|ServiceClientInterface */
Expand Down Expand Up @@ -69,4 +76,33 @@ public function testSignalThrowsWorkflowServiceException(): void

$this->workflowStub->signal('signalName');
}

public function testEmptyHistoryContinuesWaitingForHistoryEvents(): void
{
$responseWithHistory = (new GetWorkflowExecutionHistoryResponse())
->setHistory(
(new History)->setEvents(
[
(new HistoryEvent())
->setEventType(EventType::EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED)
->setWorkflowExecutionCompletedEventAttributes(
(new WorkflowExecutionCompletedEventAttributes())->setResult(
(new Payloads())->setPayloads([(new Payload())->setData('hello')])
)
)
]
)
);

$this->serviceClient
->expects(static::exactly(2))
->method('GetWorkflowExecutionHistory')
->willReturnOnConsecutiveCalls(
new GetWorkflowExecutionHistoryResponse(),
$responseWithHistory
);

$result = $this->workflowStub->getResult();
$this->assertNull($result);
}
}

0 comments on commit f10d8d5

Please sign in to comment.