mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 17:38:04 +08:00
WIP: P4
This commit is contained in:
@ -5,6 +5,14 @@ This module provides utility classes and functions for testing
|
||||
Redis broadcast channel functionality.
|
||||
"""
|
||||
|
||||
from .test_data import (
|
||||
LARGE_MESSAGES,
|
||||
SMALL_MESSAGES,
|
||||
SPECIAL_MESSAGES,
|
||||
BufferTestConfig,
|
||||
ConcurrencyTestConfig,
|
||||
ErrorTestConfig,
|
||||
)
|
||||
from .test_helpers import (
|
||||
ConcurrentPublisher,
|
||||
SubscriptionMonitor,
|
||||
@ -12,25 +20,17 @@ from .test_helpers import (
|
||||
measure_throughput,
|
||||
wait_for_condition,
|
||||
)
|
||||
from .test_data import (
|
||||
BufferTestConfig,
|
||||
ConcurrencyTestConfig,
|
||||
ErrorTestConfig,
|
||||
LARGE_MESSAGES,
|
||||
SMALL_MESSAGES,
|
||||
SPECIAL_MESSAGES,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"LARGE_MESSAGES",
|
||||
"SMALL_MESSAGES",
|
||||
"SPECIAL_MESSAGES",
|
||||
"BufferTestConfig",
|
||||
"ConcurrencyTestConfig",
|
||||
"ConcurrentPublisher",
|
||||
"ErrorTestConfig",
|
||||
"SubscriptionMonitor",
|
||||
"assert_message_order",
|
||||
"measure_throughput",
|
||||
"wait_for_condition",
|
||||
"BufferTestConfig",
|
||||
"ConcurrencyTestConfig",
|
||||
"ErrorTestConfig",
|
||||
"LARGE_MESSAGES",
|
||||
"SMALL_MESSAGES",
|
||||
"SPECIAL_MESSAGES",
|
||||
]
|
||||
|
||||
@ -75,7 +75,7 @@ VERY_LARGE_MESSAGES = [
|
||||
SPECIAL_MESSAGES = [
|
||||
b"", # Empty message
|
||||
b"\x00\x01\x02", # Binary data with null bytes
|
||||
"unicode_test_你好".encode("utf-8"), # Unicode
|
||||
"unicode_test_你好".encode(), # Unicode
|
||||
b"special_chars_!@#$%^&*()_+-=[]{}|;':\",./<>?", # Special characters
|
||||
b"newlines\n\r\t", # Control characters
|
||||
]
|
||||
@ -241,8 +241,8 @@ EDGE_CASE_MESSAGES = [
|
||||
b"\x00", # Single null byte
|
||||
b"\xff", # Single max byte value
|
||||
b"a", # Single ASCII character
|
||||
"ä".encode("utf-8"), # Single unicode character (2 bytes)
|
||||
"𐍈".encode("utf-8"), # Unicode character outside BMP (4 bytes)
|
||||
"ä".encode(), # Single unicode character (2 bytes)
|
||||
"𐍈".encode(), # Unicode character outside BMP (4 bytes)
|
||||
b"\x00" * 1000, # 1000 null bytes
|
||||
b"\xff" * 1000, # 1000 max byte values
|
||||
]
|
||||
|
||||
@ -8,7 +8,7 @@ operations, monitoring subscriptions, and measuring performance.
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from collections.abc import Callable, Generator
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@ -62,7 +62,7 @@ class ConcurrentPublisher:
|
||||
if self.delay > 0:
|
||||
time.sleep(self.delay)
|
||||
except Exception as e:
|
||||
_logger.error(f"Publisher {thread_id} error: {e}")
|
||||
_logger.error("Publisher %s error: %s", thread_id, e)
|
||||
|
||||
with self._lock:
|
||||
self.published_messages.append(messages)
|
||||
@ -280,7 +280,7 @@ def assert_message_order(received: list[bytes], expected: list[bytes]) -> bool:
|
||||
|
||||
for i, (recv_msg, exp_msg) in enumerate(zip(received, expected)):
|
||||
if recv_msg != exp_msg:
|
||||
_logger.error(f"Message order mismatch at index {i}: expected {exp_msg}, got {recv_msg}")
|
||||
_logger.error("Message order mismatch at index %s: expected %s, got %s", i, exp_msg, recv_msg)
|
||||
return False
|
||||
|
||||
return True
|
||||
@ -309,7 +309,7 @@ def measure_throughput(
|
||||
operation()
|
||||
count += 1
|
||||
except Exception as e:
|
||||
_logger.error(f"Operation failed: {e}")
|
||||
_logger.error("Operation failed: %s", e)
|
||||
break
|
||||
|
||||
elapsed = time.time() - start_time
|
||||
|
||||
@ -3,13 +3,12 @@ Tests for HumanInputForm domain model and repository.
|
||||
"""
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from core.workflow.entities.human_input_form import HumanInputForm, HumanInputFormStatus, HumanInputSubmissionType
|
||||
from core.repositories.sqlalchemy_human_input_form_repository import SQLAlchemyHumanInputFormRepository
|
||||
from core.workflow.entities.human_input_form import HumanInputForm, HumanInputFormStatus
|
||||
|
||||
|
||||
class TestHumanInputForm:
|
||||
@ -201,7 +200,11 @@ class TestSQLAlchemyHumanInputFormRepository:
|
||||
"""Test converting DB model to domain model."""
|
||||
from models.human_input import (
|
||||
HumanInputForm as DBForm,
|
||||
)
|
||||
from models.human_input import (
|
||||
HumanInputFormStatus as DBStatus,
|
||||
)
|
||||
from models.human_input import (
|
||||
HumanInputSubmissionType as DBSubmissionType,
|
||||
)
|
||||
|
||||
@ -233,9 +236,7 @@ class TestSQLAlchemyHumanInputFormRepository:
|
||||
def test_to_db_model(self, repository):
|
||||
"""Test converting domain model to DB model."""
|
||||
from models.human_input import (
|
||||
HumanInputForm as DBForm,
|
||||
HumanInputFormStatus as DBStatus,
|
||||
HumanInputSubmissionType as DBSubmissionType,
|
||||
)
|
||||
|
||||
domain_form = HumanInputForm.create(
|
||||
|
||||
Reference in New Issue
Block a user