diff --git a/haigha/channel.py b/haigha/channel.py index f344af0..81f1ed0 100644 --- a/haigha/channel.py +++ b/haigha/channel.py @@ -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): ''' diff --git a/haigha/tests/unit/channel_test.py b/haigha/tests/unit/channel_test.py index 0eefe23..d6fa4f1 100644 --- a/haigha/tests/unit/channel_test.py +++ b/haigha/tests/unit/channel_test.py @@ -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() diff --git a/haigha/tests/unit/classes/queue_class_test.py b/haigha/tests/unit/classes/queue_class_test.py index 35dc71c..f3f15a1 100644 --- a/haigha/tests/unit/classes/queue_class_test.py +++ b/haigha/tests/unit/classes/queue_class_test.py @@ -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 ) @@ -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 ) diff --git a/haigha/tests/unit/message_test.py b/haigha/tests/unit/message_test.py index 6981a4a..3bf5c81 100644 --- a/haigha/tests/unit/message_test.py +++ b/haigha/tests/unit/message_test.py @@ -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 )