diff --git a/src/Horarium.Test/RunnerJobTest.cs b/src/Horarium.Test/RunnerJobTest.cs index 6f6ee74..f445ea7 100644 --- a/src/Horarium.Test/RunnerJobTest.cs +++ b/src/Horarium.Test/RunnerJobTest.cs @@ -131,5 +131,87 @@ public async Task Start_ExecutionWithDelay_WithThrottle() // Assert jobRepositoryMock.Verify(r => r.GetReadyJob(It.IsAny(), It.IsAny()), Times.Once); } + + [Fact] + public async Task Start_ExecutionWithDelay_IncreaseInterval() + { + // Arrange + var jobRepositoryMock = new Mock(); + + jobRepositoryMock.Setup(x => x.GetReadyJob(It.IsAny(), It.IsAny())) + .ReturnsAsync(() => null); + + var settings = new HorariumSettings + { + IntervalStartJob = TimeSpan.FromSeconds(1), + JobThrottleSettings = new JobThrottleSettings + { + UseJobThrottle = true, + IntervalMultiplier = 1, + JobRetrievalAttempts = 1, + } + }; + + var runnerJobs = new RunnerJobs(jobRepositoryMock.Object, + settings, + new JsonSerializerSettings(), + Mock.Of(), + Mock.Of()); + + // Act + runnerJobs.Start(); + await Task.Delay(settings.IntervalStartJob - TimeSpan.FromMilliseconds(500)); + jobRepositoryMock.Invocations.Clear(); + + var interval = settings.IntervalStartJob + + settings.IntervalStartJob.Multiply(settings.JobThrottleSettings.IntervalMultiplier); + await Task.Delay(interval); + interval += settings.IntervalStartJob.Multiply(settings.JobThrottleSettings.IntervalMultiplier); + await Task.Delay(interval); + interval += settings.IntervalStartJob.Multiply(settings.JobThrottleSettings.IntervalMultiplier); + await Task.Delay(interval); + + // Assert + jobRepositoryMock.Verify(r => r.GetReadyJob(It.IsAny(), It.IsAny()), Times.Exactly(3)); + } + + [Fact] + public async Task Start_ExecutionWithDelay_MaxInterval() + { + // Arrange + var jobRepositoryMock = new Mock(); + + jobRepositoryMock.Setup(x => x.GetReadyJob(It.IsAny(), It.IsAny())) + .ReturnsAsync(() => null); + + var settings = new HorariumSettings + { + IntervalStartJob = TimeSpan.FromSeconds(1), + JobThrottleSettings = new JobThrottleSettings + { + UseJobThrottle = true, + IntervalMultiplier = 1, + JobRetrievalAttempts = 1, + MaxJobThrottleInterval = TimeSpan.FromSeconds(1) + } + }; + + var runnerJobs = new RunnerJobs(jobRepositoryMock.Object, + settings, + new JsonSerializerSettings(), + Mock.Of(), + Mock.Of()); + + // Act + runnerJobs.Start(); + await Task.Delay(settings.IntervalStartJob - TimeSpan.FromMilliseconds(500)); + jobRepositoryMock.Invocations.Clear(); + + await Task.Delay(TimeSpan.FromSeconds(5)); + + // Assert + jobRepositoryMock.Verify(r => r.GetReadyJob(It.IsAny(), It.IsAny()), Times.Exactly(5)); + } + } } \ No newline at end of file