Beispiel #1
0
    def _run_scenario(self, cls, method, context, args):

        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        pool = multiprocessing.Pool(concurrency)

        run_args = utils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args))
        iter_result = pool.imap(base._run_scenario_once, run_args)

        results_queue = collections.deque([], maxlen=concurrency)
        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = {
                    "duration": timeout,
                    "idle_duration": 0,
                    "error": utils.format_exc(e)
                }
            results_queue.append(result)

            if time.time() - start > duration:
                break

        results = list(results_queue)

        pool.terminate()
        pool.join()

        return base.ScenarioRunnerResult(results)
    def _run_scenario(self, cls, method, context, args):

        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        pool = multiprocessing.Pool(concurrency)

        run_args = utils.infinite_run_args_generator(
                    self._iter_scenario_args(cls, method, context, args))
        iter_result = pool.imap(base._run_scenario_once, run_args)

        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = base.format_result_on_timeout(e, timeout)

            self._send_result(result)

            if time.time() - start > duration:
                break

        pool.terminate()
        pool.join()
Beispiel #3
0
    def _run_scenario(self, cls, method, context, args):
        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        pool = multiprocessing.Pool(concurrency)

        run_args = utils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args, self.aborted))
        iter_result = pool.imap(base._run_scenario_once, run_args)

        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = base.format_result_on_timeout(e, timeout)
            except StopIteration:
                break

            self._send_result(result)

            if time.time() - start > duration:
                break

        pool.terminate()
        pool.join()
Beispiel #4
0
    def _run_scenario(self, cls, method, context, args):

        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        pool = multiprocessing.Pool(concurrency)

        run_args = utils.infinite_run_args_generator(
                    self._iter_scenario_args(cls, method, context, args))
        iter_result = pool.imap(base._run_scenario_once, run_args)

        results = []
        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = {"duration": timeout, "idle_duration": 0,
                          "scenario_output": {},
                          "atomic_actions": [],
                          "error": utils.format_exc(e)}
            results.append(result)

            if time.time() - start > duration:
                break

        pool.terminate()
        pool.join()

        return base.ScenarioRunnerResult(results)
Beispiel #5
0
    def _run_scenario_continuously_for_duration(self, cls, method, context,
                                                args, duration, concurrent,
                                                timeout):
        pool = multiprocessing.Pool(concurrent)

        def _scenario_args(i):
            return (i, cls, method, base._get_scenario_context(context), args)

        run_args = utils.infinite_run_args_generator(_scenario_args)
        iter_result = pool.imap(base._run_scenario_once, run_args)

        results_queue = collections.deque([], maxlen=concurrent)
        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = {"time": timeout, "idle_time": 0,
                          "error": utils.format_exc(e)}
            results_queue.append(result)

            if time.time() - start > duration:
                break

        results = list(results_queue)

        pool.terminate()
        pool.join()

        return results
Beispiel #6
0
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified benchmark scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method_name: Name of the method that implements the scenario
        :param context: Benchmark context that contains users, admin & other
                        information, that was created before benchmark started.
        :param args: Arguments to call the scenario method with

        :returns: List of results fore each single scenario iteration,
                  where each result is a dictionary
        """
        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        duration = self.config.get("duration")

        pool = multiprocessing.Pool(concurrency)

        run_args = butils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args,
                                     self.aborted))
        iter_result = pool.imap(runner._run_scenario_once, run_args)

        start = time.time()
        while True:
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = runner.format_result_on_timeout(e, timeout)
            except StopIteration:
                break

            self._send_result(result)

            if time.time() - start > duration:
                break

        pool.terminate()
        pool.join()
Beispiel #7
0
 def test_infinite_run_args_generator(self):
     args = lambda x: (x, "a", "b", 123)
     for i, real_args in enumerate(utils.infinite_run_args_generator(args)):
         self.assertEqual((i, "a", "b", 123), real_args)
         if i > 5:
             break
Beispiel #8
0
 def test_infinite_run_args_generator(self):
     args = lambda x: (x, "a", "b", 123)
     for i, real_args in enumerate(utils.infinite_run_args_generator(args)):
         self.assertEqual((i, "a", "b", 123), real_args)
         if i > 5:
             break