def runner(args, screen=None): global_setup = get_fixture('global_setup') if global_setup is not None: global_setup(args) try: return _launch_processes(args, screen) finally: global_teardown = get_fixture('global_teardown') if global_teardown is not None: global_teardown()
async def done(self): teardown = get_fixture('teardown') if teardown is not None: try: teardown(self.wid) except Exception as e: # we can't stop the teardown process self.console.print_error(e)
def _worker_done(num, console, future): teardown = get_fixture('teardown') if teardown is not None: try: teardown(num) except Exception as e: # we can't stop the teardown process console.print_error(e)
def _worker_done(num, future): teardown = get_fixture('teardown') if teardown is not None: try: teardown(num) except Exception as e: # we can't stop the teardown process log(e)
def __init__(self, wid, results, console, args, statsd=None, delay=0, loop=None): self.wid = wid self.results = results self.console = console self.loop = loop or asyncio.get_event_loop() self.args = args self.statsd = statsd self.delay = delay self.count = 0 self.worker_start = 0 self.eventer = EventSender(console) # fixtures self._session_setup = get_fixture('setup_session') self._session_teardown = get_fixture('teardown_session') self._setup = get_fixture('setup') self._teardown = get_fixture('teardown')
def runner(args, screen=None): global_setup = get_fixture('global_setup') if global_setup is not None: try: global_setup(args) except Exception: log("The global_setup() fixture failed") raise try: return _launch_processes(args, screen) finally: global_teardown = get_fixture('global_teardown') if global_teardown is not None: try: global_teardown() except Exception as e: # we can't stop the teardown process log(e)
def runner(args): global_setup = get_fixture('global_setup') if global_setup is not None: try: global_setup(args) except Exception as e: args.shared_console.print("The global_setup() fixture failed") args.shared_console.print_error(e) raise try: return _launch_processes(args) finally: global_teardown = get_fixture('global_teardown') if global_teardown is not None: try: global_teardown() except Exception as e: # we can't stop the teardown process args.shared_console.print_error(e)
def __call__(self): global_setup = get_fixture("global_setup") if global_setup is not None: try: global_setup(self.args) except Exception as e: self.console.print("The global_setup() fixture failed") self.console.print_error(e) raise try: return self._launch_processes() finally: global_teardown = get_fixture("global_teardown") if global_teardown is not None: try: global_teardown() except Exception as e: # we can't stop the teardown process self.console.print_error(e)
def __init__(self, console, listeners=None): self.console = console if listeners is None: listeners = [] self._listeners = listeners self._stopped = False fixture_listeners = get_fixture("events") if fixture_listeners is not None: for listener in fixture_listeners: self.add_listener(CustomListener(listener))
def __init__(self, console, listeners=None): self.console = console if listeners is None: listeners = [] self._listeners = listeners self._stopped = False fixture_listeners = get_fixture('events') if fixture_listeners is not None: for listener in fixture_listeners: self.add_listener(CustomListener(listener))
def __call__(self): global_setup = get_fixture('global_setup') if global_setup is not None: try: global_setup(self.args) except Exception as e: self.console.print("The global_setup() fixture failed") self.console.print_error(e) raise try: return self._launch_processes() finally: global_teardown = get_fixture('global_teardown') if global_teardown is not None: try: global_teardown() except Exception as e: # we can't stop the teardown process self.console.print_error(e)
def __call__(self): global_setup = get_fixture("global_setup") if global_setup is not None: try: global_setup(self.args) except Exception as e: self.console.print("The global_setup() fixture failed") self.console.print_error(e) raise try: return self._launch_processes() finally: global_teardown = get_fixture("global_teardown") if global_teardown is not None: try: ok, fail = self._results["OK"].value, self._results[ "FAILED"].value workers = self._results["WORKER"].value global_teardown(dict(ok=ok, fail=fail, workers=workers)) except Exception as e: # we can't stop the teardown process self.console.print_error(e)
async def worker(num, loop, results, args, stream, statsd): global _STOP quiet = args.quiet duration = args.duration verbose = args.verbose exception = args.exception count = 1 start = _now() howlong = 0 setup = get_fixture('setup') if setup is not None: try: options = await setup(num, args) except Exception as e: log(e) await stream.put('WORKER_STOPPED') return if options is None: options = {} elif not isinstance(options, dict): log('The setup function needs to return a dict') await stream.put('WORKER_STOPPED') return else: options = {} async with Session(loop, stream, verbose, statsd, **options) as session: while howlong < duration and not _STOP: howlong = _now() - start result = await step(session, quiet, verbose, stream) if result == 1: results['OK'] += 1 elif result == -1: results['FAILED'] += 1 if exception: await stream.put('WORKER_STOPPED') _STOP = True elif result == 0: break count += 1 if not _STOP: await stream.put('WORKER_STOPPED')
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)
async def _worker(num, loop, args, statsd, delay): global _STOP quiet = args.quiet duration = args.duration verbose = args.verbose exception = args.exception console = args.shared_console if args.single_mode: single = get_scenario(args.single_mode) else: single = None count = 1 start = _now() howlong = 0 setup = get_fixture('setup') if setup is not None: try: options = await setup(num, args) except Exception as e: console.print_error(e) return if options is None: options = {} elif not isinstance(options, dict): console.print('The setup function needs to return a dict') return else: options = {} ssetup = get_fixture('setup_session') steardown = get_fixture('teardown_session') async with Session(loop, console, verbose, statsd, **options) as session: session.args = args session.worker_id = num if ssetup is not None: await ssetup(num, session) while (howlong < duration and not _STOP and not _RESULTS['REACHED'] == 1): if args.max_runs and count > args.max_runs: break current_time = _now() howlong = current_time - start session.step = count result = await step(num, count, session, quiet, verbose, console, single) if result == 1: _RESULTS['OK'] += 1 _RESULTS['MINUTE_OK'] += 1 elif result == -1: _RESULTS['FAILED'] += 1 _RESULTS['MINUTE_FAILED'] += 1 if exception: _STOP = True elif result == 0: break if _reached_tolerance(current_time, args): _STOP = True os.kill(os.getpid(), signal.SIGINT) count += 1 if args.delay > 0.: await asyncio.sleep(args.delay) else: # forces a context switch await asyncio.sleep(0) if steardown is not None: try: await steardown(num, session) except Exception as e: # we can't stop the teardown process console.print_error(e)
async def worker(num, loop, results, args, stream, statsd): global _STOP quiet = args.quiet duration = args.duration verbose = args.verbose exception = args.exception if args.single_mode: single = get_scenario(args.single_mode) else: single = None count = 1 start = _now() howlong = 0 setup = get_fixture('setup') if setup is not None: try: options = await setup(num, args) except Exception as e: log(e) await stream.put('WORKER_STOPPED') return if options is None: options = {} elif not isinstance(options, dict): log('The setup function needs to return a dict') await stream.put('WORKER_STOPPED') return else: options = {} ssetup = get_fixture('setup_session') steardown = get_fixture('teardown_session') async with Session(loop, stream, verbose, statsd, **options) as session: session.args = args session.worker_id = num if ssetup is not None: await ssetup(num, session) while howlong < duration and not _STOP: if args.max_runs and count > args.max_runs: break howlong = _now() - start session.step = count result = await step(session, quiet, verbose, stream, single) if result == 1: results['OK'] += 1 elif result == -1: results['FAILED'] += 1 if exception: await stream.put('WORKER_STOPPED') _STOP = True elif result == 0: break count += 1 if steardown is not None: try: await steardown(num, session) except Exception as e: # we can't stop the teardown process log(e) if not _STOP: await stream.put('WORKER_STOPPED')