@@ -5360,9 +5360,11 @@ def _unfinished_handler_warning_cls(self) -> Type:
5360
5360
5361
5361
5362
5362
@workflow .defn
5363
- class UnfinishedHandlersWithCancellationWorkflow :
5363
+ class UnfinishedHandlersWithCancellationOrFailureWorkflow :
5364
5364
@workflow .run
5365
- async def run (self ) -> NoReturn :
5365
+ async def run (self , workflow_termination_type : Literal ["cancellation" , "failure" ]) -> NoReturn :
5366
+ if workflow_termination_type == "failure" :
5367
+ raise ApplicationError ("Deliberately failing workflow with an unfinished handler" )
5366
5368
await workflow .wait_condition (lambda : False )
5367
5369
5368
5370
@workflow .update
@@ -5376,23 +5378,36 @@ async def my_signal(self):
5376
5378
5377
5379
5378
5380
async def test_unfinished_update_handler_with_workflow_cancellation (client : Client ):
5379
- await _UnfinishedHandlersWithCancellationTest (
5380
- client , "update"
5381
- ).test_warning_is_issued_when_cancellation_causes_exit_with_unfinished_handler ()
5381
+ await _UnfinishedHandlersWithCancellationOrFailureTest (
5382
+ client , "update" , "cancellation" ,
5383
+ ).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler ()
5382
5384
5383
5385
5384
5386
async def test_unfinished_signal_handler_with_workflow_cancellation (client : Client ):
5385
- await _UnfinishedHandlersWithCancellationTest (
5386
- client , "signal"
5387
- ).test_warning_is_issued_when_cancellation_causes_exit_with_unfinished_handler ()
5387
+ await _UnfinishedHandlersWithCancellationOrFailureTest (
5388
+ client , "signal" , "cancellation" ,
5389
+ ).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler ()
5390
+
5391
+
5392
+ async def test_unfinished_update_handler_with_workflow_failure (client : Client ):
5393
+ await _UnfinishedHandlersWithCancellationOrFailureTest (
5394
+ client , "update" , "failure" ,
5395
+ ).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler ()
5396
+
5397
+
5398
+ async def test_unfinished_signal_handler_with_workflow_failure (client : Client ):
5399
+ await _UnfinishedHandlersWithCancellationOrFailureTest (
5400
+ client , "signal" , "failure" ,
5401
+ ).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler ()
5388
5402
5389
5403
5390
5404
@dataclass
5391
- class _UnfinishedHandlersWithCancellationTest :
5405
+ class _UnfinishedHandlersWithCancellationOrFailureTest :
5392
5406
client : Client
5393
5407
handler_type : Literal ["update" , "signal" ]
5408
+ workflow_termination_type : Literal ["cancellation" , "failure" ]
5394
5409
5395
- async def test_warning_is_issued_when_cancellation_causes_exit_with_unfinished_handler (
5410
+ async def test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler (
5396
5411
self ,
5397
5412
):
5398
5413
assert await self ._run_workflow_and_get_warning ()
@@ -5402,31 +5417,33 @@ async def _run_workflow_and_get_warning(self) -> bool:
5402
5417
update_id = "update-id"
5403
5418
task_queue = "tq"
5404
5419
5405
- # We require a cancellation request and an update to be delivered in the same WFT. To do
5406
- # this we send the start, cancel, and update/signal requests, and then start the worker
5407
- # after they've all been accepted by the server.
5420
+ # We require a startWorkflow, an update, and maybe a cancellation request, to be delivered
5421
+ # in the same WFT. To do this we start the worker after they've all been accepted by the
5422
+ # server.
5408
5423
handle = await self .client .start_workflow (
5409
- UnfinishedHandlersWithCancellationWorkflow .run ,
5424
+ UnfinishedHandlersWithCancellationOrFailureWorkflow .run ,
5425
+ self .workflow_termination_type ,
5410
5426
id = workflow_id ,
5411
5427
task_queue = task_queue ,
5412
5428
)
5413
- await handle .cancel ()
5429
+ if self .workflow_termination_type == "cancellation" :
5430
+ await handle .cancel ()
5414
5431
5415
5432
if self .handler_type == "update" :
5416
5433
update_task = asyncio .create_task (
5417
5434
handle .execute_update (
5418
- UnfinishedHandlersWithCancellationWorkflow .my_update , id = update_id
5435
+ UnfinishedHandlersWithCancellationOrFailureWorkflow .my_update , id = update_id
5419
5436
)
5420
5437
)
5421
5438
await assert_eq_eventually (
5422
5439
True , lambda : workflow_update_exists (self .client , workflow_id , update_id )
5423
5440
)
5424
5441
else :
5425
- await handle .signal (UnfinishedHandlersWithCancellationWorkflow .my_signal )
5442
+ await handle .signal (UnfinishedHandlersWithCancellationOrFailureWorkflow .my_signal )
5426
5443
5427
5444
async with new_worker (
5428
5445
self .client ,
5429
- UnfinishedHandlersWithCancellationWorkflow ,
5446
+ UnfinishedHandlersWithCancellationOrFailureWorkflow ,
5430
5447
task_queue = task_queue ,
5431
5448
):
5432
5449
with pytest .WarningsRecorder () as warnings :
0 commit comments