Example #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));
        }
Example #2
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));
                }
        }