Skip to content

Commit

Permalink
Merge pull request #61 from wildfoundry/premature-close
Browse files Browse the repository at this point in the history
fix for premature close
  • Loading branch information
willmcgugan authored May 28, 2018
2 parents 19d24ed + c574f81 commit cd2e808
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.2.5] - 2018-05-28

### Fixed

- Traceback if close is called prior to WebSocket ready

## [0.2.4] - 2018-05-15

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Welcome to Dataplicity Lomond's documentation!
==============================================

Lomond is a Pythonic Websockets client library designed for reliability
Lomond is a Pythonic WebSockets client library designed for reliability
and ease of use.

Sponsor
Expand Down
2 changes: 1 addition & 1 deletion lomond/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import unicode_literals

__version__ = "0.2.4"
__version__ = "0.2.5"
8 changes: 7 additions & 1 deletion lomond/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def __repr__(self):
@property
def session_time(self):
"""Get the time (in seconds) since the WebSocket session started."""
return time.time() - self._start_time
return (
0.0
if self._start_time is None else
time.time() - self._start_time
)

def close(self):
"""Close the websocket, if it is open."""
Expand Down Expand Up @@ -341,6 +345,8 @@ def run(self,
url = websocket.url
# Connecting event
yield events.Connecting(url)
if websocket.is_closed:
return

# Create socket and connect to remote server
try:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,17 @@ def test_echo(self):
assert events[6].name == 'closed'
assert events[7].name == 'disconnected'
assert events[7].graceful

def test_premature_close_connecting(self):
"""Test close after connecting event."""
ws = WebSocket('ws://NEVERCONNECTS')
for event in ws:
if event.name == 'connecting':
ws.close()

def test_premature_close_connected(self):
"""Test close after connected event."""
ws = WebSocket(self.WS_URL + 'graceful')
for event in ws:
if event.name == 'connected':
ws.close()

0 comments on commit cd2e808

Please sign in to comment.