Fix integration tests (#4059)

This commit is contained in:
pablonyx
2025-02-21 15:56:11 -08:00
committed by GitHub
parent ffb7d5b85b
commit 5a131f4547
11 changed files with 37 additions and 12 deletions

View File

@@ -145,7 +145,7 @@ jobs:
run: | run: |
cd deployment/docker_compose cd deployment/docker_compose
docker compose -f docker-compose.multitenant-dev.yml -p onyx-stack down -v docker compose -f docker-compose.multitenant-dev.yml -p onyx-stack down -v
# NOTE: Use pre-ping/null pool to reduce flakiness due to dropped connections # NOTE: Use pre-ping/null pool to reduce flakiness due to dropped connections
- name: Start Docker containers - name: Start Docker containers
run: | run: |
@@ -157,6 +157,7 @@ jobs:
REQUIRE_EMAIL_VERIFICATION=false \ REQUIRE_EMAIL_VERIFICATION=false \
DISABLE_TELEMETRY=true \ DISABLE_TELEMETRY=true \
IMAGE_TAG=test \ IMAGE_TAG=test \
INTEGRATION_TESTS_MODE=true \
docker compose -f docker-compose.dev.yml -p onyx-stack up -d docker compose -f docker-compose.dev.yml -p onyx-stack up -d
id: start_docker id: start_docker
@@ -199,7 +200,7 @@ jobs:
cd backend/tests/integration/mock_services cd backend/tests/integration/mock_services
docker compose -f docker-compose.mock-it-services.yml \ docker compose -f docker-compose.mock-it-services.yml \
-p mock-it-services-stack up -d -p mock-it-services-stack up -d
# NOTE: Use pre-ping/null to reduce flakiness due to dropped connections # NOTE: Use pre-ping/null to reduce flakiness due to dropped connections
- name: Run Standard Integration Tests - name: Run Standard Integration Tests
run: | run: |

View File

@@ -361,6 +361,7 @@ def connector_external_group_sync_generator_task(
cc_pair = get_connector_credential_pair_from_id( cc_pair = get_connector_credential_pair_from_id(
db_session=db_session, db_session=db_session,
cc_pair_id=cc_pair_id, cc_pair_id=cc_pair_id,
eager_load_credential=True,
) )
if cc_pair is None: if cc_pair is None:
raise ValueError( raise ValueError(

View File

@@ -15,6 +15,7 @@ from onyx.background.indexing.memory_tracer import MemoryTracer
from onyx.configs.app_configs import INDEX_BATCH_SIZE from onyx.configs.app_configs import INDEX_BATCH_SIZE
from onyx.configs.app_configs import INDEXING_SIZE_WARNING_THRESHOLD from onyx.configs.app_configs import INDEXING_SIZE_WARNING_THRESHOLD
from onyx.configs.app_configs import INDEXING_TRACER_INTERVAL from onyx.configs.app_configs import INDEXING_TRACER_INTERVAL
from onyx.configs.app_configs import INTEGRATION_TESTS_MODE
from onyx.configs.app_configs import LEAVE_CONNECTOR_ACTIVE_ON_INITIALIZATION_FAILURE from onyx.configs.app_configs import LEAVE_CONNECTOR_ACTIVE_ON_INITIALIZATION_FAILURE
from onyx.configs.app_configs import POLL_CONNECTOR_OFFSET from onyx.configs.app_configs import POLL_CONNECTOR_OFFSET
from onyx.configs.constants import DocumentSource from onyx.configs.constants import DocumentSource
@@ -89,8 +90,8 @@ def _get_connector_runner(
) )
# validate the connector settings # validate the connector settings
if not INTEGRATION_TESTS_MODE:
runnable_connector.validate_connector_settings() runnable_connector.validate_connector_settings()
except Exception as e: except Exception as e:
logger.exception(f"Unable to instantiate connector due to {e}") logger.exception(f"Unable to instantiate connector due to {e}")

View File

@@ -158,7 +158,7 @@ POSTGRES_USER = os.environ.get("POSTGRES_USER") or "postgres"
POSTGRES_PASSWORD = urllib.parse.quote_plus( POSTGRES_PASSWORD = urllib.parse.quote_plus(
os.environ.get("POSTGRES_PASSWORD") or "password" os.environ.get("POSTGRES_PASSWORD") or "password"
) )
POSTGRES_HOST = os.environ.get("POSTGRES_HOST") or "localhost" POSTGRES_HOST = os.environ.get("POSTGRES_HOST") or "127.0.0.1"
POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5432" POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5432"
POSTGRES_DB = os.environ.get("POSTGRES_DB") or "postgres" POSTGRES_DB = os.environ.get("POSTGRES_DB") or "postgres"
AWS_REGION_NAME = os.environ.get("AWS_REGION_NAME") or "us-east-2" AWS_REGION_NAME = os.environ.get("AWS_REGION_NAME") or "us-east-2"
@@ -626,6 +626,8 @@ POD_NAMESPACE = os.environ.get("POD_NAMESPACE")
DEV_MODE = os.environ.get("DEV_MODE", "").lower() == "true" DEV_MODE = os.environ.get("DEV_MODE", "").lower() == "true"
INTEGRATION_TESTS_MODE = os.environ.get("INTEGRATION_TESTS_MODE", "").lower() == "true"
MOCK_CONNECTOR_FILE_PATH = os.environ.get("MOCK_CONNECTOR_FILE_PATH") MOCK_CONNECTOR_FILE_PATH = os.environ.get("MOCK_CONNECTOR_FILE_PATH")
TEST_ENV = os.environ.get("TEST_ENV", "").lower() == "true" TEST_ENV = os.environ.get("TEST_ENV", "").lower() == "true"

View File

@@ -3,6 +3,7 @@ from typing import Type
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from onyx.configs.app_configs import INTEGRATION_TESTS_MODE
from onyx.configs.constants import DocumentSource from onyx.configs.constants import DocumentSource
from onyx.configs.constants import DocumentSourceRequiringTenantContext from onyx.configs.constants import DocumentSourceRequiringTenantContext
from onyx.connectors.airtable.airtable_connector import AirtableConnector from onyx.connectors.airtable.airtable_connector import AirtableConnector
@@ -187,6 +188,9 @@ def validate_ccpair_for_user(
user: User | None, user: User | None,
tenant_id: str | None, tenant_id: str | None,
) -> None: ) -> None:
if INTEGRATION_TESTS_MODE:
return
# Validate the connector settings # Validate the connector settings
connector = fetch_connector_by_id(connector_id, db_session) connector = fetch_connector_by_id(connector_id, db_session)
credential = fetch_credential_by_id_for_user( credential = fetch_credential_by_id_for_user(
@@ -199,7 +203,10 @@ def validate_ccpair_for_user(
if not connector: if not connector:
raise ValueError("Connector not found") raise ValueError("Connector not found")
if connector.source == DocumentSource.INGESTION_API: if (
connector.source == DocumentSource.INGESTION_API
or connector.source == DocumentSource.MOCK_CONNECTOR
):
return return
if not credential: if not credential:

View File

@@ -220,7 +220,14 @@ class GoogleDriveConnector(LoadConnector, PollConnector, SlimConnector):
return self._creds return self._creds
def load_credentials(self, credentials: dict[str, Any]) -> dict[str, str] | None: def load_credentials(self, credentials: dict[str, Any]) -> dict[str, str] | None:
self._primary_admin_email = credentials[DB_CREDENTIALS_PRIMARY_ADMIN_KEY] try:
self._primary_admin_email = credentials[DB_CREDENTIALS_PRIMARY_ADMIN_KEY]
except KeyError:
raise ValueError(
"Primary admin email missing, "
"should not call this property "
"before calling load_credentials"
)
self._creds, new_creds_dict = get_google_creds( self._creds, new_creds_dict = get_google_creds(
credentials=credentials, credentials=credentials,

View File

@@ -194,9 +194,14 @@ def get_connector_credential_pair_from_id_for_user(
def get_connector_credential_pair_from_id( def get_connector_credential_pair_from_id(
db_session: Session, db_session: Session,
cc_pair_id: int, cc_pair_id: int,
eager_load_credential: bool = False,
) -> ConnectorCredentialPair | None: ) -> ConnectorCredentialPair | None:
stmt = select(ConnectorCredentialPair).distinct() stmt = select(ConnectorCredentialPair).distinct()
stmt = stmt.where(ConnectorCredentialPair.id == cc_pair_id) stmt = stmt.where(ConnectorCredentialPair.id == cc_pair_id)
if eager_load_credential:
stmt = stmt.options(joinedload(ConnectorCredentialPair.credential))
result = db_session.execute(stmt) result = db_session.execute(stmt)
return result.scalar_one_or_none() return result.scalar_one_or_none()

View File

@@ -3,7 +3,7 @@ import os
ADMIN_USER_NAME = "admin_user" ADMIN_USER_NAME = "admin_user"
API_SERVER_PROTOCOL = os.getenv("API_SERVER_PROTOCOL") or "http" API_SERVER_PROTOCOL = os.getenv("API_SERVER_PROTOCOL") or "http"
API_SERVER_HOST = os.getenv("API_SERVER_HOST") or "localhost" API_SERVER_HOST = os.getenv("API_SERVER_HOST") or "127.0.0.1"
API_SERVER_PORT = os.getenv("API_SERVER_PORT") or "8080" API_SERVER_PORT = os.getenv("API_SERVER_PORT") or "8080"
API_SERVER_URL = f"{API_SERVER_PROTOCOL}://{API_SERVER_HOST}:{API_SERVER_PORT}" API_SERVER_URL = f"{API_SERVER_PROTOCOL}://{API_SERVER_HOST}:{API_SERVER_PORT}"
MAX_DELAY = 45 MAX_DELAY = 45

View File

@@ -30,8 +30,10 @@ class ConnectorManager:
name=name, name=name,
source=source, source=source,
input_type=input_type, input_type=input_type,
connector_specific_config=connector_specific_config connector_specific_config=(
or {"file_locations": []}, connector_specific_config
or ({"file_locations": []} if source == DocumentSource.FILE else {})
),
access_type=access_type, access_type=access_type,
groups=groups or [], groups=groups or [],
) )

View File

@@ -88,8 +88,6 @@ class UserManager:
if not session_cookie: if not session_cookie:
raise Exception("Failed to login") raise Exception("Failed to login")
print(f"Logged in as {test_user.email}")
# Set cookies in the headers # Set cookies in the headers
test_user.headers["Cookie"] = f"fastapiusersauth={session_cookie}; " test_user.headers["Cookie"] = f"fastapiusersauth={session_cookie}; "
test_user.cookies = {"fastapiusersauth": session_cookie} test_user.cookies = {"fastapiusersauth": session_cookie}

View File

@@ -36,6 +36,7 @@ services:
- OPENID_CONFIG_URL=${OPENID_CONFIG_URL:-} - OPENID_CONFIG_URL=${OPENID_CONFIG_URL:-}
- TRACK_EXTERNAL_IDP_EXPIRY=${TRACK_EXTERNAL_IDP_EXPIRY:-} - TRACK_EXTERNAL_IDP_EXPIRY=${TRACK_EXTERNAL_IDP_EXPIRY:-}
- CORS_ALLOWED_ORIGIN=${CORS_ALLOWED_ORIGIN:-} - CORS_ALLOWED_ORIGIN=${CORS_ALLOWED_ORIGIN:-}
- INTEGRATION_TESTS_MODE=${INTEGRATION_TESTS_MODE:-}
# Gen AI Settings # Gen AI Settings
- GEN_AI_MAX_TOKENS=${GEN_AI_MAX_TOKENS:-} - GEN_AI_MAX_TOKENS=${GEN_AI_MAX_TOKENS:-}
- QA_TIMEOUT=${QA_TIMEOUT:-} - QA_TIMEOUT=${QA_TIMEOUT:-}