public RunContext(RunContextParam parameters) { GrandOutput = CreateGrandOutputWithFakeHandler(parameters.HandlerExtraLoad, parameters.UseLocalTestStrategy, parameters.DispatcherMaxCapacity); LoopCount = parameters.LoopCount; Barrier = new Barrier(parameters.PoolThreadCount + parameters.NewThreadCount + 1); _newThreadCount = parameters.NewThreadCount; }
public RunContext( RunContextParam parameters ) { GrandOutput = CreateGrandOutputWithFakeHandler( parameters.HandlerExtraLoad, parameters.UseLocalTestStrategy, parameters.DispatcherMaxCapacity ); LoopCount = parameters.LoopCount; Barrier = new Barrier( parameters.PoolThreadCount + parameters.NewThreadCount + 1 ); _newThreadCount = parameters.NewThreadCount; }
public void ThroughputHypothesisAndBlockInputs() { RunContextParam p = new RunContextParam(); Assert.That(p.SendingThreadProbToSleep == 0); RunStressTestAndGetLostMessageCount(p); p.SendingThreadProbToSleep = 0.1; do { p.SendingThreadProbToSleep += 0.1; if (p.SendingThreadProbToSleep > 1.0) { break; } }while(RunStressTestAndGetLostMessageCount(p) > 0); }
static int RunStressTestAndGetLostMessageCount(RunContextParam p) { TestHelper.ConsoleMonitor.Info().Send("Prob to sleep: {0}", p.SendingThreadProbToSleep); int nbThreads = p.PoolThreadCount + p.NewThreadCount; int criticalErrorCount = 0; EventHandler <SystemActivityMonitor.LowLevelErrorEventArgs> h = (sender, e) => ++ criticalErrorCount; SystemActivityMonitor.OnError += h; int nbLost = 0; int maxQueuedCount = 0; try { int nbCalls = 0; using (RunContext c = new RunContext(p)) { c.RunAndGetPerfTraceCount((context, monitor, random) => { Interlocked.Increment(ref nbCalls); using (monitor.OpenTrace().Send("A group...")) { monitor.Trace().Send("PerfTrace: {0}", context.IncrementPerfTrace()); if (p.SendingThreadProbToSleep > random.NextDouble()) { int ms = random.Next(10); Thread.Sleep(ms); } } }); Assert.That(nbCalls, Is.EqualTo(nbThreads * p.LoopCount)); nbLost = c.GrandOutput.LostEventCount; maxQueuedCount = c.GrandOutput.MaxQueuedCount; } ActivityMonitor.CriticalErrorCollector.WaitOnErrorFromBackgroundThreadsPending(); } finally { SystemActivityMonitor.OnError -= h; } int theoricalTotal = nbThreads * p.LoopCount * 3; int receivedTotal = CK.Monitoring.GrandOutputHandlers.FakeHandler.TotalHandleCount; TestHelper.ConsoleMonitor.Info().Send("Local Test Strategy:{6} - Total should be {0}, Total received = {1}, Binary size = {2}, MaxQueuedCount={3}, Number of lost messages={4}, Number of Critical Errors={5}.", theoricalTotal, receivedTotal, CK.Monitoring.GrandOutputHandlers.FakeHandler.SizeHandled, maxQueuedCount, nbLost, criticalErrorCount, p.UseLocalTestStrategy); if (receivedTotal == theoricalTotal) { Assert.That(CK.Monitoring.GrandOutputHandlers.FakeHandler.HandlePerfTraceCount, Is.EqualTo(nbThreads * p.LoopCount)); } else { Assert.That(criticalErrorCount > 0); Assert.That(receivedTotal, Is.EqualTo(theoricalTotal - nbLost)); } return(nbLost); }
public void ThroughputHypothesisAndBlockInputs() { RunContextParam p = new RunContextParam(); Assert.That( p.SendingThreadProbToSleep == 0 ); RunStressTestAndGetLostMessageCount( p ); p.SendingThreadProbToSleep = 0.1; do { p.SendingThreadProbToSleep += 0.1; if( p.SendingThreadProbToSleep > 1.0 ) break; } while( RunStressTestAndGetLostMessageCount( p ) > 0 ); }
static int RunStressTestAndGetLostMessageCount( RunContextParam p ) { TestHelper.ConsoleMonitor.Info().Send( "Prob to sleep: {0}", p.SendingThreadProbToSleep ); int nbThreads = p.PoolThreadCount + p.NewThreadCount; int criticalErrorCount = 0; EventHandler<SystemActivityMonitor.LowLevelErrorEventArgs> h = ( sender, e ) => ++criticalErrorCount; SystemActivityMonitor.OnError += h; int nbLost = 0; int maxQueuedCount = 0; try { int nbCalls = 0; using( RunContext c = new RunContext( p ) ) { c.RunAndGetPerfTraceCount( ( context, monitor, random ) => { Interlocked.Increment( ref nbCalls ); using( monitor.OpenTrace().Send( "A group..." ) ) { monitor.Trace().Send( "PerfTrace: {0}", context.IncrementPerfTrace() ); if( p.SendingThreadProbToSleep > random.NextDouble() ) { int ms = random.Next( 10 ); Thread.Sleep( ms ); } } } ); Assert.That( nbCalls, Is.EqualTo( nbThreads * p.LoopCount ) ); nbLost = c.GrandOutput.LostEventCount; maxQueuedCount = c.GrandOutput.MaxQueuedCount; } ActivityMonitor.CriticalErrorCollector.WaitOnErrorFromBackgroundThreadsPending(); } finally { SystemActivityMonitor.OnError -= h; } int theoricalTotal = nbThreads * p.LoopCount * 3; int receivedTotal = CK.Monitoring.GrandOutputHandlers.FakeHandler.TotalHandleCount; TestHelper.ConsoleMonitor.Info().Send( "Local Test Strategy:{6} - Total should be {0}, Total received = {1}, Binary size = {2}, MaxQueuedCount={3}, Number of lost messages={4}, Number of Critical Errors={5}.", theoricalTotal, receivedTotal, CK.Monitoring.GrandOutputHandlers.FakeHandler.SizeHandled, maxQueuedCount, nbLost, criticalErrorCount, p.UseLocalTestStrategy ); if( receivedTotal == theoricalTotal ) { Assert.That( CK.Monitoring.GrandOutputHandlers.FakeHandler.HandlePerfTraceCount, Is.EqualTo( nbThreads * p.LoopCount ) ); } else { Assert.That( criticalErrorCount > 0 ); Assert.That( receivedTotal, Is.EqualTo( theoricalTotal - nbLost ) ); } return nbLost; }