Skip to content

Commit 1cb8463

Browse files
committed
Test that run ID is set in update handle
1 parent 173826f commit 1cb8463

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/worker/test_workflow.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,6 +4423,46 @@ async def test_workflow_update_task_fails(client: Client, env: WorkflowEnvironme
44234423
assert bad_validator_fail_ct == 2
44244424

44254425

4426+
@workflow.defn
4427+
class UpdateContinueAsNewWorkflow:
4428+
def __init__(self) -> None:
4429+
self.counter = 0
4430+
4431+
@workflow.run
4432+
async def run(self) -> None:
4433+
while True:
4434+
current_value = self.counter
4435+
await workflow.wait_condition(lambda: self.counter > current_value)
4436+
workflow.continue_as_new()
4437+
4438+
@workflow.update
4439+
async def update(self) -> None:
4440+
self.counter += 1
4441+
4442+
4443+
async def test_workflow_update_handle_contains_latest_run_id(
4444+
client: Client, env: WorkflowEnvironment
4445+
):
4446+
# The update triggers a CAN, so the first update handle returned should have the
4447+
# original run ID but the second should have the post-CAN run ID.
4448+
async with new_worker(client, UpdateContinueAsNewWorkflow) as worker:
4449+
wf_handle = await client.start_workflow(
4450+
UpdateContinueAsNewWorkflow.run,
4451+
id=f"update-continue-as-new-workflow-{uuid.uuid4()}",
4452+
task_queue=worker.task_queue,
4453+
)
4454+
upd_handle = await wf_handle.start_update(
4455+
UpdateContinueAsNewWorkflow.update,
4456+
wait_for_stage=WorkflowUpdateStage.ACCEPTED,
4457+
)
4458+
assert upd_handle.workflow_run_id == wf_handle.result_run_id
4459+
# upd_handle = await wf_handle.start_update(
4460+
# UpdateContinueAsNewWorkflow.update,
4461+
# wait_for_stage=WorkflowUpdateStage.ACCEPTED,
4462+
# )
4463+
# assert upd_handle.workflow_run_id != wf_handle.result_run_id
4464+
4465+
44264466
@workflow.defn
44274467
class ImmediatelyCompleteUpdateAndWorkflow:
44284468
def __init__(self) -> None:

0 commit comments

Comments
 (0)