def reference_stitch_transaction(step): node = world.config['nodeId'] stitch = world.responses['previousTransaction'][node] referencing_address = static.REFERENCING_ADDRESS api = api_utils.prepare_api_call(node) transaction_bundle = transactions.create_transaction_bundle(referencing_address, 'REFERENCE9TAG', 0) def transactions_to_approve(node, arg_list): response = api_utils.fetch_call('getTransactionsToApprove', arg_list['api'], {'depth': 3}) arg_list['responses']['getTransactionsToApprove'][node] = response return response gtta_results = pool.start_pool(transactions_to_approve, 1, {node: {'api': api, 'responses': world.responses}}) branch = pool.fetch_results(gtta_results[0], 30) options = {'trunk': stitch, 'branch': branch, 'trytes': transaction_bundle.as_tryte_strings(), 'min_weight_magnitude': 9} def make_transaction(node, arg_list): response = transactions.attach_store_and_broadcast(arg_list['api'], options) arg_list['responses']['attachToTangle'][node] = response return response transaction_results = pool.start_pool(make_transaction, 1, {node: {'api': api, 'responses': world.responses}}) pool.fetch_results(transaction_results[0], 30)
def compare_thread_return(step, api_call): """ Prepare response list for comparison. :param api_call: The API call you would like to find a response for :param step.hashes: A gherkin table present in the feature file specifying the values and the associated type to be found in the response. """ logger.debug(world.responses) future_results = world.config['future_results'][api_call] for result in future_results: response_list = pool.fetch_results(result, 5) # Exclude duration from response list if 'duration' in response_list: del response_list['duration'] if 'info' in response_list: del response_list['info'] response_keys = response_list.keys() expected_values = {} api_utils.prepare_options(step.hashes, expected_values) keys = expected_values.keys() # Confirm that the lists are of equal length before comparing assert len(keys) == len(response_keys), \ 'Response: {} does not contain the same number of arguments: {}'.format(keys, response_keys) for count in range(len(keys)): response_key = response_keys[count] response_value = response_list[response_key] expected_value = expected_values[response_key] assert response_value == expected_value, \ 'Returned: {} does not match the expected value: {}'.format(response_value, expected_value)
def compare_thread_return(step, apiCall): """Prepare response list for comparison""" logger.debug(world.responses) future_results = world.config['future_results'][apiCall] for result in future_results: response_list = pool.fetch_results(result, 1) # Exclude duration from response list if 'duration' in response_list: del response_list['duration'] response_keys = response_list.keys() expected_values = {} api_utils.prepare_options(step.hashes, expected_values) keys = expected_values.keys() # Confirm that the lists are of equal length before comparing assert len(keys) == len( response_keys ), 'Response: {} does not contain the same number of arguments: {}'.format( keys, response_keys) for count in range(len(keys)): response_key = response_keys[count] response_value = response_list[response_key] expected_value = expected_values[response_key] assert response_value == expected_value, \ 'Returned: {} does not match the expected value: {}'.format(response_value,expected_value) logger.info('Responses match')
def fetch_future_results(future_results, num_tests, response_vals): """ Fetches the results of a given set of future reference points and stores them in the provided list. :param future_results: The list containing the future_result references for response fetching. :param num_tests: The maximum number of tests. :param response_vals: The list to place the response values in. """ instance = 0 for result in future_results: instance += 1 if instance % 25 == 0: logger.info('Fetching result: {}/{}'.format(instance, num_tests)) response = pool.fetch_results(result, 30) response_vals.append(response)
def spam_call_gtta(step, numTests): """Spams getTransactionsToApprove calls a number of times among available nodes in a cluster""" start = time() node = next(iter(world.machine['nodes'])) apiCall = 'getTransactionsToApprove' world.config['nodeId'] = node world.config['apiCall'] = apiCall nodes = {} for current_node in world.machine['nodes']: api = api_utils.prepare_api_call(current_node) nodes[current_node] = api def run_call(node, api): logger.debug('Running Thread on {}'.format(node)) response = api.get_transactions_to_approve(depth=3) return response logging.info('Calls being made to %s', node) responseVal = [] args = (nodes) future_results = pool.start_pool(run_call, numTests, args) i = 0 for result in future_results: i += 1 if i % 25 == 0: logger.info('Fetching result: {}/{}'.format(i, numTests)) response = pool.fetch_results(result, 30) responseVal.append(response) logger.info(len(responseVal)) world.responses[apiCall] = {} world.responses[apiCall][node] = responseVal end = time() time_spent = end - start logger.info('Time spent on loop: {}'.format(time_spent))