Exemple #1
0
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method: Name of the method that implements the scenario
        :param context: context that contains users, admin & other
                        information, that was created before scenario is
                        execution starts.
        :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")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        pool = multiprocessing.Pool(concurrency)
        manager = multiprocessing.Manager()
        event_queue = manager.Queue()
        stop_event_listener = threading.Event()

        def event_listener():
            while not stop_event_listener.isSet():
                while not event_queue.empty():
                    self.send_event(**event_queue.get())
                else:
                    time.sleep(0.01)

        event_listener_thread = threading.Thread(target=event_listener)
        event_listener_thread.start()

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

        start = time.time()
        try:
            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
        finally:
            stop_event_listener.set()
            event_listener_thread.join()
            pool.terminate()
            pool.join()
            self._flush_results()
Exemple #2
0
    def _run_scenario(self, cls, method, context, args):
        """Runs the specified scenario with given arguments.

        :param cls: The Scenario class where the scenario is implemented
        :param method: Name of the method that implements the scenario
        :param context: context that contains users, admin & other
                        information, that was created before scenario is
                        execution starts.
        :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")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        pool = multiprocessing.Pool(concurrency)
        manager = multiprocessing.Manager()
        event_queue = manager.Queue()
        stop_event_listener = threading.Event()

        def event_listener():
            while not stop_event_listener.isSet():
                while not event_queue.empty():
                    self.send_event(**event_queue.get())
                else:
                    time.sleep(0.01)

        event_listener_thread = threading.Thread(target=event_listener)
        event_listener_thread.start()

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

        start = time.time()
        try:
            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
        finally:
            stop_event_listener.set()
            event_listener_thread.join()
            pool.terminate()
            pool.join()
            self._flush_results()
Exemple #3
0
    def test_format_result_on_timeout(self, mock_format_exc):
        mock_exc = mock.MagicMock()

        expected = {
            "duration": 100,
            "idle_duration": 0,
            "output": {"additive": [], "complete": []},
            "atomic_actions": {},
            "error": mock_format_exc.return_value
        }

        self.assertEqual(runner.format_result_on_timeout(mock_exc, 100),
                         expected)
        mock_format_exc.assert_called_once_with(mock_exc)
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(runner.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,
            "output": {"additive": [], "complete": []},
            "atomic_actions": [],
            "error": mock_format_exc.return_value
        }

        self.assertEqual(runner.format_result_on_timeout(mock_exc, 100),
                         expected)
        mock_format_exc.assert_called_once_with(mock_exc)
    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(runner.format_result_on_timeout(mock_exc, 100),
                         expected)
        mock_format_exc.assert_called_once_with(mock_exc)
Exemple #7
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 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")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        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(_run_scenario_once_with_unpack_args, 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()
        self._flush_results()
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 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")

        # FIXME(andreykurilin): unify `_worker_process`, use it here and remove
        #     usage of `multiprocessing.Pool`(usage of separate process for
        #     each concurrent iteration is redundant).
        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(_run_scenario_once_with_unpack_args, 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()
        self._flush_results()
    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")
        pause = self.config.get("pause", 0.5)

        pool = multiprocessing.Pool(concurrency)

        run_args = butils.infinite_run_args_generator(
            self._iter_scenario_args(cls, method, context, args,
                                     self.aborted, pause))
        iter_result = pool.imap(_run_scenario_once_with_sleep, 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()