Skip to content

Commit f3701df

Browse files
committed
make call_activity additional test
1 parent 3b6d931 commit f3701df

File tree

5 files changed

+109
-3
lines changed

5 files changed

+109
-3
lines changed

azure/durable_functions/models/history/HistoryEvent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ def __init__(self):
77
self.EventType: HistoryEventType
88
self.EventId: int
99
self.IsPlayed: bool
10-
self.Timestamp: datetime
10+
self.Timestamp: str
1111
self.IsProcessed: bool = False

azure/durable_functions/orchestrator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _add_to_actions(self, generation_state):
9090
self.durable_context.actions.append(generation_state.actions)
9191

9292
def _reset_timestamp(self):
93-
last_timestamp = dt_parse(self.durable_context.decision_started_event.Timestamp)
93+
last_timestamp = dt_parse(self.durable_context.decision_started_event['Timestamp'])
9494
decision_started_events = list(
9595
filter(lambda e_: (
9696
e_["EventType"] == HistoryEventType.OrchestratorStarted
@@ -100,7 +100,7 @@ def _reset_timestamp(self):
100100
self.durable_context.currentUtcDateTime = None
101101
else:
102102
self.durable_context.decision_started_event = decision_started_events[0]
103-
self.durable_context.currentUtcDateTime = dt_parse(self.durable_context.decision_started_event.Timestamp)
103+
self.durable_context.currentUtcDateTime = dt_parse(self.durable_context.decision_started_event['Timestamp'])
104104

105105
@classmethod
106106
def create(cls, fn):
File renamed without changes.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
HANDLE_ONE = '{"history":[{"EventType":12,"EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:18:41.3240927Z"},' \
2+
'{"OrchestrationInstance":{"InstanceId":"48d0f95957504c2fa579e810a390b938",' \
3+
'"ExecutionId":"fd183ee02e4b4fd18c95b773cfb5452b"},"EventType":0,"ParentInstance":null,' \
4+
'"Name":"DurableFunctionsOrchestratorJS","Version":"","Input":"null","Tags":null,"EventId":-1,' \
5+
'"IsPlayed":false,"Timestamp":"2019-12-08T23:18:39.756132Z"}],"input":null,' \
6+
'"instanceId":"48d0f95957504c2fa579e810a390b938","isReplaying":false,"parentInstanceId":null}'
7+
8+
STATE_ONE = '{"isDone":false,"actions":[[{"functionName":"Hello","input":"Tokyo","actionType":0}]]}'
9+
10+
HANDLE_TWO = '{"history":[{"EventType":12,"EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:18:41.3240927Z"},' \
11+
'{"OrchestrationInstance":{"InstanceId":"48d0f95957504c2fa579e810a390b938",' \
12+
'"ExecutionId":"fd183ee02e4b4fd18c95b773cfb5452b"},"EventType":0,"ParentInstance":null,' \
13+
'"Name":"DurableFunctionsOrchestratorJS","Version":"","Input":"null","Tags":null,"EventId":-1,' \
14+
'"IsPlayed":true,"Timestamp":"2019-12-08T23:18:39.756132Z"},{"EventType":4,"Name":"Hello","Version":"",' \
15+
'"Input":null,"EventId":0,"IsPlayed":false,"Timestamp":"2019-12-08T23:29:51.5313393Z"},{"EventType":13,' \
16+
'"EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:29:51.5320985Z"},{"EventType":12,"EventId":-1,' \
17+
'"IsPlayed":false,"Timestamp":"2019-12-08T23:29:52.4899106Z"},{"EventType":5,"TaskScheduledId":0,' \
18+
'"Result":"Hello Tokyo!","EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:29:51.7873033Z"}],' \
19+
'"input":null,"instanceId":"48d0f95957504c2fa579e810a390b938","isReplaying":true,"parentInstanceId":null}'
20+
21+
STATE_TWO = '{"isDone":false,"actions":[[{"functionName":"Hello","input":"Tokyo","actionType":0}],' \
22+
'[{"functionName":"Hello","input":"Seattle","actionType":0}]]}'
23+
24+
HANDLE_THREE = '{"history":[{"EventType":12,"EventId":-1,"IsPlayed":false,' \
25+
'"Timestamp":"2019-12-08T23:18:41.3240927Z"},{"OrchestrationInstance":{' \
26+
'"InstanceId":"48d0f95957504c2fa579e810a390b938","ExecutionId":"fd183ee02e4b4fd18c95b773cfb5452b"},' \
27+
'"EventType":0,"ParentInstance":null,"Name":"DurableFunctionsOrchestratorJS","Version":"",' \
28+
'"Input":"null","Tags":null,"EventId":-1,"IsPlayed":true,"Timestamp":"2019-12-08T23:18:39.756132Z"},' \
29+
'{"EventType":4,"Name":"Hello","Version":"","Input":null,"EventId":0,"IsPlayed":false,' \
30+
'"Timestamp":"2019-12-08T23:29:51.5313393Z"},{"EventType":13,"EventId":-1,"IsPlayed":false,' \
31+
'"Timestamp":"2019-12-08T23:29:51.5320985Z"},{"EventType":12,"EventId":-1,"IsPlayed":false,' \
32+
'"Timestamp":"2019-12-08T23:29:52.4899106Z"},{"EventType":5,"TaskScheduledId":0,"Result":"Hello ' \
33+
'Tokyo!","EventId":-1,"IsPlayed":true,"Timestamp":"2019-12-08T23:29:51.7873033Z"},{"EventType":4,' \
34+
'"Name":"Hello","Version":"","Input":null,"EventId":1,"IsPlayed":false,' \
35+
'"Timestamp":"2019-12-08T23:34:12.2632487Z"},{"EventType":13,"EventId":-1,"IsPlayed":false,' \
36+
'"Timestamp":"2019-12-08T23:34:12.263286Z"},{"EventType":12,"EventId":-1,"IsPlayed":false,' \
37+
'"Timestamp":"2019-12-08T23:34:12.8710525Z"},{"EventType":5,"TaskScheduledId":1,"Result":"Hello ' \
38+
'Seattle!","EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:34:12.561288Z"}],"input":null,' \
39+
'"instanceId":"48d0f95957504c2fa579e810a390b938","isReplaying":true,"parentInstanceId":null}'
40+
41+
STATE_THREE = '{"isDone":false,"actions":[[{"functionName":"Hello","input":"Tokyo","actionType":0}],' \
42+
'[{"functionName":"Hello","input":"Seattle","actionType":0}],[{"functionName":"Hello","input":"London",' \
43+
'"actionType":0}]]}'
44+
45+
HANDLE_FOUR = '{"history":[{"EventType":12,"EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:18:41.3240927Z"},' \
46+
'{"OrchestrationInstance":{"InstanceId":"48d0f95957504c2fa579e810a390b938",' \
47+
'"ExecutionId":"fd183ee02e4b4fd18c95b773cfb5452b"},"EventType":0,"ParentInstance":null,' \
48+
'"Name":"DurableFunctionsOrchestratorJS","Version":"","Input":"null","Tags":null,"EventId":-1,' \
49+
'"IsPlayed":true,"Timestamp":"2019-12-08T23:18:39.756132Z"},{"EventType":4,"Name":"Hello","Version":"",' \
50+
'"Input":null,"EventId":0,"IsPlayed":false,"Timestamp":"2019-12-08T23:29:51.5313393Z"},{"EventType":13,' \
51+
'"EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:29:51.5320985Z"},{"EventType":12,' \
52+
'"EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:29:52.4899106Z"},{"EventType":5,' \
53+
'"TaskScheduledId":0,"Result":"Hello Tokyo!","EventId":-1,"IsPlayed":true,' \
54+
'"Timestamp":"2019-12-08T23:29:51.7873033Z"},{"EventType":4,"Name":"Hello","Version":"","Input":null,' \
55+
'"EventId":1,"IsPlayed":false,"Timestamp":"2019-12-08T23:34:12.2632487Z"},{"EventType":13,"EventId":-1,' \
56+
'"IsPlayed":false,"Timestamp":"2019-12-08T23:34:12.263286Z"},{"EventType":12,"EventId":-1,' \
57+
'"IsPlayed":false,"Timestamp":"2019-12-08T23:34:12.8710525Z"},{"EventType":5,"TaskScheduledId":1,' \
58+
'"Result":"Hello Seattle!","EventId":-1,"IsPlayed":true,"Timestamp":"2019-12-08T23:34:12.561288Z"},' \
59+
'{"EventType":4,"Name":"Hello","Version":"","Input":null,"EventId":2,"IsPlayed":false,' \
60+
'"Timestamp":"2019-12-08T23:35:01.5011494Z"},{"EventType":13,"EventId":-1,"IsPlayed":false,' \
61+
'"Timestamp":"2019-12-08T23:35:01.5011554Z"},{"EventType":12,"EventId":-1,"IsPlayed":false,' \
62+
'"Timestamp":"2019-12-08T23:36:20.866617Z"},{"EventType":5,"TaskScheduledId":2,"Result":"Hello ' \
63+
'London!","EventId":-1,"IsPlayed":false,"Timestamp":"2019-12-08T23:36:20.5364383Z"}],"input":null,' \
64+
'"instanceId":"48d0f95957504c2fa579e810a390b938","isReplaying":true,"parentInstanceId":null} '
65+
66+
STATE_FOUR = '{"isDone":true,"actions":[[{"functionName":"Hello","input":"Tokyo","actionType":0}],' \
67+
'[{"functionName":"Hello","input":"Seattle","actionType":0}],[{"functionName":"Hello","input":"London",' \
68+
'"actionType":0}]],"output":["Hello Tokyo!","Hello Seattle!","Hello London!"]} '
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
import json
3+
4+
from azure.durable_functions.orchestrator import Orchestrator
5+
from tests.orchestrator.chaining_context import *
6+
7+
8+
def generator_function(context):
9+
outputs = []
10+
11+
task1 = yield context.df.callActivity("Hello", "Tokyo")
12+
task2 = yield context.df.callActivity("Hello", "Seattle")
13+
task3 = yield context.df.callActivity("Hello", "London")
14+
15+
outputs.append(task1)
16+
outputs.append(task2)
17+
outputs.append(task3)
18+
19+
return outputs
20+
21+
22+
@pytest.mark.parametrize("context, output_state",
23+
[(HANDLE_ONE, STATE_ONE),
24+
(HANDLE_TWO, STATE_TWO),
25+
(HANDLE_THREE, STATE_THREE),
26+
(HANDLE_FOUR, STATE_FOUR)])
27+
def test_initial_activity_one(context, output_state):
28+
orchestrator = Orchestrator(generator_function)
29+
result = json.loads(orchestrator.handle(context))
30+
expected = json.loads(output_state)
31+
assert expected.get("isDone") == result.get("isDone")
32+
expected_actions = expected.get("actions")
33+
result_actions = result.get("actions")
34+
assert len(expected_actions) == len(result_actions)
35+
for index in range(len(expected_actions)):
36+
assert expected_actions[index][0]["functionName"] == result_actions[index][0]["functionName"]
37+
assert expected_actions[index][0]["input"] == result_actions[index][0]["input"]
38+
assert expected_actions[index][0]["actionType"] == result_actions[index][0]["actionType"]

0 commit comments

Comments
 (0)