xBis7 commented on code in PR #51586:
URL: https://github.com/apache/airflow/pull/51586#discussion_r2143064168


##########
airflow-core/tests/unit/core/test_db_discovery.py:
##########
@@ -0,0 +1,165 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import contextlib
+import logging
+import os
+import shutil
+import socket
+import time
+from unittest.mock import patch
+
+import pytest
+from sqlalchemy import text
+
+from airflow import settings
+from airflow.utils import db_discovery
+from airflow.utils.db_discovery import DbDiscoveryStatus
+
+from tests_common.test_utils.config import conf_vars
+
+log = logging.getLogger(__name__)
+
+
+def dispose_connection_pool():
+    """Dispose any cached sockets so that the next query will force a new 
connect."""
+    settings.engine.dispose()
+    # Wait for SqlAlchemy.
+    time.sleep(0.5)
+
+
+def make_db_test_call():
+    """
+    Create a session and execute a query.
+
+    It will establish a new connection if there isn't one available.
+    New connections use DNS lookup.
+    """
+    from airflow.utils.session import create_session
+
+    with create_session() as session:
+        session.execute(text("SELECT 1"))
+
+
+def assert_query_raises_exc(expected_error_msg: str, expected_status: str, 
expected_retry_num: int):
+    with pytest.raises(socket.gaierror, match=expected_error_msg):
+        make_db_test_call()
+
+    assert len(db_discovery.db_health_status) == 2
+
+    assert db_discovery.db_health_status[0] == expected_status
+    assert db_discovery.db_retry_count == expected_retry_num
+
+
+@pytest.mark.backend("postgres")
+class TestDbDiscoveryIntegration:

Review Comment:
   I added a common fixture that will be auto used.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to