-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathtest_dts_class_based_entities_e2e.py
More file actions
141 lines (111 loc) · 5.6 KB
/
test_dts_class_based_entities_e2e.py
File metadata and controls
141 lines (111 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from datetime import datetime, timezone
import os
import time
import pytest
from durabletask import client, entities, task
from durabletask.azuremanaged.client import DurableTaskSchedulerClient
from durabletask.azuremanaged.worker import DurableTaskSchedulerWorker
# NOTE: These tests assume a sidecar process is running. Example command:
# docker run -i -p 8080:8080 -p 8082:8082 -d mcr.microsoft.com/dts/dts-emulator:latest
pytestmark = pytest.mark.dts
# Read the environment variables
taskhub_name = os.getenv("TASKHUB", "default")
endpoint = os.getenv("ENDPOINT", "http://localhost:8080")
def test_client_signal_class_entity():
invoked = False
class EmptyEntity(entities.DurableEntity):
def do_nothing(self, _):
nonlocal invoked # don't do this in a real app!
invoked = True
# Start a worker, which will connect to the sidecar in a background thread
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None) as w:
w.add_entity(EmptyEntity)
w.start()
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None)
entity_id = entities.EntityInstanceId("EmptyEntity", "testEntity")
c.signal_entity(entity_id, "do_nothing")
time.sleep(2) # wait for the signal to be processed
assert invoked
def test_client_get_class_entity():
invoked = False
class EmptyEntity(entities.DurableEntity):
def do_nothing(self, _):
self.set_state(1)
nonlocal invoked # don't do this in a real app!
invoked = True
# Start a worker, which will connect to the sidecar in a background thread
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None) as w:
w.add_entity(EmptyEntity)
w.start()
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None)
entity_id = entities.EntityInstanceId("EmptyEntity", "testEntity")
c.signal_entity(entity_id, "do_nothing")
time.sleep(2) # wait for the signal to be processed
state = c.get_entity(entity_id)
assert state is not None
assert state.id == entity_id
assert state.get_locked_by() is None
assert state.last_modified < datetime.now(timezone.utc)
assert state.get_state(int) == 1
assert invoked
def test_orchestration_signal_class_entity():
invoked = False
class EmptyEntity(entities.DurableEntity):
def do_nothing(self, _):
nonlocal invoked # don't do this in a real app!
invoked = True
def empty_orchestrator(ctx: task.OrchestrationContext, _):
entity_id = entities.EntityInstanceId("EmptyEntity", "testEntity")
ctx.signal_entity(entity_id, "do_nothing")
# Start a worker, which will connect to the sidecar in a background thread
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None) as w:
w.add_orchestrator(empty_orchestrator)
w.add_entity(EmptyEntity)
w.start()
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None)
id = c.schedule_new_orchestration(empty_orchestrator)
state = c.wait_for_orchestration_completion(id, timeout=30)
time.sleep(2) # wait for the signal to be processed - signals cannot be awaited from inside the orchestrator
assert invoked
assert state is not None
assert state.name == task.get_name(empty_orchestrator)
assert state.instance_id == id
assert state.failure_details is None
assert state.runtime_status == client.OrchestrationStatus.COMPLETED
assert state.serialized_input is None
assert state.serialized_output is None
assert state.serialized_custom_status is None
def test_orchestration_call_class_entity():
invoked = False
class EmptyEntity(entities.DurableEntity):
def do_nothing(self, _):
nonlocal invoked # don't do this in a real app!
invoked = True
def empty_orchestrator(ctx: task.OrchestrationContext, _):
entity_id = entities.EntityInstanceId("EmptyEntity", "testEntity")
yield ctx.call_entity(entity_id, "do_nothing")
# Start a worker, which will connect to the sidecar in a background thread
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None) as w:
w.add_orchestrator(empty_orchestrator)
w.add_entity(EmptyEntity)
w.start()
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
taskhub=taskhub_name, token_credential=None)
id = c.schedule_new_orchestration(empty_orchestrator)
state = c.wait_for_orchestration_completion(id, timeout=30)
assert invoked
assert state is not None
assert state.name == task.get_name(empty_orchestrator)
assert state.instance_id == id
assert state.failure_details is None
assert state.runtime_status == client.OrchestrationStatus.COMPLETED
assert state.serialized_input is None
assert state.serialized_output is None
assert state.serialized_custom_status is None