zoukankan      html  css  js  c++  java
  • 如何重写LoadRunner的函数?

    参考:

    http://ptfrontline.wordpress.com/2010/06/22/overriding-lr-functions-with-custom-code/

    Most people do not know that LR supports overriding existing functions with custom ones in a very easy way.

    I had a situation where I had a pre-made script that had fixed think-time values for the lr_think_time() calls, and they of course were completely wrong. So my problem was that I had a lot of lr_think_time() places and I didn’t want to go through them all myself. 

    In most cases a search-and-replace would do the trick, but I stumbled upon the overriding of functions and implemented it that way instead, making my changes to the script stay in one place only instead of manipulating all the actions in the script.

    Remember: DO NOT CALL THE OVERRIDDEN FUNCTION INSIDE THE NEW CODE!!! – You’ll just end up with an endless loop, and terminate in stack-errors or similar…

    Here’s an empty script where I’ve overridden the lr_think_time() function with a custom one:

    01 #define lr_think_time my_think_time  // This define overrides lr_think_time() with my_think_time()
    02   
    03 double my_think_time(double sec)
    04 // This simulates the 50% to 150% think-time randomness ...
    05 {
    06     double x;
    07   
    08     x = ((50.0+rand()%100)/100)*sec; // 50% to 150% randomness
    09   
    10     lr_force_think_time( x ); // force the think time (this is undocumented command)
    11   
    12     return x; // return how many seconds we waited
    13 }
    14   
    15 ///////////////////////////////////////////////////////////////////////////////
    16   
    17 Action()
    18 {
    19     lr_think_time(10); // This will use the my_think_time() function !!
    20   
    21     return 0;
    22 }

    One could get creative and start overriding all sorts of functions with this. An example would be to set specific headers for specific web_url() calls depending on the params. You could override the web_url() call, examine the parameters and add any needed HTTP headers before doing a web_custom_request() instead ..

    Enjoy!

  • 相关阅读:
    【SpringCloud】工程分类概况
    【Spring Alibaba】Sentinel/Nacos/RocketMQ/Seata/
    【Eureka】服务架构类知识点
    求车速
    尼科彻斯定理
    Tom数
    弟弟的作业
    汽水瓶
    POJ-2533-Longest Ordered Subsequence(LIS模板)
    HDU-1331-Function Run Fun(动态规划3)
  • 原文地址:https://www.cnblogs.com/preftest/p/2053890.html
Copyright © 2011-2022 走看看