使用 VS2008 负载测试功能获取无 cookie 会话页面的统计信息

发布于 2024-08-24 11:59:42 字数 123 浏览 5 评论 0原文

我正在使用 Visual Studio 负载测试工具对网页进行负载测试,但在显示结果时遇到问题。问题是无 cookie 会话。每次新用户访问页面时,页面 URLL 都会发生变化,并且我无法计算平均页面响应时间。对此我们能做些什么呢?

I'm load testing a web page using visual studio load testing tool, but I have problems displaying results. The problem is cookieless session. Everytime new user comes to a page, page URLL changes and I'm not able to calculate average page response time. What can be done about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2024-08-31 11:59:42

我们将 cookie 移至查询字符串。

在此之前,我编写了一个不区分大小写的 url 验证事件处理程序,该处理程序忽略 Url 的会话部分。下面的仅消除了区分大小写的情况。

class QueryLessCaseInsensitiveValidateResponseUrl : ValidateResponseUrl
{
    public override void Validate(object sender, ValidationEventArgs e)
    {
        Uri uri;
        string uriString = string.IsNullOrEmpty(e.Request.ExpectedResponseUrl) ? e.Request.Url : e.Request.ExpectedResponseUrl;
        if (!Uri.TryCreate(e.Request.Url, UriKind.Absolute, out uri))
        {
            e.Message = "The request URL could not be parsed";
            e.IsValid = false;
        }
        else
        {
            Uri uri2;
            string leftPart = uri.GetLeftPart(UriPartial.Path);
            if (!Uri.TryCreate(uriString, UriKind.Absolute, out uri2))
            {
                e.Message = "The request URL could not be parsed";
                e.IsValid = false;
            }
            else
            {
                uriString = uri2.GetLeftPart(UriPartial.Path);
                ////this removes the query string
                //uriString.Substring(0, uriString.Length - uri2.Query.Length);
                Uri uritemp = new Uri(uriString);
                if (uritemp.Query.Length > 0)
                {
                    string fred = "There is a problem";
                }
                //changed to ignore case
                if (string.Equals(leftPart, uriString, StringComparison.OrdinalIgnoreCase))
                {
                    e.IsValid = true;
                }
                else
                {
                    e.Message = string.Format("The value of the ExpectedResponseUrl property '{0}' does not equal the actual response URL '{1}'. QueryString parameters were ignored.", new object[] { uriString, leftPart });
                    e.IsValid = false;
                }
            }
        }
    }
}

调用者

public EventHandler<ValidationEventArgs> AddUrlValidationEventHandler(WebTestContext context, WebTest webTest)
{
    EventHandler<ValidationEventArgs> urlValidationRuleEventHandler = null;
    // Initialize validation rules that apply to all requests in the WebTest
    if ((context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
    {
        QueryLessCaseInsensitiveValidateResponseUrl validationRule1 = new QueryLessCaseInsensitiveValidateResponseUrl();
        urlValidationRuleEventHandler = new EventHandler<ValidationEventArgs>(validationRule1.Validate);
        webTest.ValidateResponse += urlValidationRuleEventHandler;
    }
    return urlValidationRuleEventHandler;

}

现在我需要做的就是添加

    //add case insensitive url validation for all requests
    urlValidationRuleEventHandler = common.AddUrlValidationEventHandler(this.Context, this);

到 Web 测试中以获得不区分大小写的调用。
请注意,此代码包含以下不适当的行

string fred = "There is a problem";

We moved the cookie to the querystring.

Before that I wrote a case insensitive url validation event handler that ignores the session component of the Url. The one below only removes case sensitivity.

class QueryLessCaseInsensitiveValidateResponseUrl : ValidateResponseUrl
{
    public override void Validate(object sender, ValidationEventArgs e)
    {
        Uri uri;
        string uriString = string.IsNullOrEmpty(e.Request.ExpectedResponseUrl) ? e.Request.Url : e.Request.ExpectedResponseUrl;
        if (!Uri.TryCreate(e.Request.Url, UriKind.Absolute, out uri))
        {
            e.Message = "The request URL could not be parsed";
            e.IsValid = false;
        }
        else
        {
            Uri uri2;
            string leftPart = uri.GetLeftPart(UriPartial.Path);
            if (!Uri.TryCreate(uriString, UriKind.Absolute, out uri2))
            {
                e.Message = "The request URL could not be parsed";
                e.IsValid = false;
            }
            else
            {
                uriString = uri2.GetLeftPart(UriPartial.Path);
                ////this removes the query string
                //uriString.Substring(0, uriString.Length - uri2.Query.Length);
                Uri uritemp = new Uri(uriString);
                if (uritemp.Query.Length > 0)
                {
                    string fred = "There is a problem";
                }
                //changed to ignore case
                if (string.Equals(leftPart, uriString, StringComparison.OrdinalIgnoreCase))
                {
                    e.IsValid = true;
                }
                else
                {
                    e.Message = string.Format("The value of the ExpectedResponseUrl property '{0}' does not equal the actual response URL '{1}'. QueryString parameters were ignored.", new object[] { uriString, leftPart });
                    e.IsValid = false;
                }
            }
        }
    }
}

Called by

public EventHandler<ValidationEventArgs> AddUrlValidationEventHandler(WebTestContext context, WebTest webTest)
{
    EventHandler<ValidationEventArgs> urlValidationRuleEventHandler = null;
    // Initialize validation rules that apply to all requests in the WebTest
    if ((context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
    {
        QueryLessCaseInsensitiveValidateResponseUrl validationRule1 = new QueryLessCaseInsensitiveValidateResponseUrl();
        urlValidationRuleEventHandler = new EventHandler<ValidationEventArgs>(validationRule1.Validate);
        webTest.ValidateResponse += urlValidationRuleEventHandler;
    }
    return urlValidationRuleEventHandler;

}

Now all I need to do is add

    //add case insensitive url validation for all requests
    urlValidationRuleEventHandler = common.AddUrlValidationEventHandler(this.Context, this);

into a web test to get case insensitive calling.
Be aware that this code contains the following innappropriate line

string fred = "There is a problem";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文