Load Testing Asynchronous requests with LoadRunner

In this blog article, we will see about load testing asynchronous requests with LoadRunner. Nowadays web applications built with blend of synchronous and asynchronous nature. e.g. user can read sports column along with cricket score update in the same website.

What is synchronous request?

User will trigger the HTTP requests manually, in turn server will provide response. E.g. launching www.QAInsights.com, my server will respond to the request. User will be initiating the requests manually.

What is asynchronous request?

Assume you are browsing ICICIDirect.com, while checking your portfolio, stock price ticker automatically gets updated. Application (website) will be initiating the requests automatically at regular intervals. Below are the three types of asynchronous communication patterns:

1. Polling

2. Long Polling

3. Push

[sociallocker][/sociallocker]

Polling: The browser will be sending HTTP requests at a regular intervals. The web server will respond for the HTTP requests.

Long Polling: The browser generate HTTP requests whenever server has an update, it will process the HTTP request and responds.

Push: Browser send HTTP requests to the server; server process the requests and responds to never end. Browser will not close the connection. Whenever server has an update, it will send a ‘sub message’. During the connection, server sends ping message to the client to prevent the connection.

How HP LoadRunner handles asynchronous communication?

Before recording such web applications, we need to enable Async Scan. To enable async scan in HP LoadRunner, go to Recording Options, under General folder, click on Code Generation as shown below.

[auto_thumb width=”150″ height=”150″ link=”” lightbox=”true” align=”center” title=”Load Testing Asynchronous Business Process with HP LoadRunner – Recording Options – QAInsights” alt=”Load Testing Asynchronous Business Process with HP LoadRunner – Recording Options – QAInsights” iframe=”false” frame=”true” crop=”true”]http://qainsights.com/wp-content/uploads/2013/05/Load-Testing-Asynchronous-Business-Process-with-HP-LoadRunner-Recording-Options-QAInsights.gif[/auto_thumb]

Check Enable Async Scan check box as shown above. To view/edit async scan options, click on Async Options…

[auto_thumb width=”150″ height=”150″ link=”” lightbox=”true” align=”center” title=”Load Testing Asynchronous Business Process with HP LoadRunner – Async Options – QAInsights” alt=”Load Testing Asynchronous Business Process with HP LoadRunner – Async Options – QAInsights” iframe=”false” frame=”true” crop=”true”]http://qainsights.com/wp-content/uploads/2013/05/Load-Testing-Asynchronous-Business-Process-with-HP-LoadRunner-Async-Options-QAInsights.gif[/auto_thumb]

Below is the recorded script which has async calls can be viewed in Design studio.

[auto_thumb width=”150″ height=”150″ link=”” lightbox=”true” align=”center” title=”Load Testing Asynchronous Business Process with HP LoadRunner – Async Calls – QAInsights” alt=”Load Testing Asynchronous Business Process with HP LoadRunner – Async Calls – QAInsights” iframe=”false” frame=”true” crop=”true”]http://qainsights.com/wp-content/uploads/2013/05/Load-Testing-Asynchronous-Business-Process-with-HP-LoadRunner-Async-Calls-QAInsights.gif[/auto_thumb]

LoadRunner will add the following headers in the global header file. For asynchronous calls, you could see AsyncCallbacks.c header file.

#ifndef _GLOBALS_H
#define _GLOBALS_H
//--------------------------------------------------------------------
// Include Files
#include "lrun.h"
#include "web_api.h"
#include "lrw_custom_body.h"
#include "AsyncCallbacks.c"
//--------------------------------------------------------------------
// Global Variables
#endif // _GLOBALS_H

In the script you can see following comments and the async requests.

/* Added by Async CodeGen.
ID=Poll_0
ScanType = Recording
The following urls are considered part of this conversation:
http://yoururl.com
http://yoururl.com

TODO - The following callbacks have been added to AsyncCallbacks.c.
Add your code to the callback implementations as necessary.
   Poll_0_RequestCB
   Poll_0_ResponseBodyBufferCB
   Poll_0_ResponseCB
*/
    web_reg_async_attributes("ID=Poll_0",
       "URL=http://yoururl.com&ref=&url=yoururl.html",
       "Pattern=Poll",
       "PollIntervalMs=200",
       "RequestCB=Poll_0_RequestCB",
       "ResponseBodyBufferCB=Poll_0_ResponseBodyBufferCB",
       "ResponseCB=Poll_0_ResponseCB",
       LAST);

Each web_reg_async_attributes has an ID, which you can find in subsequent requests. Pattern indicates the type of async calls: Push, Poll, and Long Poll.

For push conversations, LoadRunner will not remove any steps in the code. But for Poll and Long Poll, LoadRunner removes steps which can be seen in commented sections as shown below.

/* Removed by Async CodeGen.
ID = Poll_0
*/
   /*
web_url("wDoxg1RBcO00Wm_2",
       "URL=yoururl.coml",
       "Resource=0",
       "RecContentType=text/xml",
       "Referer=",
       "Snapshot=t57.inf",
       "Mode=HTML",
       LAST);
   */

