55
66from cadence .api .v1 .common_pb2 import WorkflowExecution
77from cadence .api .v1 .service_workflow_pb2 import StartWorkflowExecutionRequest , StartWorkflowExecutionResponse
8- from cadence .api .v1 .workflow_pb2 import WorkflowIdReusePolicy
98from cadence .client import Client , StartWorkflowOptions
109from cadence .data_converter import DefaultDataConverter
1110
@@ -31,12 +30,15 @@ class TestStartWorkflowOptions:
3130
3231 def test_default_values (self ):
3332 """Test default values for StartWorkflowOptions."""
34- options = StartWorkflowOptions ()
33+ options = StartWorkflowOptions (
34+ task_list = "test-task-list" ,
35+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
36+ task_start_to_close_timeout = timedelta (seconds = 30 )
37+ )
3538 assert options .workflow_id is None
36- assert options .task_list == ""
37- assert options .execution_start_to_close_timeout is None
38- assert options .task_start_to_close_timeout is None
39- assert options .workflow_id_reuse_policy == WorkflowIdReusePolicy .WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
39+ assert options .task_list == "test-task-list"
40+ assert options .execution_start_to_close_timeout == timedelta (minutes = 10 )
41+ assert options .task_start_to_close_timeout == timedelta (seconds = 30 )
4042 assert options .cron_schedule is None
4143
4244 def test_custom_values (self ):
@@ -46,15 +48,13 @@ def test_custom_values(self):
4648 task_list = "test-task-list" ,
4749 execution_start_to_close_timeout = timedelta (minutes = 30 ),
4850 task_start_to_close_timeout = timedelta (seconds = 10 ),
49- workflow_id_reuse_policy = WorkflowIdReusePolicy .WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE ,
5051 cron_schedule = "0 * * * *"
5152 )
5253
5354 assert options .workflow_id == "custom-id"
5455 assert options .task_list == "test-task-list"
5556 assert options .execution_start_to_close_timeout == timedelta (minutes = 30 )
5657 assert options .task_start_to_close_timeout == timedelta (seconds = 10 )
57- assert options .workflow_id_reuse_policy == WorkflowIdReusePolicy .WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE
5858 assert options .cron_schedule == "0 * * * *"
5959
6060
@@ -84,7 +84,7 @@ async def test_build_request_with_string_workflow(self, mock_client):
8484 assert request .workflow_type .name == "TestWorkflow"
8585 assert request .task_list .name == "test-task-list"
8686 assert request .identity == client .identity
87- assert request .workflow_id_reuse_policy == WorkflowIdReusePolicy . WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
87+ assert request .workflow_id_reuse_policy == 0 # Default protobuf value when not set
8888 assert request .request_id != "" # Should be a UUID
8989
9090 # Verify UUID format
@@ -99,7 +99,9 @@ def test_workflow():
9999 client = Client (domain = "test-domain" , target = "localhost:7933" )
100100
101101 options = StartWorkflowOptions (
102- task_list = "test-task-list"
102+ task_list = "test-task-list" ,
103+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
104+ task_start_to_close_timeout = timedelta (seconds = 30 )
103105 )
104106
105107 request = await client ._build_start_workflow_request (test_workflow , (), options )
@@ -111,7 +113,11 @@ async def test_build_request_generates_workflow_id(self, mock_client):
111113 """Test that workflow_id is generated when not provided."""
112114 client = Client (domain = "test-domain" , target = "localhost:7933" )
113115
114- options = StartWorkflowOptions (task_list = "test-task-list" )
116+ options = StartWorkflowOptions (
117+ task_list = "test-task-list" ,
118+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
119+ task_start_to_close_timeout = timedelta (seconds = 30 )
120+ )
115121
116122 request = await client ._build_start_workflow_request ("TestWorkflow" , (), options )
117123
@@ -122,19 +128,42 @@ async def test_build_request_generates_workflow_id(self, mock_client):
122128 @pytest .mark .asyncio
123129 async def test_build_request_missing_task_list (self , mock_client ):
124130 """Test that missing task_list raises ValueError."""
125- client = Client (domain = "test-domain" , target = "localhost:7933" )
131+ with pytest .raises (TypeError ): # task_list is now required positional argument
132+ StartWorkflowOptions () # No task_list
126133
127- options = StartWorkflowOptions () # No task_list
134+ def test_missing_timeout_raises_error (self ):
135+ """Test that missing both timeouts raises ValueError."""
136+ with pytest .raises (ValueError , match = "either execution_start_to_close_timeout or task_start_to_close_timeout is required" ):
137+ StartWorkflowOptions (task_list = "test-task-list" )
128138
129- with pytest .raises (ValueError , match = "task_list is required" ):
130- await client ._build_start_workflow_request ("TestWorkflow" , (), options )
139+ def test_only_execution_timeout (self ):
140+ """Test that only execution_start_to_close_timeout is valid."""
141+ options = StartWorkflowOptions (
142+ task_list = "test-task-list" ,
143+ execution_start_to_close_timeout = timedelta (minutes = 10 )
144+ )
145+ assert options .execution_start_to_close_timeout == timedelta (minutes = 10 )
146+ assert options .task_start_to_close_timeout is None
147+
148+ def test_only_task_timeout (self ):
149+ """Test that only task_start_to_close_timeout is valid."""
150+ options = StartWorkflowOptions (
151+ task_list = "test-task-list" ,
152+ task_start_to_close_timeout = timedelta (seconds = 30 )
153+ )
154+ assert options .execution_start_to_close_timeout is None
155+ assert options .task_start_to_close_timeout == timedelta (seconds = 30 )
131156
132157 @pytest .mark .asyncio
133158 async def test_build_request_with_input_args (self , mock_client ):
134159 """Test building request with input arguments."""
135160 client = Client (domain = "test-domain" , target = "localhost:7933" )
136161
137- options = StartWorkflowOptions (task_list = "test-task-list" )
162+ options = StartWorkflowOptions (
163+ task_list = "test-task-list" ,
164+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
165+ task_start_to_close_timeout = timedelta (seconds = 30 )
166+ )
138167
139168 request = await client ._build_start_workflow_request ("TestWorkflow" , ("arg1" , 42 , {"key" : "value" }), options )
140169
@@ -169,6 +198,8 @@ async def test_build_request_with_cron_schedule(self, mock_client):
169198
170199 options = StartWorkflowOptions (
171200 task_list = "test-task-list" ,
201+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
202+ task_start_to_close_timeout = timedelta (seconds = 30 ),
172203 cron_schedule = "0 * * * *"
173204 )
174205
@@ -206,7 +237,9 @@ async def mock_build_request(workflow, args, options):
206237 "TestWorkflow" ,
207238 "arg1" , "arg2" ,
208239 task_list = "test-task-list" ,
209- workflow_id = "test-workflow-id"
240+ workflow_id = "test-workflow-id" ,
241+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
242+ task_start_to_close_timeout = timedelta (seconds = 30 )
210243 )
211244
212245 assert isinstance (execution , WorkflowExecution )
@@ -231,7 +264,9 @@ async def test_start_workflow_grpc_error(self, mock_client):
231264 with pytest .raises (Exception , match = "Failed to start workflow: gRPC error" ):
232265 await client .start_workflow (
233266 "TestWorkflow" ,
234- task_list = "test-task-list"
267+ task_list = "test-task-list" ,
268+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
269+ task_start_to_close_timeout = timedelta (seconds = 30 )
235270 )
236271
237272 @pytest .mark .asyncio
@@ -261,7 +296,8 @@ async def mock_build_request(workflow, args, options):
261296 "arg1" ,
262297 task_list = "test-task-list" ,
263298 workflow_id = "custom-id" ,
264- execution_start_to_close_timeout = timedelta (minutes = 30 )
299+ execution_start_to_close_timeout = timedelta (minutes = 30 ),
300+ task_start_to_close_timeout = timedelta (seconds = 30 )
265301 )
266302
267303 # Verify options were properly constructed
@@ -292,7 +328,8 @@ async def test_integration_workflow_invocation():
292328 {"data" : "value" },
293329 task_list = "integration-task-list" ,
294330 workflow_id = "integration-workflow-id" ,
295- execution_start_to_close_timeout = timedelta (minutes = 10 )
331+ execution_start_to_close_timeout = timedelta (minutes = 10 ),
332+ task_start_to_close_timeout = timedelta (seconds = 30 )
296333 )
297334
298335 # Verify result
0 commit comments