Пример #1
0
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)
Пример #2
0
def threaded_call(step, apiCall, node):
    logger.info("Creating thread for {}".format(apiCall))
    world.config['apiCall'] = apiCall
    world.config['nodeId'] = node
    arg_list = step.hashes

    options = {}
    api_utils.prepare_options(arg_list, options)
    api = api_utils.prepare_api_call(node)

    def make_call(node, arg_list):
        response = api_utils.fetch_call(apiCall, arg_list['api'],
                                        arg_list['options'])
        arg_list['responses'][apiCall] = {}
        arg_list['responses'][apiCall][node] = response
        return response

    args = {
        node: {
            'api': api,
            'options': options,
            'responses': world.responses
        }
    }
    future_results = pool.start_pool(make_call, 1, args)

    if 'future_results' not in world.config:
        world.config['future_results'] = {}
    world.config['future_results'][apiCall] = future_results
Пример #3
0
def spam_call(step, api_call, num_tests, node):
    """
    Spams an API call a number of times among the specified nodes in a cluster

    :param api_call: The API call you would like to make
    :param num_tests: The number of iterations you would like to run
    :param node: The node that the call will be sent to. This can be set to 'all nodes' and it will run the test
                 on all the available nodes.
    :param step.hashes: A gherkin table present in the feature file specifying the
                        arguments and the associated type.
    """
    start = time()
    world.config['apiCall'] = api_call
    arg_list = step.hashes
    nodes = {}
    response_val = []

    options = {}
    api_utils.prepare_options(arg_list, options)

    # See if call will be made on one node or all
    api_utils.assign_nodes(node, nodes)
    call_node = world.config['nodeId']

    def run_call(node, args):
        logger.debug('Running Thread on {}'.format(node))
        api = args['api']
        options = args['options']
        response = api_utils.fetch_call(api_call, api, options)
        return response

    for current_node in nodes:
        nodes[current_node]['options'] = options

    future_results = pool.start_pool(run_call, num_tests, nodes)

    responses.fetch_future_results(future_results, num_tests, response_val)

    world.responses[api_call] = {}
    world.responses[api_call][call_node] = response_val

    end = time()
    time_spent = end - start
    logger.info('Time spent on loop: {}'.format(time_spent))
Пример #4
0
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))
def threaded_call(step, api_call, node):
    """
    Makes an asynchronous API call on the specified node and stores the future result reference in the
    world.config variable.

    :param api_call: The API call you would like to make.
    :param node: The identifier for the node you would like to run the call on.
    :param step.hashes: A gherkin table present in the feature file specifying the
                        arguments and the associated type.
    """
    logger.info("Creating thread for {}".format(api_call))
    world.config['apiCall'] = api_call
    world.config['nodeId'] = node
    arg_list = step.hashes

    options = {}
    api_utils.prepare_options(arg_list, options)
    api = api_utils.prepare_api_call(node)

    def make_call(node, arg_list):
        response = api_utils.fetch_call(api_call, arg_list['api'],
                                        arg_list['options'])
        arg_list['responses'][api_call] = {}
        arg_list['responses'][api_call][node] = response
        return response

    args = {
        node: {
            'api': api,
            'options': options,
            'responses': world.responses
        }
    }
    future_results = pool.start_pool(make_call, 1, args)

    if 'future_results' not in world.config:
        world.config['future_results'] = {}
    world.config['future_results'][api_call] = future_results