示例#1
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);
        }
示例#2
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;
 }