@@ -95,6 +95,25 @@ def generator_function_reducing_when_all(context):
95
95
yield context .call_activity ("Hello" , "London" )
96
96
return ""
97
97
98
+
99
+ def generator_function_reuse_task_in_whenany (context ):
100
+ task1 = context .call_activity ("Hello" , "Tokyo" )
101
+ task2 = context .call_activity ("Hello" , "Seattle" )
102
+ pending_tasks = [task1 , task2 ]
103
+
104
+ # Yield until first task is completed
105
+ finished_task1 = yield context .task_any (pending_tasks )
106
+
107
+ # Remove completed task from pending tasks
108
+ pending_tasks .remove (finished_task1 )
109
+
110
+ task3 = context .call_activity ("Hello" , "London" )
111
+ tasks = pending_tasks + [task3 ]
112
+
113
+ # Yield remaining tasks
114
+ yield context .task_any (tasks )
115
+ return ""
116
+
98
117
def generator_function_compound_tasks (context ):
99
118
yield context .call_activity ("Hello" , "Tokyo" )
100
119
@@ -731,6 +750,31 @@ def test_reducing_when_any_pattern():
731
750
732
751
assert_orchestration_state_equals (expected , result )
733
752
753
+ def test_reducing_when_any_pattern ():
754
+ """Tests that a user can call when_any on a progressively smaller list of already scheduled tasks"""
755
+ context_builder = ContextBuilder ('generator_function_reuse_task_in_whenany' , replay_schema = ReplaySchema .V2 )
756
+ add_hello_completed_events (context_builder , 0 , "\" Hello Tokyo!\" " )
757
+ add_hello_completed_events (context_builder , 1 , "\" Hello Seattle!\" " )
758
+ add_hello_completed_events (context_builder , 2 , "\" Hello London!\" " )
759
+
760
+ result = get_orchestration_state_result (
761
+ context_builder , generator_function_reuse_task_in_whenany )
762
+
763
+ # this scenario is only supported for V2 replay
764
+ expected_state = base_expected_state ("" ,replay_schema = ReplaySchema .V2 )
765
+ expected_state ._actions = [
766
+ [WhenAnyAction (
767
+ [CallActivityAction ("Hello" , "Seattle" ), CallActivityAction ("Hello" , "Tokyo" )]),
768
+ WhenAnyAction (
769
+ [CallActivityAction ("Hello" , "London" )])
770
+ ]
771
+ ]
772
+
773
+ expected_state ._is_done = True
774
+ expected = expected_state .to_json ()
775
+
776
+ assert_orchestration_state_equals (expected , result )
777
+
734
778
def test_compound_tasks_return_single_action_in_V2 ():
735
779
"""Tests that compound tasks, in the v2 replay schema, are represented as a single "deep" action"""
736
780
context_builder = ContextBuilder ('test_v2_replay_schema' , replay_schema = ReplaySchema .V2 )
0 commit comments