Share this page

# Example: lr_end_transaction_instance

In the following example,lr_start_transaction measures the time of a transaction that performs a withdrawal from a bank server. Once the server API call is completed and returns a value to the status variable, the transaction is complete. However, the test also wants to verify how long an unsuccessful withdrawal transaction will take if the customer is over the withdrawal limit. An instance of the transaction "withdraw" is created for this purpose. lr_end_transaction_instance marks the end of this transaction instance.

    long id;
    int status;

    /* Call to server API */
    int amount_overdrawn = get_amount_overdrawn();
    while (amount_overdrawn < LIMIT) {
    /* Notify that a transaction is starting */
        id = lr_start_transaction("withdraw");

    /* Call to server API */
        status = bank_withdraw(500);

    /* End transaction with operation result - pass or fail */
        if (status == 0)
            lr_end_transaction("withdraw", LR_PASS);
        else
            lr_end_transaction("withdraw", LR_FAIL);

        amount_overdrawn = get_amount_overdrawn();
    }
    /* The client is unable to withdraw anymore as the overdraft limit has been reached. Try to withdraw anyway to record the server response time */
        id = lr_start_transaction_instance("withdraw", 0);

    /* This call will fail, but we want to time it */
        status = bank_withdraw(500);
        lr_end_transaction_instance(id, LR_PASS);

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: