perf(selection): 优化选股执行性能
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
import zhixing_server.modules.selection.presentation.http as selection_http
|
||||
from zhixing_server.bootstrap.app import create_app
|
||||
from zhixing_server.bootstrap.config import Settings
|
||||
from zhixing_server.modules.selection.application.run import PreparedSelectionRun
|
||||
from zhixing_server.modules.selection.domain.models import SelectionSignal, ZhixingB1Category
|
||||
from zhixing_server.modules.selection.domain.runs import (
|
||||
@@ -19,7 +22,10 @@ from zhixing_server.modules.selection.domain.runs import (
|
||||
from zhixing_server.modules.selection.infrastructure.postgres_reader import (
|
||||
SelectionMarketDataNotReady,
|
||||
)
|
||||
from zhixing_server.modules.selection.presentation.http import get_selection_service
|
||||
from zhixing_server.modules.selection.presentation.http import (
|
||||
get_selection_postgres_pool,
|
||||
get_selection_service,
|
||||
)
|
||||
|
||||
TARGET = date(2026, 8, 8)
|
||||
|
||||
@@ -128,6 +134,17 @@ def _client(service: FakeSelectionService) -> TestClient:
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def test_selection_dependency_reuses_one_bounded_pool(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(selection_http, "_SELECTION_POOL_CACHE", {})
|
||||
settings = Settings(database_url="postgresql://test", selection_max_workers=4)
|
||||
|
||||
first = get_selection_postgres_pool(settings)
|
||||
second = get_selection_postgres_pool(settings)
|
||||
|
||||
assert first is second
|
||||
assert first.max_connections == 6
|
||||
|
||||
|
||||
def test_trigger_returns_accepted_run_and_schedules_execution() -> None:
|
||||
service = FakeSelectionService()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user