Skip to content

Commit 195f5c1

Browse files
committed
address comments
Signed-off-by: Tim Li <ltim@uber.com>
1 parent 7c4b3ae commit 195f5c1

File tree

2 files changed

+48
-69
lines changed

2 files changed

+48
-69
lines changed

cadence/client.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ async def signal_with_start_workflow(
236236
self,
237237
workflow: Union[str, WorkflowDefinition],
238238
signal_name: str,
239-
signal_input: Any = None,
240-
*args,
239+
signal_args: list[Any],
240+
*workflow_args: Any,
241241
**options_kwargs: Unpack[StartWorkflowOptions],
242242
) -> WorkflowExecution:
243243
"""
@@ -246,8 +246,8 @@ async def signal_with_start_workflow(
246246
Args:
247247
workflow: WorkflowDefinition or workflow type name string
248248
signal_name: Name of the signal
249-
signal_input: Input data for the signal
250-
*args: Arguments to pass to the workflow if it needs to be started
249+
signal_args: List of arguments to pass to the signal handler
250+
*workflow_args: Arguments to pass to the workflow if it needs to be started
251251
**options_kwargs: StartWorkflowOptions as keyword arguments
252252
253253
Returns:
@@ -261,13 +261,15 @@ async def signal_with_start_workflow(
261261
options = _validate_and_apply_defaults(StartWorkflowOptions(**options_kwargs))
262262

263263
# Build the start workflow request
264-
start_request = self._build_start_workflow_request(workflow, args, options)
264+
start_request = self._build_start_workflow_request(
265+
workflow, workflow_args, options
266+
)
265267

266268
# Encode signal input
267269
signal_payload = None
268-
if signal_input is not None:
270+
if signal_args:
269271
try:
270-
signal_payload = self.data_converter.to_data([signal_input])
272+
signal_payload = self.data_converter.to_data(signal_args)
271273
except Exception as e:
272274
raise ValueError(f"Failed to encode signal input: {e}")
273275

@@ -286,11 +288,6 @@ async def signal_with_start_workflow(
286288
await self.workflow_stub.SignalWithStartWorkflowExecution(request)
287289
)
288290

289-
# Emit metrics if available
290-
if self.metrics_emitter:
291-
# TODO: Add metrics similar to Go client
292-
pass
293-
294291
execution = WorkflowExecution()
295292
execution.workflow_id = start_request.workflow_id
296293
execution.run_id = response.run_id

tests/integration_tests/test_client.py

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
)
88
from cadence.error import EntityNotExistsError
99
from tests.integration_tests.helper import CadenceHelper, DOMAIN_NAME
10-
from cadence.api.v1.service_workflow_pb2 import DescribeWorkflowExecutionRequest
10+
from cadence.api.v1.service_workflow_pb2 import (
11+
DescribeWorkflowExecutionRequest,
12+
GetWorkflowExecutionHistoryRequest,
13+
)
1114
from cadence.api.v1.common_pb2 import WorkflowExecution
1215

1316

@@ -137,59 +140,27 @@ async def test_workflow_stub_start_and_describe(helper: CadenceHelper):
137140
)
138141

139142

140-
# trying parametrized test for table test
141-
@pytest.mark.parametrize(
142-
"test_case,workflow_id,start_first,expected_same_run",
143-
[
144-
(
145-
"new_workflow",
146-
"test-workflow-signal-with-start-123",
147-
False,
148-
False,
149-
),
150-
(
151-
"existing_workflow",
152-
"test-workflow-signal-existing-456",
153-
True,
154-
True,
155-
),
156-
],
157-
)
158143
@pytest.mark.usefixtures("helper")
159-
async def test_signal_with_start_workflow(
160-
helper: CadenceHelper,
161-
test_case: str,
162-
workflow_id: str,
163-
start_first: bool,
164-
expected_same_run: bool,
165-
):
144+
async def test_signal_with_start_workflow(helper: CadenceHelper):
166145
"""Test signal_with_start_workflow method.
167146
168-
Test cases:
169-
1. new_workflow: SignalWithStartWorkflow starts a new workflow if it doesn't exist
170-
2. existing_workflow: SignalWithStartWorkflow signals existing workflow without restart
147+
This integration test verifies:
148+
1. Starting a workflow via signal_with_start_workflow
149+
2. Sending a signal to the workflow
150+
3. Signal appears in the workflow's history with correct name and payload
171151
"""
172152
async with helper.client() as client:
173-
workflow_type = f"test-workflow-signal-{test_case}"
174-
task_list_name = f"test-task-list-signal-{test_case}"
153+
workflow_type = "test-workflow-signal-with-start"
154+
task_list_name = "test-task-list-signal-with-start"
155+
workflow_id = "test-workflow-signal-with-start-123"
175156
execution_timeout = timedelta(minutes=5)
176157
signal_name = "test-signal"
177-
signal_input = {"data": "test-signal-data"}
178-
179-
first_run_id = None
180-
if start_first:
181-
first_execution = await client.start_workflow(
182-
workflow_type,
183-
task_list=task_list_name,
184-
execution_start_to_close_timeout=execution_timeout,
185-
workflow_id=workflow_id,
186-
)
187-
first_run_id = first_execution.run_id
158+
signal_arg = {"data": "test-signal-data"}
188159

189160
execution = await client.signal_with_start_workflow(
190161
workflow_type,
191162
signal_name,
192-
signal_input,
163+
[signal_arg],
193164
"arg1",
194165
"arg2",
195166
task_list=task_list_name,
@@ -202,20 +173,31 @@ async def test_signal_with_start_workflow(
202173
assert execution.run_id is not None
203174
assert execution.run_id != ""
204175

205-
if expected_same_run:
206-
assert execution.run_id == first_run_id
207-
208-
describe_request = DescribeWorkflowExecutionRequest(
209-
domain=DOMAIN_NAME,
210-
workflow_execution=WorkflowExecution(
211-
workflow_id=execution.workflow_id,
212-
run_id=execution.run_id,
213-
),
176+
# Fetch workflow history to verify signal was recorded
177+
history_response = await client.workflow_stub.GetWorkflowExecutionHistory(
178+
GetWorkflowExecutionHistoryRequest(
179+
domain=DOMAIN_NAME,
180+
workflow_execution=execution,
181+
skip_archival=True,
182+
)
214183
)
215184

216-
response = await client.workflow_stub.DescribeWorkflowExecution(
217-
describe_request
218-
)
185+
# Verify signal event appears in history with correct name and payload
186+
signal_events = [
187+
event
188+
for event in history_response.history.events
189+
if event.HasField("workflow_execution_signaled_event_attributes")
190+
]
219191

220-
assert response.workflow_execution_info.type.name == workflow_type
221-
assert response.workflow_execution_info.task_list == task_list_name
192+
assert len(signal_events) == 1, "Expected exactly one signal event in history"
193+
signal_event = signal_events[0]
194+
assert (
195+
signal_event.workflow_execution_signaled_event_attributes.signal_name
196+
== signal_name
197+
), f"Expected signal name '{signal_name}'"
198+
199+
# Verify signal payload matches what we sent
200+
signal_payload_data = signal_event.workflow_execution_signaled_event_attributes.input.data.decode()
201+
assert signal_arg["data"] in signal_payload_data, (
202+
f"Expected signal payload to contain '{signal_arg['data']}'"
203+
)

0 commit comments

Comments
 (0)