Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ async def run(self):
except Exception as e:
self.log.error("Failed to cancel the job: %s with error : %s", self.job_id, str(e))
raise e
else:
# The triggerer only calls on_kill() when CancelledError propagates out of run().
raise


class DataprocSubmitJobDirectTrigger(DataprocBaseTrigger):
Expand Down Expand Up @@ -437,6 +440,9 @@ async def run(self) -> AsyncIterator[TriggerEvent]:
except Exception as e:
self.log.error("Failed to cancel the job: %s with error : %s", self.job_id, str(e))
raise e
else:
# The triggerer only calls on_kill() when CancelledError propagates out of run().
raise


class DataprocClusterTrigger(DataprocBaseTrigger):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,18 @@ async def test_submit_trigger_run_cancelled(

await async_gen.aclose()

@pytest.mark.asyncio
@pytest.mark.skipif(not AIRFLOW_V_3_3_PLUS, reason="Cancellation is handled inline before Airflow 3.3.0")
@mock.patch("airflow.providers.google.cloud.triggers.dataproc.DataprocSubmitTrigger.get_async_hook")
async def test_submit_trigger_run_reraises_cancelled_error(self, mock_get_async_hook, submit_trigger):
mock_async_hook = mock_get_async_hook.return_value
mock_async_hook.get_job_client = mock.AsyncMock()
mock_async_hook.get_job.side_effect = asyncio.CancelledError

with pytest.raises(asyncio.CancelledError):
async for _ in submit_trigger.run():
pass


class TestDataprocSubmitJobDirectTrigger:
def test_serialization(self, submit_job_direct_trigger):
Expand Down Expand Up @@ -1183,3 +1195,19 @@ async def test_run_cancelled_tolerates_a_job_dataproc_never_received(
await async_gen.asend(None)

mock_get_sync_hook.return_value.cancel_job.assert_called_once()

@pytest.mark.asyncio
@pytest.mark.skipif(not AIRFLOW_V_3_3_PLUS, reason="Cancellation is handled inline before Airflow 3.3.0")
@mock.patch(
"airflow.providers.google.cloud.triggers.dataproc.DataprocSubmitJobDirectTrigger.get_async_hook"
)
async def test_run_reraises_cancelled_error(self, mock_get_async_hook, submit_job_direct_trigger):
mock_hook = mock_get_async_hook.return_value
submit_future = asyncio.Future()
submit_future.set_result(Job(reference={"job_id": TEST_JOB_ID}))
mock_hook.submit_job.return_value = submit_future
mock_hook.get_job.side_effect = asyncio.CancelledError

with pytest.raises(asyncio.CancelledError):
async for _ in submit_job_direct_trigger.run():
pass