Skip to content

Commit 1d27a16

Browse files
Adds test
Signed-off-by: Elena Kolevska <[email protected]>
1 parent 538a926 commit 1d27a16

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

ext/dapr-ext-workflow/dapr/ext/workflow/dapr_workflow_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def get_workflow_state(
139139
self._logger.warning(f"Workflow instance not found: {instance_id}")
140140
return None
141141
self._logger.error(f"Unhandled RPC error while fetching workflow state: {error.code()} - {error.details()}")
142-
raise error
142+
raise
143143

144144
def wait_for_workflow_start(
145145
self, instance_id: str, *, fetch_payloads: bool = False, timeout_in_seconds: int = 60

ext/dapr-ext-workflow/tests/test_workflow_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from dapr.ext.workflow.dapr_workflow_client import DaprWorkflowClient
2222
from durabletask import client
2323
import durabletask.internal.orchestrator_service_pb2 as pb
24+
from grpc import StatusCode, RpcError
2425

2526
mock_schedule_result = 'workflow001'
2627
mock_raise_event_result = 'event001'
@@ -29,6 +30,18 @@
2930
mock_resume_result = 'resume001'
3031
mock_purge_result = 'purge001'
3132
mock_instance_id = 'instance001'
33+
wf_exists = False
34+
35+
class SimulatedRpcError(RpcError):
36+
def __init__(self, code, details):
37+
self._code = code
38+
self._details = details
39+
40+
def code(self):
41+
return self._code
42+
43+
def details(self):
44+
return self._details
3245

3346

3447
class FakeTaskHubGrpcClient:
@@ -43,8 +56,13 @@ def schedule_new_orchestration(
4356
return mock_schedule_result
4457

4558
def get_orchestration_state(self, instance_id, fetch_payloads):
59+
global wf_exists
60+
if not wf_exists:
61+
raise SimulatedRpcError(code="UNKNOWN", details="no such instance exists")
62+
4663
return self._inner_get_orchestration_state(instance_id, client.OrchestrationStatus.PENDING)
4764

65+
4866
def wait_for_orchestration_start(self, instance_id, fetch_payloads, timeout):
4967
return self._inner_get_orchestration_state(instance_id, client.OrchestrationStatus.RUNNING)
5068

@@ -100,6 +118,13 @@ def test_client_functions(self):
100118
)
101119
assert actual_schedule_result == mock_schedule_result
102120

121+
actual_get_result = wfClient.get_workflow_state(instance_id=mock_instance_id,
122+
fetch_payloads=True)
123+
assert actual_get_result is None
124+
125+
126+
global wf_exists
127+
wf_exists = True
103128
actual_get_result = wfClient.get_workflow_state(
104129
instance_id=mock_instance_id, fetch_payloads=True
105130
)

0 commit comments

Comments
 (0)