How to use _send_workers_event method in Molotov

Best Python code snippet using molotov_python

runner.py

Source:runner.py Github

copy

Full Screen

...95 await self.console.stop()96 await self.eventer.stop()97 tasks = [98 self.ensure_future(self.console.display()),99 self.ensure_future(self._send_workers_event(1)),100 self.ensure_future(run(args.quiet, self.console)),101 ]102 self.loop.run_until_complete(self.gather(*tasks))103 else:104 self._process()105 return self._results106 def _shutdown(self, signal, frame):107 stop()108 self._kill_tasks()109 # send sigterms110 for proc in self._procs:111 proc.terminate()112 def _runner(self):113 args = self.args114 def _prepare():115 tasks = []116 delay = 0117 if args.ramp_up > 0.0:118 step = args.ramp_up / args.workers119 else:120 step = 0.0121 for i in range(self.args.workers):122 worker = Worker(123 i,124 self._results,125 self.console,126 self.args,127 self.statsd,128 delay,129 self.loop,130 )131 f = self.ensure_future(worker.run())132 tasks.append(f)133 delay += step134 return tasks135 if self.args.quiet:136 return _prepare()137 else:138 msg = "Preparing {} worker{}"139 msg = msg.format(args.workers, "s" if args.workers > 1 else "")140 return self.console.print_block(msg, _prepare)141 def _process(self):142 set_timer()143 # coroutine that will kill everything when duration is up144 if self.args.duration and self.args.force_shutdown:145 async def _duration_killer():146 cancelled = object()147 res = await cancellable_sleep(self.args.duration, result=cancelled)148 if res is cancelled or (res and not res.canceled()):149 self._shutdown(None, None)150 await asyncio.sleep(0)151 _duration_killer = self.ensure_future(_duration_killer())152 else:153 _duration_killer = None154 if self.args.processes > 1:155 signal.signal(signal.SIGINT, self._shutdown)156 signal.signal(signal.SIGTERM, self._shutdown)157 self.loop = asyncio.new_event_loop()158 asyncio.set_event_loop(self.loop)159 if self.args.debug:160 self.console.print("**** RUNNING IN DEBUG MODE == SLOW ****")161 self.loop.set_debug(True)162 self._set_statsd()163 if self.statsd is not None:164 self._tasks.append(self.ensure_future(self.statsd.connect()))165 if self.args.original_pid == os.getpid():166 self._tasks.append(self.ensure_future(self._send_workers_event(1)))167 if not self.args.quiet:168 fut = self._display_results(self.args.console_update)169 update = self.ensure_future(fut)170 display = self.ensure_future(self.console.display())171 display = self.gather(update, display)172 self._tasks.append(display)173 workers = self.gather(*self._runner())174 def _stop(cb):175 if _duration_killer is not None:176 if not _duration_killer.done():177 _duration_killer.cancel()178 stop()179 workers.add_done_callback(_stop)180 self._tasks.append(workers)181 try:182 self.loop.run_until_complete(self.gather(*self._tasks))183 finally:184 if self.statsd is not None:185 self.loop.run_until_complete(self.ensure_future(self.statsd.close()))186 self._kill_tasks()187 self.loop.close()188 def _kill_tasks(self):189 cancellable_sleep.cancel_all()190 for task in reversed(self._tasks):191 with suppress(asyncio.CancelledError):192 task.cancel()193 for task in self._tasks:194 del task195 self._tasks[:] = []196 def display_results(self):197 ok, fail = self._results["OK"].value, self._results["FAILED"].value198 workers = self._results["WORKER"].value199 pat = "SUCCESSES: %s | FAILURES: %s | WORKERS: %s"200 return pat % (ok, fail, workers)201 async def _display_results(self, update_interval):202 while not is_stopped():203 self.console.print(self.display_results(), end="\r")204 await cancellable_sleep(update_interval)205 await self.console.stop()206 async def _send_workers_event(self, update_interval):207 while not self.eventer.stopped() and not is_stopped():208 workers = self._results["WORKER"].value209 await self.eventer.send_event("current_workers", workers=workers)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Molotov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful