SameerMesiah97 commented on code in PR #67229:
URL: https://github.com/apache/airflow/pull/67229#discussion_r3295224176
##########
providers/cncf/kubernetes/tests/unit/cncf/kubernetes/triggers/test_pod.py:
##########
@@ -263,6 +290,139 @@ async def test_run_loop_return_failed_event(self,
mock_hook, mock_method, mock_w
assert actual_event == expected_event
+ @pytest.mark.asyncio
+ @mock.patch(f"{TRIGGER_PATH}._wait_for_pod_start")
+ @mock.patch(f"{TRIGGER_PATH}.define_pod_container_state")
+ @mock.patch(f"{TRIGGER_PATH}.hook")
+ async def
test_run_loop_emits_timeout_event_when_execution_deadline_reached(
+ self, mock_hook, mock_define_state, mock_wait_pod
+ ):
+ """
+ When ``execution_deadline`` (the operator's translation of
+ ``execution_timeout``) has already passed before the trigger picks
+ the task up, the trigger short-circuits at the top of ``run()`` and
+ emits a ``timeout`` event immediately instead of starting the wait
+ chain. The operator's existing terminal-event path then fails the
+ task and runs ``on_finish_action`` (pod delete).
+ """
+ # Already-past deadline → ``run()`` short-circuit trips it.
+ past_deadline = 1
+ trigger_with_deadline = KubernetesPodTrigger(
+ pod_name=POD_NAME,
+ pod_namespace=NAMESPACE,
+ base_container_name=BASE_CONTAINER_NAME,
+ kubernetes_conn_id=CONN_ID,
+ poll_interval=POLL_INTERVAL,
+ cluster_context=CLUSTER_CONTEXT,
+ config_dict=CONFIG_DICT,
+ in_cluster=IN_CLUSTER,
+ get_logs=GET_LOGS,
+ startup_timeout=STARTUP_TIMEOUT_SECS,
+ startup_check_interval=STARTUP_CHECK_INTERVAL_SECS,
+ schedule_timeout=STARTUP_TIMEOUT_SECS,
+ trigger_start_time=TRIGGER_START_TIME,
+ on_finish_action=ON_FINISH_ACTION,
+ execution_deadline=past_deadline,
+ )
+ # If the short-circuit fails, ``_wait_for_pod_start`` would be called
+ # next; making it RUNNING ensures the test fails loudly rather than
+ # accidentally emitting some other terminal event.
+ mock_wait_pod.return_value = ContainerState.RUNNING
+ mock_define_state.return_value = ContainerState.RUNNING
+ mock_hook.get_pod.return_value =
self._mock_pod_result(mock.AsyncMock())
+
+ actual_event = await trigger_with_deadline.run().asend(None)
+
+ # ``last_log_time`` is intentionally absent from this short-circuit and
+ # from the ``PodLaunchTimeoutException`` handler — both fire before any
+ # log fetching has happened. The mid-poll deadline check (in
+ # ``_wait_for_container_completion``) is the only timeout site that
+ # carries ``last_log_time`` because that's where it can be meaningfully
+ # populated.
+ assert actual_event.payload["status"] == "timeout"
+ assert actual_event.payload["namespace"] == NAMESPACE
+ assert actual_event.payload["name"] == POD_NAME
+ assert "execution_timeout" in actual_event.payload["message"]
+
+ @pytest.mark.asyncio
+ @mock.patch(f"{TRIGGER_PATH}._wait_for_pod_start")
+ @mock.patch(f"{TRIGGER_PATH}.define_pod_container_state")
+ @mock.patch(f"{TRIGGER_PATH}.hook")
+ async def
test_run_loop_does_not_emit_timeout_when_execution_deadline_not_reached(
Review Comment:
I am not sure what purpose this test serves? Is the premise not tautological
i.e. timeout should not be emitted if the deadline is not reached?
--
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]