/* Removed by Async CodeGen.
ID = Poll_0
*/
   /*
web_url("wDoxg1RBcO00Wm_3",
       "URL=http://yoururl",
       "Resource=0",
       "RecContentType=text/xml",
       "Referer=",
       "Snapshot=t58.inf",
       "Mode=HTML",
       LAST);
   */

LoadRunner adds web_stop_async at the end of the conversation with the matching ID as shown below.

/* Added by Async CodeGen.
ID = Poll_0
*/
   web_stop_async("ID=Poll_0",
       LAST);

   web_url("wDoxg1RBcO00Wm_4",
       "URL=http://yoururl.com",
       "Resource=0",
       "RecContentType=text/xml",
       "Referer=",
       "Snapshot=t59.inf",
       "Mode=HTML",
       LAST);

Now we will see about remaining parameter in web_reg_sync_attributes such as RequestCB, ResponseBodyBufferCB  and ResponseCB. These three are called as callbacks.

  • RequestCB : this call back will be called before the request
  • ResponseBodyBufferCB: This callback is available for all patterns (push, poll and long poll). this callback is any content found in response body buffer.
  • ResponseCB: this callback will be called after each response is received.

Thanks for visiting QAInsights! Check out our new portal Testifications.com to get updates on Software Testing related certifications.

We’re always posting interesting articles on QAInsights. I request you to subscribe so you don’t miss out anything. Searching for QA Jobs Openings, check it at www.QAJobOpenings.com

Want to start a blog like this, please visit SpidyDomain to buy cheap web hosting and register domain.

Subscribe to our QAInsights YouTube Channel

Subscribe our free weekly newsletter or Google feeds

About the Author

1 thought on “Load Testing Asynchronous requests with LoadRunner”

  1. Nice article.
    I had to create the Asynchronous call/request manually and also copied samples for the CallBack functions.
    How can one retrieve the responses as per sample CallBack functions?
    E.G, this is my Action with the request

    Action()
    {
    web_reg_async_attributes(“ID=Push_0”,
    “URL=https://{pURL}”,
    “Pattern=Push”,
    “RequestCB=Push_0_RequestCB”,
    “ResponseHeadersCB=Push_0_ResponseHeadersCB”,
    “ResponseBodyBufferCB=Push_0_ResponseBodyBufferCB”,
    “ResponseCB=Push_0_ResponseCB”,
    LAST);

    web_custom_request(“Request”,
    “URL={pURL}”,
    “Method=GET”,
    “Resource=0”,
    “RecContentType=application/json”,
    “Referer=”,
    “Mode=HTTP”,
    LAST);

    web_stop_async(“ID=Push_0”,
    LAST);
    }

    This is the CallBack manually created/copied.
    CallBack()
    {
    intPush_0_RequestCB()
    {
    //enter your implementation for RequestCB() here

    //call web_util_request_set_url() here to modify request url:
    web_util_set_request_url(“{pURL}”);
    //call web_util_set_request_body() here to modify request body:
    // web_util_set_request_body(“”);
    lr_output_message(“>>> Push_0_RequestCB”);
    return WEB_ASYNC_CB_RC_OK;
    }

    intPush_0_ResponseHeadersCB(
    int aHttpStatusCode,
    constchar* aAccumulatedHeadersStr,
    int aAccumulatedHeadersLen)
    {
    //Enter your implementation for ResponseHeadersCB() here.

    // lr_output_message(“>>> Push_0_ResponseHeadersCB ” + aHttpStatusCode + ” / ”
    // + aAccumulatedHeadersStr.substr(0, 10) + ” / ”
    // + aAccumulatedHeadersLen);
    lr_output_message(“>>> Push_0_ResponseHeadersCB”);

    return WEB_ASYNC_CB_RC_OK;
    }
    intPush_0_ResponseBodyBufferCB(
    constchar* aLastBufferStr,
    int aLastBufferLen,
    constchar* aAccumulatedStr,
    int aHttpStatusCode)
    {
    //enter your implementation for ResponseBodyBufferCB() here
    // lr_output_message(“>>> Push_0_ResponseBodyBufferCB ” + aLastBufferStr.substr(0, 20)
    // + ” / ” + aLastBufferLen + ” / ” + aAccumulatedStr.substr(0, 20)
    // + ” / ” + aAccumulatedLen + ” / ” + aHttpStatusCode);

    return WEB_ASYNC_CB_RC_OK;
    }
    intPush_0_ResponseCB(
    constchar* aResponseHeadersStr,
    int aResponseHeadersLen,
    constchar* aResponseBodyStr,
    int aResponseBodyLen,
    int aHttpStatusCode)
    {
    //enter your implementation for ResponseCB() here

    // lr_output_message(“>>> Push_0_ResponseBodyBufferCB ” + aLastBufferStr.substr(0, 20)
    // + ” / ” + aLastBufferLen + ” / ” + aAccumulatedStr.substr(0, 20)
    // + ” / ” + aAccumulatedLen + ” / ” + aHttpStatusCode);
    return WEB_ASYNC_CB_RC_OK;
    }
    }

    The Callback is also references in the Globals
    #include “AsyncCB.c”
    #include “as_web.h”

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hamster - Launch JMeter Recent Test Plans SwiftlyDownload for free
+
Share via
Copy link