@@ -6439,3 +6439,104 @@ async def test_concurrent_sleeps_use_proper_options(
64396439
64406440 # Force replay with a query to ensure determinism
64416441 await handle .query ("__temporal_workflow_metadata" )
6442+
6443+
6444+ @workflow .defn
6445+ class SignalsActivitiesTimersUpdatesTracingWorkflow :
6446+ def __init__ (self ) -> None :
6447+ self .events = []
6448+ self .do_finish = False
6449+
6450+ @workflow .run
6451+ async def run (self ) -> list [str ]:
6452+ tt = asyncio .create_task (self .run_timer ())
6453+ at = asyncio .create_task (self .run_act ())
6454+ await asyncio .gather (tt , at )
6455+ await workflow .wait_condition (lambda : self .do_finish )
6456+ return self .events
6457+
6458+ @workflow .signal
6459+ async def dosig (self , name : str ):
6460+ self .events .append (f"sig-{ name } -sync" )
6461+ fut = asyncio .Future ()
6462+ fut .set_result (True )
6463+ await fut
6464+ self .events .append (f"sig-{ name } -1" )
6465+ await workflow .wait_condition (lambda : True )
6466+ self .events .append (f"sig-{ name } -2" )
6467+
6468+ @workflow .update
6469+ async def doupdate (self , name : str ):
6470+ self .events .append (f"update-{ name } -sync" )
6471+ fut = asyncio .Future ()
6472+ fut .set_result (True )
6473+ await fut
6474+ self .events .append (f"update-{ name } -1" )
6475+ await workflow .wait_condition (lambda : True )
6476+ self .events .append (f"update-{ name } -2" )
6477+
6478+ @workflow .signal
6479+ async def do_finish (self ):
6480+ self .do_finish = True
6481+
6482+ async def run_timer (self ):
6483+ self .events .append ("timer-sync" )
6484+ await workflow .sleep (0.1 )
6485+ fut = asyncio .Future ()
6486+ fut .set_result (True )
6487+ await fut
6488+ self .events .append ("timer-1" )
6489+ await workflow .wait_condition (lambda : True )
6490+ self .events .append ("timer-2" )
6491+
6492+ async def run_act (self ):
6493+ self .events .append ("act-sync" )
6494+ await workflow .execute_activity (
6495+ say_hello , "Enchi" , schedule_to_close_timeout = timedelta (seconds = 5 )
6496+ )
6497+ fut = asyncio .Future ()
6498+ fut .set_result (True )
6499+ await fut
6500+ self .events .append ("act-1" )
6501+ await workflow .wait_condition (lambda : True )
6502+ self .events .append ("act-2" )
6503+
6504+
6505+ async def test_async_loop_ordering (client : Client ):
6506+ task_queue = f"tq-{ uuid .uuid4 ()} "
6507+ handle = await client .start_workflow (
6508+ SignalsActivitiesTimersUpdatesTracingWorkflow .run ,
6509+ id = f"wf-{ uuid .uuid4 ()} " ,
6510+ task_queue = task_queue ,
6511+ )
6512+ await handle .signal (SignalsActivitiesTimersUpdatesTracingWorkflow .dosig , "before" )
6513+
6514+ async with new_worker (
6515+ client ,
6516+ SignalsActivitiesTimersUpdatesTracingWorkflow ,
6517+ activities = [say_hello ],
6518+ task_queue = task_queue ,
6519+ ):
6520+ await handle .signal (SignalsActivitiesTimersUpdatesTracingWorkflow .dosig , "1" )
6521+ await handle .execute_update (
6522+ SignalsActivitiesTimersUpdatesTracingWorkflow .doupdate , "1"
6523+ )
6524+ await handle .signal (SignalsActivitiesTimersUpdatesTracingWorkflow .do_finish )
6525+ expected = [
6526+ "sig-before-sync" ,
6527+ "sig-before-1" ,
6528+ "sig-1-sync" ,
6529+ "sig-1-1" ,
6530+ "update-1-sync" ,
6531+ "update-1-1" ,
6532+ 'timer-sync' ,
6533+ 'act-sync' ,
6534+ 'sig-before-2' ,
6535+ 'sig-1-2' ,
6536+ 'update-1-2' ,
6537+ 'act-1' ,
6538+ 'act-2' ,
6539+ 'timer-1' ,
6540+ 'timer-2' ,
6541+ ]
6542+ assert await handle .result () == expected
0 commit comments