Skip to content

Commit

Permalink
change base type of ProtocolMessageAction to IntEnum
Browse files Browse the repository at this point in the history
fix hanging test
  • Loading branch information
mohyour committed Sep 14, 2022
1 parent fce2edf commit 940d0cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions ably/realtime/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import websockets
import json
from ably.util.exceptions import AblyAuthException
from enum import Enum
from enum import Enum, IntEnum

log = logging.getLogger(__name__)

Expand All @@ -17,6 +17,11 @@ class ConnectionState(Enum):
FAILED = 'failed'


class ProtocolMessageAction(IntEnum):
CONNECTED = 4
ERROR = 9


class RealtimeConnection:
def __init__(self, realtime):
self.options = realtime.options
Expand Down Expand Up @@ -60,13 +65,13 @@ async def ws_read_loop(self):
raw = await self.__websocket.recv()
msg = json.loads(raw)
action = msg['action']
if action == 4: # CONNECTED
if action == ProtocolMessageAction.CONNECTED: # CONNECTED
if self.__connected_future:
self.__connected_future.set_result(None)
self.__connected_future = None
else:
log.warn('CONNECTED message receieved but connected_future not set')
if action == 9: # ERROR
log.warn('CONNECTED message received but connected_future not set')
if action == ProtocolMessageAction.ERROR: # ERROR
error = msg["error"]
if error['nonfatal'] is False:
self.__state = ConnectionState.FAILED
Expand Down
2 changes: 1 addition & 1 deletion ably/realtime/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, key=None, **kwargs):
if key is not None:
options = Options(key=key, **kwargs)
else:
raise ValueError("Key is missing. Provide an API key")
raise ValueError("Key is missing. Provide an API key.")

self.__auth = Auth(self, options)
self.__options = options
Expand Down

0 comments on commit 940d0cc

Please sign in to comment.