mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-23 16:54:20 +01:00
tests: add websocket capacity test
This commit is contained in:
committed by
Jacob Plaster
parent
13e7d505f8
commit
286e922eb1
42
bfxapi/tests/test_ws_capacity.py
Normal file
42
bfxapi/tests/test_ws_capacity.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import pytest
|
||||
import json
|
||||
import time
|
||||
import asyncio
|
||||
from .helpers import (create_stubbed_client, ws_publish_connection_init, ws_publish_auth_accepted)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ws_creates_new_socket():
|
||||
client = create_stubbed_client()
|
||||
client.ws.ws_capacity = 5
|
||||
# publsh connection created message
|
||||
await ws_publish_connection_init(client.ws)
|
||||
# create a bunch of websocket subscriptions
|
||||
for symbol in ['tXRPBTC', 'tLTCUSD']:
|
||||
await client.ws.subscribe('candles', symbol, timeframe='1m')
|
||||
assert len(client.ws.sockets) == 1
|
||||
assert client.ws.get_total_available_capcity() == 3
|
||||
# subscribe to a few more to force the lib to create a new ws conenction
|
||||
for symbol in ['tETHBTC', 'tBTCUSD', 'tETHUSD', 'tLTCBTC']:
|
||||
await client.ws.subscribe('candles', symbol, timeframe='1m')
|
||||
assert len(client.ws.sockets) == 2
|
||||
assert client.ws.get_total_available_capcity() == 4
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ws_uses_authenticated_socket():
|
||||
client = create_stubbed_client()
|
||||
client.ws.ws_capacity = 2
|
||||
# publsh connection created message
|
||||
await ws_publish_connection_init(client.ws)
|
||||
# create a bunch of websocket subscriptions
|
||||
for symbol in ['tXRPBTC', 'tLTCUSD', 'tETHBTC', 'tBTCUSD', 'tETHUSD', 'tLTCBTC']:
|
||||
await client.ws.subscribe('candles', symbol, timeframe='1m')
|
||||
# publsh connection created message on socket (0 by default)
|
||||
await ws_publish_connection_init(client.ws)
|
||||
# send auth accepted (on socket by default)
|
||||
await ws_publish_auth_accepted(client.ws)
|
||||
# socket 0 should be the authenticated socket
|
||||
assert client.ws.get_authenticated_socket().id == 0
|
||||
# there should be no other authenticated sockets
|
||||
for socket in client.ws.sockets.values():
|
||||
if socket.id != 0:
|
||||
assert socket.isAuthenticated == False
|
||||
Reference in New Issue
Block a user