示例#1
0
 def start(self):
     params = list(self._get_thread_params())
     with self._writer:
         self.map(self.run_nose, params)
         log.info("Workers finished, awaiting result writer")
         while not self._writer.is_queue_empty() and self._writer.is_alive(
         ):
             time.sleep(0.1)
         log.info("Results written, shutting down")
         self.close()
示例#2
0
    def _start_workers(self):
        log.info("Total workers: %s", self.params.worker_count)

        thread.set_total(self.params.concurrency)
        workers = multiprocessing.Pool(processes=self.params.worker_count)
        args = list(self._concurrency_slicer())

        workers.map(spawn_worker, args)
        workers.close()
        workers.join()
示例#3
0
def spawn_worker(params):
    """
    This method has to be module level function

    :type params: Params
    """
    setup_logging(params)
    log.info("Adding worker: idx=%s\tconcurrency=%s\tresults=%s",
             params.worker_index, params.concurrency, params.report)
    worker = Worker(params)
    worker.start()
    worker.join()
示例#4
0
def import_plugins():
    path = os.environ.get(PLUGINS_PATH, None)
    if not path:
        log.debug('Plugins PATH not found, continue without plugins')
        return

    # add plugins path to PYTHONPATH
    sys.path.append(path)

    package = Path(path).resolve().name
    log.info(f'Plugins package {package}')

    #  modules listing in the root package
    for (_, module_name, _) in iter_modules([path]):
        log.info(f'Importing module {module_name}')
        import_module(module_name)
示例#5
0
 def close(self):
     log.info("Workers finished, awaiting result writer")
     while not store.writer.is_queue_empty() and store.writer.is_alive():
         time.sleep(0.1)
     log.info("Results written, shutting down")
     super(Worker, self).close()
示例#6
0
    def run_nose(self, params):
        """
        :type params: Params
        """
        if not params.tests:
            raise RuntimeError("Nothing to test.")

        thread.set_index(params.thread_index)
        log.debug("[%s] Starting nose2 iterations: %s", params.worker_index,
                  params)
        assert isinstance(params.tests, list)
        # argv.extend(['--with-apiritif', '--nocapture', '--exe', '--nologcapture'])

        end_time = self.params.ramp_up + self.params.hold_for
        end_time += time.time() if end_time else 0
        time.sleep(params.delay)
        store.writer.concurrency += 1

        config = {"tests": params.tests}
        if params.verbose:
            config["verbosity"] = 3

        iteration = 0
        handlers = ActionHandlerFactory.create_all()
        log.debug(f'Action handlers created {handlers}')
        thread.put_into_thread_store(action_handlers=handlers)
        for handler in handlers:
            handler.startup()
        try:
            while not graceful():
                log.debug("Starting iteration:: index=%d,start_time=%.3f",
                          iteration, time.time())
                thread.set_iteration(iteration)

                session = ApiritifSession()
                config["session"] = session
                ApiritifTestProgram(config=config)

                log.debug("Finishing iteration:: index=%d,end_time=%.3f",
                          iteration, time.time())
                iteration += 1

                # reasons to stop
                if session.stop_reason:
                    if "Nothing to test." in session.stop_reason:
                        raise RuntimeError("Nothing to test.")
                    elif session.stop_reason.startswith(
                            NormalShutdown.__name__):
                        log.info(session.stop_reason)
                    else:
                        raise RuntimeError(
                            f"Unknown stop_reason: {session.stop_reason}")
                elif 0 < params.iterations <= iteration:
                    log.debug("[%s] iteration limit reached: %s",
                              params.worker_index, params.iterations)
                elif 0 < end_time <= time.time():
                    log.debug("[%s] duration limit reached: %s",
                              params.worker_index, params.hold_for)
                else:
                    continue  # continue if no one is faced

                break

        finally:
            store.writer.concurrency -= 1

            for handler in handlers:
                handler.finalize()