Skip to content

Commit 37d8627

Browse files
committed
MOD: Add repeater mode to mock live server
1 parent 8cea4ea commit 37d8627

File tree

2 files changed

+147
-75
lines changed

2 files changed

+147
-75
lines changed

tests/conftest.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"""
44
from __future__ import annotations
55

6+
import asyncio
67
import pathlib
78
import random
89
import string
10+
import threading
911
from collections.abc import AsyncGenerator
1012
from collections.abc import Generator
1113
from collections.abc import Iterable
@@ -188,15 +190,37 @@ async def fixture_mock_live_server(
188190
1,
189191
)
190192

193+
loop = asyncio.new_event_loop()
194+
thread = threading.Thread(
195+
name="MockLiveServer",
196+
target=loop.run_forever,
197+
args=(),
198+
daemon=True,
199+
)
200+
thread.start()
201+
191202
with caplog.at_level("DEBUG"):
192-
mock_live_server = await MockLiveServer.create(
193-
host="127.0.0.1",
194-
port=unused_tcp_port,
195-
dbn_path=TESTS_ROOT / "data",
196-
)
197-
await mock_live_server.start()
203+
mock_live_server = asyncio.run_coroutine_threadsafe(
204+
coro=MockLiveServer.create(
205+
host="127.0.0.1",
206+
port=unused_tcp_port,
207+
dbn_path=TESTS_ROOT / "data",
208+
),
209+
loop=loop,
210+
).result()
211+
198212
yield mock_live_server
199-
await mock_live_server.stop()
213+
214+
asyncio.run_coroutine_threadsafe(
215+
coro=mock_live_server.stop(),
216+
loop=loop,
217+
).result()
218+
219+
loop.run_in_executor(
220+
None,
221+
loop.stop,
222+
)
223+
thread.join()
200224

201225

202226
@pytest.fixture(name="historical_client")

0 commit comments

Comments
 (0)