22import time
33
44import pytest
5- from azure .identity import DefaultAzureCredential
65
76from durabletask import client , entities , task
87from durabletask .azuremanaged .client import DurableTaskSchedulerClient
1514# Read the environment variables
1615taskhub_name = os .getenv ("TASKHUB" , "default" )
1716endpoint = os .getenv ("ENDPOINT" , "http://localhost:8080" )
18- # endpoint = os.getenv("ENDPOINT", "https://andy-dts-testin-byaje2c8.northcentralus.durabletask.io")
19- credential = None if endpoint == "http://localhost:8080" else DefaultAzureCredential ()
2017
2118
2219def test_client_signal_entity ():
@@ -51,7 +48,7 @@ def empty_entity(ctx: entities.EntityContext, _):
5148 invoked = True
5249
5350 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
54- entity_id = entities .EntityInstanceId ("empty_entity" , "testEntity " )
51+ entity_id = entities .EntityInstanceId ("empty_entity" , f" { ctx . instance_id } _testEntity " )
5552 ctx .signal_entity (entity_id , "do_nothing" )
5653
5754 # Start a worker, which will connect to the sidecar in a background thread
@@ -87,7 +84,7 @@ def empty_entity(ctx: entities.EntityContext, _):
8784 invoked = True
8885
8986 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
90- entity_id = entities .EntityInstanceId ("empty_entity" , "testEntity " )
87+ entity_id = entities .EntityInstanceId ("empty_entity" , f" { ctx . instance_id } _testEntity " )
9188 yield ctx .call_entity (entity_id , "do_nothing" )
9289
9390 # Start a worker, which will connect to the sidecar in a background thread
@@ -122,7 +119,7 @@ def empty_entity(ctx: entities.EntityContext, _):
122119 invoked = True
123120
124121 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
125- entity_id = entities .EntityInstanceId ("empty_entity" , "testEntity " )
122+ entity_id = entities .EntityInstanceId ("empty_entity" , f" { ctx . instance_id } _testEntity " )
126123 with (yield ctx .lock_entities ([entity_id ])):
127124 yield ctx .call_entity (entity_id , "do_nothing" )
128125
@@ -170,11 +167,12 @@ def empty_entity(ctx: entities.EntityContext, _):
170167 nonlocal invoked # don't do this in a real app!
171168 invoked = True
172169 elif ctx .operation == "signal_other" :
173- entity_id = entities .EntityInstanceId ("empty_entity" , "otherEntity" )
170+ entity_id = entities .EntityInstanceId ("empty_entity" ,
171+ ctx .entity_id .key .replace ("_testEntity" , "_otherEntity" ))
174172 ctx .signal_entity (entity_id , "do_nothing" )
175173
176174 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
177- entity_id = entities .EntityInstanceId ("empty_entity" , "testEntity " )
175+ entity_id = entities .EntityInstanceId ("empty_entity" , f" { ctx . instance_id } _testEntity " )
178176 yield ctx .call_entity (entity_id , "signal_other" )
179177
180178 # Start a worker, which will connect to the sidecar in a background thread
@@ -231,13 +229,14 @@ def empty_entity(ctx: entities.EntityContext, _):
231229 pass
232230
233231 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
234- entity_id = entities .EntityInstanceId ("empty_entity" , "testEntity " )
232+ entity_id = entities .EntityInstanceId ("empty_entity" , f" { ctx . instance_id } _testEntity " )
235233 with (yield ctx .lock_entities ([entity_id ])):
236234 # Cannot signal entities that have been locked
237235 assert pytest .raises (Exception , ctx .signal_entity , entity_id , "do_nothing" )
238- ctx .call_entity (entity_id , "do_nothing" )
236+ entity_call_task = ctx .call_entity (entity_id , "do_nothing" )
239237 # Cannot call entities that have been locked and already called, but not yet returned a result
240238 assert pytest .raises (Exception , ctx .call_entity , entity_id , "do_nothing" )
239+ yield entity_call_task
241240
242241 # Start a worker, which will connect to the sidecar in a background thread
243242 with DurableTaskSchedulerWorker (host_address = endpoint , secure_channel = True ,
@@ -269,7 +268,7 @@ def empty_entity(ctx: entities.EntityContext, _):
269268 invoke_count += 1
270269
271270 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
272- entity_id = entities .EntityInstanceId ("empty_entity" , "testEntity3 " )
271+ entity_id = entities .EntityInstanceId ("empty_entity" , f" { ctx . instance_id } _testEntity " )
273272 with (yield ctx .lock_entities ([entity_id ])):
274273 yield ctx .call_entity (entity_id , "do_nothing" )
275274 raise Exception ("Simulated exception" )
@@ -300,7 +299,7 @@ def empty_entity(ctx: entities.EntityContext, _):
300299 invoke_count += 1
301300
302301 def empty_orchestrator (ctx : task .OrchestrationContext , _ ):
303- entity_id = entities .EntityInstanceId ("empty_entity" , "testEntity3 " )
302+ entity_id = entities .EntityInstanceId ("empty_entity" , f" { ctx . instance_id } _testEntity " )
304303 yield ctx .lock_entities ([entity_id ])
305304 yield ctx .call_entity (entity_id , "do_nothing" )
306305
@@ -323,7 +322,8 @@ def empty_orchestrator(ctx: task.OrchestrationContext, _):
323322
324323
325324# TODO: Uncomment this test
326- # Will not pass until https://msazure.visualstudio.com/One/_git/AAPT-DTMB/pullrequest/13610881 is merged and deployed to the docker image
325+ # Will not pass until https://msazure.visualstudio.com/One/_git/AAPT-DTMB/pullrequest/13610881 is merged and
326+ # deployed to the docker image
327327# def test_entity_unlocks_when_user_calls_continue_as_new():
328328# invoke_count = 0
329329
@@ -332,7 +332,7 @@ def empty_orchestrator(ctx: task.OrchestrationContext, _):
332332# invoke_count += 1
333333
334334# def empty_orchestrator(ctx: task.OrchestrationContext, entity_call_count: int):
335- # entity_id = entities.EntityInstanceId("empty_entity", "testEntity6 ")
335+ # entity_id = entities.EntityInstanceId("empty_entity", "testEntity ")
336336# nonlocal invoke_count
337337# if not ctx.is_replaying:
338338# invoke_count += 1
@@ -343,15 +343,15 @@ def empty_orchestrator(ctx: task.OrchestrationContext, _):
343343
344344# # Start a worker, which will connect to the sidecar in a background thread
345345# with DurableTaskSchedulerWorker(host_address=endpoint, secure_channel=True,
346- # taskhub=taskhub_name, token_credential=credential ) as w:
346+ # taskhub=taskhub_name, token_credential=None ) as w:
347347# w.add_orchestrator(empty_orchestrator)
348348# w.add_entity(empty_entity)
349349# w.start()
350350
351351# c = DurableTaskSchedulerClient(host_address=endpoint, secure_channel=True,
352- # taskhub=taskhub_name, token_credential=credential )
352+ # taskhub=taskhub_name, token_credential=None )
353353# time.sleep(2) # wait for the signal and orchestration to be processed
354354# id = c.schedule_new_orchestration(empty_orchestrator, input=2)
355- # c.wait_for_orchestration_completion(id, timeout=500 )
355+ # c.wait_for_orchestration_completion(id, timeout=30 )
356356
357357# assert invoke_count == 6
0 commit comments