def run(self): """ Run the test. """ utils.print_header("Start {}...\n".format(self.get_kind_of_test())) if not self.options.log: utils.start_capture_console() self.start_time = time.time() if self.options.adding or self.options.getting \ and self.options.clients > 1: self.start_tester_in_thread() else: self.list_tester.append(self.create_tester()) utils.run_async_method(None, self.list_tester[-1].test) self.finish_time = time.time() utils.stop_capture_console() self.collect_result() with open(self.result_path, 'w') as result: self.write_result(result) self.write_result(sys.stdout) requests_sender.RequestsSender.close_log_file() utils.print_header("\nFinish {}\n".format(self.get_kind_of_test()))
async def test(self): """ The function execute testing steps. """ if not self.log: utils.start_capture_console() # 1. Create pool config. await self._create_pool_config() # 2. Open pool ledger await self._open_pool() # 3. Create My Wallet and Get Wallet Handle await self._create_wallet() await self._open_wallet() # 4 Create and sender DID await self._create_submitter_did() await self._test() await self._close_pool_and_wallet() utils.print_header("\n\t======== Finished ========") utils.stop_capture_console()
def submit_several_reqs_from_files(self, args, files, kind): """ Submit several request that stored in files. :param args: arguments to submit requests. :param files: return by request_builder.RequestBuilder.build_several_adding_req_to_files :param kind: kind of request. """ threads = list() utils.print_header('\n\tSubmitting {} requests...'.format(kind)) if not self.log: utils.start_capture_console() for file_name in files: temp_thread = threading.Thread(target=self.submit_reqs_in_thread, kwargs={ 'args': args, 'file': file_name, 'kind': kind }) temp_thread.start() threads.append(temp_thread) for thread in threads: thread.join() utils.stop_capture_console() utils.print_header('\n\tSubmitting requests complete')
async def build_several_getting_req_to_files(self, args, req_kind, number_of_file, data_files: list): """ Build several ADD request and write them to list of temporary files. :param args: contain all necessary arguments to build a request (pool_handle, wallet_handle, submitter_did) :param req_kind: kind of ADD request (schema, nym, attribute, claim). :param number_of_file: number of temporary file you want to store requests. Number of request will be divided equally among temp files. :param data_files: list file that store request information. :return: """ utils.print_header("\n\tBuilding several get {} requests..." .format(req_kind)) if not self.log: utils.start_capture_console() req_builder = RequestBuilder.get_getting_req_builder(req_kind) files = list() lst_opened_files = list() file_iter = 0 for data_file_path in data_files: with open(data_file_path, 'r') as data_file: for line in data_file: if str(line) == '\n': continue req = await req_builder(args, json.dumps(line)) if file_iter >= number_of_file: file_iter = 0 if file_iter >= len(lst_opened_files): file_name = utils.generate_random_string( suffix='_{}.txt'.format(str(time.time()))) temp_file = open(file_name, 'w') lst_opened_files.append(temp_file) files.append(file_name) print(req, file=lst_opened_files[file_iter]) file_iter += 1 for file in lst_opened_files: file.close() if not self.log: utils.stop_capture_console() utils.print_header("\n\tBuilding request complete") return files
async def build_several_adding_req_to_files(self, args: dict, req_kind, number_of_file, number_of_req): """ Build several ADD request and write them to list of temporary files. :param args: contain all necessary arguments to build a request (pool_handle, wallet_handle, submitter_did) :param req_kind: kind of ADD request (schema, nym, attribute, claim). :param number_of_file: number of temporary file you want to store requests. Number of request will be divided equally among temp files. :param number_of_req: total of requests you want to build. :return: list of temporary file name. """ utils.print_header("\n\tBuilding several {} requests..." .format(req_kind)) if not self.log: utils.start_capture_console() works = RequestBuilder.divide(number_of_file, number_of_req) req_builder = RequestBuilder.get_adding_req_builder(req_kind) files = list() print(self.req_info_file_path) req_info_file = open(self.req_info_file_path, "w") for work in works: file_name = utils.generate_random_string( suffix='_{}.txt'.format(str(time.time()))) file_name = os.path.join(self.path, file_name) temp_file = open(file_name, "w") utils.print_ok_green(str(work)) for i in range(work): req = await req_builder(args) print(req[1], file=req_info_file) print(req[0], file=temp_file) temp_file.close() files.append(file_name) req_info_file.close() if not self.log: utils.stop_capture_console() utils.print_header("\n\tBuilding request complete") return files