@@ -171,6 +171,70 @@ def orchestrator(ctx: task.OrchestrationContext, orchestrator_input):
171
171
assert actions [0 ].scheduleTask .input .value == encoded_input
172
172
173
173
174
+ def test_schedule_activity_actions_router_without_app_id ():
175
+ """Tests that scheduleTask action contains correct router fields when app_id is specified"""
176
+ def dummy_activity (ctx , _ ):
177
+ pass
178
+
179
+ def orchestrator (ctx : task .OrchestrationContext , _ ):
180
+ yield ctx .call_activity (dummy_activity , input = 42 )
181
+
182
+ registry = worker ._Registry ()
183
+ name = registry .add_orchestrator (orchestrator )
184
+
185
+ # Prepare execution started event with source app set on router
186
+ exec_evt = helpers .new_execution_started_event (name , TEST_INSTANCE_ID , encoded_input = None )
187
+ exec_evt .router .sourceAppID = "source-app"
188
+
189
+ new_events = [
190
+ helpers .new_orchestrator_started_event (),
191
+ exec_evt ,
192
+ ]
193
+
194
+ executor = worker ._OrchestrationExecutor (registry , TEST_LOGGER )
195
+ result = executor .execute (TEST_INSTANCE_ID , [], new_events )
196
+ actions = result .actions
197
+
198
+ assert len (actions ) == 1
199
+ action = actions [0 ]
200
+ assert action .router .sourceAppID == "source-app"
201
+ assert action .router .targetAppID == ''
202
+ assert action .scheduleTask .router .sourceAppID == "source-app"
203
+ assert action .scheduleTask .router .targetAppID == ''
204
+
205
+
206
+ def test_schedule_activity_actions_router_with_app_id ():
207
+ """Tests that scheduleTask action contains correct router fields when app_id is specified"""
208
+ def dummy_activity (ctx , _ ):
209
+ pass
210
+
211
+ def orchestrator (ctx : task .OrchestrationContext , _ ):
212
+ yield ctx .call_activity (dummy_activity , input = 42 , app_id = "target-app" )
213
+
214
+ registry = worker ._Registry ()
215
+ name = registry .add_orchestrator (orchestrator )
216
+
217
+ # Prepare execution started event with source app set on router
218
+ exec_evt = helpers .new_execution_started_event (name , TEST_INSTANCE_ID , encoded_input = None )
219
+ exec_evt .router .sourceAppID = "source-app"
220
+
221
+ new_events = [
222
+ helpers .new_orchestrator_started_event (),
223
+ exec_evt ,
224
+ ]
225
+
226
+ executor = worker ._OrchestrationExecutor (registry , TEST_LOGGER )
227
+ result = executor .execute (TEST_INSTANCE_ID , [], new_events )
228
+ actions = result .actions
229
+
230
+ assert len (actions ) == 1
231
+ action = actions [0 ]
232
+ assert action .router .sourceAppID == "source-app"
233
+ assert action .router .targetAppID == "target-app"
234
+ assert action .scheduleTask .router .sourceAppID == "source-app"
235
+ assert action .scheduleTask .router .targetAppID == "target-app"
236
+
237
+
174
238
def test_activity_task_completion ():
175
239
"""Tests the successful completion of an activity task"""
176
240
@@ -561,6 +625,70 @@ def orchestrator(ctx: task.OrchestrationContext, _):
561
625
assert complete_action .result .value == "42"
562
626
563
627
628
+ def test_create_sub_orchestration_actions_router_without_app_id ():
629
+ """Tests that createSubOrchestration action contains correct router fields when app_id is specified"""
630
+ def suborchestrator (ctx : task .OrchestrationContext , _ ):
631
+ pass
632
+
633
+ def orchestrator (ctx : task .OrchestrationContext , _ ):
634
+ yield ctx .call_sub_orchestrator (suborchestrator , input = None )
635
+
636
+ registry = worker ._Registry ()
637
+ suborchestrator_name = registry .add_orchestrator (suborchestrator )
638
+ orchestrator_name = registry .add_orchestrator (orchestrator )
639
+
640
+ exec_evt = helpers .new_execution_started_event (orchestrator_name , TEST_INSTANCE_ID , encoded_input = None )
641
+ exec_evt .router .sourceAppID = "source-app"
642
+
643
+ new_events = [
644
+ helpers .new_orchestrator_started_event (),
645
+ exec_evt ,
646
+ ]
647
+
648
+ executor = worker ._OrchestrationExecutor (registry , TEST_LOGGER )
649
+ result = executor .execute (TEST_INSTANCE_ID , [], new_events )
650
+ actions = result .actions
651
+
652
+ assert len (actions ) == 1
653
+ action = actions [0 ]
654
+ assert action .router .sourceAppID == "source-app"
655
+ assert action .router .targetAppID == ''
656
+ assert action .createSubOrchestration .router .sourceAppID == "source-app"
657
+ assert action .createSubOrchestration .router .targetAppID == ''
658
+
659
+
660
+ def test_create_sub_orchestration_actions_router_with_app_id ():
661
+ """Tests that createSubOrchestration action contains correct router fields when app_id is specified"""
662
+ def suborchestrator (ctx : task .OrchestrationContext , _ ):
663
+ pass
664
+
665
+ def orchestrator (ctx : task .OrchestrationContext , _ ):
666
+ yield ctx .call_sub_orchestrator (suborchestrator , input = None , app_id = "target-app" )
667
+
668
+ registry = worker ._Registry ()
669
+ suborchestrator_name = registry .add_orchestrator (suborchestrator )
670
+ orchestrator_name = registry .add_orchestrator (orchestrator )
671
+
672
+ exec_evt = helpers .new_execution_started_event (orchestrator_name , TEST_INSTANCE_ID , encoded_input = None )
673
+ exec_evt .router .sourceAppID = "source-app"
674
+
675
+ new_events = [
676
+ helpers .new_orchestrator_started_event (),
677
+ exec_evt ,
678
+ ]
679
+
680
+ executor = worker ._OrchestrationExecutor (registry , TEST_LOGGER )
681
+ result = executor .execute (TEST_INSTANCE_ID , [], new_events )
682
+ actions = result .actions
683
+
684
+ assert len (actions ) == 1
685
+ action = actions [0 ]
686
+ assert action .router .sourceAppID == "source-app"
687
+ assert action .router .targetAppID == "target-app"
688
+ assert action .createSubOrchestration .router .sourceAppID == "source-app"
689
+ assert action .createSubOrchestration .router .targetAppID == "target-app"
690
+
691
+
564
692
def test_sub_orchestration_task_failed ():
565
693
"""Tests that a sub-orchestration task is completed when the sub-orchestration fails"""
566
694
def suborchestrator (ctx : task .OrchestrationContext , _ ):
0 commit comments