public void ProfileSession_SetIterations()
        {
            var session = ProfilerSession.StartSession()
                          .SetIterations(12);

            Assert.AreEqual(12, session.Settings.Iterations);
        }
        public void ProfileSession_SetDuration()
        {
            var session = ProfilerSession.StartSession()
                          .SetDuration(TimeSpan.FromSeconds(1));

            Assert.AreEqual(TimeSpan.FromSeconds(1), session.Settings.Duration);
        }
        public void ProfileSession_Executino_Default()
        {
            var session = ProfilerSession.StartSession()
                          .Task(c => { });

            Assert.IsInstanceOf <SimpleTaskExecution>(session.Settings.Execution);
        }
 public void ProfilesSessionExtension_AfterPostExecuteTask_EnsureContext()
 {
     var session = ProfilerSession.StartSession()
                   .PostExecute(c => c.Clear())
                   .PreExecute(c =>
     {
         c.Set("pre", "before");
         Assert.That(c.Get <string>("post") == null);
         Assert.That(c.Get <string>("task") == null);
     })
                   .Task(c =>
     {
         c.Set("task", "Task");
         Assert.That(c.Get <string>("pre") == "before");
         Assert.That(c.Get <string>("post") == null);
     })
                   .PostExecute(c =>
     {
         c.Set("post", "after");
         Assert.That(c.Get <string>("pre") == "before");
         Assert.That(c.Get <string>("task") == "Task");
     })
                   .SetIterations(10)
                   .RunSession();
 }
        public void ProfileSession_SetDuration_Runner()
        {
            var session = ProfilerSession.StartSession()
                          .SetDuration(TimeSpan.FromSeconds(1));

            session.Settings.Runner.Should().BeOfType <DurationRunner>();
        }
 public void ProfilesSessionExtension_AfterPostExecuteTask_MultiplePrePost()
 {
     var session = ProfilerSession.StartSession()
                   .PreExecute(c => Assert.That(c.SessionData.Count <= 1))
                   .PreExecute(c =>
     {
         c.Set("pre", "before");
         Assert.That(c.Get <string>("post") == null);
         Assert.That(c.Get <string>("task") == null);
     })
                   .PostExecute(c =>
     {
         Assert.That(c.SessionData.Count > 0);
         c.Clear();
     })
                   .PostExecute(c =>
     {
         c.Set("post", "after");
         Assert.That(c.Get <string>("pre") == "before");
         Assert.That(c.Get <string>("task") == "Task");
     })
                   .Task(c =>
     {
         c.Set("task", "Task");
         Assert.That(c.Get <string>("pre") == "before");
         Assert.That(c.Get <string>("post") == null);
     })
                   .SetIterations(10)
                   .RunSession();
 }
        public void ProfileSession_SetIterations_Runner()
        {
            var session = ProfilerSession.StartSession()
                          .SetIterations(1);

            session.Settings.Runner.Should().BeOfType <IterationRunner>();
        }
Example #8
0
        public void LoadTesting_MultipleProcessors()
        {
            GlobalConfiguration.Setup(s => s.UseOptions(new Options
            {
                MaxItemsInQueue = 10,
                MinProcessors   = 10,
                MaxProcessors   = 50
            }));

            var pipelineId = Guid.NewGuid().ToString();
            var config     = new PipelineConfiguration
            {
                Id             = pipelineId,
                InputHandler   = new HandlerNode("CustomInput"),
                OutputHandlers = new List <HandlerNode>
                {
                    new HandlerNode("ConsoleOutput")
                    {
                        Filters = new List <string>
                        {
                            "Message -> msg",
                            "Level -> lvl"
                        }
                    },
                    new HandlerNode(typeof(ThreadWaitHandler))
                }
            };

            var builder = new PipelineBuilder();

            builder.BuildPipeline(config);

            var result = ProfilerSession.StartSession()
                         .Task(ctx =>
            {
                var client = new EventDispatcher();
                client.Process(pipelineId, new LogMessage {
                    Level = "Info", Message = $"Loadtesting {ctx.Get<int>(ContextKeys.Iteration)} on Thread {ctx.Get<int>(ContextKeys.ThreadId)}", Title = "Loadtest"
                });
            })
                         .SetIterations(100)
                         .SetThreads(10)
                         .Settings(s => s.RunWarmup = false)
                         .RunSession();

            ProcessingServer.Server.WaitAll(pipelineId);

            // delay to ensure all threads are ended
            System.Threading.Tasks.Task.Delay(3000);

            var storage = GlobalConfiguration.Configuration.Resolve <IStorage>();

            Assert.GreaterOrEqual(100 * 10, storage.Get <long>(new StorageKey(pipelineId, "ProcessedEventsMetric")));

            var stats = new StatisticsApi(pipelineId);

            Assert.AreEqual(10, stats.GetMetricValue(MetricType.ThreadCount));

            result.Trace("### LoadTesting");
        }
