Index: Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj
===================================================================
diff -u -rd6e6eadf4a2521df75b6d371bacbb181a43058a3 -r9c29a906e8ee9c993982d4dc4a3bf2e148af40a0
--- Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision d6e6eadf4a2521df75b6d371bacbb181a43058a3)
+++ Core/Common/test/Core.Common.TestUtil/Core.Common.TestUtil.csproj (.../Core.Common.TestUtil.csproj) (revision 9c29a906e8ee9c993982d4dc4a3bf2e148af40a0)
@@ -66,10 +66,6 @@
..\..\..\..\packages\log4net.2.0.4\lib\net40-full\log4net.dll
True
-
- ..\..\..\..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll
- True
-
..\..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll
True
Index: Core/Common/test/Core.Common.TestUtil/TestHelper.cs
===================================================================
diff -u -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 -r9c29a906e8ee9c993982d4dc4a3bf2e148af40a0
--- Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302)
+++ Core/Common/test/Core.Common.TestUtil/TestHelper.cs (.../TestHelper.cs) (revision 9c29a906e8ee9c993982d4dc4a3bf2e148af40a0)
@@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
-using System.Drawing.Drawing2D;
-using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -13,18 +11,13 @@
using log4net.Config;
using log4net.Core;
-using Newtonsoft.Json;
-
using NUnit.Framework;
namespace Core.Common.TestUtil
{
public class TestHelper
{
private static string solutionRoot;
- private static int assertInTestMethod;
- private static string lastTestName;
- private static Color[] colors;
public static string SolutionRoot
{
@@ -154,7 +147,7 @@
public static double AssertIsFasterThan(float maxMilliseconds, string message, Action action, bool rankHddAccess)
{
var stopwatch = new Stopwatch();
- double actualMillisecond = default(double);
+ var actualMillisecond = default(double);
stopwatch.Start();
action();
@@ -166,43 +159,16 @@
stopwatch.Reset();
- string testName = GetCurrentTestClassMethodName();
+ var machineHddPerformanceRank = GetMachineHddPerformanceRank();
+ var rank = machineHddPerformanceRank;
- if (testName == lastTestName) // check if there are more than one assert in a single test
- {
- assertInTestMethod++;
- testName += assertInTestMethod;
- }
- else
- {
- lastTestName = testName;
- assertInTestMethod = 1; // reset
- }
-
- float machinePerformanceRank = GetMachinePerformanceRank();
-
- float machineHddPerformanceRank = GetMachineHddPerformanceRank();
-
- var reportDirectory = GetSolutionRoot() + Path.DirectorySeparatorChar + "target/";
- CreateDirectoryIfNotExists(reportDirectory);
-
- var path = reportDirectory + "performance-times.html";
- WriteTimesToLogFile(maxMilliseconds, (int)actualMillisecond, machinePerformanceRank,
- machineHddPerformanceRank, rankHddAccess, testName, false, path);
-
- path = reportDirectory + "performance-times-charts.html";
- WriteTimesToLogFile(maxMilliseconds, (int)actualMillisecond, machinePerformanceRank,
- machineHddPerformanceRank, rankHddAccess, testName, true, path);
-
- float rank = machineHddPerformanceRank;
-
if (rankHddAccess) // when test relies a lot on HDD - multiply rank by hdd speed factor
{
rank *= machineHddPerformanceRank;
}
var userMessage = String.IsNullOrEmpty(message) ? "" : message + ". ";
- if (rank != 1.0f)
+ if ( ! rank.Equals(1.0f))
{
Assert.IsTrue(rank * actualMillisecond < maxMilliseconds, userMessage + "Maximum of {0} milliseconds exceeded. Actual was {1}, machine performance weighted actual was {2}",
maxMilliseconds, actualMillisecond, actualMillisecond * rank);
@@ -456,190 +422,6 @@
return 1.0f;
}
- private static void WriteTimesToLogFile(float maxMilliseconds, float actualMilliseconds, float machineRank, float machineHddRank, bool useHddAccessRank, string testName, bool includeCharts, string path)
- {
- if (!File.Exists(path))
- {
- if (!includeCharts)
- {
- File.AppendAllText(path, @"View with charts
");
- }
-
- if (machineRank != 1.0f)
- {
- File.AppendAllText(path, String.Format("Machine performance rank (multiplier):{0}
", machineRank));
- File.AppendAllText(path, @"Time is in milliseconds
");
- File.AppendAllText(path, String.Format("\n| Time | Name | {0}MaxTime | ActualTime | RankedActualTime | Percentage |
", includeCharts ? "Chart | " : ""));
- }
- else
- {
- File.AppendAllText(path, @"Time is in milliseconds
");
- File.AppendAllText(path, String.Format("\n| Time | Name | {0}MaxTime | ActualTime | Percentage |
", includeCharts ? "Chart | " : ""));
- }
- }
-
- string contents;
-
- float rank = machineRank * (useHddAccessRank ? machineHddRank : 1.0f);
-
- var chartContent = includeCharts ? String.Format(" | ", testName) : "";
-
- float fraction;
- if (machineRank != 1.0f)
- {
- contents = String.Format(CultureInfo.InvariantCulture,
- "| {0} | {1} | {2}{3:G5} | {4:G5} | {5:G5} | ",
- DateTime.Now, testName, chartContent, maxMilliseconds, actualMilliseconds, actualMilliseconds * rank);
- fraction = (maxMilliseconds - actualMilliseconds * rank) / maxMilliseconds;
- }
- else
- {
- contents = String.Format(CultureInfo.InvariantCulture,
- "
| {0} | {1} | {2}{3:G5} | {4:G5} | ", DateTime.Now, testName, chartContent,
- maxMilliseconds, actualMilliseconds);
- fraction = (maxMilliseconds - actualMilliseconds) / maxMilliseconds;
- }
-
- string color = ColorTranslator.ToHtml(GetPerformanceColor(fraction));
- contents += String.Format(CultureInfo.InvariantCulture, "{1:G5}% | ", color, (100 - fraction * 100));
-
- contents += "
\n";
- File.AppendAllText(path, contents);
-
- // update test reports in JSON files on build server (tests statistics)
- // TODO: find way to write it somewhere so that it will be shared between build agents
-
- int buildNumber = 0;
- string s = Environment.GetEnvironmentVariable("BUILD_NUMBER");
- if (!String.IsNullOrEmpty(s))
- {
- buildNumber = Int32.Parse(s); // defined on build server
- }
-
- // generate JSON files locally
- string testHistoryDirectoryPath = GetSolutionRoot() + "/target/performace-test-reports";
- CreateDirectoryIfNotExists(testHistoryDirectoryPath);
-
- string testHistoryFilePath = testHistoryDirectoryPath + Path.DirectorySeparatorChar + testName + ".json";
-
- var testInfos = new List();
-
- if (File.Exists(testHistoryFilePath))
- {
- testInfos = JsonConvert.DeserializeObject>(File.ReadAllText(testHistoryFilePath));
- }
-
- if (buildNumber == 0)
- {
- if (testInfos == null || testInfos.Count == 0)
- {
- testInfos = new List();
- }
- else
- {
- var maxBuildNumber = testInfos.Select(i => i.BuildNumber).Max();
-
- // reset build numbers if they were not set
- foreach (var testInfo in testInfos)
- {
- if (testInfo.BuildNumber == 0)
- {
- testInfo.BuildNumber = buildNumber;
- buildNumber++;
- }
- }
-
- buildNumber = maxBuildNumber + 1;
- }
- }
-
- int maxTestInfoCount = 100; // max number of tests locally
-
- while (testInfos.Count >= maxTestInfoCount)
- {
- testInfos.RemoveAt(0);
- }
-
- testInfos.Add(new TestRunInfo
- {
- TestName = testName,
- Actual = actualMilliseconds,
- ActualWeighted =
- (int)(actualMilliseconds * machineRank * (useHddAccessRank ? machineHddRank : 1.0)),
- Max = maxMilliseconds,
- MachineHddRank = machineHddRank,
- MachineRank = machineRank,
- Time = DateTime.Now.ToString(CultureInfo.InvariantCulture),
- BuildNumber = buildNumber,
- UseMachineHddRank = useHddAccessRank
- });
-
- CreateChart(testInfos, testHistoryFilePath + ".html");
-
- string json = JsonConvert.SerializeObject(testInfos, Formatting.Indented);
- File.WriteAllText(testHistoryFilePath, json);
- }
-
- private static void CreateChart(List testInfos, string filePath)
- {
- var content = File.ReadAllText(SolutionRoot + "/Core/Common/test/Core.Common.TestUtil/test-data/chart.template.html");
-
- var seriesPassed = "";
- var seriesFailed = "";
- var seriesThreshold = "";
- for (var i = 0; i < testInfos.Count; i++)
- {
- var info = testInfos[i];
- if (info.Actual > info.Max)
- {
- seriesFailed += "[" + info.BuildNumber + ", " + info.ActualWeighted + "], ";
- }
- else
- {
- seriesPassed += "[" + info.BuildNumber + ", " + info.ActualWeighted + "], ";
- }
-
- seriesThreshold += "[" + info.BuildNumber + ", " + info.Max + "], ";
- }
-
- content = content.Replace("$$SERIES_PASSED$$", seriesPassed);
- content = content.Replace("$$SERIES_FAILED$$", seriesFailed);
- content = content.Replace("$$SERIES_THRESHOLD$$", seriesThreshold);
-
- File.WriteAllText(filePath, content);
- }
-
- private static Color GetPerformanceColor(double fraction)
- {
- if (fraction < 0)
- {
- return Color.Red;
- }
-
- if (colors == null)
- {
- var bitmap = new Bitmap(101, 1);
- Graphics graphics = Graphics.FromImage(bitmap);
-
- var rectangle = new Rectangle(0, 0, 101, 1);
-
- var brush = new LinearGradientBrush(rectangle, Color.Green, Color.Yellow, 0.0f);
-
- graphics.FillRectangle(brush, rectangle);
-
- colors = new Color[101];
- for (int i = 0; i < 101; i++)
- {
- colors[i] = bitmap.GetPixel(i, 0);
- }
- }
-
- // 25% is the best result GREEN, less or greater than goes to yellow
- var localValue = fraction >= 0.25 ? Math.Min(1, (fraction - 0.25) / 0.75) : Math.Max(0, (0.25 - fraction) / 0.25);
-
- return colors[(int)(localValue * 100.0)];
- }
-
///
/// Checks if all messages from occur in
///
@@ -697,21 +479,5 @@
}
}
- #region Nested type: TestRunInfo
-
- internal class TestRunInfo
- {
- public string Time;
- public string TestName;
- public float Actual; // millis
- public float ActualWeighted; // millis
- public float Max; // millis
- public int BuildNumber;
- public float MachineHddRank;
- public float MachineRank;
- public bool UseMachineHddRank;
- }
-
- #endregion
}
}
\ No newline at end of file
Index: Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj
===================================================================
diff -u -r29cfa36a80794e6c3264d29ec8e72d204f3302d3 -r9c29a906e8ee9c993982d4dc4a3bf2e148af40a0
--- Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision 29cfa36a80794e6c3264d29ec8e72d204f3302d3)
+++ Core/Common/test/Core.Common.Utils.Test/Core.Common.Utils.Test.csproj (.../Core.Common.Utils.Test.csproj) (revision 9c29a906e8ee9c993982d4dc4a3bf2e148af40a0)
@@ -80,11 +80,7 @@
3.0
-
- 3.5
-
-
Index: Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs
===================================================================
diff -u -r7e491a8cd7dc86b6ead9f4be9bb32754e16cf302 -r9c29a906e8ee9c993982d4dc4a3bf2e148af40a0
--- Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs (.../TestHelperTests.cs) (revision 7e491a8cd7dc86b6ead9f4be9bb32754e16cf302)
+++ Core/Common/test/Core.Common.Utils.Test/TestHelperTests.cs (.../TestHelperTests.cs) (revision 9c29a906e8ee9c993982d4dc4a3bf2e148af40a0)
@@ -1,9 +1,7 @@
using System;
using System.Drawing;
-using System.Globalization;
using System.IO;
using System.Linq;
-using System.Reflection;
using System.Windows.Forms;
using Core.Common.TestUtil;
using Core.Common.Utils.Test.Properties;
@@ -58,57 +56,6 @@
TestHelper.AssertLogMessageIsGenerated(() => log.Error("hello"), "hello");
}
- [Test]
- public void GetPerformanceColors()
- {
- var type = typeof(TestHelper);
- var methodInfo = type.GetMethod("GetPerformanceColor", BindingFlags.NonPublic | BindingFlags.Static);
-
- var colorRed = (Color) methodInfo.Invoke(null, new object[]
- {
- -0.05
- });
- var colorYellow1 = (Color) methodInfo.Invoke(null, new object[]
- {
- 0.0
- });
- var colorYellow2 = (Color) methodInfo.Invoke(null, new object[]
- {
- 1.0
- });
- var colorYellow3 = (Color) methodInfo.Invoke(null, new object[]
- {
- 1.05
- });
- var colorGreen = (Color) methodInfo.Invoke(null, new object[]
- {
- 0.25
- });
-
- Assert.AreEqual("Red", colorRed.Name);
- Assert.AreEqual("fffcfe00", colorYellow1.Name);
- Assert.AreEqual("fffcfe00", colorYellow2.Name);
- Assert.AreEqual("fffcfe00", colorYellow3.Name);
- Assert.AreEqual("ff008000", colorGreen.Name);
-
- // dump all colors to html file for visual test
- const string path = "GetPerformanceColors.html";
- DeleteIfExists(path);
- var contents = "";
- for (var i = -0.05; i <= 1.1; i += 0.05)
- {
- var color = (Color) methodInfo.Invoke(null, new object[]
- {
- i
- });
- var htmlColor = ColorTranslator.ToHtml(color);
- contents += string.Format(CultureInfo.InvariantCulture, "| {1:G5}% |
", htmlColor, i);
- }
- contents += "
";
-
- File.AppendAllText(path, contents);
- }
-
private static void DeleteIfExists(string path)
{
if (!File.Exists(path) & !Directory.Exists(path))