Skip to content

Commit 188bb6d

Browse files
committed
remove duplicate logic
Signed-off-by: Tim Li <[email protected]>
1 parent c357057 commit 188bb6d

File tree

2 files changed

+23
-44
lines changed

2 files changed

+23
-44
lines changed

cadence/client.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -218,28 +218,6 @@ async def start_workflow(
218218
except Exception as e:
219219
raise Exception(f"Failed to start workflow: {e}") from e
220220

221-
async def execute_workflow(
222-
self,
223-
workflow: Union[str, Callable],
224-
*args,
225-
**options_kwargs
226-
) -> WorkflowExecution:
227-
"""
228-
Start a workflow execution and return the execution handle.
229-
230-
Args:
231-
workflow: Workflow function or workflow type name string
232-
*args: Arguments to pass to the workflow
233-
**options_kwargs: StartWorkflowOptions as keyword arguments
234-
235-
Returns:
236-
WorkflowExecution that contains workflow_id and run_id
237-
238-
Raises:
239-
ValueError: If required parameters are missing or invalid
240-
Exception: If the gRPC call fails
241-
"""
242-
return await self.start_workflow(workflow, *args, **options_kwargs)
243221

244222

245223

tests/cadence/test_client_workflow.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -276,48 +276,49 @@ async def mock_build_request(workflow, args, options):
276276
assert captured_options.execution_start_to_close_timeout == timedelta(minutes=30)
277277

278278

279-
class TestClientExecuteWorkflow:
280-
"""Test Client.execute_workflow method."""
279+
class TestClientStartWorkflow:
280+
"""Test Client.start_workflow method."""
281281

282282
@pytest.mark.asyncio
283-
async def test_execute_workflow_success(self, mock_client):
284-
"""Test successful workflow execution."""
285-
# Mock start_workflow to return execution
283+
async def test_start_workflow_success(self, mock_client):
284+
"""Test successful workflow start."""
285+
# Mock the gRPC stub
286286
execution = WorkflowExecution()
287287
execution.workflow_id = "test-workflow-id"
288288
execution.run_id = "test-run-id"
289289

290+
response = StartWorkflowExecutionResponse()
291+
response.run_id = "test-run-id"
292+
290293
client = Client(domain="test-domain", target="localhost:7933")
291-
client.start_workflow = AsyncMock(return_value=execution)
294+
client._workflow_stub = Mock()
295+
client._workflow_stub.StartWorkflowExecution = AsyncMock(return_value=response)
292296

293-
result_execution = await client.execute_workflow(
297+
result_execution = await client.start_workflow(
294298
"TestWorkflow",
295299
"arg1", "arg2",
296-
task_list="test-task-list"
300+
task_list="test-task-list",
301+
workflow_id="test-workflow-id"
297302
)
298303

299304
assert isinstance(result_execution, WorkflowExecution)
300-
assert result_execution is execution
301305
assert result_execution.workflow_id == "test-workflow-id"
302306
assert result_execution.run_id == "test-run-id"
303307

304-
# Verify start_workflow was called with correct arguments
305-
client.start_workflow.assert_called_once_with(
306-
"TestWorkflow",
307-
"arg1", "arg2",
308-
task_list="test-task-list"
309-
)
308+
# Verify gRPC call was made
309+
client._workflow_stub.StartWorkflowExecution.assert_called_once()
310310

311311
@pytest.mark.asyncio
312-
async def test_execute_workflow_propagates_error(self, mock_client):
313-
"""Test that execute_workflow propagates errors from start_workflow."""
312+
async def test_start_workflow_propagates_error(self, mock_client):
313+
"""Test that start_workflow propagates gRPC errors."""
314314
client = Client(domain="test-domain", target="localhost:7933")
315-
client.start_workflow = AsyncMock(side_effect=ValueError("Invalid task_list"))
315+
client._workflow_stub = Mock()
316+
client._workflow_stub.StartWorkflowExecution = AsyncMock(side_effect=ValueError("gRPC error"))
316317

317-
with pytest.raises(ValueError, match="Invalid task_list"):
318-
await client.execute_workflow(
318+
with pytest.raises(Exception, match="Failed to start workflow"):
319+
await client.start_workflow(
319320
"TestWorkflow",
320-
task_list=""
321+
task_list="valid-task-list"
321322
)
322323

323324

@@ -334,7 +335,7 @@ async def test_integration_workflow_invocation():
334335
client._workflow_stub.StartWorkflowExecution = AsyncMock(return_value=response)
335336

336337
# Test the complete flow
337-
execution = await client.execute_workflow(
338+
execution = await client.start_workflow(
338339
"IntegrationTestWorkflow",
339340
"test-arg",
340341
42,

0 commit comments

Comments
 (0)