Skip to content

Commit 42e3fc6

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

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

tests/worker/test_workflow.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5360,9 +5360,11 @@ 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(self, workflow_termination_type: Literal["cancellation", "failure"]) -> NoReturn:
5366+
if workflow_termination_type == "failure":
5367+
raise ApplicationError("Deliberately failing workflow with an unfinished handler")
53665368
await workflow.wait_condition(lambda: False)
53675369

53685370
@workflow.update
@@ -5376,23 +5378,36 @@ async def my_signal(self):
53765378

53775379

53785380
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()
53825384

53835385

53845386
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()
53885402

53895403

53905404
@dataclass
5391-
class _UnfinishedHandlersWithCancellationTest:
5405+
class _UnfinishedHandlersWithCancellationOrFailureTest:
53925406
client: Client
53935407
handler_type: Literal["update", "signal"]
5408+
workflow_termination_type: Literal["cancellation", "failure"]
53945409

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(
53965411
self,
53975412
):
53985413
assert await self._run_workflow_and_get_warning()
@@ -5402,31 +5417,33 @@ async def _run_workflow_and_get_warning(self) -> bool:
54025417
update_id = "update-id"
54035418
task_queue = "tq"
54045419

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.
54085423
handle = await self.client.start_workflow(
5409-
UnfinishedHandlersWithCancellationWorkflow.run,
5424+
UnfinishedHandlersWithCancellationOrFailureWorkflow.run,
5425+
self.workflow_termination_type,
54105426
id=workflow_id,
54115427
task_queue=task_queue,
54125428
)
5413-
await handle.cancel()
5429+
if self.workflow_termination_type == "cancellation":
5430+
await handle.cancel()
54145431

54155432
if self.handler_type == "update":
54165433
update_task = asyncio.create_task(
54175434
handle.execute_update(
5418-
UnfinishedHandlersWithCancellationWorkflow.my_update, id=update_id
5435+
UnfinishedHandlersWithCancellationOrFailureWorkflow.my_update, id=update_id
54195436
)
54205437
)
54215438
await assert_eq_eventually(
54225439
True, lambda: workflow_update_exists(self.client, workflow_id, update_id)
54235440
)
54245441
else:
5425-
await handle.signal(UnfinishedHandlersWithCancellationWorkflow.my_signal)
5442+
await handle.signal(UnfinishedHandlersWithCancellationOrFailureWorkflow.my_signal)
54265443

54275444
async with new_worker(
54285445
self.client,
5429-
UnfinishedHandlersWithCancellationWorkflow,
5446+
UnfinishedHandlersWithCancellationOrFailureWorkflow,
54305447
task_queue=task_queue,
54315448
):
54325449
with pytest.WarningsRecorder() as warnings:

0 commit comments

Comments
 (0)