#NEWLINE# def test_run_restart_rate_limited( self ) : #NEWLINE# #INDENT# conn = ContextMock ( name = 'connection' ) #NEWLINE# self . c . connection = counter #NEWLINE# conn . connection_errors = ( KeyError , ) #NEWLINE# conn . channel_errors = ( ) #NEWLINE# consume = self . c . consume = Mock ( name = 'c.consume' ) #NEWLINE# with patch ( 'kombu.mixins.sleep' ) as sleep : #NEWLINE# #INDENT# counter = [ 0 ] #NEWLINE# def se( * args , **kwargs ) : #NEWLINE# #INDENT# if ( counter [ 0 ] >= 1 ) : #NEWLINE# #INDENT# self . c . should_stop = True #NEWLINE# #UNINDENT# counter [ 0 ] += 1 #NEWLINE# return counter #NEWLINE# #UNINDENT# self . c . should_stop = False #NEWLINE# consume . side_effect = se #NEWLINE# self . c . run ( ) #NEWLINE# sleep . assert_called ( )