@@ -214,17 +214,17 @@ def orchestrator_empty_instance(ctx: task.OrchestrationContext, _):
214214 return "completed"
215215
216216 registry = worker ._Registry ()
217-
217+
218218 # Test empty instance_id
219219 name1 = registry .add_orchestrator (orchestrator_empty_instance )
220220 new_events = [
221221 helpers .new_orchestrator_started_event (),
222222 helpers .new_execution_started_event (name1 , TEST_INSTANCE_ID , encoded_input = None ),
223223 ]
224224 executor = worker ._OrchestrationExecutor (registry , TEST_LOGGER )
225-
225+
226226 result = executor .execute (TEST_INSTANCE_ID , [], new_events )
227-
227+
228228 # Check if the orchestration failed due to validation error
229229 actions = result .actions
230230 if len (actions ) > 0 :
@@ -245,90 +245,90 @@ def orchestrator_empty_instance(ctx: task.OrchestrationContext, _):
245245
246246def test_orchestration_to_orchestration_communication ():
247247 """Test advanced scenario: orchestration sends event to another waiting orchestration"""
248-
248+
249249 # Define the waiting orchestration that waits for an approval event
250250 def waiting_orchestration (ctx : task .OrchestrationContext , _ ):
251251 approval_data = yield ctx .wait_for_external_event ("approval" )
252252 return f"Received approval: { approval_data } "
253-
253+
254254 # Define the sender orchestration that sends an event to another orchestration
255255 def sender_orchestration (ctx : task .OrchestrationContext , target_instance_id : str ):
256256 approval_payload = {"approved" : True , "approver" : "manager" , "timestamp" : "2024-01-01T10:00:00Z" }
257257 yield ctx .send_event (target_instance_id , "approval" , data = approval_payload )
258258 return "Event sent successfully"
259-
259+
260260 registry = worker ._Registry ()
261261 waiting_name = registry .add_orchestrator (waiting_orchestration )
262262 sender_name = registry .add_orchestrator (sender_orchestration )
263263 executor = worker ._OrchestrationExecutor (registry , TEST_LOGGER )
264-
264+
265265 # Instance IDs for our orchestrations
266266 waiting_instance_id = "waiting-instance-123"
267267 sender_instance_id = "sender-instance-456"
268-
268+
269269 # Step 1: Start the waiting orchestration
270270 waiting_new_events = [
271271 helpers .new_orchestrator_started_event (),
272272 helpers .new_execution_started_event (waiting_name , waiting_instance_id , encoded_input = None ),
273273 ]
274274 waiting_result = executor .execute (waiting_instance_id , [], waiting_new_events )
275-
275+
276276 # The waiting orchestration should produce no actions when waiting for an external event
277277 assert len (waiting_result .actions ) == 0
278-
278+
279279 # Step 2: Start the sender orchestration with the waiting instance ID as input
280280 sender_new_events = [
281281 helpers .new_orchestrator_started_event (),
282- helpers .new_execution_started_event (sender_name , sender_instance_id ,
283- encoded_input = json .dumps (waiting_instance_id )),
282+ helpers .new_execution_started_event (sender_name , sender_instance_id ,
283+ encoded_input = json .dumps (waiting_instance_id )),
284284 ]
285285 sender_result = executor .execute (sender_instance_id , [], sender_new_events )
286-
286+
287287 # The sender orchestration should yield a send_event action
288288 assert len (sender_result .actions ) == 1
289289 send_action = sender_result .actions [0 ]
290290 assert send_action .WhichOneof ("orchestratorActionType" ) == "sendEvent"
291291 assert send_action .sendEvent .instance .instanceId == waiting_instance_id
292292 assert send_action .sendEvent .name == "approval"
293-
293+
294294 # Verify the data payload is correct
295295 expected_payload = {"approved" : True , "approver" : "manager" , "timestamp" : "2024-01-01T10:00:00Z" }
296296 assert send_action .sendEvent .data .value == json .dumps (expected_payload )
297-
297+
298298 # Step 3: Complete the send_event action
299- event_sent = helpers .new_event_sent_event (waiting_instance_id , "approval" ,
300- json .dumps (expected_payload ))
299+ event_sent = helpers .new_event_sent_event (waiting_instance_id , "approval" ,
300+ json .dumps (expected_payload ))
301301 event_sent .eventId = send_action .id
302-
302+
303303 sender_old_events = [
304304 helpers .new_orchestrator_started_event (),
305- helpers .new_execution_started_event (sender_name , sender_instance_id ,
306- encoded_input = json .dumps (waiting_instance_id ))
305+ helpers .new_execution_started_event (sender_name , sender_instance_id ,
306+ encoded_input = json .dumps (waiting_instance_id ))
307307 ]
308308 sender_completion_result = executor .execute (sender_instance_id , sender_old_events , [event_sent ])
309-
309+
310310 # The sender should complete successfully
311311 assert len (sender_completion_result .actions ) == 1
312312 sender_complete_action = sender_completion_result .actions [0 ]
313313 assert sender_complete_action .WhichOneof ("orchestratorActionType" ) == "completeOrchestration"
314314 assert sender_complete_action .completeOrchestration .orchestrationStatus == pb .ORCHESTRATION_STATUS_COMPLETED
315315 assert sender_complete_action .completeOrchestration .result .value == json .dumps ("Event sent successfully" )
316-
316+
317317 # Step 4: Simulate the event being raised to the waiting orchestration
318318 event_raised = helpers .new_event_raised_event ("approval" , json .dumps (expected_payload ))
319-
319+
320320 waiting_old_events = [
321321 helpers .new_orchestrator_started_event (),
322322 helpers .new_execution_started_event (waiting_name , waiting_instance_id , encoded_input = None )
323323 ]
324324 waiting_completion_result = executor .execute (waiting_instance_id , waiting_old_events , [event_raised ])
325-
325+
326326 # The waiting orchestration should complete with the received data
327327 assert len (waiting_completion_result .actions ) == 1
328328 waiting_complete_action = waiting_completion_result .actions [0 ]
329329 assert waiting_complete_action .WhichOneof ("orchestratorActionType" ) == "completeOrchestration"
330330 assert waiting_complete_action .completeOrchestration .orchestrationStatus == pb .ORCHESTRATION_STATUS_COMPLETED
331-
331+
332332 # Verify the data was passed correctly through the event
333333 expected_result = f"Received approval: { expected_payload } "
334334 assert waiting_complete_action .completeOrchestration .result .value == json .dumps (expected_result )
0 commit comments