• 如何重写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!

  • 相关阅读:
    一个泛型栈类(GenericStack)
    Google Maps API v2初探
    浅谈工作中celery与Redis遇到的一些问题 PTSD
    python PTSD
    77%的Linux运维都不懂的内核问题
    教程 | Linux常用命令大全
    分布式架构系列: 负载均衡技术详解
    10大Python开源项目推荐(Github平均star2135)
    你必须学写 Python 装饰器的五个理由
    五分钟搞定 Linux 文档全部知识,就看这篇文章
  • 原文地址:https://www.cnblogs.com/preftest/p/2053890.html
Copyright © 2020-2023  润新知