Ejemplo n.º 1
0
    async def _run(self):
        verbose = self.args.verbose
        exception = self.args.exception

        if self.args.single_mode:
            single = get_scenario(self.args.single_mode)
        elif self.args.single_run:
            single = next_scenario()
        else:
            single = None

        self.count = 1
        self.worker_start = _now()

        try:
            options = await self.setup()
        except FixtureError as e:
            self.results["SETUP_FAILED"] += 1
            stop(why=e)
            return

        async with get_session(self.loop, self.console, verbose, self.statsd,
                               **options) as session:
            get_context(session).args = self.args
            get_context(session).worker_id = self.wid
            try:
                await self.session_setup(session)
            except FixtureError as e:
                self.results["SESSION_SETUP_FAILED"] += 1
                stop(why=e)
                return

            while self._may_run():
                step_start = _now()
                get_context(session).step = self.count
                result = await self.step(self.count, session, scenario=single)
                if result == 1:
                    self.results["OK"] += 1
                    self.results["MINUTE_OK"] += 1
                elif result != 0:
                    self.results["FAILED"] += 1
                    self.results["MINUTE_FAILED"] += 1
                    if exception:
                        stop(why=result)

                if not is_stopped() and self._reached_tolerance(step_start):
                    stop()
                    cancellable_sleep.cancel_all()
                    break

                self.count += 1
                if self.args.delay > 0.0:
                    await cancellable_sleep(self.args.delay)
                else:
                    # forces a context switch
                    await asyncio.sleep(0)

            await self.session_teardown(session)
Ejemplo n.º 2
0
            async def sizer(session):
                if get_context(
                        session).worker_id == 200 and not _RES2["messed"]:
                    # worker 2 will mess with the timer
                    # since we're faking all timers, the current
                    # time in the test is always around 0
                    # so to have now() - get_timer() > 60
                    # we need to set a negative value here
                    # to trick it
                    set_timer(-61)
                    _RES2["messed"] = True
                    _RES2["fail"] = _RES2["succ"] = 0

                if get_context(session).worker_id > 100:
                    # starting to introduce errors passed the 100th
                    if random.randint(0, 10) == 1:
                        _RES2["fail"] += 1
                        raise AssertionError()
                    else:
                        _RES2["succ"] += 1

                # forces a switch
                await asyncio.sleep(0)
Ejemplo n.º 3
0
 async def here_two(session):
     if get_context(session).statsd is not None:
         get_context(session).statsd.increment("yopla")
     _RES.append(2)
Ejemplo n.º 4
0
 async def staty(session):
     get_context(session).statsd.increment("yopla")