public void IncrementTest() { var testId = "PulseUnitTest"; var message = "Hello World"; HealthCounterRepository.Increment(testId, message); var res = HealthCounterRepository.ProbeAndPrune().ToList(); Assert.That(res.Count, Is.EqualTo(1)); var entry = res[0]; Assert.That(entry.Count, Is.EqualTo(1)); Assert.That(entry.Id, Is.EqualTo(testId)); Assert.That(entry.Message, Is.EqualTo(message)); Assert.That(entry.TimeStamp, Is.EqualTo(TimeProvider.GetUtcNow())); TimeProvider.Step(TimeSpan.FromSeconds(5)); HealthCounterRepository.Increment(testId, message + "2"); res = HealthCounterRepository.ProbeAndPrune().ToList(); Assert.That(res.Count, Is.EqualTo(1)); entry = res[0]; Assert.That(entry.Count, Is.EqualTo(2)); Assert.That(entry.Id, Is.EqualTo(testId)); Assert.That(entry.Message, Is.EqualTo(message + "2")); Assert.That(entry.TimeStamp, Is.EqualTo(TimeProvider.GetUtcNow())); TimeProvider.Step(MaxAge + TimeSpan.FromSeconds(5)); HealthCounterRepository.Increment(testId, message + "3"); res = HealthCounterRepository.ProbeAndPrune().ToList(); entry = res[0]; Assert.That(entry.Count, Is.EqualTo(1)); }
private void Pulse(object source, ElapsedEventArgs eea) { try { var potentialErrorSleep = ErrorSleepConfiguration .First(cfg => cfg.Key <= _pulseErrorCount).Value; if (_pluseLastError + potentialErrorSleep > _timeProvider.GetUtcNow()) { return; // noop because of error, longer and longer sleep. } try { _executor.Pulse(); _pulseErrorCount = 0; } catch (Exception e) { _pluseLastError = _timeProvider.GetUtcNow(); _logging.LogException(e, $"Executor failed to pulse. Successive error count : {++_pulseErrorCount}"); _healthCounterRepository.Increment(nameof(Executor.Executor), e.Message); } #if DEBUG var status = _executor.GetStatus(); foreach (var pluginStatus in status.PluginStatuses) { Console.Write($"{pluginStatus.SourceUrn} : "); if (pluginStatus.Busy && pluginStatus.CurrentTask == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("MISSING NODE"); } else if (pluginStatus.Busy) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("BUSY"); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("FREE"); } Console.ForegroundColor = ConsoleColor.Gray; } Console.WriteLine($"Last Executor pulse @ {_timeProvider.GetUtcNow().ToLocalTime()}"); #endif } catch { //ignore } finally { try { _timer.Start(); } catch (ObjectDisposedException) { // ignore } } }