test: improve event-loop mocking
This commit is contained in:
@@ -50,18 +50,18 @@ def test_exchangews_cleanup_error(mocker, caplog):
|
|||||||
|
|
||||||
|
|
||||||
def patch_eventloop_threading(exchange):
|
def patch_eventloop_threading(exchange):
|
||||||
is_init = False
|
init_event = threading.Event()
|
||||||
|
|
||||||
def thread_fuck():
|
def thread_func():
|
||||||
nonlocal is_init
|
|
||||||
exchange._loop = asyncio.new_event_loop()
|
exchange._loop = asyncio.new_event_loop()
|
||||||
is_init = True
|
init_event.set()
|
||||||
exchange._loop.run_forever()
|
exchange._loop.run_forever()
|
||||||
|
|
||||||
x = threading.Thread(target=thread_fuck, daemon=True)
|
x = threading.Thread(target=thread_func, daemon=True)
|
||||||
x.start()
|
x.start()
|
||||||
while not is_init:
|
# Wait for thread to be properly initialized with timeout
|
||||||
pass
|
if not init_event.wait(timeout=5.0):
|
||||||
|
raise RuntimeError("Failed to initialize event loop thread")
|
||||||
|
|
||||||
|
|
||||||
async def test_exchangews_ohlcv(mocker, time_machine, caplog):
|
async def test_exchangews_ohlcv(mocker, time_machine, caplog):
|
||||||
|
|||||||
Reference in New Issue
Block a user