summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Test/TestBase.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2011-06-09 17:14:03 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2011-06-09 17:14:03 -0700
commita921328045f5711fa4136a1f57d5db4745117905 (patch)
treefe2d7cfa663bdd22d4a85f3b19f9a66636610763 /src/DotNetOpenAuth.Test/TestBase.cs
parent2751e08721af51437ae5738e2da23dd460df6cc8 (diff)
parentd916633668329aa07f0b6f2ee952268a5dff8069 (diff)
downloadDotNetOpenAuth-a921328045f5711fa4136a1f57d5db4745117905.zip
DotNetOpenAuth-a921328045f5711fa4136a1f57d5db4745117905.tar.gz
DotNetOpenAuth-a921328045f5711fa4136a1f57d5db4745117905.tar.bz2
Merge branch 'v3.4' into sample2legged
Diffstat (limited to 'src/DotNetOpenAuth.Test/TestBase.cs')
-rw-r--r--src/DotNetOpenAuth.Test/TestBase.cs40
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
}
}