Best Python code snippet using slash
server.py
Source:server.py
...99 with _get_test_context(self.tests[test_index], logging=False):100 pass101 self.finished_tests.append(test_index)102 self._tests_distrubuter.clear_unstarted_tests()103 def _get_worker_session_id(self, client_id):104 return "worker_{}".format(client_id)105 def connect(self, client_id, client_pid):106 _logger.notice("Client_id {} connected", client_id)107 self.connected_clients.add(client_id)108 client_session_id = '{}_{}'.format(context.session.id.split('_')[0], client_id)109 context.session.logging.create_worker_symlink(self._get_worker_session_id(client_id), client_session_id)110 hooks.worker_connected(session_id=client_session_id) # pylint: disable=no-member111 self.worker_session_ids.append(client_session_id)112 self.worker_to_pid[client_id] = client_pid113 self.executing_tests[client_id] = None114 if len(self.connected_clients) >= config.root.parallel.num_workers:115 _logger.notice("All workers connected to server")116 self.state = ServerStates.WAIT_FOR_COLLECTION_VALIDATION117 def validate_collection(self, client_id, sorted_client_collection):118 if not self._sorted_collection == sorted_client_collection:119 _logger.error("Client_id {} sent wrong collection", client_id, extra={'capture': False})120 return False121 self.num_collections_validated += 1122 _logger.debug("Worker {} validated tests successfully", client_id)123 if self.num_collections_validated >= config.root.parallel.num_workers and self.state == ServerStates.WAIT_FOR_COLLECTION_VALIDATION:124 _logger.notice("All workers collected tests successfully, start serving tests")125 self.state = ServerStates.SERVE_TESTS126 return True127 def disconnect(self, client_id, has_failure=False):128 _logger.notice("Client {} sent disconnect", client_id)129 self.connected_clients.remove(client_id)130 if has_failure:131 self.state = ServerStates.STOP_TESTS_SERVING132 def get_test(self, client_id):133 if not self.executing_tests[client_id] is None:134 _logger.error("Client_id {} requested new test without sending former result", client_id,135 extra={'capture': False})136 return PROTOCOL_ERROR137 if self.state == ServerStates.STOP_TESTS_SERVING:138 return NO_MORE_TESTS139 elif self.state in [ServerStates.WAIT_FOR_CLIENTS, ServerStates.WAIT_FOR_COLLECTION_VALIDATION]:140 return WAITING_FOR_CLIENTS141 elif self.state == ServerStates.SERVE_TESTS and self._tests_distrubuter.has_unstarted_tests():142 test_index = self._tests_distrubuter.get_next_test_for_client(client_id)143 if test_index is None: #we have omre tests but current worker cannot execute them144 return NO_MORE_TESTS145 test = self.tests[test_index]146 self.executing_tests[client_id] = test_index147 hooks.test_distributed(test_logical_id=test.__slash__.id, worker_session_id=self._get_worker_session_id(client_id)) # pylint: disable=no-member148 _logger.notice("#{}: {}, Client_id: {}", test_index + 1, test.__slash__.address, client_id,149 extra={'highlight': True, 'filter_bypass': True})150 return (self.collection[test_index], test_index)151 else:152 _logger.debug("No unstarted tests, sending end to client_id {}", client_id)153 self.state = ServerStates.STOP_TESTS_SERVING154 return NO_MORE_TESTS155 def finished_test(self, client_id, result_dict):156 _logger.debug("Client_id {} finished_test", client_id)157 test_index = self.executing_tests.get(client_id, None)158 if test_index is not None:159 self.finished_tests.append(test_index)160 self.executing_tests[client_id] = None161 with _get_test_context(self.tests[test_index], logging=False) as (result, _):...
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!!