Example #9
0
 public void Acceptance_TrueCondition()
 {
     ProfilerSession.StartSession()
     .Task(Task)
     .Assert(pr => pr.Iterations.Count() == 1)
     .RunSession();
 }
        public void ProfilesSessionExtension_AfterPostExecuteTask_EnsureOrder()
        {
            string one   = null;
            string two   = null;
            string three = null;

            var session = ProfilerSession.StartSession()
                          .PreExecute(() => three = "before")
                          .PostExecute(() =>
            {
                one   = two;
                two   = three;
                three = "after";
            })
                          .Task(() =>
            {
                two   = three;
                three = "task";
            })
                          .RunSession();

            Assert.That(three == "after");
            Assert.That(two == "task");
            Assert.That(one == "before");
        }
Example #11
0
 public void Acceptance_MultipleTrueCondition()
 {
     ProfilerSession.StartSession()
     .Task(Task)
     .Assert(pr => pr.Iterations.Count() == 1)
     .Assert(pr => pr.AverageMilliseconds > 0)
     .RunSession();
 }
        public void ProfileSession_Interval()
        {
            var session = ProfilerSession.StartSession()
                          .Task(c => { })
                          .SetInterval(TimeSpan.FromSeconds(.5));

            Assert.IsInstanceOf <TimedTaskExecution>(session.Settings.Execution);
        }
Example #13
0
 public void Acceptance_FalseCondition()
 {
     Assert.Throws <MeasureMap.AssertionException>(() => ProfilerSession.StartSession()
                                                   .Task(Task)
                                                   .SetIterations(2)
                                                   .Assert(pr => pr.Iterations.Count() == 1)
                                                   .RunSession());
 }
        public void ProfileSession_SetOptioins_After_Duration()
        {
            var session = ProfilerSession.StartSession()
                          .SetDuration(TimeSpan.FromSeconds(1))
                          .SetSettings(new ProfilerSettings());

            session.Settings.Duration.Should().Be(TimeSpan.FromSeconds(1));
        }
        public void ProfileSession_SetOptioins_After_Iterations()
        {
            var session = ProfilerSession.StartSession()
                          .SetIterations(10)
                          .SetSettings(new ProfilerSettings());

            session.Settings.Iterations.Should().Be(10);
        }
        public void ProfileSession_SetDuration_TotalTime()
        {
            var result = ProfilerSession.StartSession()
                         .SetDuration(TimeSpan.FromSeconds(1))
                         .Task(() => { })
                         .RunSession();

            result.Elapsed().Should().BeGreaterThan(TimeSpan.FromSeconds(1)).And.BeLessThan(TimeSpan.FromSeconds(1.5));
        }
        public void ProfileSession_AverageTicks()
        {
            var result = ProfilerSession.StartSession()
                         .Task(Task)
                         .SetIterations(200)
                         .RunSession();

            Assert.IsTrue(result.AverageTicks > 0);
        }
Example #18
0
        public void ProfilerSettings_SetFromSession()
        {
            var session = ProfilerSession.StartSession()
                          .Settings(s =>
            {
                s.Iterations = 120;
            });

            session.Settings.Iterations.Should().Be(120);
        }
        public void ProfileSession_SetDuration_Iterations()
        {
            var cnt    = 0;
            var result = ProfilerSession.StartSession()
                         .SetDuration(TimeSpan.FromSeconds(1))
                         .Task(() => { cnt++; })
                         .RunSession();

            result.Iterations.Count().Should().BeGreaterThan(100);
        }
Example #20
0
        public void Acceptance_RunSessionOnce()
        {
            int count  = 0;
            var result = ProfilerSession.StartSession()
                         .Task(() => count++)
                         .RunSession();

            // the task is rune once more to be able to initialize properly
            Assert.AreEqual(result.Iterations.Count() + 1, count);
        }
