Modify callbacks
For a list of protocols that support asynchronous communication, see 64-bit recording, Async, and IPv6 support.
After VuGen scans a Vuser script for asynchronous communication, the Async tab of the Design Studio lists the asynchronous conversations that were found in the script. For each asynchronous conversation found during the scan, VuGen adds the required callback function declarations in the AsyncCallbacks.c file.
For more details on using callback functions, see Implement callbacks.
To implement the required behavior, you can modify the callbacks that were added by VuGen. Modifying a callback includes:
In poll and long-poll conversations, requested URLs often change in each polling iteration. The change is usually determined by client-side logic, usually implemented by JavaScript that is executed by the browser. Parts of the URL may be determined by correlation of a known parameter, such as a session ID. For details, see Parse URLs.
Request URLs in an asynchronous conversation are modified before the request is sent by using the RequestCB and the web_util_set_request_url function.
The request body in requests that are part of an asynchronous conversation may need to be modified before the request is sent. You use the RequestCB and the web_util_set_request_body util function to modify the request body.
Modifying the request body is useful in poll and long-poll conversations in which each new request requires a different request body.
Each RequestCB that is generated by VuGen contains a commented snippet. You can "uncomment" the snippet in order to use the web_util_set_request_body util function.
If VuGen finds that different requests have different body values in the recorded conversation, the generated RequestCB will contain a comment that prompts you to check the recording in order to implement the request body sent in each request when the script runs.
You can modify the response callback in an asynchronous conversation to verify validity of the responses, or to wait for a specific event. For example, you could check the response headers for each response to determine if a specific value was received.
When the expected value has been received, you can use a web_stop_async step in the Action file to end the asynchronous conversation.
The following code sample provides an example for ending a synchronized conversation. In this example, in the AsyncCallback.c file, the scripts counts 10 iterations of the polling conversation, after which it creates a new parameter, stopAsync.
Example:
int Poll_0_ResponseCB(
...{
//increment iteration counter for every response received.
static int iter = 0;
iter++;
//Once the desired number of responses has been reached,
//create and save the parameter.
if (iter > 10) {
lr_save_int(iter, "stopAsync");
}
return WEB_ASYNC_CB_RC_OK;
}
In the Action file, the web_sync step uses the generated parameter, stopAsync, to end the conversation:
Example:
web_reg_async_attributes("ID=Poll_0","Pattern=Poll",
"URL=http://pumpkin:2080/nioamfpoll;AMFSessionId=6F8D6108-E309-38B2-3D65-963B431D0A38",
"PollIntervalMs=3000",
"RequestCB=Poll_0_RequestCB",
"ResponseCB=Poll_0_ResponseCB",
LAST);
web_custom_request("nioamfpoll;AMFSessionId=6F8D6108-E309-38B2-3D65-963B431D0A38_2",
"URL=http://pumpkin:2080/nioamfpoll;AMFSessionId=6F8D6108-E309-38B2-3D65-963B431D0A38",
"Method=POST",
"Resource=0",
"RecContentType=application/x-amf",
"Referer=http://pumpkin:8081/lcds-samples/traderdesktop/traderdesktop.swf/[[DYNAMIC]]/3",
"Snapshot=t11.inf",
"Mode=HTML",
"EncType=application/x-amf",
"BodyBinary=\\x00\\x03\\x00\\x00\\x00\\x01\\x00\\x04null\\x00\\x02/6\\x00\\x00\\x00Z\n\\x00\\x00\\x00\\x01\\x11\n\\x07\\x07DSC\\x8D\\x02\n\\x0B\\x01\\x01\\x06\\x01\n\\x05\tDSId\\x06I6F8D611E-DC1C-9D0C-2BBA-36CC2AB8633B\\x01\\x0C!\\xC0\\xBE\\xA6Z74\\xBE\\xC3\\xCF\\xC7\\xFA\\xE6\\xC3\t\\xE2\\x92\\x01\\x06\\x01\\x01\\x04\\x02",
LAST);
lr_think_time(30);
//suspend the script until the desired number
//of iterations have been performed.
web_sync("ParamCreated=stopAsync", "RetryIntervalMs=1000", "RetryTimeoutMs=300000", LAST);
web_stop_async("ID=Poll_0",LAST);
For more details about ending an asynchronous conversation, see Define the end of an asynchronous conversation.