Skip to content

Commit

Permalink
MOD: Add repeater mode to mock live server
Browse files Browse the repository at this point in the history
  • Loading branch information
nmacholl committed Oct 10, 2023
1 parent 8cea4ea commit 37d8627
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 75 deletions.
38 changes: 31 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"""
from __future__ import annotations

import asyncio
import pathlib
import random
import string
import threading
from collections.abc import AsyncGenerator
from collections.abc import Generator
from collections.abc import Iterable
Expand Down Expand Up @@ -188,15 +190,37 @@ async def fixture_mock_live_server(
1,
)

loop = asyncio.new_event_loop()
thread = threading.Thread(
name="MockLiveServer",
target=loop.run_forever,
args=(),
daemon=True,
)
thread.start()

with caplog.at_level("DEBUG"):
mock_live_server = await MockLiveServer.create(
host="127.0.0.1",
port=unused_tcp_port,
dbn_path=TESTS_ROOT / "data",
)
await mock_live_server.start()
mock_live_server = asyncio.run_coroutine_threadsafe(
coro=MockLiveServer.create(
host="127.0.0.1",
port=unused_tcp_port,
dbn_path=TESTS_ROOT / "data",
),
loop=loop,
).result()

yield mock_live_server
await mock_live_server.stop()

asyncio.run_coroutine_threadsafe(
coro=mock_live_server.stop(),
loop=loop,
).result()

loop.run_in_executor(
None,
loop.stop,
)
thread.join()


@pytest.fixture(name="historical_client")
Expand Down
Loading

0 comments on commit 37d8627

Please sign in to comment.