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()
Exemple #2
0
    def _run_scenario(self, cls, method_name, context, args):

        times = self.config["times"]
        period = self.config["period"]
        timeout = self.config.get("timeout", 600)

        async_results = []

        pools = []
        for i in range(times):
            pool = multiprocessing.Pool(1)
            scenario_args = ((i, cls, method_name,
                              base._get_scenario_context(context), args),)
            async_result = pool.apply_async(base._run_scenario_once,
                                            scenario_args)
            async_results.append(async_result)

            pool.close()
            pools.append(pool)

            if i < times - 1:
                time.sleep(period)

        for async_result in async_results:
            try:
                result = async_result.get(timeout=timeout)
            except multiprocessing.TimeoutError as e:
                result = base.format_result_on_timeout(e, timeout)

            self._send_result(result)

        for pool in pools:
            pool.join()
Exemple #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()
Exemple #4
0
    def test_format_result_on_timeout(self, mock_format_exc):
        mock_exc = mock.MagicMock()

        expected = {
            "duration": 100,
            "idle_duration": 0,
            "scenario_output": {"errors": "", "data": {}},
            "atomic_actions": {},
            "error": mock_format_exc.return_value,
        }

        self.assertEqual(base.format_result_on_timeout(mock_exc, 100), expected)
        mock_format_exc.assert_called_once_with(mock_exc)
Exemple #5
0
    def test_format_result_on_timeout(self, mock_format_exc):
        mock_exc = mock.MagicMock()

        expected = {
            "duration": 100,
            "idle_duration": 0,
            "scenario_output": {"errors": "", "data": {}},
            "atomic_actions": [],
            "error": mock_format_exc.return_value
        }

        self.assertEqual(base.format_result_on_timeout(mock_exc, 100),
                         expected)
        mock_format_exc.assert_called_once_with(mock_exc)
    def _run_scenario(self, cls, method, context, args):

        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        # NOTE(msdubov): If not specified, perform single scenario run.
        times = self.config.get("times", 1)

        pool = multiprocessing.Pool(concurrency)
        iter_result = pool.imap(base._run_scenario_once,
                                self._iter_scenario_args(cls, method, context,
                                                         args, times))
        for i in range(times):
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = base.format_result_on_timeout(e, timeout)

            self._send_result(result)

        pool.close()
        pool.join()
Exemple #7
0
    def _run_scenario(self, cls, method, context, args):

        timeout = self.config.get("timeout", 600)
        concurrency = self.config.get("concurrency", 1)
        # NOTE(msdubov): If not specified, perform single scenario run.
        times = self.config.get("times", 1)

        pool = multiprocessing.Pool(concurrency)
        iter_result = pool.imap(
            base._run_scenario_once,
            self._iter_scenario_args(cls, method, context, args, times))
        for i in range(times):
            try:
                result = iter_result.next(timeout)
            except multiprocessing.TimeoutError as e:
                result = base.format_result_on_timeout(e, timeout)

            self._send_result(result)

        pool.close()
        pool.join()
Exemple #8
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(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()
Exemple #9
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(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()