Copilot commented on code in PR #74010:
URL: https://github.com/apache/airflow/pull/74010#discussion_r4751682666
##########
task-sdk/tests/task_sdk/execution_time/test_secrets.py:
##########
@@ -175,6 +179,110 @@ async def asend(*_args, **_kwargs):
await backend.aget_variable("denied_var")
+class TestOutOfSyncSupervisorComms:
+ """A desynced supervisor connection must surface, not turn into "not
found".
+
+ Both the backend and the dispatchers catch ``Exception`` to fall through
to the next backend,
+ so each of them needs its own re-raise for the error to reach the task.
+ """
+
+ @pytest.mark.parametrize("method", ["get_connection", "get_variable"])
+ def test_backend_raises(self, mock_supervisor_comms, method):
+ mock_supervisor_comms.send.side_effect =
AirflowSupervisorCommsOutOfSync("out of sync")
+
+ with pytest.raises(AirflowSupervisorCommsOutOfSync, match="out of
sync"):
+ getattr(ExecutionAPISecretsBackend(), method)("some_key")
+
+ @pytest.mark.asyncio
+ @pytest.mark.parametrize("method", ["aget_connection", "aget_variable"])
+ async def test_backend_raises_async(self, mock_supervisor_comms, method):
+ async def asend(*_args, **_kwargs):
+ raise AirflowSupervisorCommsOutOfSync("out of sync")
+
+ mock_supervisor_comms.asend = asend
+
+ with pytest.raises(AirflowSupervisorCommsOutOfSync, match="out of
sync"):
+ await getattr(ExecutionAPISecretsBackend(), method)("some_key")
+
+ def test_get_connection_does_not_fall_through(self, mock_supervisor_comms,
monkeypatch):
+ from unittest.mock import MagicMock
+
+ from airflow.sdk.execution_time import context as ctx_module
+
+ mock_supervisor_comms.send.side_effect =
AirflowSupervisorCommsOutOfSync("out of sync")
+ later_backend = MagicMock(name="LaterBackend")
Review Comment:
Give the fallback backend mocks `spec=ExecutionAPISecretsBackend`, as
required by Airflow's testing guidelines. Without a spec, `MagicMock`
fabricates nonexistent backend methods and can hide interface mistakes. Apply
the same change at lines 230, 251, and 273.
--
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]