New Plugin SKV MS Throttle
Showing
4 changed files
with
87 additions
and
7 deletions
... | @@ -203,11 +203,13 @@ namespace LIL_VSTT_Plugins | ... | @@ -203,11 +203,13 @@ namespace LIL_VSTT_Plugins |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | [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")] | 206 | [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")] |
207 | public class SetRequestThinkTime : WebTestPlugin | 207 | public class SetRequestThinkTime : WebTestPlugin |
208 | { | 208 | { |
209 | [DisplayName("Debug"), DefaultValue(false), Description("Debug logging when thinktime is set on requests")] | 209 | [DisplayName("Debug"), DefaultValue(false), Description("Debug logging when thinktime is set on requests")] |
210 | public bool DebugMode { get; set; } | 210 | public bool DebugMode { get; set; } |
211 | [DisplayName("Modify If Over (sec)"), DefaultValue(0), Description("Only modify the request think time if over this value. Default is 0.")] | ||
212 | public int ModifyOver { get; set; } | ||
211 | public override void PreRequest(object sender, PreRequestEventArgs e) | 213 | public override void PreRequest(object sender, PreRequestEventArgs e) |
212 | { | 214 | { |
213 | WebTestContext ctx = e.WebTest.Context; | 215 | WebTestContext ctx = e.WebTest.Context; |
... | @@ -215,7 +217,7 @@ namespace LIL_VSTT_Plugins | ... | @@ -215,7 +217,7 @@ namespace LIL_VSTT_Plugins |
215 | if (ctx.ContainsKey("ThinkTime")) | 217 | if (ctx.ContainsKey("ThinkTime")) |
216 | { | 218 | { |
217 | int tt = Int32.Parse(ctx["ThinkTime"].ToString()); | 219 | int tt = Int32.Parse(ctx["ThinkTime"].ToString()); |
218 | if (e.Request.ThinkTime > 0) | 220 | if (e.Request.ThinkTime > ModifyOver) |
219 | { | 221 | { |
220 | if (DebugMode) e.WebTest.AddCommentToResult("Setting Think Time to " + tt); | 222 | if (DebugMode) e.WebTest.AddCommentToResult("Setting Think Time to " + tt); |
221 | e.Request.ThinkTime = tt; | 223 | e.Request.ThinkTime = tt; | ... | ... |
... | @@ -13,6 +13,62 @@ using System.Text.RegularExpressions; | ... | @@ -13,6 +13,62 @@ using System.Text.RegularExpressions; |
13 | 13 | ||
14 | namespace LIL_VSTT_Plugins | 14 | namespace LIL_VSTT_Plugins |
15 | { | 15 | { |
16 | [DisplayName("MS Throttle Broms")] | ||
17 | [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.")] | ||
18 | public class ZMSThrottle : WebTestPlugin | ||
19 | { | ||
20 | [DisplayName("Minsta Paustid"), DefaultValue(100), Description("Minsta paus i sekunder vid begäran om throttling")] | ||
21 | public int MinimumPaus { get; set; } | ||
22 | [DisplayName("Högsta Paustid"), DefaultValue(300), Description("Högsta paus i sekunder vid begäran om throttling")] | ||
23 | public int MaximumPaus { get; set; } | ||
24 | [DisplayName("Debugläge"), DefaultValue(false), Description("Sätter pausen oavsett svar samt loggar")] | ||
25 | public bool Debug { get; set; } | ||
26 | [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.")] | ||
27 | public bool Acceptera500 { get; set; } | ||
28 | [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.")] | ||
29 | public bool DontStopIteration { get; set; } | ||
30 | |||
31 | Random rnd = new Random(); | ||
32 | Regex rx = new Regex("externalSystemRequestLimitReached\"?:?true", RegexOptions.IgnoreCase); | ||
33 | |||
34 | public override void PreRequest(object sender, PreRequestEventArgs e) | ||
35 | { | ||
36 | base.PreRequest(sender, e); | ||
37 | if(Acceptera500 == true) | ||
38 | e.Request.IgnoreHttpStatusCode = true; | ||
39 | } | ||
40 | |||
41 | public override void PostRequest(object sender, PostRequestEventArgs e) | ||
42 | { | ||
43 | base.PostRequest(sender, e); | ||
44 | bool isLimitReachedFound = false; | ||
45 | if(e.ResponseExists && e.Response.StatusCode == System.Net.HttpStatusCode.InternalServerError) | ||
46 | { | ||
47 | if(rx.IsMatch(e.Response.BodyString)) | ||
48 | { | ||
49 | e.Request.ThinkTime = rnd.Next(MinimumPaus, MaximumPaus); | ||
50 | isLimitReachedFound = true; | ||
51 | e.WebTest.AddCommentToResult("ExternalSystemRequestLimitReached:true pausar i " + e.Request.ThinkTime + " sekunder"); | ||
52 | if (!DontStopIteration) | ||
53 | { | ||
54 | e.WebTest.AddCommentToResult("Stoppar iterationen av skriptet efter detta anrop"); | ||
55 | e.WebTest.Stop(); | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | if(Acceptera500 == true && (int)e.Response.StatusCode >= 400 && isLimitReachedFound == false) | ||
60 | { | ||
61 | e.Request.Outcome = Outcome.Fail; | ||
62 | e.WebTest.AddCommentToResult("Failar eftersom statuskod >= 400 samt ExternalSystemRequestLimitReached:true inte fanns i svaret"); | ||
63 | } | ||
64 | if (Debug) | ||
65 | { | ||
66 | e.WebTest.AddCommentToResult("Sätter pausen eftersom debugläge är aktiverat"); | ||
67 | e.Request.ThinkTime = rnd.Next(MinimumPaus, MaximumPaus); | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
16 | [DisplayName("Validera Header")] | 72 | [DisplayName("Validera Header")] |
17 | [Description("(C) Mårten\r\nValiderar att en header har ett visst värde i svaret.")] | 73 | [Description("(C) Mårten\r\nValiderar att en header har ett visst värde i svaret.")] |
18 | public class ValidateHeader : ValidationRule | 74 | public class ValidateHeader : ValidationRule | ... | ... |
... | @@ -11,10 +11,10 @@ | ... | @@ -11,10 +11,10 @@ |
11 | <TestDirectory useLoadContext="true" /> | 11 | <TestDirectory useLoadContext="true" /> |
12 | </AssemblyResolution> | 12 | </AssemblyResolution> |
13 | </UnitTestRunConfig> | 13 | </UnitTestRunConfig> |
14 | <WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207"> | 14 | <WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207" simulateThinkTimes="true"> |
15 | <Browser name="Internet Explorer 9.0" MaxConnections="6"> | 15 | <Browser name="Internet Explorer 11.0" MaxConnections="6"> |
16 | <Headers> | 16 | <Headers> |
17 | <Header name="User-Agent" value="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)" /> | 17 | <Header name="User-Agent" value="Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" /> |
18 | <Header name="Accept" value="*/*" /> | 18 | <Header name="Accept" value="*/*" /> |
19 | <Header name="Accept-Language" value="{{$IEAcceptLanguage}}" /> | 19 | <Header name="Accept-Language" value="{{$IEAcceptLanguage}}" /> |
20 | <Header name="Accept-Encoding" value="GZIP" /> | 20 | <Header name="Accept-Encoding" value="GZIP" /> | ... | ... |
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <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=""> | 2 | <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=""> |
3 | <Items> | 3 | <Items> |
4 | <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" /> | 4 | <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" /> |
5 | <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" /> | ||
5 | </Items> | 6 | </Items> |
7 | <ContextParameters> | ||
8 | <ContextParameter Name="ThinkTime" Value="10" /> | ||
9 | </ContextParameters> | ||
10 | <WebTestPlugins> | ||
11 | <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."> | ||
12 | <RuleParameters> | ||
13 | <RuleParameter Name="MinimumPaus" Value="100" /> | ||
14 | <RuleParameter Name="MaximumPaus" Value="300" /> | ||
15 | <RuleParameter Name="Debug" Value="False" /> | ||
16 | <RuleParameter Name="AccepteraInte500" Value="False" /> | ||
17 | <RuleParameter Name="DontStopIteration" Value="False" /> | ||
18 | <RuleParameter Name="Acceptera500" Value="False" /> | ||
19 | </RuleParameters> | ||
20 | </WebTestPlugin> | ||
21 | <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"> | ||
22 | <RuleParameters> | ||
23 | <RuleParameter Name="DebugMode" Value="False" /> | ||
24 | <RuleParameter Name="ModifyOver" Value="0" /> | ||
25 | </RuleParameters> | ||
26 | </WebTestPlugin> | ||
27 | </WebTestPlugins> | ||
6 | </WebTest> | 28 | </WebTest> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment