Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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()
Esempio n. 4
0
    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)
Esempio n. 5
0
 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()
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 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()
Esempio n. 12
0
 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)
Esempio n. 13
0
 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)
Esempio n. 14
0
 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)
Esempio n. 15
0
 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()
Esempio n. 16
0
 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)