Skip to content

Commit

Permalink
Handle any exception in closing a channel inside of the exception
Browse files Browse the repository at this point in the history
handler.
Fix several tests
  • Loading branch information
awestendorf committed Sep 12, 2013
1 parent f05b725 commit a3c79ee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions haigha/channel.py
Expand Up @@ -210,8 +210,10 @@ def process_frames(self):
# Spec says that channel should be closed if there's a framing error.
# Unsure if we can send close if the current exception is transport
# level (e.g. gevent.GreenletExit)
self.close( 500, "Failed to dispatch %s"%(str(frame)) )
raise
try:
self.close( 500, "Failed to dispatch %s"%(str(frame)) )
finally:
raise

def next_frame(self):
'''
Expand Down
15 changes: 15 additions & 0 deletions haigha/tests/unit/channel_test.py
Expand Up @@ -246,6 +246,21 @@ def test_process_frames_logs_and_closes_when_dispatch_error_raised(self):
assert_raises( RuntimeError, c.process_frames )
assertEquals( f1, c._frame_buffer[0] )

def test_process_frames_logs_and_closes_when_dispatch_error_raised_even_when_exception_on_close(self):
c = Channel(None,None,{})
c._connection = mock()
c._connection.logger = mock()

f0 = MethodFrame(20, 30, 40)
f1 = MethodFrame('ch_id', 'c_id', 'm_id')
c._frame_buffer = deque([ f0, f1 ])

expect( c.dispatch ).args( f0 ).raises( RuntimeError("zomg it broked") )
expect( c.close ).raises( ValueError() )

assert_raises( RuntimeError, c.process_frames )
assertEquals( f1, c._frame_buffer[0] )

def test_process_frames_logs_and_closes_when_systemexit_raised(self):
c = Channel(None,None,{})
c._connection = mock()
Expand Down
4 changes: 2 additions & 2 deletions haigha/tests/unit/classes/queue_class_test.py
Expand Up @@ -117,7 +117,7 @@ def test_recv_declare_ok_with_callback(self):
expect( rframe.args.read_long ).returns( 5 )
expect( cb ).args( 'queue', 32, 5 )

assert_equals( (32,5), self.klass._recv_declare_ok(rframe) )
assert_equals( ('queue',32,5), self.klass._recv_declare_ok(rframe) )
assert_equals( 1, len(self.klass._declare_cb) )
assert_false( cb in self.klass._declare_cb )

Expand All @@ -131,7 +131,7 @@ def test_recv_declare_ok_without_callback(self):
expect( rframe.args.read_long ).returns( 32 )
expect( rframe.args.read_long ).returns( 5 )

assert_equals( (32,5), self.klass._recv_declare_ok(rframe) )
assert_equals( ('queue',32,5), self.klass._recv_declare_ok(rframe) )
assert_equals( 1, len(self.klass._declare_cb) )
assert_false( None in self.klass._declare_cb )

Expand Down
2 changes: 1 addition & 1 deletion haigha/tests/unit/message_test.py
Expand Up @@ -13,7 +13,7 @@ class MessageTest(Chai):

def test_init_no_args(self):
m = Message()
self.assertEquals( None, m._body )
self.assertEquals( '', m._body )
self.assertEquals( None, m._delivery_info )
self.assertEquals( {}, m._properties )

Expand Down

0 comments on commit a3c79ee

Please sign in to comment.