How to induce delay in Loadrunner Java Vuser script

I had to send two xml mes­sages to a JMS queue with slight delay between them. Since I am writ­ing a Java Vuser script, I wast­ed no time in choos­ing Thread.sleep( mil­li sec) func­tion. This worked fine in Vugen so I was sure. But dur­ing the exe­cu­tion of Sce­nario in Load Con­troller, I observed that the expect­ed out­put of the trans­ac­tion is bro­ken and the trans­ac­tion is failed.

Upon inves­ti­ga­tion I found that the two mes­sages are not going to the queue in the order we expect­ed. The sec­ond mes­sage is going ear­ly caus­ing the trans­ac­tion to fail. This is because the Con­troller is NOT induc­ing the delay I men­tioned in Thread.sleep func­tion. So the cor­rect func­tion to use is lr.think_time(sec). This func­tion caus­es the Con­troller to actu­al­ly wait for the spec­i­fied num­ber of sec­onds.

Just this 1 line of code result­ed in wastage of 2 per­son days! But again, this can be learned only by expe­ri­ence.


Comments

Leave a Reply

%d bloggers like this: