Ejemplo n.º 1
0
    def setUp(self, connections=2):
        """ Create all threads necessary to run the parametrized test. Each thread will stablish a
        connection and will bind to one queues.
        """
        self._threads = [Consumer(messages=self.messages) for i in xrange(0, connections)]

        map(lambda tq: tq[0].add_queue(QUEUE_NAME.format(number=tq[1])),
            izip(cycle(self._threads), xrange(0, self.queues)))
Ejemplo n.º 2
0
    def setUp(self, connections=2):
        """ Create all connections necessary to run the parametrized test. Each connection will stablish a
        will bind on a set of queues.
        """
        self._ioloop = pika.adapters.select_connection.IOLoop()

        # All consumers share the follwoing array, each time that ones consumer
        # has finished its work checks if the other ones have finished their work, the
        # last one will close the ioloop.
        self._consumers_finsihed = [False] * connections

        self._consumers = [Consumer(self._ioloop, i, self.messages, self._consumers_finsihed)
                           for i in xrange(0, connections)]

        # it spreads the queues over the consumers until they run out.
        map(lambda cq: cq[0].add_queue(QUEUE_NAME.format(number=cq[1])),
            izip(cycle(self._consumers), xrange(0, self.queues)))
Ejemplo n.º 3
0
def run(tests=None, queues=None, messages=None):
    """ Runs all many queues consumer tests using the `queues` amount
    with the `messages` amount published in each one.

    The tests to be executed can be filtered using the *args, setting as
    arguments those test that we wanna run.

    :param tests: list, Runs only these tests i.e ['pika_thread', ['pika_async']
                               By default runs all tests
    :param queues: integer, defaults QUEUES. Runs the test using this amount of queues
    :param messages: integer, defaults MESSAGES. Runs the test using this amount of messages
    """
    def AMQP_OPERATION(f, args, result):
        if f(*args) != result:
            raise Exception("{}({}) did not return {}".format(f.__name__,
                                                              args,
                                                              result))

    queues_ = queues if queues else QUEUES
    messages_ = messages if messages else MESSAGES
    tests_ = tests

    logging.info('Running the tests with {} messages and {} queues, total messages {}'.format(messages_,
                                                                                              queues_,
                                                                                              messages_*queues_))

    try:
        # create all AMQP entities and bind the queues. We
        # use a "macro" that checks that all was fine, otherwise
        # raises a exception.
        logging.info("Creating the Exchange {}".format(EXCHANGE_NAME))
        AMQP_OPERATION(create_exchange, (EXCHANGE_NAME, 'fanout'), True)
        logging.info("Creating {} queues".format(queues_))
        for i in xrange(0, queues_):
            queue_name = QUEUE_NAME.format(number=i)
            logging.debug("Creating the Queue {} and binding it".format(queue_name))
            AMQP_OPERATION(create_queue, (queue_name,), True)
            AMQP_OPERATION(purge_queue, (queue_name,), True)
            AMQP_OPERATION(set_binding, (EXCHANGE_NAME, queue_name, 'queue'), True)

        logging.info("Queues created")
        logging.info("Running tests")
        results = []
        for test in _installed_tests():

            logging.info("+ {} test".format(test.NAME))
            # filter those test that haven't been given.
            if tests_ and test.NAME not in tests_:
                logging.info("- filtered".format(test.NAME))
                continue

            # Each instsance returns a list of sort of executions to evaluate each
            # test sceanrio with different configurations. At leas each test runs 
            # once time. Parameters are build using the queues and messaages parameters
            # given to the constructor.
            t = test(EXCHANGE_NAME, QUEUE_NAME, queues_, messages_)
            for parameters in t.parameters():
                logging.info("- Running with params {}".format(parameters))
                try:
                    t.setUp(**parameters)
                    real, user, sys = t.run(**parameters)
                    results.append(
                        (test.NAME,
                         parameters,
                         real, user, sys,
                         (messages_*queues_)/real))
                    logging.info(_green_message("Finished"))
                except (Exception, TestFailed), e:
                    logging.warning(_red_message("Failed {}".format(str(e))))
                    logging.debug(traceback.format_exc())
                finally:
                    # always call the tearDown method for the specific
                    # test to avoid leave the environment dirty.
                    try:
                        t.tearDown(**parameters)
                    except Exception:
                        logging.warning(_red_message("tearDown failed"))
Ejemplo n.º 4
0
            for parameters in t.parameters():
                logging.info("- Running with params {}".format(parameters))
                try:
                    t.setUp(**parameters)
                    real, user, sys = t.run(**parameters)
                    results.append(
                        (test.NAME,
                         parameters,
                         real, user, sys,
                         (messages_*queues_)/real))
                    logging.info(_green_message("Finished"))
                except (Exception, TestFailed), e:
                    logging.warning(_red_message("Failed {}".format(str(e))))
                    logging.debug(traceback.format_exc())
                finally:
                    # always call the tearDown method for the specific
                    # test to avoid leave the environment dirty.
                    try:
                        t.tearDown(**parameters)
                    except Exception:
                        logging.warning(_red_message("tearDown failed"))
    finally:
        # We have to remove the AMQP entities created before
        # event there was a exception.
        delete_exchange(EXCHANGE_NAME)
        for i in xrange(0, queues_):
            delete_queue(QUEUE_NAME.format(number=i))
        logging.info('Leaving all AMQP stuff cleaned, removed exchanges and queues used by the tests')

    return results