@@ -6146,3 +6146,45 @@ async def test_workflow_run_sees_workflow_init(client: Client):
61466146 task_queue = worker .task_queue ,
61476147 )
61486148 assert workflow_result == "hello, world"
6149+
6150+
6151+ @workflow .defn
6152+ class UpdateCancellationWorkflow :
6153+ def __init__ (self ) -> None :
6154+ self .non_terminating_operation_has_started = False
6155+
6156+ @workflow .run
6157+ async def run (self ) -> NoReturn :
6158+ await asyncio .Future ()
6159+
6160+ @workflow .update (unfinished_policy = workflow .HandlerUnfinishedPolicy .ABANDON )
6161+ async def non_terminating_update (self ) -> NoReturn :
6162+ self .non_terminating_operation_has_started = True
6163+ await asyncio .Future ()
6164+
6165+ @workflow .update
6166+ async def wait_until_non_terminating_operation_has_started (self ) -> None :
6167+ await workflow .wait_condition (
6168+ lambda : self .non_terminating_operation_has_started
6169+ )
6170+
6171+
6172+ async def test_update_cancellation (client : Client ):
6173+ async with new_worker (client , UpdateCancellationWorkflow ) as worker :
6174+ wf_handle = await client .start_workflow (
6175+ UpdateCancellationWorkflow .run ,
6176+ id = str (uuid .uuid4 ()),
6177+ task_queue = worker .task_queue ,
6178+ )
6179+ # Asynchronously run an update that will never complete
6180+ non_terminating_update = asyncio .create_task (
6181+ wf_handle .execute_update (UpdateCancellationWorkflow .non_terminating_update )
6182+ )
6183+ # Wait until we know the update handler has started executing
6184+ await wf_handle .execute_update (
6185+ UpdateCancellationWorkflow .wait_until_non_terminating_operation_has_started
6186+ )
6187+ # Cancel the workflow and confirm that update caller sees update failed
6188+ await wf_handle .cancel ()
6189+ with pytest .raises (WorkflowUpdateFailedError ):
6190+ await non_terminating_update
0 commit comments