是否可以在ASP.NET负载测试会话中持久保留WebTestContext? [英] Is it possible to persist WebTestContext across ASP.NET load test session?

查看:62
本文介绍了是否可以在ASP.NET负载测试会话中持久保留WebTestContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Visual Studio 2010终极负载测试对企业Web应用程序(我没有构建)进行负载测试.我希望每个虚拟用户都先登录,然后在随机测试运行结束时注销.我可以适当地配置负载测试.但是,这很复杂.会话密钥将被注入URL,如下所示:

I want to load test an enterprise Web application (which I did not build), using a Visual Studio 2010 Ultimate Load Test. I want each virtual user to log in at the beginning, and log out at the end of their run of random tests. I can properly configured the load test to do so. However, there is a complication. The session key is injected into the URL, like this:

http://ProductName/(S(ilv3lp2yhbqdyr2tbcj5mout))/System/Container.aspx

我将Visual Studio WebTests转换为编码测试,然后使用使用特定于会话的URL的代码对其进行了改进.这很好.我需要做的是,在特定虚拟用户运行的各种测试中,从登录WebTest类到注销WebTest类,始终保留此会话编码的URL.

I converted the Visual Studio WebTests to coded tests, and then retrofit them with code that uses the session-specific URL. This works fine. What I need to do is persist this session encoded URL across the various tests that specific virtual user runs, starting with the login WebTest class, to the logout WebTest class.

单个WebTest类能够在每个测试的开始和结束时登录和注销.但是,这不是正常使用的准确表示.该应用程序模拟大型机终端,从不切断Web浏览器请求之间的连接或会话.每个会话都是一个较长的交互式HTTP请求,就像大型机终端与例如IBM AS400进行交互一样. Usert通常在一天的开始时登录到大型机,并(应该)在一天的结束时注销.同样,此Web应用程序将维护HTTP请求,直到用户注销或IIS会话超时为止.因此,重要的是,在所有测试之间,我必须在URL中保持相同的会话,以确保不会累积内存泄漏和其他讨厌的错误.

The individual WebTest classes are capable of logging in and out at the beginning and end of each test. However, this is not an accurate representation of normal use. This application emulates a mainframe terminal, and never cuts the connection or session between Web browser requests. Each session is one long, interactive HTTP request, just like a mainframe terminal interacts with, for example, an IBM AS400. Usert typically log in to the mainframe at the beginning of day, and (should) log out at the end of day. Likewise, this Web application maintains the HTTP request until the user logs out, or the IIS session timeout occurs. Therefore, it is important I keep the same session in the URL, between all tests, to ensure memory leaks and other nasty bugs don't accumulating.

请分享您的想法!

推荐答案

问题1:在测试迭代中保留会话ID

您可以将数据存储在用户上下文"中,该数据在测试迭代中保持不变.在名称为"$ LoadTestUserContext"的WebTestContext中可以找到它. (但是请注意,此上下文参数仅出现在负载测试运行中,而不出现在独立的Web测试运行中)

You can store data in the 'user context' which is persistent across test iterations. It is found in the WebTestContext having the name '$LoadTestUserContext'. (But note that this context parameter only appears in load test runs, not in standalone web test runs)

// within WebTestPlugin.PreRequest() or MyExtractionRule.Extract()
// e is the corresponding eventargs object...
LoadTestUserContext userContext = (LoadTestUserContext)e.WebTest.Context["$LoadTestUserContext"];
...
// setting the value in the user context (i.e. in the extraction rule)
userContext["sessionId"] = "(extracted session id)";
...
// getting the value from the user context (i.e. in WebTestPlugin PreWebTest event)
e.WebTest.Context["sessionId"] = userContext["sessionId"];

您必须将WebTestPlugin(将用户上下文中的值提取到Web测试上下文中)添加到所有Web测试中,以使该值可在所有测试中使用.

You'll have to add a WebTestPlugin (that fetches the value from the user context into the web test context) to all of your web tests to make the value available across all tests.

问题2:仅在负载测试开始和结束时登录/注销

  • 将登录和注销功能提取到各自独立的测试中(请记住,注销测试还需要WebTestPlugin来获取存储的sessionId)
  • 在负载测试"中,编辑测试混合"对话框使您可以指定初始化和终止"测试:将它们设置为刚创建的登录"和注销"测试
  • 在负载测试方案中,将新用户百分比"设置为0.

新用户所占百分比"设置的一些其他说明

新用户所占百分比"设置命名不当,并不表示其完整行为.

The "Percentage of New Users" setting is poorly named and does not indicate its full behaviour.

  • 新用户"开始测试迭代时,它将使用新的$ WebTestUserId(并获得新的新用户上下文,您不需要想要)
  • 非新用户"启动测试迭代时,将保留相同的旧$ WebTestUserId(以及您想要的旧用户上下文)
  • When a "New User" starts a test iteration, it takes a new $WebTestUserId (and gets a new fresh user context, which you don't want)
  • When a non-"New User" starts a test iteration, it keeps the same old $WebTestUserId (and the old user context, which you do want)

到目前为止,一切都很好.但是意外的部分是这样:

So far so good. But the unexpected part is this:

  • 每个新用户"在负载测试期间执行以下操作:

  • Each "New User" executes the following during a load test:

Initialize > web test iteration > Terminate

非新用户"在负载测试的整个过程中执行以下操作:

A non-"New User" executes the following for the entire duration of the load test:

Initialize > iteration1 > iteration2 > ... > iterationN > Terminate

换句话说,新用户"会不断地登录和注销(您不需要).非新用户"仅在整个负载测试中一次登录并注销 ,并在持续时间内(您想要的)连续运行测试迭代.

In other words, "New Users" are constantly logging in and out (which you don't want). Non-"New Users" only login and logout once in the entire load test, and continually run test iterations for the duration (which you do want).

这篇关于是否可以在ASP.NET负载测试会话中持久保留WebTestContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