mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
fix telemetry send task isolation (#2187)
This commit is contained in:
@@ -13,12 +13,11 @@ class TelemetryManager:
|
|||||||
await telemetry.send({ ... })
|
await telemetry.send({ ... })
|
||||||
"""
|
"""
|
||||||
|
|
||||||
send_tasks: list[asyncio.Task] = []
|
|
||||||
|
|
||||||
def __init__(self, ap: core_app.Application):
|
def __init__(self, ap: core_app.Application):
|
||||||
self.ap = ap
|
self.ap = ap
|
||||||
|
|
||||||
self.telemetry_config = {}
|
self.telemetry_config = {}
|
||||||
|
self.send_tasks: list[asyncio.Task] = []
|
||||||
|
|
||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
self.telemetry_config = self.ap.instance_config.data.get('space', {})
|
self.telemetry_config = self.ap.instance_config.data.get('space', {})
|
||||||
|
|||||||
26
tests/unit_tests/test_telemetry.py
Normal file
26
tests/unit_tests/test_telemetry.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from langbot.pkg.telemetry.telemetry import TelemetryManager
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_send_tasks_are_scoped_to_manager_instance(monkeypatch):
|
||||||
|
async def fake_send(self, payload):
|
||||||
|
return payload
|
||||||
|
|
||||||
|
monkeypatch.setattr(TelemetryManager, 'send', fake_send)
|
||||||
|
|
||||||
|
first = TelemetryManager(SimpleNamespace())
|
||||||
|
second = TelemetryManager(SimpleNamespace())
|
||||||
|
|
||||||
|
assert first.send_tasks is not second.send_tasks
|
||||||
|
|
||||||
|
await first.start_send_task({'event': 'first'})
|
||||||
|
await first.send_tasks[0]
|
||||||
|
|
||||||
|
assert len(first.send_tasks) == 1
|
||||||
|
assert second.send_tasks == []
|
||||||
Reference in New Issue
Block a user