1
1
from azure .durable_functions .models .ReplaySchema import ReplaySchema
2
+ from azure .durable_functions .models .actions .WhenAnyAction import WhenAnyAction
2
3
from tests .test_utils .ContextBuilder import ContextBuilder
3
4
from .orchestrator_test_utils \
4
5
import get_orchestration_state_result , assert_orchestration_state_equals , assert_valid_schema
9
10
10
11
11
12
def base_expected_state (output = None , replay_schema : ReplaySchema = ReplaySchema .V1 ) -> OrchestratorState :
12
- return OrchestratorState (is_done = False , actions = [], output = output , replay_schema = replay_schema . value )
13
+ return OrchestratorState (is_done = False , actions = [], output = output , replay_schema = replay_schema )
13
14
14
15
def add_timer_fired_events (context_builder : ContextBuilder , id_ : int , timestamp : str ):
15
16
fire_at : str = context_builder .add_timer_created_event (id_ , timestamp )
@@ -99,4 +100,28 @@ def test_timers_can_be_cancelled():
99
100
expected = expected_state .to_json ()
100
101
101
102
assert_orchestration_state_equals (expected , result )
102
- assert result ["actions" ][0 ][1 ]["isCanceled" ]
103
+ assert result ["actions" ][0 ][1 ]["isCanceled" ]
104
+
105
+ def test_timers_can_be_cancelled_replayV2 ():
106
+
107
+ context_builder = ContextBuilder ("test_timers_can_be_cancelled" , replay_schema = ReplaySchema .V2 )
108
+ fire_at1 = context_builder .current_datetime + timedelta (minutes = 5 )
109
+ fire_at2 = context_builder .current_datetime + timedelta (minutes = 10 )
110
+ add_timer_fired_events (context_builder , 0 , str (fire_at1 ))
111
+ add_timer_fired_events (context_builder , 1 , str (fire_at2 ))
112
+
113
+ result = get_orchestration_state_result (
114
+ context_builder , generator_function_timer_can_be_cancelled )
115
+
116
+ expected_state = base_expected_state (output = 'Done!' , replay_schema = ReplaySchema .V2 )
117
+ expected_state ._actions = [
118
+ [WhenAnyAction (
119
+ [CreateTimerAction (fire_at = fire_at1 ), CreateTimerAction (fire_at = fire_at2 , is_cancelled = True )]
120
+ )]
121
+ ]
122
+
123
+ expected_state ._is_done = True
124
+ expected = expected_state .to_json ()
125
+
126
+ assert_orchestration_state_equals (expected , result )
127
+ assert result ["actions" ][0 ][0 ]['compoundActions' ][1 ]["isCanceled" ]
0 commit comments