Best Python code snippet using slash
test_parallel.py
Source:test_parallel.py  
...263        parallel_manager = ParallelManager([])264        parallel_manager.start_server_in_thread(runnables)265        time.sleep(0.1)266        with slash.assert_raises(ParallelTimeout) as caught:267            parallel_manager.wait_all_workers_to_connect()268        assert caught.exception.args[0] == 'Not all clients connected'269def test_worker_error_logs(parallel_suite, config_override):270    config_override("parallel.communication_timeout_secs", 2)271    parallel_suite[0].when_run.interrupt()272    summary = parallel_suite.run(num_workers=1, verify=False)273    [interrupted_result] = summary.get_all_results_for_test(parallel_suite[0])274    assert interrupted_result.is_interrupted()275    for result in summary.session.results:276        if result != interrupted_result:277            assert result.is_success() or result.is_not_run()278    file_path = os.path.join(summary.session.parallel_manager.workers_error_dircetory, 'errors-worker-1.log')279    assert os.path.isfile(file_path)280    with open(file_path) as error_file:281        line = error_file.readline()...parallel_manager.py
Source:parallel_manager.py  
...67        self.kill_workers()68        self.report_worker_error_logs()69        get_xmlrpc_proxy(config.root.parallel.server_addr, self.server.port).report_session_error(failure_message)70        raise ParallelTimeout(failure_message)71    def wait_all_workers_to_connect(self):72        while self.server.state == ServerStates.WAIT_FOR_CLIENTS:73            if time.time() - self.server.start_time > config.root.parallel.worker_connect_timeout * self.workers_num:74                self.handle_error("Timeout: Not all clients connected to server, terminating.\n\75                                   Clients connected: {}".format(self.server.connected_clients))76            time.sleep(TIME_BETWEEN_CHECKS)77    def check_worker_timed_out(self):78        workers_last_connection_time = self.keepalive_server.get_workers_last_connection_time()79        for worker_id in self.server.get_connected_clients():80            worker_last_connection_time = workers_last_connection_time.get(worker_id, None)81            if worker_last_connection_time is None: #worker keepalive thread didn't started yet82                continue83            if time.time() - worker_last_connection_time > config.root.parallel.communication_timeout_secs:84                _logger.error("Worker {} is down, terminating session", worker_id, extra={'capture': False})85                self.report_worker_error_logs()86                self.workers[worker_id].handle_timeout()87                get_xmlrpc_proxy(config.root.parallel.server_addr, self.server.port).report_client_failure(worker_id)88    def check_no_requests_timeout(self):89        if time.time() - self.keepalive_server.last_request_time > config.root.parallel.no_request_timeout:90            _logger.error("No request sent to server for {} seconds, terminating",91                          config.root.parallel.no_request_timeout, extra={'capture': False})92            if self.server.has_connected_clients():93                _logger.error("Clients that are still connected to server: {}",94                              self.server.connected_clients, extra={'capture': False})95            if self.server.has_more_tests():96                _logger.error("Number of unstarted tests: {}", len(self.server.get_unstarted_tests()),97                              extra={'capture': False})98            if self.server.executing_tests:99                _logger.error("Currently executed tests indexes: {}", self.server.executing_tests.values(),100                              extra={'capture': False})101            self.handle_error("No request sent to server for {} seconds, terminating".format(config.root.parallel.no_request_timeout))102    def start(self):103        self.try_connect()104        try:105            for worker in list(self.workers.values()):106                worker.start()107            self.wait_all_workers_to_connect()108            while self.server.should_wait_for_request():109                self.check_worker_timed_out()110                self.check_no_requests_timeout()111                time.sleep(TIME_BETWEEN_CHECKS)112        except INTERRUPTION_EXCEPTIONS:113            _logger.error("Server interrupted, stopping workers and terminating", extra={'capture': False})114            get_xmlrpc_proxy(config.root.parallel.server_addr, self.server.port).session_interrupted()115            self.kill_workers()116            raise117        finally:118            for worker in list(self.workers.values()):119                worker.wait_to_finish()120            get_xmlrpc_proxy(config.root.parallel.server_addr, self.server.port).stop_serve()121            get_xmlrpc_proxy(config.root.parallel.server_addr, self.keepalive_server.port).stop_serve()...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
