Skip to content

Commit d6ca246

Browse files
committed
Add coverage for workflow failure
1 parent 3f0b11c commit d6ca246

File tree

1 file changed

+52
-19
lines changed

1 file changed

+52
-19
lines changed

tests/worker/test_workflow.py

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5360,9 +5360,15 @@ def _unfinished_handler_warning_cls(self) -> Type:
53605360

53615361

53625362
@workflow.defn
5363-
class UnfinishedHandlersWithCancellationWorkflow:
5363+
class UnfinishedHandlersWithCancellationOrFailureWorkflow:
53645364
@workflow.run
5365-
async def run(self) -> NoReturn:
5365+
async def run(
5366+
self, workflow_termination_type: Literal["cancellation", "failure"]
5367+
) -> NoReturn:
5368+
if workflow_termination_type == "failure":
5369+
raise ApplicationError(
5370+
"Deliberately failing workflow with an unfinished handler"
5371+
)
53665372
await workflow.wait_condition(lambda: False)
53675373

53685374
@workflow.update
@@ -5376,23 +5382,44 @@ async def my_signal(self):
53765382

53775383

53785384
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()
5385+
await _UnfinishedHandlersWithCancellationOrFailureTest(
5386+
client,
5387+
"update",
5388+
"cancellation",
5389+
).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler()
53825390

53835391

53845392
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()
5393+
await _UnfinishedHandlersWithCancellationOrFailureTest(
5394+
client,
5395+
"signal",
5396+
"cancellation",
5397+
).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler()
5398+
5399+
5400+
async def test_unfinished_update_handler_with_workflow_failure(client: Client):
5401+
await _UnfinishedHandlersWithCancellationOrFailureTest(
5402+
client,
5403+
"update",
5404+
"failure",
5405+
).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler()
5406+
5407+
5408+
async def test_unfinished_signal_handler_with_workflow_failure(client: Client):
5409+
await _UnfinishedHandlersWithCancellationOrFailureTest(
5410+
client,
5411+
"signal",
5412+
"failure",
5413+
).test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler()
53885414

53895415

53905416
@dataclass
5391-
class _UnfinishedHandlersWithCancellationTest:
5417+
class _UnfinishedHandlersWithCancellationOrFailureTest:
53925418
client: Client
53935419
handler_type: Literal["update", "signal"]
5420+
workflow_termination_type: Literal["cancellation", "failure"]
53945421

5395-
async def test_warning_is_issued_when_cancellation_causes_exit_with_unfinished_handler(
5422+
async def test_warning_is_issued_when_cancellation_or_failure_causes_exit_with_unfinished_handler(
53965423
self,
53975424
):
53985425
assert await self._run_workflow_and_get_warning()
@@ -5402,31 +5429,37 @@ async def _run_workflow_and_get_warning(self) -> bool:
54025429
update_id = "update-id"
54035430
task_queue = "tq"
54045431

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.
5432+
# We require a startWorkflow, an update, and maybe a cancellation request, to be delivered
5433+
# in the same WFT. To do this we start the worker after they've all been accepted by the
5434+
# server.
54085435
handle = await self.client.start_workflow(
5409-
UnfinishedHandlersWithCancellationWorkflow.run,
5436+
UnfinishedHandlersWithCancellationOrFailureWorkflow.run,
5437+
self.workflow_termination_type,
54105438
id=workflow_id,
54115439
task_queue=task_queue,
54125440
)
5413-
await handle.cancel()
5441+
if self.workflow_termination_type == "cancellation":
5442+
await handle.cancel()
54145443

54155444
if self.handler_type == "update":
54165445
update_task = asyncio.create_task(
54175446
handle.execute_update(
5418-
UnfinishedHandlersWithCancellationWorkflow.my_update, id=update_id
5447+
UnfinishedHandlersWithCancellationOrFailureWorkflow.my_update,
5448+
id=update_id,
54195449
)
54205450
)
54215451
await assert_eq_eventually(
5422-
True, lambda: workflow_update_exists(self.client, workflow_id, update_id)
5452+
True,
5453+
lambda: workflow_update_exists(self.client, workflow_id, update_id),
54235454
)
54245455
else:
5425-
await handle.signal(UnfinishedHandlersWithCancellationWorkflow.my_signal)
5456+
await handle.signal(
5457+
UnfinishedHandlersWithCancellationOrFailureWorkflow.my_signal
5458+
)
54265459

54275460
async with new_worker(
54285461
self.client,
5429-
UnfinishedHandlersWithCancellationWorkflow,
5462+
UnfinishedHandlersWithCancellationOrFailureWorkflow,
54305463
task_queue=task_queue,
54315464
):
54325465
with pytest.WarningsRecorder() as warnings:

0 commit comments

Comments
 (0)