Commit 727db387 727db387cd7c32c6093dd371cd41c1803fb43fbc by Christian Gerdes

New Plugin SKV MS Throttle

1 parent a5fe0681
......@@ -203,11 +203,13 @@ namespace LIL_VSTT_Plugins
}
}
[DisplayName("Set Request Think Time"), Description("Changes the thinktime on requests with a set thinktime over 0 to the value of the ThinkTime context parameter")]
[DisplayName("Set Request Think Time"), Description("Changes the thinktime on requests with a set thinktime over 0 or any given value to the value of the ThinkTime context parameter")]
public class SetRequestThinkTime : WebTestPlugin
{
[DisplayName("Debug"), DefaultValue(false), Description("Debug logging when thinktime is set on requests")]
public bool DebugMode { get; set; }
[DisplayName("Modify If Over (sec)"), DefaultValue(0), Description("Only modify the request think time if over this value. Default is 0.")]
public int ModifyOver { get; set; }
public override void PreRequest(object sender, PreRequestEventArgs e)
{
WebTestContext ctx = e.WebTest.Context;
......@@ -215,7 +217,7 @@ namespace LIL_VSTT_Plugins
if (ctx.ContainsKey("ThinkTime"))
{
int tt = Int32.Parse(ctx["ThinkTime"].ToString());
if (e.Request.ThinkTime > 0)
if (e.Request.ThinkTime > ModifyOver)
{
if (DebugMode) e.WebTest.AddCommentToResult("Setting Think Time to " + tt);
e.Request.ThinkTime = tt;
......
......@@ -13,6 +13,62 @@ using System.Text.RegularExpressions;
namespace LIL_VSTT_Plugins
{
[DisplayName("MS Throttle Broms")]
[Description("Ökar betänketiden på request som får ett 500 svar från MS Throttle att lugna ner sig lite. Slumpar en tid mellan angiven min och max.")]
public class ZMSThrottle : WebTestPlugin
{
[DisplayName("Minsta Paustid"), DefaultValue(100), Description("Minsta paus i sekunder vid begäran om throttling")]
public int MinimumPaus { get; set; }
[DisplayName("Högsta Paustid"), DefaultValue(300), Description("Högsta paus i sekunder vid begäran om throttling")]
public int MaximumPaus { get; set; }
[DisplayName("Debugläge"), DefaultValue(false), Description("Sätter pausen oavsett svar samt loggar")]
public bool Debug { get; set; }
[DisplayName("Acceptera 500 koden"), DefaultValue(false), Description("Om MS svarar med en 500 kod SAMT throttle JSON finns i svaret med ExternalLimitReached:true ignoreras 500 koden så att anropet inte failar.")]
public bool Acceptera500 { get; set; }
[DisplayName("Stoppa inte iterationen"), DefaultValue(false), Description("Om MS svarar med en 500 kod SAMT throttle JSON finns i svaret med ExternalLimitReached:true stoppas exekveringen av skriptet.")]
public bool DontStopIteration { get; set; }
Random rnd = new Random();
Regex rx = new Regex("externalSystemRequestLimitReached\"?:?true", RegexOptions.IgnoreCase);
public override void PreRequest(object sender, PreRequestEventArgs e)
{
base.PreRequest(sender, e);
if(Acceptera500 == true)
e.Request.IgnoreHttpStatusCode = true;
}
public override void PostRequest(object sender, PostRequestEventArgs e)
{
base.PostRequest(sender, e);
bool isLimitReachedFound = false;
if(e.ResponseExists && e.Response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
{
if(rx.IsMatch(e.Response.BodyString))
{
e.Request.ThinkTime = rnd.Next(MinimumPaus, MaximumPaus);
isLimitReachedFound = true;
e.WebTest.AddCommentToResult("ExternalSystemRequestLimitReached:true pausar i " + e.Request.ThinkTime + " sekunder");
if (!DontStopIteration)
{
e.WebTest.AddCommentToResult("Stoppar iterationen av skriptet efter detta anrop");
e.WebTest.Stop();
}
}
}
if(Acceptera500 == true && (int)e.Response.StatusCode >= 400 && isLimitReachedFound == false)
{
e.Request.Outcome = Outcome.Fail;
e.WebTest.AddCommentToResult("Failar eftersom statuskod >= 400 samt ExternalSystemRequestLimitReached:true inte fanns i svaret");
}
if (Debug)
{
e.WebTest.AddCommentToResult("Sätter pausen eftersom debugläge är aktiverat");
e.Request.ThinkTime = rnd.Next(MinimumPaus, MaximumPaus);
}
}
}
[DisplayName("Validera Header")]
[Description("(C) Mårten\r\nValiderar att en header har ett visst värde i svaret.")]
public class ValidateHeader : ValidationRule
......
......@@ -11,10 +11,10 @@
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 9.0" MaxConnections="6">
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207" simulateThinkTimes="true">
<Browser name="Internet Explorer 11.0" MaxConnections="6">
<Headers>
<Header name="User-Agent" value="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" />
<Header name="User-Agent" value="Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
......
<?xml version="1.0" encoding="utf-8"?>
<WebTest Name="WebTest1 - Copy" Id="91d7c2e3-269a-4c8c-bf86-34a59b587b73" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="WebTest1.a5a27e2d-474c-43bb-be4d-1b12e85851a0.rec.webtestresult" ResultsLocale="">
<WebTest Name="WebTest2" Id="91d7c2e3-269a-4c8c-bf86-34a59b587b73" Owner="" Priority="2147483647" Enabled="True" CssProjectStructure="" CssIteration="" Timeout="0" WorkItemIds="" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010" Description="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="default" StopOnError="False" RecordedResultFile="WebTest1.a5a27e2d-474c-43bb-be4d-1b12e85851a0.rec.webtestresult" ResultsLocale="">
<Items>
<Request Method="GET" Guid="2abac3b8-caac-4dee-a55a-a006b6372154" Version="1.1" Url="http://fileserver2/" ThinkTime="0" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
<Request Method="GET" Guid="2abac3b8-caac-4dee-a55a-a006b6372154" Version="1.1" Url="http://localhost:1848/api/throttle/1" ThinkTime="1" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
<Request Method="GET" Guid="2abac3b8-caac-4dee-a55a-a006b6372154" Version="1.1" Url="http://localhost:1848/api/throttle/0" ThinkTime="1" Timeout="300" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8" ExpectedHttpStatusCode="0" ExpectedResponseUrl="" ReportingName="" IgnoreHttpStatusCode="False" />
</Items>
<ContextParameters>
<ContextParameter Name="ThinkTime" Value="10" />
</ContextParameters>
<WebTestPlugins>
<WebTestPlugin Classname="LIL_VSTT_Plugins.ZMSThrottle, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="MS Throttle Broms" Description="Ökar betänketiden på request som får ett 500 svar från MS Throttle att lugna ner sig lite. Slumpar en tid mellan angiven min och max.">
<RuleParameters>
<RuleParameter Name="MinimumPaus" Value="100" />
<RuleParameter Name="MaximumPaus" Value="300" />
<RuleParameter Name="Debug" Value="False" />
<RuleParameter Name="AccepteraInte500" Value="False" />
<RuleParameter Name="DontStopIteration" Value="False" />
<RuleParameter Name="Acceptera500" Value="False" />
</RuleParameters>
</WebTestPlugin>
<WebTestPlugin Classname="LIL_VSTT_Plugins.SetRequestThinkTime, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="Set Request Think Time" Description="Changes the thinktime on requests with a set thinktime over 0 or any given value to the value of the ThinkTime context parameter">
<RuleParameters>
<RuleParameter Name="DebugMode" Value="False" />
<RuleParameter Name="ModifyOver" Value="0" />
</RuleParameters>
</WebTestPlugin>
</WebTestPlugins>
</WebTest>
\ No newline at end of file
......