Изменена логика задания таймаутов ожидания

This commit is contained in:
2026-02-21 22:45:41 +03:00
parent 608cd42719
commit 058c19d677
10 changed files with 59 additions and 41 deletions

View File

@@ -1,9 +1,12 @@
import asyncio
from config_manager.v2 import ConfigManagerV2
from config_manager.v2 import ConfigManagerV2, ManagementServerSettings
class ReloadApp(ConfigManagerV2):
DEFAULT_UPDATE_INTERVAL = 0.05
DEFAULT_WORK_INTERVAL = 0.2
def execute(self) -> None:
return
@@ -11,9 +14,9 @@ class ReloadApp(ConfigManagerV2):
def test_invalid_config_keeps_last_valid(tmp_path):
async def scenario() -> None:
cfg = tmp_path / "config.yaml"
cfg.write_text("work_interval: 0.2\nupdate_interval: 0.05\n", encoding="utf-8")
cfg.write_text("log: {}\n", encoding="utf-8")
app = ReloadApp(str(cfg))
app = ReloadApp(str(cfg), management_settings=ManagementServerSettings(enabled=False))
runner = asyncio.create_task(app.start())
await asyncio.sleep(0.12)

View File

@@ -1,9 +1,12 @@
import asyncio
from config_manager.v2 import ConfigManagerV2
from config_manager.v2 import ConfigManagerV2, ManagementServerSettings
class DemoApp(ConfigManagerV2):
DEFAULT_UPDATE_INTERVAL = 0.05
DEFAULT_WORK_INTERVAL = 0.05
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.calls = 0
@@ -15,9 +18,9 @@ class DemoApp(ConfigManagerV2):
def test_execute_loop_runs(tmp_path):
async def scenario() -> None:
cfg = tmp_path / "config.yaml"
cfg.write_text("work_interval: 0.05\nupdate_interval: 0.05\n", encoding="utf-8")
cfg.write_text("log: {}\n", encoding="utf-8")
app = DemoApp(str(cfg))
app = DemoApp(str(cfg), management_settings=ManagementServerSettings(enabled=False))
runner = asyncio.create_task(app.start())
await asyncio.sleep(0.18)

View File

@@ -1,6 +1,6 @@
import asyncio
from config_manager.v2 import ConfigManagerV2
from config_manager.v2 import ConfigManagerV2, ManagementServerSettings
from config_manager.v2.control.base import ControlChannel, StartHandler, StatusHandler, StopHandler
@@ -23,6 +23,9 @@ class DummyControlChannel(ControlChannel):
class ControlledApp(ConfigManagerV2):
DEFAULT_UPDATE_INTERVAL = 0.05
DEFAULT_WORK_INTERVAL = 0.05
def execute(self) -> None:
return
@@ -30,10 +33,14 @@ class ControlledApp(ConfigManagerV2):
def test_control_channel_can_stop_manager(tmp_path):
async def scenario() -> None:
cfg = tmp_path / "config.yaml"
cfg.write_text("work_interval: 0.05\nupdate_interval: 0.05\n", encoding="utf-8")
cfg.write_text("log: {}\n", encoding="utf-8")
channel = DummyControlChannel()
app = ControlledApp(str(cfg), control_channel=channel)
app = ControlledApp(
str(cfg),
control_channel=channel,
management_settings=ManagementServerSettings(enabled=False),
)
runner = asyncio.create_task(app.start())
await asyncio.sleep(0.12)
@@ -49,6 +56,6 @@ def test_control_channel_can_stop_manager(tmp_path):
assert "stop signal accepted" in stop_text
await runner
assert channel.stopped is True
# Менеджер при остановке не вызывает control_channel.stop() (канал остаётся доступным)
asyncio.run(scenario())

View File

@@ -2,10 +2,13 @@ import asyncio
import threading
import time
from config_manager.v2 import ConfigManagerV2
from config_manager.v2 import ConfigManagerV2, ManagementServerSettings
class BlockingApp(ConfigManagerV2):
DEFAULT_UPDATE_INTERVAL = 0.05
DEFAULT_WORK_INTERVAL = 0.05
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.started_event = threading.Event()
@@ -23,9 +26,9 @@ class BlockingApp(ConfigManagerV2):
def test_stop_waits_for_active_execute_and_prevents_next_run(tmp_path):
async def scenario() -> None:
cfg = tmp_path / "config.yaml"
cfg.write_text("work_interval: 0.05\nupdate_interval: 0.05\n", encoding="utf-8")
cfg.write_text("log: {}\n", encoding="utf-8")
app = BlockingApp(str(cfg))
app = BlockingApp(str(cfg), management_settings=ManagementServerSettings(enabled=False))
runner = asyncio.create_task(app.start())
started = await asyncio.to_thread(app.started_event.wait, 1.0)