amoghrajesh commented on code in PR #65590:
URL: https://github.com/apache/airflow/pull/65590#discussion_r3117312729
##########
airflow-core/tests/unit/jobs/test_triggerer_job.py:
##########
@@ -382,6 +382,62 @@ def test_run_inline_trigger_timeout(self, session,
cap_structlog) -> None:
)
assert {"event": "Trigger cancelled due to timeout", "log_level":
"error"} in cap_structlog
+ def test_run_trigger_calls_on_cancel_for_user_action(self, session,
cap_structlog) -> None:
+ """on_cancel() is called when CancelledError carries the "user-action"
message."""
+ trigger_runner = TriggerRunner()
+ trigger_runner.triggers = {
+ 1: {"task": MagicMock(spec=asyncio.Task), "is_watcher": False,
"name": "mock_name", "events": 0}
+ }
+ mock_trigger = MagicMock(spec=BaseTrigger)
+ mock_trigger.run.side_effect = asyncio.CancelledError("user-action")
+ mock_trigger.task_instance = MagicMock()
+ mock_trigger.task_instance.map_index = -1
+ mock_trigger.on_cancel = AsyncMock()
+
+ with pytest.raises(asyncio.CancelledError):
+ asyncio.run(trigger_runner.run_trigger(1, mock_trigger))
+
+ mock_trigger.on_cancel.assert_awaited_once()
+ assert any("on_cancel" in str(entry) for entry in cap_structlog), (
Review Comment:
Fixed it, it now asserts against the event dict.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]