77)
88from cadence .error import EntityNotExistsError
99from 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+ )
1114from 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