mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
![servarr[bot]](/assets/img/avatar_default.png)
* New: Differentiate between short term and long term (more than 6 hours) indexer failures (cherry picked from commit 2adedb97da5ad31b65f0dc2eec5c263efe95731f) * fixup! Mock Localization Co-authored-by: Mark McDowall <mark@mcdowall.ca> Co-authored-by: Qstick <qstick@gmail.com>
93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using NzbDrone.Core.HealthCheck.Checks;
|
|
using NzbDrone.Core.Indexers;
|
|
using NzbDrone.Core.Localization;
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
namespace NzbDrone.Core.Test.HealthCheck.Checks
|
|
{
|
|
[TestFixture]
|
|
public class IndexerStatusCheckFixture : CoreTest<IndexerStatusCheck>
|
|
{
|
|
private List<IIndexer> _indexers = new List<IIndexer>();
|
|
private List<IndexerStatus> _blockedIndexers = new List<IndexerStatus>();
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
Mocker.GetMock<IIndexerFactory>()
|
|
.Setup(v => v.GetAvailableProviders())
|
|
.Returns(_indexers);
|
|
|
|
Mocker.GetMock<IIndexerStatusService>()
|
|
.Setup(v => v.GetBlockedProviders())
|
|
.Returns(_blockedIndexers);
|
|
|
|
Mocker.GetMock<ILocalizationService>()
|
|
.Setup(s => s.GetLocalizedString(It.IsAny<string>()))
|
|
.Returns("Some Warning Message");
|
|
}
|
|
|
|
private Mock<IIndexer> GivenIndexer(int i, double backoffHours, double failureHours)
|
|
{
|
|
var id = i;
|
|
|
|
var mockIndexer = new Mock<IIndexer>();
|
|
mockIndexer.SetupGet(s => s.Definition).Returns(new IndexerDefinition { Id = id });
|
|
mockIndexer.SetupGet(s => s.SupportsSearch).Returns(true);
|
|
|
|
_indexers.Add(mockIndexer.Object);
|
|
|
|
if (backoffHours != 0.0)
|
|
{
|
|
_blockedIndexers.Add(new IndexerStatus
|
|
{
|
|
ProviderId = id,
|
|
InitialFailure = DateTime.UtcNow.AddHours(-failureHours),
|
|
MostRecentFailure = DateTime.UtcNow.AddHours(-0.1),
|
|
EscalationLevel = 5,
|
|
DisabledTill = DateTime.UtcNow.AddHours(backoffHours)
|
|
});
|
|
}
|
|
|
|
return mockIndexer;
|
|
}
|
|
|
|
[Test]
|
|
public void should_not_return_error_when_no_indexers()
|
|
{
|
|
Subject.Check().ShouldBeOk();
|
|
}
|
|
|
|
[Test]
|
|
public void should_return_warning_if_indexer_unavailable()
|
|
{
|
|
GivenIndexer(1, 2.0, 4.0);
|
|
GivenIndexer(2, 0.0, 0.0);
|
|
|
|
Subject.Check().ShouldBeWarning();
|
|
}
|
|
|
|
[Test]
|
|
public void should_return_error_if_all_indexers_unavailable()
|
|
{
|
|
GivenIndexer(1, 2.0, 4.0);
|
|
|
|
Subject.Check().ShouldBeError();
|
|
}
|
|
|
|
[Test]
|
|
public void should_return_warning_if_few_indexers_unavailable()
|
|
{
|
|
GivenIndexer(1, 2.0, 4.0);
|
|
GivenIndexer(2, 2.0, 4.0);
|
|
GivenIndexer(3, 0.0, 0.0);
|
|
|
|
Subject.Check().ShouldBeWarning();
|
|
}
|
|
}
|
|
}
|