Skip to content

Commit a901b4d

Browse files
committed
Add test verifying async ordering
1 parent b7e62c9 commit a901b4d

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

temporalio/worker/_workflow_instance.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,13 @@ def activate(
369369
# Let errors bubble out of these to the caller to fail the task
370370
self._apply(job)
371371

372-
# Ensure the main workflow function is called, and called last, if needed
373-
if self._primary_task_initter is not None and self._primary_task is None:
374-
self._primary_task_initter()
375372
# Conditions are not checked on query activations. Query activations always come without
376373
# any other jobs.
377374
self._run_once(check_conditions=not is_query)
375+
# Ensure the main workflow function is called on first task, and called last.
376+
if self._primary_task_initter is not None and self._primary_task is None:
377+
self._primary_task_initter()
378+
self._run_once(check_conditions=True)
378379
except Exception as err:
379380
# We want some errors during activation, like those that can happen
380381
# during payload conversion, to be able to fail the workflow not the

tests/worker/test_workflow.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6445,14 +6445,12 @@ async def test_concurrent_sleeps_use_proper_options(
64456445
class SignalsActivitiesTimersUpdatesTracingWorkflow:
64466446
def __init__(self) -> None:
64476447
self.events = []
6448-
self.do_finish = False
64496448

64506449
@workflow.run
64516450
async def run(self) -> list[str]:
64526451
tt = asyncio.create_task(self.run_timer())
64536452
at = asyncio.create_task(self.run_act())
64546453
await asyncio.gather(tt, at)
6455-
await workflow.wait_condition(lambda: self.do_finish)
64566454
return self.events
64576455

64586456
@workflow.signal
@@ -6475,10 +6473,6 @@ async def doupdate(self, name: str):
64756473
await workflow.wait_condition(lambda: True)
64766474
self.events.append(f"update-{name}-2")
64776475

6478-
@workflow.signal
6479-
async def do_finish(self):
6480-
self.do_finish = True
6481-
64826476
async def run_timer(self):
64836477
self.events.append("timer-sync")
64846478
await workflow.sleep(0.1)
@@ -6517,26 +6511,26 @@ async def test_async_loop_ordering(client: Client):
65176511
activities=[say_hello],
65186512
task_queue=task_queue,
65196513
):
6514+
await asyncio.sleep(0.2)
65206515
await handle.signal(SignalsActivitiesTimersUpdatesTracingWorkflow.dosig, "1")
65216516
await handle.execute_update(
65226517
SignalsActivitiesTimersUpdatesTracingWorkflow.doupdate, "1"
65236518
)
6524-
await handle.signal(SignalsActivitiesTimersUpdatesTracingWorkflow.do_finish)
6525-
expected = [
6519+
expected_old = [
65266520
"sig-before-sync",
65276521
"sig-before-1",
6522+
"sig-before-2",
6523+
"timer-sync",
6524+
"act-sync",
6525+
"act-1",
6526+
"act-2",
65286527
"sig-1-sync",
65296528
"sig-1-1",
6529+
"sig-1-2",
65306530
"update-1-sync",
65316531
"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',
6532+
"update-1-2",
6533+
"timer-1",
6534+
"timer-2"
65416535
]
6542-
assert await handle.result() == expected
6536+
assert await handle.result() == expected_old

0 commit comments

Comments
 (0)