fix: _on_candle_closed async 콜백 구조 수정 — asyncio.create_task 제거

동기 콜백 내부에서 asyncio.create_task()를 호출하면 이벤트 루프
컨텍스트 밖에서 실패하여 캔들 처리가 전혀 이루어지지 않는 버그 수정.

- _on_candle_closed: 동기 → async, create_task → await
- handle_message (KlineStream/MultiSymbolStream): 동기 → async, on_candle await
- test_callback_called_on_closed_candle: AsyncMock + await handle_message로 수정

Made-with: Cursor
This commit is contained in:
21in7
2026-03-02 01:00:59 +09:00
parent 361b0f4e00
commit 5e6cdcc358
3 changed files with 12 additions and 13 deletions

View File

@@ -63,11 +63,11 @@ async def test_kline_stream_parses_message():
@pytest.mark.asyncio
async def test_callback_called_on_closed_candle():
received = []
callback = AsyncMock()
stream = KlineStream(
symbol="XRPUSDT",
interval="1m",
on_candle=lambda c: received.append(c),
on_candle=callback,
)
raw_msg = {
"k": {
@@ -80,8 +80,8 @@ async def test_callback_called_on_closed_candle():
"x": True,
}
}
stream.handle_message(raw_msg)
assert len(received) == 1
await stream.handle_message(raw_msg)
assert callback.call_count == 1
@pytest.mark.asyncio