51Testing软件测试论坛

标题: 压力测试-参数化-唯一编号取值 [打印本页]

作者: joycena    时间: 2013-12-25 15:18
标题: 压力测试-参数化-唯一编号取值
int myfile_w,myfile_r1,myfile_r2;
    char *file_w="F:\\test\\w.txt";
    char *file_r1="F:\\test\\r1.txt";
    char *file_r2="F:\\test\\r2.txt";
    long  text[1024];                       
  char booking_no[30]="wjn";      
    char  *num_no=lr_eval_string("{unit_no}");   
  char ccl_file[1024]="TARGET_PATH=/ccl/send/";   

lr_output_message("num_no: %s",num_no);//打印输出 num_no 的值
    strcat(booking_no,num_no);            
                                                   
lr_output_message("booking_no: %s",booking_no); //打印输出 booking_no 的值
   
    //文件 操作 步骤1-读取file_r1内容全新覆盖/写入file_w;  步骤2-将booking_no追加到file_w;
      myfile_r1=fopen(file_r1,"r");      
    myfile_w=fopen(file_w,"w");   
    while(!feof(myfile_r1))        
    {                              
              fgets(text,1024,myfile_r1);
             fputs(text,myfile_w);
    }
    fclose(myfile_r1);      
    fclose(myfile_w);
   
       myfile_w=fopen(file_w,"a");   
    fprintf(myfile_w,"%s",booking_no);   
    fclose(myfile_w);

ftp_logon_ex(&ftp_session,"ftp_logon","URL=ftp://usrname:password@192.168.1.11:21",LAST);
   
      strcat(ccl_file,booking_no);   
    strcat(ccl_file,".txt");      
    lr_output_message("ccl_f : %s",ccl_file); //打印输出 ccl_file 的值
         ftp_put_ex(&ftp_session, "Ftp_Put",
               "SOURCE_PATH=F:/test/w.txt",
                ccl_file, ENDITEM,            LAST);      
   ftp_logout_ex(&ftp_session);
return 0;

-------
其中:  *num_no=lr_eval_string("{unit_no}");   
将 num_no 值进行参数化: unit number , 开始为1, 块大小为1000000 且每次出现发送.

当控制台 并发 3个用户, 此时输出的 ccl_file文件名按 测试目标正确输出, 但 booking_no 却部分出现数据串的现象.
结果如下 :
booking_no        ccl_file        说明
2582545531        wjn1        booking_no 预期为 wjn1
wjn300000002wjn2        wjn2        booking_no 预期为 wjn2
wjn300000003        wjn3        booking_no 预期为 wjn3
2582545531        wjn100000001        booking_no 预期为 wjn100000001
wjn300000002wjn2        wjn100000002        booking_no 预期为 wjn100000002
wjn100000003        wjn100000003        booking_no 预期为 wjn100000003
2582545531        wjn200000001        booking_no 预期为 wjn200000001
wjn200000002        wjn200000002        booking_no 预期为 wjn200000002
wjn200000003        wjn200000003        booking_no 预期为 wjn200000003
作者: Nio    时间: 2013-12-31 16:43
代码运行场景设计不正确。
这段代码适用于单用户运行。

代码中未能解决,多用户同时操作同一个文件的异常问题。以及顺序问题。
作者: 云层    时间: 2014-2-9 19:28
太复杂了,用LR自己的参数化可以生成绝对唯一的字串
作者: msnshow    时间: 2014-8-27 21:03
的确是太复杂了,看着头晕,LR自带的就很好用了,没必要自己写代码,这样运行又占资源




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2