Skip to content

Commit

Permalink
Raise ConnectionClosed in Connection.synchronous if the transport has
Browse files Browse the repository at this point in the history
been cleared
  • Loading branch information
awestendorf committed Mar 19, 2014
1 parent 39e2309 commit 9500ef0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions haigha/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def transport(self):
@property
def synchronous(self):
'''True if transport is synchronous, False otherwise.'''
if self._transport==None:
if self._close_info and len(self._close_info['reply_text'])>0:
raise ConnectionClosed("connection is closed: %s : %s"%\
(self._close_info['reply_code'],self._close_info['reply_text']) )
raise ConnectionClosed("connection is closed")
return self.transport.synchronous

def connect(self, host, port):
Expand Down
18 changes: 18 additions & 0 deletions haigha/tests/unit/connection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ def test_properties(self):
self.assertEqual( self.connection._frames_read, self.connection.frames_read )
self.assertEqual( self.connection._frames_written, self.connection.frames_written )

def test_synchronous_when_no_transport(self):
self.connection._transport = None
with assert_raises( connection.ConnectionClosed ):
self.connection.synchronous

self.connection._close_info = {
'reply_code':100,
'reply_text':'breakdown'
}
with assert_raises( connection.ConnectionClosed ):
self.connection.synchronous

def test_synchronous_when_transport(self):
self.connection._transport.synchronous = True
assert_true( self.connection.synchronous )
self.connection._transport.synchronous = False
assert_false( self.connection.synchronous )

def test_connect_when_asynchronous_transport(self):
self.connection._transport.synchronous = False
self.connection._connected = 'maybe'
Expand Down

0 comments on commit 9500ef0

Please sign in to comment.