diff options
Diffstat (limited to 'src/DotNetOpenAuth.Test/TestBase.cs')
-rw-r--r-- | src/DotNetOpenAuth.Test/TestBase.cs | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/DotNetOpenAuth.Test/TestBase.cs b/src/DotNetOpenAuth.Test/TestBase.cs index 8aeca2d..4a6eaca 100644 --- a/src/DotNetOpenAuth.Test/TestBase.cs +++ b/src/DotNetOpenAuth.Test/TestBase.cs @@ -11,6 +11,8 @@ namespace DotNetOpenAuth.Test { using System.Web; using DotNetOpenAuth.Messaging.Reflection; using DotNetOpenAuth.OAuth.Messages; + using DotNetOpenAuth.OpenId.RelyingParty; + using DotNetOpenAuth.Test.Performance; using log4net; using NUnit.Framework; @@ -65,6 +67,34 @@ namespace DotNetOpenAuth.Test { log4net.LogManager.Shutdown(); } + internal static Stats MeasurePerformance(Action action, float maximumAllowedUnitTime, int samples = 10, int iterations = 100, string name = null) { + if (!PerformanceTestUtilities.IsOptimized(typeof(OpenIdRelyingParty).Assembly)) { + Assert.Inconclusive("Unoptimized code."); + } + + var timer = new MultiSampleCodeTimer(samples, iterations); + Stats stats; + using (new HighPerformance()) { + stats = timer.Measure(name ?? TestContext.CurrentContext.Test.FullName, action); + } + + stats.AdjustForScale(PerformanceTestUtilities.Baseline.Median); + + TestUtilities.TestLogger.InfoFormat( + "Performance counters: median {0}, mean {1}, min {2}, max {3}, stddev {4} ({5}%).", + stats.Median, + stats.Mean, + stats.Minimum, + stats.Maximum, + stats.StandardDeviation, + stats.StandardDeviation / stats.Median * 100); + + Assert.IsTrue(stats.Mean < maximumAllowedUnitTime, "The mean time of {0} exceeded the maximum allowable of {1}.", stats.Mean, maximumAllowedUnitTime); + TestUtilities.TestLogger.InfoFormat("Within {0}% of the maximum allowed time of {1}.", Math.Round((maximumAllowedUnitTime - stats.Mean) / maximumAllowedUnitTime * 100, 1), maximumAllowedUnitTime); + + return stats; + } + /// <summary> /// Sets HttpContext.Current to some empty (but non-null!) value. /// </summary> @@ -73,15 +103,5 @@ namespace DotNetOpenAuth.Test { new HttpRequest("mock", "http://mock", "mock"), new HttpResponse(new StringWriter())); } - -#pragma warning disable 0618 - protected internal static void SuspendLogging() { - LogManager.GetLoggerRepository().Threshold = LogManager.GetLoggerRepository().LevelMap["OFF"]; - } - - protected internal static void ResumeLogging() { - LogManager.GetLoggerRepository().Threshold = LogManager.GetLoggerRepository().LevelMap["ALL"]; - } -#pragma warning restore 0618 } } |