Commit b78c0546 b78c054636ccbd4530e65eb8d514ca357de3c9a8 by Christian Gerdes

New plugins

Convert Date Parameter to Age
Clean Temp Files
1 parent 727db387
......@@ -24,6 +24,67 @@ using System.Net;
namespace LIL_VSTT_Plugins
{
[DisplayName("Convert Date Parameter to Age")]
[Description("Converts the date in given parameters into todays age and saves with suffix as new parameter")]
public class ConvertDateToAge : WebTestPlugin
{
[DisplayName("Parameter RegEx"), DefaultValue(""), Description("Regular expression. If the parameter exists in context and matches it will be convertet into a date. Will not fail the script if date cannot be converted.")]
public string ParameterRegEx { get; set; }
[DisplayName("Date Format"), DefaultValue("yyyy-MM-dd"), Description("The format of the date string in the parameter to convert from, see https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings")]
public string DateFormat { get; set; }
[DisplayName("Age Parameter Suffix"), DefaultValue("_Age"), Description("The suffix to be added for new parameters. If set to null or empty the original parameter will be overwritten.")]
public string Suffix { get; set; }
Regex regex = null;
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
base.PreWebTest(sender, e);
if (regex == null) regex = new Regex(ParameterRegEx);
Dictionary<string, object> temp = new Dictionary<string, object>();
bool convertSuccess = false;
// Iterate through all context variables
foreach (KeyValuePair<string, object> obj in e.WebTest.Context)
{
if(regex.IsMatch(obj.Key))
{
try
{
// Try to convert to a date using the specified format
DateTime parsedDate;
convertSuccess = DateTime.TryParseExact(obj.Value.ToString(), DateFormat, null, System.Globalization.DateTimeStyles.None, out parsedDate);
// Save the age
if (convertSuccess) temp.Add(obj.Key + Suffix, CalculateAge(parsedDate));
else e.WebTest.AddCommentToResult("Failed to calculate age using \"" + obj.Value.ToString() + "\" of parameter \"" + obj.Key + "\"" + " and format \"" + DateFormat + "\"");
}
catch (Exception ex)
{
e.WebTest.AddCommentToResult("Failed to convert date parameter to age: " + ex.Message);
}
}
}
// Add the new ones to the webtest context
foreach (KeyValuePair<string, object> obj in temp)
{
e.WebTest.Context[obj.Key] = obj.Value;
e.WebTest.AddCommentToResult("Saved value \"" + obj.Value + "\" into \"" + obj.Key + "\"");
}
}
public static int CalculateAge(DateTime birthDay)
{
int years = DateTime.Now.Year - birthDay.Year;
if ((birthDay.Month > DateTime.Now.Month) || (birthDay.Month == DateTime.Now.Month && birthDay.Day > DateTime.Now.Day))
years--;
return years;
}
}
[DisplayName("Force UrlEncoded Cookies")]
[Description("Reparses all cookies set by the server and stores the value in UrlEncoded format. Cookies with illegal characters will otherwise cause none of the previous set cookies to be added to new requests.")]
public class DebugCookies : WebTestPlugin
......
......@@ -23,6 +23,39 @@ using System.Text.RegularExpressions;
namespace LIL_VSTT_Plugins
{
/// <summary>
/// LoadTest Clear Temp
/// </summary>
[DisplayName("Clean Temp Files")]
[Description("(C) Copyright 2020 LIGHTS IN LINE AB\r\nCrashed loadtests can leave a lot of test logs in the temp folder of the agent. This plugin removes them before starting a new loadtest.")]
public class CleanTempFolder : ILoadTestPlugin
{
//store the load test object.
LoadTest mLoadTest;
public void Initialize(LoadTest loadTest)
{
mLoadTest = loadTest;
loadTest.LoadTestStarting += new EventHandler(mLoadTest_Starting);
}
void mLoadTest_Starting(object sender, EventArgs e)
{
System.IO.DirectoryInfo di = new DirectoryInfo(System.IO.Path.GetTempPath());
foreach (FileInfo file in di.GetFiles("*.dat"))
{
try
{
file.Delete();
}
catch (Exception) { };
}
File.Create(System.IO.Path.GetTempPath() + "\\Cleaned_DAT_by_plugin.txt");
}
}
/// <summary>
/// LoadTest Plugin DisableSSLSessionCache
/// </summary>
[DisplayName("SSL Session Cache Disabled")]
......
......@@ -29,7 +29,7 @@ namespace LIL_VSTT_Plugins
public bool DontStopIteration { get; set; }
Random rnd = new Random();
Regex rx = new Regex("externalSystemRequestLimitReached\"?:?true", RegexOptions.IgnoreCase);
Regex rx = new Regex("externalSystemRequestLimitReached\".?:.?true", RegexOptions.IgnoreCase);
public override void PreRequest(object sender, PreRequestEventArgs e)
{
......
<?xml version="1.0" encoding="utf-8"?>
<LoadTest Name="LoadTest1" Description="" Owner="" storage="d:\git\vstt-plugins\testproject1\loadtest1.loadtest" Priority="2147483647" Enabled="true" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" WorkItemIds="" TraceLevel="None" CurrentRunConfig="Run Settings1" Id="0e35c1c4-9214-4fc4-907f-42e11a00845a" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<LoadTest Name="LoadTest1" Description="" Owner="" storage="c:\ws\repos\vstt-plugins\testproject1\loadtest1.loadtest" Priority="2147483647" Enabled="true" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" WorkItemIds="" TraceLevel="None" CurrentRunConfig="Run Settings1" Id="0e35c1c4-9214-4fc4-907f-42e11a00845a" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Scenarios>
<Scenario Name="Scenario1" DelayBetweenIterations="5" PercentNewUsers="0" IPSwitching="true" TestMixType="PercentageOfUsersRunning" ApplyDistributionToPacingDelay="true" MaxTestIterations="0" DisableDuringWarmup="false" DelayStartTime="0" AllowedAgents="">
<ThinkProfile Value="0.2" Pattern="Off" />
<LoadProfile Pattern="Constant" InitialUsers="1" />
<TestMix>
<TestProfile Name="WebTest1" Path="webtest1.webtest" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Percentage="100" Type="Microsoft.VisualStudio.TestTools.WebStress.DeclarativeWebTestElement, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<TestProfile Name="WebTest1" Path="webtest1.webtest" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" Percentage="100" Type="Microsoft.VisualStudio.TestTools.WebStress.DeclarativeWebTestElement, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</TestMix>
<BrowserMix>
<BrowserProfile Percentage="100">
......@@ -92,7 +92,7 @@
<Counter Name="Avg. Response Time" />
<Counter Name="Avg. Connection Wait Time">
<ThresholdRules>
<ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<RuleParameters>
<RuleParameter Name="DependentCategory" Value="LoadTest:Page" />
<RuleParameter Name="DependentCounter" Value="Avg. Page Time" />
......@@ -157,7 +157,7 @@
<Counter Name="Current Bandwidth" RangeGroup="Network Bytes" />
<Counter Name="Bytes Total/sec" RangeGroup="Network Bytes">
<ThresholdRules>
<ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<RuleParameters>
<RuleParameter Name="DependentCategory" Value="Network Interface" />
<RuleParameter Name="DependentCounter" Value="Current Bandwidth" />
......@@ -303,7 +303,7 @@
<Counter Name="Current Bandwidth" RangeGroup="Network Bytes" />
<Counter Name="Bytes Total/sec" RangeGroup="Network Bytes">
<ThresholdRules>
<ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<ThresholdRule Classname="Microsoft.VisualStudio.TestTools.WebStress.Rules.ThresholdRuleCompareCounters, Microsoft.VisualStudio.QualityTools.LoadTest, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<RuleParameters>
<RuleParameter Name="DependentCategory" Value="Network Interface" />
<RuleParameter Name="DependentCounter" Value="Current Bandwidth" />
......@@ -416,7 +416,7 @@
</CounterSet>
</CounterSets>
<RunConfigurations>
<RunConfiguration Name="Run Settings1" Description="" ResultsStoreType="Database" TimingDetailsStorage="AllIndividualDetails" SaveTestLogsOnError="true" SaveTestLogsFrequency="1" MaxErrorDetails="200" MaxErrorsPerType="1000" MaxThresholdViolations="1000" MaxRequestUrlsReported="1000" UseTestIterations="false" RunDuration="60" WarmupTime="0" CoolDownTime="0" TestIterations="12" WebTestConnectionModel="ConnectionPerUser" WebTestConnectionPoolSize="50" SampleRate="5" ValidationLevel="High" SqlTracingConnectString="" SqlTracingConnectStringDisplayValue="" SqlTracingDirectory="" SqlTracingEnabled="false" SqlTracingFileCount="2" SqlTracingRolloverEnabled="true" SqlTracingMinimumDuration="500" RunUnitTestsInAppDomain="true" CoreCount="0" ResourcesRetentionTimeInMinutes="0" AgentDiagnosticsLevel="Warning">
<RunConfiguration Name="Run Settings1" Description="" ResultsStoreType="Database" TimingDetailsStorage="AllIndividualDetails" SaveTestLogsOnError="true" SaveTestLogsFrequency="1" MaxErrorDetails="200" MaxErrorsPerType="1000" MaxThresholdViolations="1000" MaxRequestUrlsReported="1000" UseTestIterations="true" RunDuration="60" WarmupTime="0" CoolDownTime="0" TestIterations="5" WebTestConnectionModel="ConnectionPerUser" WebTestConnectionPoolSize="50" SampleRate="5" ValidationLevel="High" SqlTracingConnectString="" SqlTracingConnectStringDisplayValue="" SqlTracingDirectory="" SqlTracingEnabled="false" SqlTracingFileCount="2" SqlTracingRolloverEnabled="true" SqlTracingMinimumDuration="500" RunUnitTestsInAppDomain="true" CoreCount="0" UseMultipleIPs="false" TestAgentConfiguration="Default" AgentDiagnosticsLevel="Warning">
<CounterSetMappings>
<CounterSetMapping ComputerName="[CONTROLLER MACHINE]">
<CounterSetReferences>
......@@ -432,4 +432,7 @@
</CounterSetMappings>
</RunConfiguration>
</RunConfigurations>
<LoadTestPlugins>
<LoadTestPlugin Classname="LIL_VSTT_Plugins.CleanTempFolder, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="Clean Temp Files" Description="(C) Copyright 2020 LIGHTS IN LINE AB&#xD;&#xA;Crashed loadtests can leave a lot of test logs in the temp folder of the agent. This plugin removes them before starting a new loadtest." />
</LoadTestPlugins>
</LoadTest>
\ No newline at end of file
......
<?xml version="1.0" encoding="utf-8"?>
<WebTest Name="WebTest1" Id="c649760b-6dd8-4210-8a6d-3c6596d08668" 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="8abd3e84-6029-47ca-a3b0-abb2fb28d548" Version="1.1" Url="http://localhost:8080/EmailValidator" 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="0af8c656-b702-4c75-a66d-6e26af1030ae" Version="1.1" Url="http://localhost/" ThinkTime="0" 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="Parameter1" Value="This is not a date" />
<ContextParameter Name="TestParam1" Value="2020-10-07" />
</ContextParameters>
<WebTestPlugins>
<WebTestPlugin Classname="LIL_VSTT_Plugins.SetWebTestParameter, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="SetWebTestParameter" Description="">
<WebTestPlugin Classname="LIL_VSTT_Plugins.ConvertDateToAge, LIL_VSTT_Plugins, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null" DisplayName="Convert Date Parameter to Age" Description="Converts the date in given parameters into todays age and saves with suffix as new parameter">
<RuleParameters>
<RuleParameter Name="Parameter_Name" Value="UserName" />
<RuleParameter Name="DebugMode" Value="False" />
<RuleParameter Name="DebugLogFile" Value="C:\Temp\SetTestParameterDebug.log" />
<RuleParameter Name="Connection_String" Value="UserdataFew1.csv" />
<RuleParameter Name="Has_col_name" Value="False" />
<RuleParameter Name="Autosplit" Value="False" />
<RuleParameter Name="IgnoreBlanks" Value="True" />
<RuleParameter Name="LogFilePathString" Value="C:\Temp\Fungerande.log" />
<RuleParameter Name="LogFileAppendID" Value="False" />
<RuleParameter Name="LogFileAppendName" Value="False" />
<RuleParameter Name="Use_UniqueTestIteration" Value="False" />
<RuleParameter Name="Use_UniqueIteration" Value="False" />
<RuleParameter Name="Use_UniqueFiles" Value="False" />
<RuleParameter Name="Use_Unique" Value="False" />
<RuleParameter Name="Use_Random" Value="False" />
<RuleParameter Name="Use_Seq" Value="True" />
<RuleParameter Name="Use_Loop" Value="False" />
<RuleParameter Name="ThrowException" Value="False" />
<RuleParameter Name="Log_To_File" Value="False" />
<RuleParameter Name="Test_Names" Value="" />
<RuleParameter Name="Scenario_Names" Value="" />
<RuleParameter Name="Agent_Names" Value="" />
<RuleParameter Name="ParameterRegEx" Value="Param1" />
<RuleParameter Name="DateFormat" Value="yyyy-MM-dd" />
<RuleParameter Name="Suffix" Value="" />
</RuleParameters>
</WebTestPlugin>
</WebTestPlugins>
......