20
20
from unittest import mock
21
21
from dapr .ext .workflow .dapr_workflow_client import DaprWorkflowClient
22
22
from durabletask import client
23
+ import durabletask .internal .orchestrator_service_pb2 as pb
23
24
24
25
mock_schedule_result = 'workflow001'
25
26
mock_raise_event_result = 'event001'
26
27
mock_terminate_result = 'terminate001'
27
28
mock_suspend_result = 'suspend001'
28
29
mock_resume_result = 'resume001'
29
- mockInstanceId = 'instance001'
30
+ mock_purge_result = 'purge001'
31
+ mock_instance_id = 'instance001'
30
32
31
33
32
34
class FakeTaskHubGrpcClient :
33
- def schedule_new_orchestration (self , workflow , input , instance_id , start_at ):
35
+ def schedule_new_orchestration (
36
+ self ,
37
+ workflow ,
38
+ input ,
39
+ instance_id ,
40
+ start_at ,
41
+ reuse_id_policy : Union [pb .OrchestrationIdReusePolicy , None ] = None ,
42
+ ):
34
43
return mock_schedule_result
35
44
36
45
def get_orchestration_state (self , instance_id , fetch_payloads ):
@@ -49,7 +58,9 @@ def raise_orchestration_event(
49
58
):
50
59
return mock_raise_event_result
51
60
52
- def terminate_orchestration (self , instance_id : str , * , output : Union [Any , None ] = None ):
61
+ def terminate_orchestration (
62
+ self , instance_id : str , * , output : Union [Any , None ] = None , recursive : bool = True
63
+ ):
53
64
return mock_terminate_result
54
65
55
66
def suspend_orchestration (self , instance_id : str ):
@@ -58,6 +69,9 @@ def suspend_orchestration(self, instance_id: str):
58
69
def resume_orchestration (self , instance_id : str ):
59
70
return mock_resume_result
60
71
72
+ def purge_orchestration (self , instance_id : str , recursive : bool = True ):
73
+ return mock_purge_result
74
+
61
75
def _inner_get_orchestration_state (self , instance_id , state : client .OrchestrationStatus ):
62
76
return client .OrchestrationState (
63
77
instance_id = instance_id ,
@@ -87,35 +101,38 @@ def test_client_functions(self):
87
101
assert actual_schedule_result == mock_schedule_result
88
102
89
103
actual_get_result = wfClient .get_workflow_state (
90
- instance_id = mockInstanceId , fetch_payloads = True
104
+ instance_id = mock_instance_id , fetch_payloads = True
91
105
)
92
106
assert actual_get_result .runtime_status .name == 'PENDING'
93
- assert actual_get_result .instance_id == mockInstanceId
107
+ assert actual_get_result .instance_id == mock_instance_id
94
108
95
109
actual_wait_start_result = wfClient .wait_for_workflow_start (
96
- instance_id = mockInstanceId , timeout_in_seconds = 30
110
+ instance_id = mock_instance_id , timeout_in_seconds = 30
97
111
)
98
112
assert actual_wait_start_result .runtime_status .name == 'RUNNING'
99
- assert actual_wait_start_result .instance_id == mockInstanceId
113
+ assert actual_wait_start_result .instance_id == mock_instance_id
100
114
101
115
actual_wait_completion_result = wfClient .wait_for_workflow_completion (
102
- instance_id = mockInstanceId , timeout_in_seconds = 30
116
+ instance_id = mock_instance_id , timeout_in_seconds = 30
103
117
)
104
118
assert actual_wait_completion_result .runtime_status .name == 'COMPLETED'
105
- assert actual_wait_completion_result .instance_id == mockInstanceId
119
+ assert actual_wait_completion_result .instance_id == mock_instance_id
106
120
107
121
actual_raise_event_result = wfClient .raise_workflow_event (
108
- instance_id = mockInstanceId , event_name = 'test_event' , data = 'test_data'
122
+ instance_id = mock_instance_id , event_name = 'test_event' , data = 'test_data'
109
123
)
110
124
assert actual_raise_event_result == mock_raise_event_result
111
125
112
126
actual_terminate_result = wfClient .terminate_workflow (
113
- instance_id = mockInstanceId , output = 'test_output'
127
+ instance_id = mock_instance_id , output = 'test_output'
114
128
)
115
129
assert actual_terminate_result == mock_terminate_result
116
130
117
- actual_suspend_result = wfClient .pause_workflow (instance_id = mockInstanceId )
131
+ actual_suspend_result = wfClient .pause_workflow (instance_id = mock_instance_id )
118
132
assert actual_suspend_result == mock_suspend_result
119
133
120
- actual_resume_result = wfClient .resume_workflow (instance_id = mockInstanceId )
134
+ actual_resume_result = wfClient .resume_workflow (instance_id = mock_instance_id )
121
135
assert actual_resume_result == mock_resume_result
136
+
137
+ actual_purge_result = wfClient .purge_workflow (instance_id = mock_instance_id )
138
+ assert actual_purge_result == mock_purge_result
0 commit comments