def test_botiteration(self):
     botexc = Data.BotError((Exception("foo"), "foobar"), 2, 4, 6)
     botuser = User.StandardBotUser(
         {"XMLRPC": ("http://foo", "http://foo/login")}, "XMLRPC", "user",
         "passwd", "exp_name", "cat_name", "bar", 0.05)
     botit = Data.BotIteration(100, [botexc], [botuser], "stdout", "stderr")
     self.assertTrue(repr(botit).find('botusers') > 0)
Exemple #2
0
    def test_bottrial(self):
        botexc = Data.BotError((Exception("foo"), "foobar"), 2, 4, 6)
        botuser = User.StandardBotUser(
            {"JSON": ("http://foo", "http://foo/login")}, "JSON", "user",
            "passwd", "exp_name", "cat_name", "bar", 0.05)
        botit = Data.BotIteration(100, {"Exception": botexc}, [botuser],
                                  "stdout", "stderr")

        bottri = Data.BotTrial([botit])
        self.assertTrue(repr(bottri).find('iterations') > 0)
    def _launch_iteration(self):
        started_processes = self._start_processes()

        # Launching botusers...
        if self.verbose:
            print("[Launcher] All processes launched")
        try:
            botusers = []
            for botuser_creator_name, botuser_creator in self.scenario:
                botusers.append(botuser_creator())

            begin_time = time.time()
            for botuser in botusers:
                botuser.start()

            waiting_botusers = botusers[:]
            while len(waiting_botusers) > 0:
                number_before = len(waiting_botusers)
                waiting_botusers = [
                    botuser for botuser in waiting_botusers
                    if botuser.isAlive()
                ]
                for _ in range(number_before - len(waiting_botusers)):
                    self._print(".")
                time.sleep(0.3)
            iteration_time = time.time() - begin_time
        finally:
            complete_out, complete_err = self._stop_processes(
                started_processes)

        botuser_routes = [botuser.route for botuser in botusers]
        routes = {}
        for route in botuser_routes:
            if route in routes:
                routes[route] = routes[route] + 1
            else:
                routes[route] = 1

        self._print("  %s" % routes)

        # Compiling iteration data...
        exceptions = {}
        for botuser in botusers:
            for exception, trace in botuser.get_exceptions():
                self._add_exception(exceptions, (exception, trace))
        return Data.BotIteration(iteration_time, exceptions, botusers,
                                 complete_out, complete_err)
Exemple #4
0
    def _launch_iteration(self):

        # Launching botusers...
        started_processes = []
        try:
            for launch_file in self.launch_files:
                if self.verbose:
                    print "[Launcher] Launching... %s" % launch_file
                weblab_process = WebLabProcess.WebLabProcess(
                    launch_file, self.host, self.options, verbose=self.verbose)
                weblab_process.start()
                if self.verbose:
                    print "[Launcher] %s running" % launch_file
                started_processes.append(weblab_process)

            if len(started_processes) > 1:
                started_processes[0].step_wait()

            for weblab_process in started_processes:
                weblab_process.wait_for_process_started()

            if len(started_processes) > 1:
                started_processes[0].step_started_wait()
        except:
            for started_process in started_processes:
                if self.verbose:
                    print "[Launcher] Shutting down... %s" % started_process
                started_process.shutdown()
            raise
        if self.verbose:
            print "[Launcher] All processes launched"
        try:
            botusers = []
            for botuser_creator_name, botuser_creator in self.scenario:
                botusers.append(botuser_creator())

            begin_time = time.time()
            for botuser in botusers:
                botuser.start()

            waiting_botusers = botusers[:]
            while len(waiting_botusers) > 0:
                number_before = len(waiting_botusers)
                waiting_botusers = [
                    botuser for botuser in waiting_botusers
                    if botuser.isAlive()
                ]
                for _ in range(number_before - len(waiting_botusers)):
                    self._print(".")
                time.sleep(0.3)
            iteration_time = time.time() - begin_time
        finally:
            complete_out = ''
            complete_err = ''
            for started_process in started_processes:
                started_process.shutdown()
                complete_out += started_process.out
                complete_err += started_process.err

        botuser_routes = [botuser.route for botuser in botusers]
        routes = {}
        for route in botuser_routes:
            if route in routes:
                routes[route] = routes[route] + 1
            else:
                routes[route] = 1

        self._print("  %s" % routes)

        # Compiling iteration data...
        exceptions = {}
        for botuser in botusers:
            for exception, trace in botuser.get_exceptions():
                self._add_exception(exceptions, (exception, trace))
        return Data.BotIteration(iteration_time, exceptions, botusers,
                                 complete_out, complete_err)