示例#1
0
        public void UsableIfExceptionInOutputSpecificFilterOccurs()
        {
            Mock <IHealthReporter>          healthReporterMock = new Mock <IHealthReporter>();
            UnitTestOutput                  unitTestOutput     = new UnitTestOutput();
            DiagnosticPipelineConfiguration settings           = new DiagnosticPipelineConfiguration()
            {
                MaxBatchDelayMsec             = 10,
                PipelineCompletionTimeoutMsec = 10000,
                MaxEventBatchSize             = 2
            };
            UnitTestFilter unitTestFilter = new UnitTestFilter();

            unitTestFilter.EvaluationFailureCondition = "Trouble == true";
            const int TestEventCount = 6;
            DateTime  pipelineDisposalStart;

            using (UnitTestInput unitTestInput = new UnitTestInput())
                using (DiagnosticPipeline pipeline = new DiagnosticPipeline(
                           healthReporterMock.Object,
                           new IObservable <EventData>[] { unitTestInput },
                           null,
                           new EventSink[] { new EventSink(unitTestOutput, new IFilter[] { unitTestFilter }) },
                           settings))
                {
                    // Half of the events should cause filtering to fail with an exception
                    for (int i = 0; i < TestEventCount; i++)
                    {
                        if (i % 2 == 0)
                        {
                            unitTestInput.SendData(new Dictionary <string, object> {
                                ["Trouble"] = true
                            });
                        }
                        else
                        {
                            unitTestInput.SendMessage("Hi!");
                        }
                    }

                    pipelineDisposalStart = DateTime.Now;
                }

            // We should have got good events and warnings about bad events
            DateTime pipelineDisposalEnd = DateTime.Now;

            // We should have got good events and warnings about bad events
            Assert.True(TestEventCount / 2 == unitTestOutput.EventCount,
                        $"Events missing: expected: {TestEventCount / 2}, " +
                        $"actual: {unitTestOutput.EventCount}, " +
                        $"filter invocations: {unitTestFilter.CallCount}, " +
                        $"pipeline disposal time: {(pipelineDisposalEnd - pipelineDisposalStart).TotalMilliseconds} msec");

            healthReporterMock.Verify(o => o.ReportWarning(It.IsAny <string>(), It.Is <string>(s => s == EventFlowContextIdentifiers.Filtering)), Times.Exactly(TestEventCount / 2));
        }
示例#2
0
        public async Task CanDisposePipelineStuckInAFilter()
        {
            Mock <IHealthReporter> healthReporterMock = new Mock <IHealthReporter>();
            UnitTestOutput         unitTestOutput     = new UnitTestOutput();

            const int CompletionTimeoutMsec          = 1000;
            DiagnosticPipelineConfiguration settings = new DiagnosticPipelineConfiguration()
            {
                MaxBatchDelayMsec             = 10,
                PipelineCompletionTimeoutMsec = CompletionTimeoutMsec,
                MaxEventBatchSize             = 1,
                PipelineBufferSize            = 1,
                MaxConcurrency = 1
            };
            UnitTestFilter unitTestFilter = new UnitTestFilter();

            unitTestFilter.EvaluationDelay = TimeSpan.MaxValue;
            Stopwatch stopwatch;

            using (UnitTestInput unitTestInput = new UnitTestInput())
                using (DiagnosticPipeline pipeline = new DiagnosticPipeline(
                           healthReporterMock.Object,
                           new IObservable <EventData>[] { unitTestInput },
                           new IFilter[] { unitTestFilter },
                           new EventSink[] { new EventSink(unitTestOutput, null) },
                           settings))
                {
                    // Saturate the pipeline
                    for (int i = 0; i < 10; i++)
                    {
                        unitTestInput.SendMessage("Hi!");
                    }

                    // Wait a little bit for the pipeline to process messages and get stuck in the filter.
                    await Task.Delay(TimeSpan.FromMilliseconds(100));

                    stopwatch = Stopwatch.StartNew();
                }

            stopwatch.Stop();

            // We should have received no events on the output side--everything should have been stuck in the filter (or dropped because of buffer overflow)
            Assert.Equal(0, unitTestOutput.CallCount);

            // Ensure the pipeline stops within the timeout (plus some padding)
            Assert.InRange(stopwatch.ElapsedMilliseconds, 0, CompletionTimeoutMsec + 200);
        }
示例#3
0
        public async Task UsableIfExceptionInOutputSpecificFilterOccurs()
        {
            Mock <IHealthReporter>          healthReporterMock = new Mock <IHealthReporter>();
            UnitTestOutput                  unitTestOutput     = new UnitTestOutput();
            DiagnosticPipelineConfiguration settings           = new DiagnosticPipelineConfiguration()
            {
                MaxBatchDelayMsec             = 10,
                PipelineCompletionTimeoutMsec = 1000,
                MaxEventBatchSize             = 2
            };
            UnitTestFilter unitTestFilter = new UnitTestFilter();

            unitTestFilter.EvaluationFailureCondition = "Trouble == true";
            const int TestEventCount = 6;

            using (UnitTestInput unitTestInput = new UnitTestInput())
                using (DiagnosticPipeline pipeline = new DiagnosticPipeline(
                           healthReporterMock.Object,
                           new IObservable <EventData>[] { unitTestInput },
                           null,
                           new EventSink[] { new EventSink(unitTestOutput, new IFilter[] { unitTestFilter }) },
                           settings))
                {
                    // Half of the events should cause filtering to fail with an exception
                    for (int i = 0; i < TestEventCount; i++)
                    {
                        if (i % 2 == 0)
                        {
                            unitTestInput.SendData(new Dictionary <string, object> {
                                ["Trouble"] = true
                            });
                        }
                        else
                        {
                            unitTestInput.SendMessage("Hi!");
                        }
                    }

                    // Wait for the pipeline to drain.
                    await Task.Delay(TimeSpan.FromMilliseconds(300));

                    // We should have got good events and warnings about bad events
                    Assert.Equal(TestEventCount / 2, unitTestOutput.EventCount);
                    healthReporterMock.Verify(o => o.ReportWarning(It.IsAny <string>(), It.Is <string>(s => s == EventFlowContextIdentifiers.Filtering)), Times.Exactly(TestEventCount / 2));
                }
        }