场景设置(转自论坛)

上一篇 / 下一篇  2009-11-14 09:59:26 / 个人分类:LoadRunner

VuGen建立的第一个脚本 TestFirst的action脚本如下
char *filename = "c:\\test.txt";
Action() {

     long file;
     int id;
     char *groupname;

     /* Create a new file */
     if ((file = fopen(filename, "a" )) == NULL) {
          lr_output_message("Unable to create %s", filename);
          return -1;
     }
     
     /* Write the Vuser id and group to the log file */
     id = 1;
         groupname = "one";

     fprintf(file, "logfile of virtual user id: %d group: %s\n", id, groupname);
     fclose(file);

     return 0;
}
vu_End脚本如下
char *filepath = "c:\\test.txt";
vuser_end()
{
         long file;
     int id;
     /* Create a new file */
     if ((file = fopen(filepath, "a" )) == NULL) {
          lr_output_message("Unable to create %s", filename);
          return -1;
     }
     
     id = 1;

     fprintf(file, "%d End  ", id);
     fclose(file);
         return 0;
}

VuGen建立的第二个脚本TestSecond的Action脚本如下

char *filename = "c:\\test.txt";
Action() {

     long file;
     int id;
     char *groupname;

     /* Create a new file */
     if ((file = fopen(filename, "a" )) == NULL) {
          lr_output_message("Unable to create %s", filename);
          return -1;
     }
     
     /* Write the Vuser id and group to the log file */
     id = 2;
         groupname = "two";

     fprintf(file, "logfile of virtual user id: %d group: %s\n", id, groupname);
     fclose(file);

     return 0;
}
vu_End脚本如下:
#include "as_web.h"
char *filepath = "c:\\test.txt";
vuser_end()
{
         long file;
     int id;
     /* Create a new file */
     if ((file = fopen(filepath, "a" )) == NULL) {
          lr_output_message("Unable to create %s", filename);
          return -1;
     }
     
     id = 2;
     fprintf(file, "%d End  ", id);
     fclose(file);
         return 0;
}

上边的脚本其实很相类似只不过每个脚本中用one,two来标示每个用户(为了看到测试效果),我们这样做只是为了检测Controller如何调用脚本。
还有一点我在vu_end()加入代码,这是因为我们知道vuGen设置iteration的数值,实质是设置action的运行次数,也就是说只有运行action的iteration后才会运行vu_end。

一.设置iteration为1,在Controller中添加运行testfirst,testSecond脚本用户各一,运行结果如下:
logfile of virtual user id: 1 group: one
1 End  
logfile of virtual user id: 2 group: two
2 End
二.设置iteration为2,在Controller中添加运行testfirst,testSecond脚本用户各一,运行结果如下:
logfile of virtual user id: 2 group: two
logfile of virtual user id: 2 group: two
2 End  
logfile of virtual user id: 1 group: one
logfile of virtual user id: 1 group: one
1 End  

三.设置iteration为2,在Controller中添加运行testfirst,testSecond脚本用户各一,每隔1分钟加载1个用户,运行结果如下:
logfile of virtual user id: 1 group: one
logfile of virtual user id: 1 group: one
1 End  
logfile of virtual user id: 2 group: two
logfile of virtual user id: 2 group: two
2 End  

四.设置iteration为2,在Controller中添加运行testfirst,testSecond脚本用户各2,每隔1分
钟加载1个用户,运行结果如下:
logfile of virtual user id: 1 group: one
logfile of virtual user id: 1 group: one
1 End  
logfile of virtual user id: 2 group: two
logfile of virtual user id: 2 group: two
2 End
logfile of virtual user id: 1 group: one
logfile of virtual user id: 1 group: one
1 End
logfile of virtual user id: 2 group: two
logfile of virtual user id: 2 group: two
2 End  
五.设置iteration为2,在Controller中添加运行testfirst,testSecond脚本用户各2,设置每隔10秒加载1个用户并设置duration为40秒,运行结果如下:
logfile of virtual user id: 1 group: one
logfile of virtual user id: 1 group: one
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’省略
logfile of virtual user id: 1 group: one
2 End  
logfile of virtual user id: 2 group: two
logfile of virtual user id: 1 group: one
1 End  
logfile of virtual user id: 2 group: two
2 End  
logfile of virtual user id: 1 group: one
1 End  


以上对loadrunner的研究说明用户对应脚本,而不管他当前运行到什么状态。在第四中设置中很容易清晰的看出运行次序,可以说是从头运行到尾。(这么做只是为了研究,实际操作中情况千变万化,我只是为了测试结果清晰化)
你的三个问题从上边的试验可以得出结论,脚本影响实际程序的状态通过action脚本中运行的状态(如果你没有录制关闭页面脚本那么当前状态仍然是打开状态)。其实你设置的情况比较复杂了,我把几种不同的设置,所得出的运行结果都列举出来了。你可以自行研究。

你第一个问题 状态仍然是打开状态
你第二个问题 你的设置情况与我第五种试验设置一致,结论是仍然打开页面
你第三个问题 虚拟用户是针对loadrunner来说的,虚拟用户试和运行的机器有关系,你设置虚拟用户是为了把虚拟用户分布到不同的机器上,模拟现实世界,实际登陆用户是对你的测试软件来说的, 这是有区别的,要弄清楚概念。工具只是实现你测试目的的辅助手段,你所开发的脚本都是根据你的测试用例,在这个案例中你这么做有没有意义取决你选择的压力测试策略。如果现实中有这么做的,你就可以模拟!

我想这些测试试验可以帮助你了解iteration和虚拟用户设置对脚本调用的作用!

TAG:

 

评分:0

我来说两句

Open Toolbar