Systems & Software Talk 

LoadRunner (tm) Random Think time Function

01:23, 2009-Apr-24  ..  Posted in LoadRunner Tips and Tricks  ..  0 comments  ..  Link

LoadRunner is a product of Hewlett-Packard Development Company, L.P.

-- this corrects a bug I allowed into "production" in the previous version --

 

Here is a simple lightweight function and example for those who wish to have more precise control over each instance of think time as opposed to runtime settings gadgetry - or simply get a random number.


/*----------------------------------------------------------------------------------------------*/
/*---- BEGIN Function fRandInteger --------------------------------------------------------*/

/* Send 2 arguments - minimum and maximum.
   Output to caller is a random integer anywhere in the specified range, inclusive.*/
int fRandInteger(minInt, maxInt)
{
 int rndInt, offset;

if (maxInt == 0) 
                        return maxInt; // Caller must handle a 0 in order to prevent error.

 

offset = minInt;
rndInt =   ((minInt) + rand() % (maxInt - offset + 1));

/* Examples:
 1. lr_think_time(fRandInteger(3, 12));
 2. rndVal = fRandInteger(1, 9);
 3. rndVal = fRandInteger(1,
CALLED_UFC_FIGHTER_A_WUSS_IN_PERSON); */
return rndInt;

}

/*---- END Function fRandInteger ------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------*/

vuser_init()

{

… your code

lr_think_time(fRandInteger(3, 12));

… more of your code

 

          return 0;

}

 

 

I have found that it helps to use some pre-processor constants for well-known user types or classes and recommended think times – using this function to generate random think times. This serves the notion of a self-documenting concept. Additionally, some users or classes of users simply require more time to interactively execute a business process. Here are some example pound-defines with example code:

 

/* Constants as seconds */

#define AWAITING_PERSONAL_ECONOMIC_BAILOUT_FROM_US_CONGRESS   

#define AGILE_METHODOLOGY_PROVES_ITS_ORIG_INTENT   (- 10)

#define FAILED_TO_BREAK_UP_ONE_TOO_MANY_MICHAEL_VICK_DOGFIGHTS    340000

#define CALLED_UFC_FIGHTER_BROCK_LESNAR_A_WUSS_IN_PERSON    518400

#define CHOSE_TO_RUN_ON_MS_VISTA_VS_UNIX   (CONSTANT Please_Wait)

#define HEAD_BUTTED_SOME_SOFTBALL_SIZED_HAILSTONES    86400

#define RECEIVED_LITERACY_GENE_FROM_LLOHAN_GENE_POOL    2

#define RETRO_ROCKETS_FIRED_TOO_EARLY_ON_REENTRY   518400

#define TIME_SPENT_PREENING_MULLET    345600

 

Of course, your actual defines-implementation would have a MIN and MAX for each item. I did not do that here in order to save a bit of blog space.

Example using defines:
/*----------------------------------------------------------------------------------------------*/
/*---- BEGIN Function fRandInteger --------------------------------------------------------*/

/* Send 2 arguments - minimum and maximum.
   Output to caller is a random integer anywhere in the specified range, inclusive.*/
int fRandInteger(minInt, maxInt)
{
 int rndInt, offset;

if (maxInt == 0) 
                        return maxInt; // Caller must handle a 0 in order to prevent error.

offset = minInt;
rndInt =   ((minInt) + rand() % (maxInt - offset + 1));

/* Examples:
 1. lr_think_time(fRandInteger(3, 12));
 2. rndVal = fRandInteger(1, 9);
 3. rndVal = fRandInteger(1,
CHOSE_TO_RUN_ON_MS_VISTA_VS_UNIX); */
return rndInt;

}

/*---- END Function fRandInteger ------------------------------------------------------------*/
/*------------------------------------------------------------------------------------------------*/

 

vuser_init()

{

… your code

lr_think_time(fRandInteger(TIME_SPENT_PREENING_MULLET,

AWAITING_PERSONAL_ECONOMIC_BAILOUT_FROM_CONGRESS));

… more of your code

 

          return 0;

}


 

{ Last Page }   { Page 4 of 58 }   { Next Page }

About Me

Home
My Profile
Archives
Friends
My Photo Album

Links

Corey Goldberg
Effective Testing?
Bj Rollison I.M. Testy Blog
Alan Page: Software Testing & Rants
Dmitry's LoadRunner and QTP Blog
Veterans History Project
Air Traffic Control Watch
Music Making Fun
My home 1972-1975

Categories

Functional Testing
Performance Horror
Development
Performance Testing
General
Tools Tips
Warped Humor
LoadRunner Tips and Tricks

Recent Entries

They Need To Test More...
Software Disorder
LoadRunner (tm) & RTE 4 Func/Regr
LoadRunner (tm) Random Think time Function
Are Rock, Paper, Scissors-based Decisions Obsolete?

Friends

LauraScharp
philk10
richardw100
aalhait
jimhazen
strazzerj
Lynnem
bru
EklecticTester
jgottlieb
leakybrain
michaeljf
prainbow
rajeshmathur
rstens
Yury
zeeslo
whollymindless

Syndication

RSS Site Feed