def _kill_tasks(self): cancellable_sleep.cancel_all() for task in reversed(self._tasks): with suppress(asyncio.CancelledError): task.cancel() for task in self._tasks: del task self._tasks[:] = []
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)
async def _run(self): verbose = self.args.verbose exception = self.args.exception if self.args.single_mode: single = get_scenario(self.args.single_mode) else: single = None self.count = 1 self.worker_start = _now() setup = get_fixture('setup') if setup is not None: try: options = await setup(self.wid, self.args) except Exception as e: self.console.print_error(e) stop() return if options is None: options = {} elif not isinstance(options, dict): self.console.print('The setup function needs to return a dict') stop() return else: options = {} ssetup = get_fixture('setup_session') steardown = get_fixture('teardown_session') async with Session(self.loop, self.console, verbose, self.statsd, **options) as session: session.args = self.args session.worker_id = self.wid if ssetup is not None: try: await ssetup(self.wid, session) except Exception as e: self.console.print_error(e) stop() return while self._may_run(): step_start = _now() 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 == -1: self.results['FAILED'] += 1 self.results['MINUTE_FAILED'] += 1 if exception: stop() if not is_stopped() and self._reached_tolerance(step_start): stop() cancellable_sleep.cancel_all() break self.count += 1 if self.args.delay > 0.: await cancellable_sleep(self.args.delay) else: # forces a context switch await asyncio.sleep(0) if steardown is not None: try: await steardown(self.wid, session) except Exception as e: # we can't stop the teardown process self.console.print_error(e)