Asynchronous example - long-poll

For a list of protocols that support asynchronous communication, see 64-bit recording, Async, and IPv6 support.

The following example describes a Vuser script that emulates an application that implements a long-poll asynchronous conversation. The application is a demo of a “chat” page. A browser shows the chat page, and sends a request that remains open until a new message is sent to the chat by another user. After such a message is sent:

  • The response is finished.
  • The new message is shown in the browser.
  • The browser sends another request in order to listen for the next message sent to the chat.

Async request sequence

Note: You can modify VuGen's asynchronous request thresholds to assist VuGen in finding long-poll type conversations. For details, see Using asynchronous request thresholds.

The following is the Vuser script that VuGen generated after recording the application - before an asynchronous scan was performed. The script contains a series of web_url functions with similar URLs. Since new requests are sent as soon as the previous response is finished, no lr_think_time functions are added between the web_url functions. This help to indicate that this is a long-poll conversation and not a poll conversation.

When the Vuser script runs, requests to the chat application should be sent repeatedly every time a response from the chat application is finished. In addition, requests should be sent in parallel (simultaneously) with other actions performed in the script.

After VuGen performs an asynchronous scan on the script, the modified script looks as follows:

Copy code
/* Added by Async CodeGen.
ID=LongPol1_0
ScanType = Recording

The following urls are considered part of this conversation:
    http://example.com/request.aahx?key=111111-1111-1111-1111-111111token=12348858&message=%5B%
    http://example.com/request.aahx?key=111111-1111-1111-1111-111111token=12348858&message=%5B%
    http://example.com/request.aahx?key=111111-1111-1111-1111-111111token=12348858&message=%5B%
    http://example.com/request.aahx?key=111111-1111-1111-1111-111111token=12348858&message=%5B%

TODO - The following callbacks have been added to AsyncCallbacks.c.
Add your code to the callback implementations as necessary.
    LongPol1_0_RequestC0
    LongPol1_0_ResponseC0
*/
    web_reg_async_attributes("ID=LongPol1_0",
    "URL=http://example.com/request.aahx?key=111111-1111-1111-111111token=12348858&message=%5B%
    "Pattern=LongPol1",
    "RequestC0=LongPol1_0_RequestC0",
    "ResponseC0=LongPol1_0_ResponseC0",
    LAST);
    web_url("request.aahx_3",
    "URL=http://example.com/request.aahx?key=111111-1111-1111-111111token=12348858&message=%5B%
    "Resource=",
    "RecContentType=text/html",
    "Referer=",
    "Snapshot=%4.inf",
    "Mode=HTML",
    LAST);
 
 /* Removed by Async CodeGen.
    ID = LongPol1_0
    */
    /* http://example.com/request.aahx?key=111111-1111-1111-111111token=12348858&message=%5B%
    web_url("request.aahx_4",
    "URL=http://example.com/request.aahx?key=111111-1111-1111-111111token=12348858&message=%5B%
    "Resource=",
    "RecContentType=text/html",
    "Referer=",
    "Snapshot=%5.inf",
    "Mode=HTML",
    LAST);
    */

/* Removed by Async CodeGen.

Notice that a web_reg_async_attributes function has been added before the first web_url function that calls the chat application.

Except for the first call the chat application, all other web_url functions that call similar URLs have been commented out.

The Snapshot pane for the remaining web_url function shows that the snapshots for the removed steps now have origin = Polling.

The response times vary greatly as the responses arrive only when another user has sent a chat message. This helps to indicate that this is a long-poll conversation, and not a poll conversation.

Back to top