Parameterising Unix/Posix timestamps in VuGen

A common question from people creating web-based VuGen scripts is how to handle timestamp values that are sent as part of a name/value pair in an HTTP request.

If we look at the example GET request below, two values immediately stand out as needing to be correlated.

1
2
3
4
5
6
7
8
9
web_url("www.example.com", 
    "URL=http://www.example.com/view?jsessionid=dYyvCMH1cxEc&ts=1231715057375", 
    "TargetFrame=", 
    "Resource=0", 
    "RecContentType=text/html", 
    "Referer=http://www.example.com/", 
    "Snapshot=t2.inf", 
    "Mode=HTML", 
    LAST);

The jsessionid should be easy to correlate, but the ts value usually causes some confusion.

An experienced eye will notice that 1231715057375 looks like a timestamp in Unix Time, which is defined as the number of seconds since 00:00am on January 1, 1970. An even more experienced person will notice that the number is actually in milliseconds, rather than seconds, so it is probably being generated with the JavaScript getTime() method.

In this case, 1231715057 translates to Sun, 11 Jan 2009 23:04:17 UTC.

As this value is being generated on the client (i.e. the web browser), it will be impossible to correlate, because the actual value never appears in the HTML that is returned by the web server before the value is used in a request.

The solution is to create the timestamp value in your VuGen script at runtime, rather than trying to correlate the value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Using standard C library functions to get timestamp in seconds.
long t;
time(&t);
lr_save_int(t, "secondsTimeStamp");
lr_output_message("Seconds: %s", lr_eval_string("{secondsTimeStamp}"));
 
/* 
Using a LoadRunner function to get timestamp in milliseconds.
 
Function documentation:
web_save_timestamp_param saves the current timestamp. 
In some applications, VuGen replaces all non-empty timestamps in the script with a parameter. 
To save the value of this parameter, VuGen automatically generates a call to 
web_save_timestamp_param. 
The value saved is the number of milliseconds since midnight January 1st, 1970. */
web_save_timestamp_param("msTimeStamp", LAST);
lr_output_message("Milliseconds: %s", lr_eval_string("{msTimeStamp}"));

As creating a timestamp value is so easy to do, there is no excuse for leaving hardcoded values in your VuGen script from your initial recording, even if the script seems to run without error.

 


Related posts:

  1. Calculating the difference between two dates or timestamps Let’s say that you have to determine the difference between...
  2. Persistent Data in VuGen with MySQL One of the main drawbacks with VuGen is the inability...
  3. Harvesting file names with VuGen VuGen isn’t just a tool for load testing and application...
  4. Think time that cannot be ignored Someone asked me once if there was a way of...
  5. Changing LoadRunner/VuGen log options at runtime LoadRunner has a whole bunch of logging options. These can...


Bookmark using any bookmark manager!

 

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Parameterising Unix/Posix timestamps in VuGen”

  1. Interesting piece of trivia…

    On Friday the 13th, 2009 at 11:31:30pm UTC UNIX time will reach 1,234,567,890.

    …and just after 03:14:07 UTC on Tuesday, 19 January 2038, the 32-bit integer that stores the timestamp will roll over to -2147483648. This is known as the “Unix Millennium bug“.

Leave a Reply