Exemplo n.º 1
0
    def start_test(self, test, iteration, total, timer):
        """
            Starts the execution of a given test. It generates the nodes and
            creates threads that send tasks to the cluster's nodes and wait for
            the result. We have only 1 type of tasks, for obtaining the result.

            @type test: a dictionary, its keys are defined in util.py
            @param test: a Test object containing the test's parameters
            @type iteration: Integer
            @param iteration: the index of the current iteration
            @type total: Integer
            @param total: the total number of iterations
            @type timer: Timer
            @param timer: the timer used for timeout detection
        """

        supervisor = Supervisor()
        supervisor.register_banned_thread(timer)
        supervisor.register_banned_thread(current_thread())

        if test[MAT_SIZE] != test[NUM_NODES]:
            print "Wrong test format, matrix size must be the same as the\
                    number of nodes"
            os._exit(0)

        # contains all the Node objects, ordered by index (ascending)
        nodes = []

        datastores = []

        n = test[MAT_SIZE] # NUM_NODES = MAT_SIZE !
        for i in range(n):
            requests = 0
            if test[MAX_PENDING_REQUESTS] != 0:
                requests = self.test_generator.rand_gen.randint(1, test[MAX_PENDING_REQUESTS])
            datastores.append(Datastore(test[A][i][:],     # matrix row
                                        test[B][i],     # vector element
                                        requests,
                                        test[MIN_DATASTORE_DELAY],
                                        test[MAX_DATASTORE_DELAY],
                                        test[SEED_DS],
                                        supervisor))
            nodes.append(Node(i, n))
            supervisor.register_node(datastores[-1], nodes[-1])

        for node in nodes:
            # set the node's datastore
            node.set_datastore(datastores[nodes.index(node)])
            # the nodes need to know about each other
            node.set_nodes(nodes[:])

        self.result = {}

        # sends tasks to nodes
        # we need threads because get_x() is blocking

        threads = []
        for node in nodes:
            threads.append(Thread(target=Tester.start_node, args=(self, node)))
            supervisor.register_banned_thread(threads[-1])
            threads[-1].start()

        for t in threads:
            t.join()

        for node in nodes:
            node.shutdown()

        supervisor.check_termination()

        if self.bonus is None:
            self.bonus = supervisor.check_bonus()
        else:
            self.bonus = self.bonus and supervisor.check_bonus()

        errors = supervisor.status()
        errors.extend(self.check_result(test))

        if len(errors) == 0:
            self.passed_tests += 1
        else:
            self.bonus = False
            print test_errors_msg % (iteration, total)
            for error in errors:
                self.print_error(error)