Skip to content

Commit faf6cc4

Browse files
committed
Add tests
1 parent f39b99e commit faf6cc4

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/durabletask-azuremanaged/test_dts_class_based_entities_e2e.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timezone
12
import os
23
import time
34

@@ -39,6 +40,36 @@ def do_nothing(self, _):
3940
assert invoked
4041

4142

43+
def test_client_get_class_entity():
44+
invoked = False
45+
46+
class EmptyEntity(entities.DurableEntity):
47+
def do_nothing(self, _):
48+
self.set_state(1)
49+
nonlocal invoked # don't do this in a real app!
50+
invoked = True
51+
52+
# Start a worker, which will connect to the sidecar in a background thread
53+
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
54+
taskhub=taskhub_name, token_credential=None) as w:
55+
w.add_entity(EmptyEntity)
56+
w.start()
57+
58+
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
59+
taskhub=taskhub_name, token_credential=None)
60+
entity_id = entities.EntityInstanceId("EmptyEntity", "testEntity")
61+
c.signal_entity(entity_id, "do_nothing")
62+
time.sleep(2) # wait for the signal to be processed
63+
state = c.get_entity(entity_id)
64+
assert state is not None
65+
assert state.id == entity_id
66+
assert state.locked_by is None
67+
assert state.last_modified > datetime.now(timezone.utc)
68+
assert state.get_state(int) == 1
69+
70+
assert invoked
71+
72+
4273
def test_orchestration_signal_class_entity():
4374
invoked = False
4475

tests/durabletask-azuremanaged/test_dts_function_based_entities_e2e.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime, timezone
12
import os
23
import time
34

@@ -39,6 +40,36 @@ def empty_entity(ctx: entities.EntityContext, _):
3940
assert invoked
4041

4142

43+
def test_client_get_entity():
44+
invoked = False
45+
46+
def empty_entity(ctx: entities.EntityContext, _):
47+
nonlocal invoked # don't do this in a real app!
48+
if ctx.operation == "do_nothing":
49+
invoked = True
50+
ctx.set_state(1)
51+
52+
# Start a worker, which will connect to the sidecar in a background thread
53+
with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
54+
taskhub=taskhub_name, token_credential=None) as w:
55+
w.add_entity(empty_entity)
56+
w.start()
57+
58+
c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
59+
taskhub=taskhub_name, token_credential=None)
60+
entity_id = entities.EntityInstanceId("empty_entity", "testEntity")
61+
c.signal_entity(entity_id, "do_nothing")
62+
time.sleep(2) # wait for the signal to be processed
63+
state = c.get_entity(entity_id)
64+
assert state is not None
65+
assert state.id == entity_id
66+
assert state.locked_by is None
67+
assert state.last_modified > datetime.now(timezone.utc)
68+
assert state.get_state(int) == 1
69+
70+
assert invoked
71+
72+
4273
def test_orchestration_signal_entity():
4374
invoked = False
4475

0 commit comments

Comments
 (0)