public void ReportBackoffWriteIsLoggedAgainAfterReportDisabledWasCalled()
            {
                using (var listener = new TestEventListener())
                {
                    const long AllKeywords = -1;
                    listener.EnableEvents(TelemetryChannelEventSource.Log, EventLevel.Error, (EventKeywords)AllKeywords);

                    var manager = new BackoffLogicManager(TimeSpan.Zero);

                    manager.ReportBackoffEnabled(200);
                    manager.ReportBackoffEnabled(200);

                    manager.ReportBackoffDisabled();
                    manager.ReportBackoffDisabled();

                    manager.ReportBackoffEnabled(200);
                    manager.ReportBackoffEnabled(200);

                    var traces = listener.Messages.ToList();
                    Assert.Equal(3, traces.Count);
                    Assert.Equal(2, traces[0].EventId);
                    Assert.Equal(1, traces[1].EventId);
                    Assert.Equal(2, traces[2].EventId);
                }
            }
            public void IncrementConsecutiveErrorsAfterMinIntervalToUpdateConsecutiveErrorsPassed()
            {
                BackoffLogicManager manager = new BackoffLogicManager(TimeSpan.Zero, TimeSpan.FromMilliseconds(1));

                manager.ReportBackoffEnabled(500);
                Thread.Sleep(1);
                manager.ReportBackoffEnabled(500);

                Assert.Equal(2, manager.ConsecutiveErrors);
            }
            public void FirstErrorDelayIsSameAsSlotDelay()
            {
                var manager = new BackoffLogicManager(TimeSpan.Zero);

                manager.ReportBackoffEnabled(500);
                manager.GetBackOffTimeInterval(string.Empty);
                Assert.Equal(TimeSpan.FromSeconds(10), manager.CurrentDelay);
            }
Example #4
0
            public void ReportBackoffWriteDoesNotLogMessagesBeforeIntervalPasses()
            {
                using (var listener = new TestEventListener())
                {
                    const long AllKeywords = -1;
                    listener.EnableEvents(TelemetryChannelEventSource.Log, EventLevel.Error, (EventKeywords)AllKeywords);

                    var manager = new BackoffLogicManager(TimeSpan.FromSeconds(20));

                    manager.ReportBackoffEnabled(200);
                    manager.ReportBackoffEnabled(200);

                    var traces = listener.Messages.ToList();

                    Assert.Equal(0, traces.Count);
                }
            }
Example #5
0
            public void FirstErrorDelayIsSameAsSlotDelay()
            {
                var manager = new BackoffLogicManager(TimeSpan.Zero);

                manager.ReportBackoffEnabled(500);
                manager.ScheduleRestore(string.Empty, () => null);
                Assert.Equal(TimeSpan.FromSeconds(10), manager.CurrentDelay);
            }
            public void ConsecutiveErrorsCanAlwaysBeResetTo0()
            {
                BackoffLogicManager manager = new BackoffLogicManager(TimeSpan.Zero, TimeSpan.FromDays(1));

                manager.ReportBackoffEnabled(500);
                manager.ResetConsecutiveErrors();

                Assert.Equal(0, manager.ConsecutiveErrors);
            }
            public void ReportBackoffWriteDoesNotLogMessagesBeforeIntervalPasses()
            {
                // this test fails when run in parallel with other tests
                using (var listener = new TestEventListener(waitForDelayedEvents: false))
                {
                    const long AllKeywords = -1;
                    listener.EnableEvents(TelemetryChannelEventSource.Log, EventLevel.Error, (EventKeywords)AllKeywords);

                    var manager = new BackoffLogicManager(TimeSpan.FromSeconds(20));

                    manager.ReportBackoffEnabled(200);
                    manager.ReportBackoffEnabled(200);

                    var traces = listener.Messages.ToList();

                    Assert.AreEqual(0, traces.Count);
                }
            }
            public void ReportBackoffWritesLogMessagesAfterIntervalPasses()
            {
                using (var listener = new TestEventListener())
                {
                    const long AllKeywords = -1;
                    listener.EnableEvents(TelemetryChannelEventSource.Log, EventLevel.Error, (EventKeywords)AllKeywords);

                    var manager = new BackoffLogicManager(TimeSpan.FromMilliseconds(10));

                    System.Threading.Thread.Sleep(10);

                    manager.ReportBackoffEnabled(200);
                    manager.ReportBackoffEnabled(200);

                    var traces = listener.Messages.ToList();

                    Assert.Equal(1, traces.Count);
                }
            }
            public void DoNotIncrementConsecutiveErrorsMoreOftenThanOnceInminIntervalToUpdateConsecutiveErrors()
            {
                BackoffLogicManager manager = new BackoffLogicManager(TimeSpan.Zero, TimeSpan.FromDays(1));

                Task[] tasks = new Task[10];
                for (int i = 0; i < 10; ++i)
                {
                    tasks[i] = TaskEx.Run(() => manager.ReportBackoffEnabled(500));
                }

                Task.WaitAll(tasks);

                Assert.Equal(1, manager.ConsecutiveErrors);
            }