查看完整版本: nRobot进行数据库的并发测试

man16181 2008-8-26 09:48

nRobot进行数据库的并发测试

[size=10.5pt][font=宋体][/font][/size][size=10.5pt][/size]
[size=10.5pt][font=宋体]第一步:创建演示程序:打开SQL SERVER查询分析器,在SQL SERVER测试数据库中执行下列脚本(脚本执行操作:创建表testtable,并插入一条记录;创建[/font][/size][url=http://www.storworld.com/][size=10.5pt][font=宋体][color=#0000ff]存储[/color][/font][/size][/url][size=10.5pt][font=宋体]过程test): [/font][/size][size=10.5pt][/size]
[table][tr][td=1,1,568][size=10.5pt]        if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Test]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)[/size][size=10.5pt][/size]
[size=10.5pt]       drop procedure [dbo].[Test][/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[testtable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)[/size][size=10.5pt][/size]
[size=10.5pt]       drop table [dbo].[testtable][/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       CREATE TABLE [dbo].[testtable] ([/size][size=10.5pt][/size]
[size=10.5pt]              [testid] [int] NULL ,[/size][size=10.5pt][/size]
[size=10.5pt]              [counts] [int] NULL[/size][size=10.5pt][/size]
[size=10.5pt]       ) ON [PRIMARY][/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       insert into testtable (testid,counts) values (1,0)[/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       SET QUOTED_IDENTIFIER ON[/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       SET ANSI_NULLS ON[/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       CREATE Procedure dbo.Test[/size][size=10.5pt][/size]
[size=10.5pt]       as[/size][size=10.5pt][/size]
[size=10.5pt]         declare @count int[/size][size=10.5pt][/size]
[size=10.5pt]         begin tran TEST[/size][size=10.5pt][/size]
[size=10.5pt]           select @count=counts from testtable where testid=1[/size][size=10.5pt][/size]
[size=10.5pt]           update testtable set [/size][size=10.5pt][email=counts=@count+1][color=#0000ff]counts=@count+1[/color][/email][/size]
[size=10.5pt]         if (@@error >0) begin[/size][size=10.5pt][/size]
[size=10.5pt]              rollback tran TEST[/size][size=10.5pt][/size]
[size=10.5pt]         end else begin[/size][size=10.5pt][/size]
[size=10.5pt]              commit tran TEST[/size][size=10.5pt][/size]
[size=10.5pt]         end[/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       SET QUOTED_IDENTIFIER OFF[/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[size=10.5pt]       SET ANSI_NULLS ON[/size][size=10.5pt][/size]
[size=10.5pt]       GO[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt][/size]
[size=10.5pt]           [font=宋体]第二步:创建测试脚本:在Robot中新建VU脚本,输入以下内容: [/font][/size][size=10.5pt][/size]
[table][tr][td=1,1,568][size=10.5pt]        #include[/size][size=10.5pt][/size]
[size=10.5pt]       {[/size][size=10.5pt][/size]
[size=10.5pt]       push Timeout_scale = 200; /* Set timeouts to 200% of maximum response time */[/size][size=10.5pt][/size]
[size=10.5pt]       push Think_def = "LR";[/size][size=10.5pt][/size]
[size=10.5pt]       Min_tmout = 120000;      /* Set minimum Timeout_val to 2 minutes         */[/size][size=10.5pt][/size]
[size=10.5pt]       push Timeout_val = Min_tmout;[/size][size=10.5pt][/size]
[size=10.5pt]       ser=sqlconnect("server","sa","888","192.168.0.99","sqlserver");[/size][size=10.5pt][/size]
[size=10.5pt]       set Server_connection = ser;[/size][size=10.5pt][/size]
[size=10.5pt]       push Think_avg = 0;[/size][size=10.5pt][/size]
[size=10.5pt]       sync_point "logon";[/size][size=10.5pt][/size]
[size=10.5pt]       sqlexec ["sql_1000"] "testdb..test";[/size][size=10.5pt][/size]
[size=10.5pt]       sqldisconnect (ser);[/size][size=10.5pt][/size]
[size=10.5pt]       }[/size][size=10.5pt][/size]
[/td][/tr][/table][size=10.5pt][/size]
[size=10.5pt][font=宋体]说明:[/font][/size][size=10.5pt][/size]
[size=10.5pt]           ser=sqlconnect("server","sa","888","192.168.0.99","sqlserver")[/size][size=10.5pt][/size]
[size=10.5pt]           sa[font=宋体]为数据库用户名,888为sa密码,192.168.0.99数据库IP地址[/font][/size][size=10.5pt][/size]
[size=10.5pt]           [font=宋体]以上三项按实际的测试数据库设置更改,其他两项不用修改[/font][/size][size=10.5pt][/size]
[size=10.5pt]       sqlexec ["sql_1000"] "testdb..test"[/size][size=10.5pt][/size]
[size=10.5pt]         testdb[font=宋体]为新建[/font][/size][url=http://www.storworld.com/][size=10.5pt][font=宋体][color=#0000ff]存储[/color][/font][/size][/url][size=10.5pt][font=宋体]过程test所在的数据库,按实际的数据库修改[/font][/size][size=10.5pt][/size]
[size=10.5pt]           [font=宋体]第三步:执行测试:运行上一步创建的脚本(运行时自动创建Suite),在Run Suite窗口中的“Number of users”上输入20。运行完脚本,打开数据库查看counts的数值。把counts值改为零多次运行脚本,观察每次运行后counts的结果。[/font][/size][size=10.5pt][/size]
[size=10.5pt]           [font=宋体]测试说明[/font][/size][size=10.5pt][/size]
[size=10.5pt]           [font=宋体](1)、测试示例程序的目的是,存储过程test每执行一次,表testtable中的counts字段增加[/font][/size][size=10.5pt][/size]
[size=10.5pt]           [font=宋体](2)、第三步的测试可以发现每次执行后counts结果并不相同,而且不等于20,这说明这个程序是在并发时是问题的。[/font][/size][size=10.5pt][/size]
[size=10.5pt]           [font=宋体](3)、将存储过程中的select @count=counts from testtable where testid=1修改为select @count=counts from test[/font][/size][size=10.5pt][/size]
[size=10.5pt][/size]

lingxin5013 2008-8-26 10:01

LS 你认错路了 这里是QTP 
页: [1]
查看完整版本: nRobot进行数据库的并发测试