Exemplo n.º 1
0
    def __exit__(self, exc_type, exc_val, exc_tb):
        super(smart_transaction, self).__exit__(exc_type, exc_val, exc_tb)
        self.controller.stopTest(is_transaction=True)
        message = ''

        if exc_type:
            message = str(exc_val)
            exc = exc_type, exc_val, exc_tb
            if isinstance(exc_val, AssertionError):
                status = 'failed'
                self.controller.addFailure(exc, is_transaction=True)
            else:
                status = 'broken'
                tb = get_trace(exc)
                self.controller.addError(exc_type.__name__,
                                         message,
                                         tb,
                                         is_transaction=True)

        else:
            status = 'success'
            self.controller.addSuccess(is_transaction=True)

        put_into_thread_store(status=status, message=message)
        for func in apiritif.get_transaction_handlers()["exit"]:
            func(status, message
                 )  # params for compatibility, remove if bzt > 1.4.1 in cloud

        self.controller.afterTest(is_transaction=True)

        return not self.func_mode  # don't reraise in load mode
Exemplo n.º 2
0
    def __enter__(self):
        self.controller.set_start_time()

        super(smart_transaction, self).__enter__()
        put_into_thread_store(test_case=self.name, test_suite=self.test_suite)
        for func in apiritif.get_transaction_handlers()["enter"]:
            func()
Exemplo n.º 3
0
    def __enter__(self):
        super(smart_transaction, self).__enter__()
        put_into_thread_store(test_case=self.name, test_suite=self.test_suite)
        for func in apiritif.get_transaction_handlers()["enter"]:
            func(self.name, self.test_suite
                 )  # params for compatibility, remove if bzt > 1.4.1 in cloud

        self.controller.startTest()
Exemplo n.º 4
0
    def __exit__(self, exc_type, exc_val, exc_tb):
        super(smart_transaction, self).__exit__(exc_type, exc_val, exc_tb)

        message = ''

        if exc_type:
            message = str(exc_val)
            exc = exc_type, exc_val, exc_tb
            if isinstance(exc_val, AssertionError):
                status = 'failed'
                self.controller.addFailure(exc, is_transaction=True)
            else:
                status = 'broken'
                tb = get_trace(exc)
                self.controller.addError(exc_type.__name__,
                                         message,
                                         tb,
                                         is_transaction=True)

        else:
            status = 'success'
            self.controller.addSuccess(is_transaction=True)

        put_into_thread_store(status=status, message=message)
        for func in apiritif.get_transaction_handlers()["exit"]:
            func()

        self.controller.stopTest(is_transaction=True)

        stage = apiritif.get_stage()
        if stage == "teardown":
            self.func_mode = False
        elif graceful():  # and stage in ("setup", "main")
            raise NormalShutdown("graceful!")

        return not self.func_mode  # don't reraise in load mode
Exemplo n.º 5
0
 def mock_set_handlers(handlers):
     log_line("set: {pid: %s, idx: %s, iteration: %s, handlers: %s}," %
              (os.getpid(), thread.get_index(), thread.get_iteration(),
               handlers))
     thread.put_into_thread_store(transaction_handlers=handlers)
Exemplo n.º 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()