mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-02 10:03:05 +00:00
test: avoid potential odd timing issues in test
This commit is contained in:
@@ -67,12 +67,12 @@ async def test_exchangews_ohlcv(mocker, time_machine):
|
||||
|
||||
async def sleeper(*args, **kwargs):
|
||||
# pass
|
||||
await asyncio.sleep(1)
|
||||
await asyncio.sleep(0.12)
|
||||
return MagicMock()
|
||||
|
||||
ccxt_object.watch_ohlcv = AsyncMock(side_effect=sleeper)
|
||||
ccxt_object.close = AsyncMock()
|
||||
time_machine.move_to("2024-11-01 01:00:00 +00:00")
|
||||
time_machine.move_to("2024-11-01 01:00:02 +00:00")
|
||||
|
||||
mocker.patch("freqtrade.exchange.exchange_ws.ExchangeWS._start_forever", MagicMock())
|
||||
|
||||
@@ -84,7 +84,7 @@ async def test_exchangews_ohlcv(mocker, time_machine):
|
||||
|
||||
exchange_ws.schedule_ohlcv("ETH/BTC", "1m", CandleType.SPOT)
|
||||
exchange_ws.schedule_ohlcv("XRP/BTC", "1m", CandleType.SPOT)
|
||||
await asyncio.sleep(0.5)
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
assert exchange_ws._klines_watching == {
|
||||
("ETH/BTC", "1m", CandleType.SPOT),
|
||||
@@ -95,21 +95,18 @@ async def test_exchangews_ohlcv(mocker, time_machine):
|
||||
("XRP/BTC", "1m", CandleType.SPOT),
|
||||
}
|
||||
await asyncio.sleep(0.1)
|
||||
assert ccxt_object.watch_ohlcv.call_count == 2
|
||||
assert ccxt_object.watch_ohlcv.call_count == 6
|
||||
ccxt_object.watch_ohlcv.reset_mock()
|
||||
|
||||
time_machine.shift(timedelta(minutes=5))
|
||||
await asyncio.sleep(0.1)
|
||||
exchange_ws.schedule_ohlcv("ETH/BTC", "1m", CandleType.SPOT)
|
||||
await asyncio.sleep(0.1)
|
||||
await asyncio.sleep(1)
|
||||
# XRP/BTC should be cleaned up.
|
||||
assert exchange_ws._klines_watching == {
|
||||
("ETH/BTC", "1m", CandleType.SPOT),
|
||||
}
|
||||
# Cleanup happened.
|
||||
await asyncio.sleep(0.1)
|
||||
exchange_ws.schedule_ohlcv("ETH/BTC", "1m", CandleType.SPOT)
|
||||
await asyncio.sleep(0.1)
|
||||
assert exchange_ws._klines_watching == {
|
||||
("ETH/BTC", "1m", CandleType.SPOT),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user