Example #21
0
        public void LoadTest_HeavyWork()
        {
            // start with the warmup...
            var cnt  = 0;
            var proc = 0;

            var pipelineId = Guid.NewGuid().ToString();

            var server = new ProcessingServer();

            server.Register(pipelineId, () =>
            {
                var pipeline = new EventPipeline();
                pipeline.AddHandler(new LoadTestOuptuHandler(e =>
                {
                    proc += 1;
                    // do some heavy work
                    Thread.Sleep(100);
                }));

                return(pipeline);
            });
            server.Register(pipelineId, new InputHandler <InputItem>());



            var client = new EventDispatcher(server);

            var profiler = ProfilerSession.StartSession()
                           .SetIterations(1000)
                           .SetThreads(5)
                           .Task(() =>
            {
                lock (pipelineId)
                {
                    cnt += 1;
                }

                client.Process(pipelineId, new InputItem
                {
                    Value  = "StaticServer",
                    Name   = "test",
                    Number = cnt
                });
            }).RunSession();

            server.WaitAll(pipelineId);
            profiler.Trace();

            var monitor   = new StatisticsApi(pipelineId);
            var processed = monitor.GetMetricValue <long>(MetricType.ProcessedEvents);

            Assert.AreEqual(processed, cnt, "Processed events are not equal to sent events {0} to {1}", processed, cnt);
        }
        public void ProfilesSessionExtension_PostExecuteTask()
        {
            bool initialized = false;

            var session = ProfilerSession.StartSession()
                          .PostExecute(() => initialized = true)
                          .Task(() => Thread.Sleep(TimeSpan.FromSeconds(0.05)))
                          .RunSession();

            Assert.That(initialized);
        }
        public void ProfileSession_SetDuration_TaskExecutions()
        {
            var cnt = 0;

            ProfilerSession.StartSession()
            .SetDuration(TimeSpan.FromSeconds(1))
            .Task(() => { cnt++; })
            .RunSession();

            cnt.Should().BeGreaterThan(100);
        }
        public void ProfileSession_Delay_TimePerIteration()
        {
            var result = ProfilerSession.StartSession()
                         .SetIterations(2)
                         .RunWarmup(false)
                         .AddDelay(TimeSpan.FromSeconds(1))
                         .Task(() => { })
                         .RunSession();

            result.Iterations.Should().OnlyContain(i => i.Duration < TimeSpan.FromSeconds(1));
        }
Example #25
0
        public void MemoryProfileSession_RunSessionMultipleTimes()
        {
            int count  = 0;
            var result = ProfilerSession.StartSession()
                         .Task(() => count++)
                         .SetIterations(20)
                         .RunSession();

            // the task is rune once more to be able to initialize properly
            Assert.AreEqual(result.Iterations.Count() + 1, count);
        }
Example #26
0
        public void Acceptance_Duration()
        {
            int count  = 0;
            var result = ProfilerSession.StartSession()
                         .Task(() => count++)
                         .SetDuration(TimeSpan.FromSeconds(1))
                         .RunSession();

            // the task is rune once more to be able to initialize properly
            result.Iterations.Count().Should().BeGreaterThan(10);
        }
Example #27
0
        public void Acceptance_AddTask()
        {
            var result  = string.Empty;
            var session = ProfilerSession.StartSession()
                          .Task(() => result = "passed");

            // TODO: is it neccesary to run the session just to check if a task is set???
            session.RunSession();

            Assert.AreEqual("passed", result);
        }
Example #28
0
        public void Acceptance_Setup()
        {
            var count = 0;

            ProfilerSession.StartSession()
            .Setup(() => count += 1)
            .Task(Task)
            .SetIterations(10)
            .RunSession();

            Assert.That(count == 1);
        }
        public void WarmupSessionHandler_Disable()
        {
            var count = 0;

            ProfilerSession.StartSession()
            .Task(() => count += 1)
            .SetSettings(new ProfilerSettings {
                Iterations = 10, RunWarmup = false
            })
            .RunSession();

            Assert.That(count == 10);
        }
        public void WarmupSessionHandler_Enabled()
        {
            var count = 0;

            ProfilerSession.StartSession()
            .Task(() => count += 1)
            .SetSettings(new ProfilerSettings {
                Iterations = 10
            })
            .RunSession();

            Assert.That(count == 11);
        }