mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
feat: shorter timeout on test_connection (#18001)
* feat: shorter timeout on test_connection * pip-compile-multi --no-upgrade * Fix for SQLite * Return 408 * Add test
This commit is contained in:
@@ -19,6 +19,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from func_timeout import FunctionTimedOut
|
||||
from sqlalchemy.exc import DBAPIError
|
||||
|
||||
from superset import db, event_logger, security_manager
|
||||
@@ -38,7 +39,11 @@ from superset.databases.commands.test_connection import TestConnectionDatabaseCo
|
||||
from superset.databases.commands.validate import ValidateDatabaseParametersCommand
|
||||
from superset.databases.schemas import DatabaseTestConnectionSchema
|
||||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
|
||||
from superset.exceptions import SupersetErrorsException, SupersetSecurityException
|
||||
from superset.exceptions import (
|
||||
SupersetErrorsException,
|
||||
SupersetSecurityException,
|
||||
SupersetTimeoutException,
|
||||
)
|
||||
from superset.models.core import Database
|
||||
from superset.utils.core import backend, get_example_database
|
||||
from tests.integration_tests.base_tests import SupersetTestCase
|
||||
@@ -612,6 +617,28 @@ class TestTestConnectionDatabaseCommand(SupersetTestCase):
|
||||
== SupersetErrorType.GENERIC_DB_ENGINE_ERROR
|
||||
)
|
||||
|
||||
@mock.patch("superset.databases.commands.test_connection.func_timeout")
|
||||
@mock.patch(
|
||||
"superset.databases.commands.test_connection.event_logger.log_with_context"
|
||||
)
|
||||
def test_connection_do_ping_timeout(self, mock_event_logger, mock_func_timeout):
|
||||
"""Test to make sure do_ping exceptions gets captured"""
|
||||
database = get_example_database()
|
||||
mock_func_timeout.side_effect = FunctionTimedOut("Time out")
|
||||
db_uri = database.sqlalchemy_uri_decrypted
|
||||
json_payload = {"sqlalchemy_uri": db_uri}
|
||||
command_without_db_name = TestConnectionDatabaseCommand(
|
||||
security_manager.find_user("admin"), json_payload
|
||||
)
|
||||
|
||||
with pytest.raises(SupersetTimeoutException) as excinfo:
|
||||
command_without_db_name.run()
|
||||
assert excinfo.value.status == 408
|
||||
assert (
|
||||
excinfo.value.error.error_type
|
||||
== SupersetErrorType.CONNECTION_DATABASE_TIMEOUT
|
||||
)
|
||||
|
||||
@mock.patch("superset.databases.dao.Database.get_sqla_engine")
|
||||
@mock.patch(
|
||||
"superset.databases.commands.test_connection.event_logger.log_with_context"
|
||||
|
||||
Reference in New Issue
Block a user