def on_queue_declared(self, frame): for i in range(0, 100): msg_body = '{}:{}:{}'.format(self.__class__.__name__, i, time_now()) self.channel.basic_publish('', self.queue_name, msg_body) self.ctag = self.channel.basic_consume(self.queue_name, self.on_message, auto_ack=True)
def begin(self, channel): self.my_start_time = time_now() # Request a callback from ioloop while executing in another thread timer = threading.Timer( 0, lambda: channel.connection._adapter_add_callback_threadsafe( self.on_requested_callback)) self.addCleanup(timer.cancel) timer.start()
def _run_ioloop(self, *args, **kwargs): # pylint: disable=W0221 """We intercept this method from AsyncTestCase in order to call ioloop.stop() before AsyncTestCase starts the ioloop. """ # Request ioloop to stop before it starts my_start_time = time_now() self.stop_ioloop_only() super( TestIOLoopStopBeforeIOLoopStarts, self)._run_ioloop(*args, **kwargs) self.assertLess(time_now() - my_start_time, 0.25) # Resume I/O loop to facilitate normal course of events and closure # of connection in order to prevent reporting of a socket resource leak # from an unclosed connection. super( TestIOLoopStopBeforeIOLoopStarts, self)._run_ioloop(*args, **kwargs)
def _run_ioloop(self, *args, **kwargs): # pylint: disable=W0221 """We intercept this method from AsyncTestCase in order to call ioloop.stop() before AsyncTestCase starts the ioloop. """ # Request ioloop to stop before it starts my_start_time = time_now() self.stop_ioloop_only() super(TestIOLoopStopBeforeIOLoopStarts, self)._run_ioloop(*args, **kwargs) self.assertLess(time_now() - my_start_time, 0.25) # Resume I/O loop to facilitate normal course of events and closure # of connection in order to prevent reporting of a socket resource leak # from an unclosed connection. super(TestIOLoopStopBeforeIOLoopStarts, self)._run_ioloop(*args, **kwargs)
def _run_ioloop(self, *args, **kwargs): # pylint: disable=W0221 """We intercept this method from AsyncTestCase in order to call _adapter_add_callback_threadsafe before AsyncTestCase starts the ioloop. """ self.my_start_time = time_now() # Request a callback from our current (ioloop's) thread self.connection._adapter_add_callback_threadsafe( self.on_requested_callback) return super(TestAddCallbackThreadsafeRequestBeforeIOLoopStarts, self)._run_ioloop(*args, **kwargs)
def _run_ioloop(self, *args, **kwargs): # pylint: disable=W0221 """We intercept this method from AsyncTestCase in order to call _adapter_add_callback_threadsafe before AsyncTestCase starts the ioloop. """ self.my_start_time = time_now() # Request a callback from our current (ioloop's) thread self.connection._adapter_add_callback_threadsafe( self.on_requested_callback) return super( TestAddCallbackThreadsafeRequestBeforeIOLoopStarts, self)._run_ioloop( *args, **kwargs)
def on_ready(self, frame): self.msg_body = "%s: %i" % (self.__class__.__name__, time_now()) self.channel.basic_publish(self.exchange, self.routing_key, self.msg_body) self.channel.basic_get(self.queue, self.on_get)
def on_ready(self, frame): self.ctag = self.channel.basic_consume(self.queue, self.on_message) self.msg_body = "%s: %i" % (self.__class__.__name__, time_now()) self.channel.basic_publish(self.exchange, self.routing_key, self.msg_body)
def on_requested_callback(self): self.assertEqual(threading.current_thread().ident, self.loop_thread_ident) self.assertLess(time_now() - self.my_start_time, 0.25) self.got_callback = True self.stop()
def begin(self, channel): self.my_start_time = time_now() # Request a callback from our current (ioloop's) thread channel.connection._adapter_add_callback_threadsafe( self.on_requested_callback)