Пример #1
0
        public void UsableIfBufferOverflowOccurs()
        {
            Mock <IHealthReporter> healthReporterMock = new Mock <IHealthReporter>();
            var            deterministicTaskScheduler = new DeterministicTaskScheduler();
            UnitTestOutput unitTestOutput             = new UnitTestOutput();
            DiagnosticPipelineConfiguration settings  = new DiagnosticPipelineConfiguration()
            {
                MaxBatchDelayMsec             = 10,
                PipelineCompletionTimeoutMsec = 5000,
                PipelineBufferSize            = 1,
                MaxConcurrency    = 1,
                MaxEventBatchSize = 1
            };
            const int TestBatchSize = 6;

            using (UnitTestInput unitTestInput = new UnitTestInput())
                using (DiagnosticPipeline pipeline = new DiagnosticPipeline(
                           healthReporterMock.Object,
                           new IObservable <EventData>[] { unitTestInput },
                           null,
                           new EventSink[] { new EventSink(unitTestOutput, null) },
                           settings,
                           disposeDependencies: false,
                           taskScheduler: deterministicTaskScheduler))
                {
                    // Six events in quick succession will cause a buffer overflow
                    // (we have a buffer of 1 set for the pipeline, but the pipeline has 3 blocks, so the actual buffer space is 3).
                    // There should be no ill effects from that on the input--not catching any exceptions.
                    for (int i = 0; i < TestBatchSize; i++)
                    {
                        unitTestInput.SendMessage($"Message {i}");
                    }

                    // Wait for the pipeline to drain
                    deterministicTaskScheduler.RunTasksUntilIdle();

                    Assert.True(unitTestOutput.CallCount > 0, "At least one message should get to the output");

                    // We should get a warning about throttling
                    healthReporterMock.Verify(o => o.ReportWarning(It.IsAny <string>(), It.Is <string>(s => s == EventFlowContextIdentifiers.Throttling)), Times.AtLeastOnce());

                    // Pipeline should still be usable after this. Let's try to send a message through it.
                    unitTestOutput.CallCount = 0;
                    healthReporterMock.ResetCalls();
                    unitTestInput.SendMessage("Final message");

                    // Give the pipeline a chance to process the message
                    deterministicTaskScheduler.RunTasksUntilIdle();

                    // The message should have come through.
                    Assert.Equal(1, unitTestOutput.CallCount);

                    // There should be no new warnings or errors
                    healthReporterMock.Verify(o => o.ReportWarning(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
                    healthReporterMock.Verify(o => o.ReportProblem(It.IsAny <string>(), It.IsAny <string>()), Times.Never());
                }
        }
Пример #2
0
        public void ShouldUpdateTheStatusWhenDoAsync()
        {
            // Arrange
            DeterministicTaskScheduler taskScheduler = new DeterministicTaskScheduler();
            SystemUnderTest            sut           = new SystemUnderTest(taskScheduler);

            Assert.AreEqual("Nothing done", sut.Status);

            // Act
            sut.DoAsync(); // starts a new task and returns immediately
            Assert.AreEqual("Starting task", sut.Status);
            // Now execute the new task
            taskScheduler.RunTasksUntilIdle();

            // Assert
            Assert.AreEqual("Task done", sut.Status);
        }