Prevent back-off escalation during grace period.

pull/2279/head
Taloth Saldono 8 years ago
parent 87f3cc9014
commit 1fbe82ae47

@ -18,7 +18,7 @@ namespace NzbDrone.Core.Test.Download
_epoch = DateTime.UtcNow; _epoch = DateTime.UtcNow;
} }
private void WithStatus(DownloadClientStatus status) private DownloadClientStatus WithStatus(DownloadClientStatus status)
{ {
Mocker.GetMock<IDownloadClientStatusRepository>() Mocker.GetMock<IDownloadClientStatusRepository>()
.Setup(v => v.FindByProviderId(1)) .Setup(v => v.FindByProviderId(1))
@ -27,6 +27,8 @@ namespace NzbDrone.Core.Test.Download
Mocker.GetMock<IDownloadClientStatusRepository>() Mocker.GetMock<IDownloadClientStatusRepository>()
.Setup(v => v.All()) .Setup(v => v.All())
.Returns(new[] { status }); .Returns(new[] { status });
return status;
} }
private void VerifyUpdate() private void VerifyUpdate()
@ -77,6 +79,54 @@ namespace NzbDrone.Core.Test.Download
status.Should().NotBeNull(); status.Should().NotBeNull();
} }
[Test]
public void should_not_escalate_further_till_after_5_minutes_since_initial_failure()
{
var origStatus = WithStatus(new DownloadClientStatus
{
InitialFailure = _epoch - TimeSpan.FromMinutes(4),
MostRecentFailure = _epoch - TimeSpan.FromSeconds(4),
EscalationLevel = 3
});
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
var status = Subject.GetBlockedProviders().FirstOrDefault();
status.Should().BeNull();
origStatus.EscalationLevel.Should().Be(3);
}
[Test]
public void should_escalate_further_after_5_minutes_since_initial_failure()
{
WithStatus(new DownloadClientStatus
{
InitialFailure = _epoch - TimeSpan.FromMinutes(6),
MostRecentFailure = _epoch - TimeSpan.FromSeconds(120),
EscalationLevel = 3
});
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
Subject.RecordFailure(1);
var status = Subject.GetBlockedProviders().FirstOrDefault();
status.Should().NotBeNull();
status.EscalationLevel.Should().BeGreaterThan(3);
}
[Test] [Test]
public void should_not_escalate_beyond_3_hours() public void should_not_escalate_beyond_3_hours()
{ {

@ -93,14 +93,18 @@ namespace NzbDrone.Core.ThingiProvider.Status
var status = GetProviderStatus(providerId); var status = GetProviderStatus(providerId);
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
status.MostRecentFailure = now;
if (status.EscalationLevel == 0) if (status.EscalationLevel == 0)
{ {
status.InitialFailure = now; status.InitialFailure = now;
status.EscalationLevel = 1;
escalate = false;
} }
status.MostRecentFailure = now; var inGracePeriod = (status.InitialFailure.Value + MinimumTimeSinceInitialFailure) > now;
if (escalate)
if (escalate && !inGracePeriod)
{ {
status.EscalationLevel = Math.Min(MaximumEscalationLevel, status.EscalationLevel + 1); status.EscalationLevel = Math.Min(MaximumEscalationLevel, status.EscalationLevel + 1);
} }
@ -113,7 +117,7 @@ namespace NzbDrone.Core.ThingiProvider.Status
} }
} }
if (status.InitialFailure.Value + MinimumTimeSinceInitialFailure <= now || minimumBackOff != TimeSpan.Zero) if (!inGracePeriod || minimumBackOff != TimeSpan.Zero)
{ {
status.DisabledTill = now + CalculateBackOffPeriod(status); status.DisabledTill = now + CalculateBackOffPeriod(status);
} }

Loading…
Cancel
Save