public async Task HandleTimerEvent_HandlesExceptions() { // force an exception to occur outside of the function invocation path var ex = new Exception("Kaboom!"); _mockScheduleMonitor.Setup(p => p.UpdateStatusAsync(_testTimerName, It.IsAny <ScheduleStatus>())).ThrowsAsync(ex); var listener = new TimerListener(_attribute, _schedule, _testTimerName, _options, _mockTriggerExecutor.Object, _logger, _mockScheduleMonitor.Object, _functionShortName); Assert.Null(listener.Timer); await listener.HandleTimerEvent(); // verify the timer was started Assert.NotNull(listener.Timer); Assert.True(listener.Timer.Enabled); var logs = _logger.GetLogMessages(); var log = logs[0]; Assert.Equal(LogLevel.Error, log.Level); Assert.Equal("Error occurred during scheduled invocation for 'TimerFunctionShortName'.", log.FormattedMessage); Assert.Same(ex, log.Exception); log = logs[1]; Assert.Equal(LogLevel.Debug, log.Level); Assert.True(log.FormattedMessage.StartsWith("Timer for 'TimerFunctionShortName' started with interval")); listener.Dispose(); }
public async Task InvokeJobFunction_UpdatesScheduleMonitor() { DateTime lastOccurrence = DateTime.Now; DateTime nextOccurrence = _schedule.GetNextOccurrence(lastOccurrence); _mockScheduleMonitor.Setup(p => p.UpdateStatusAsync(_testTimerName, It.Is <ScheduleStatus>(q => q.Last == lastOccurrence && q.Next == nextOccurrence))) .Returns(Task.FromResult(true)); await _listener.InvokeJobFunction(lastOccurrence, false); _listener.Dispose(); }
public async Task InvokeJobFunction_UpdatesScheduleMonitor() { DateTime lastOccurrence = DateTime.Now; DateTime nextOccurrence = _attribute.Schedule.GetNextOccurrence(lastOccurrence); _mockScheduleMonitor.Setup(p => p.UpdateAsync(_testTimerName, lastOccurrence, nextOccurrence)).Returns(Task.FromResult(true)); await _listener.InvokeJobFunction(lastOccurrence, false); _listener.Dispose(); }