1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fix: Indexers that are enabled but aren't configured correctly will be skipped during rss/search

This commit is contained in:
kay.one 2012-01-31 17:37:36 -08:00
parent e0170a08e4
commit 2009693787
12 changed files with 159 additions and 38 deletions

View File

@ -30,8 +30,6 @@ public class IndexerTests : CoreTest
[TestCase("nzbmatrix.xml", 2)]
public void parse_feed_xml(string fileName, int warns)
{
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
@ -58,10 +56,25 @@ public void parse_feed_xml(string fileName, int warns)
ExceptionVerification.ExpectedWarns(warns);
}
private void WithConfiguredIndexers()
{
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbMatrixApiKey).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbMatrixUsername).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NewzbinUsername).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NewzbinPassword).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsOrgHash).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsOrgUId).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsrusHash).Returns("MockedConfigValue");
Mocker.GetMock<ConfigProvider>().SetupGet(c => c.NzbsrusUId).Returns("MockedConfigValue");
}
[Test]
public void newzbin_parses_languae()
{
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -169,7 +182,7 @@ public void custome_parser_full_parse(string title)
[Test]
public void downloadFeed()
{
Mocker.SetConstant(new HttpProvider());
Mocker.Resolve<HttpProvider>();
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>()
@ -228,13 +241,8 @@ public void newzbin_search_returns_valid_results(string title, int season, int e
[Test]
public void nzbmatrix_search_returns_valid_results()
{
Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixUsername)
.Returns("");
WithConfiguredIndexers();
Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixApiKey)
.Returns("");
Mocker.Resolve<HttpProvider>();
@ -249,13 +257,7 @@ public void nzbmatrix_search_returns_valid_results()
[Test]
public void nzbmatrix_multi_word_search_returns_valid_results()
{
Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixUsername)
.Returns("");
Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixApiKey)
.Returns("");
WithConfiguredIndexers();
Mocker.Resolve<HttpProvider>();
@ -280,6 +282,8 @@ public void get_query_title(string raw, string clean)
[Test]
public void size_newzbin()
{
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newzbin.xml"));
@ -294,8 +298,7 @@ public void size_newzbin()
[Test]
public void size_nzbmatrix()
{
//Setup
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -311,8 +314,7 @@ public void size_nzbmatrix()
[Test]
public void size_nzbsorg()
{
//Setup
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -328,8 +330,7 @@ public void size_nzbsorg()
[Test]
public void size_nzbsrus()
{
//Setup
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -359,6 +360,8 @@ public void Server_Unavailable_503_should_not_log_exception()
[Test]
public void none_503_server_error_should_still_log_error()
{
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Throws(new WebException("some other server error"));
@ -369,6 +372,17 @@ public void none_503_server_error_should_still_log_error()
ExceptionVerification.ExpectedWarns(0);
}
[Test]
public void indexer_that_isnt_configured_shouldnt_make_an_http_call()
{
Mocker.Resolve<NotConfiguredIndexer>().FetchRss();
Mocker.GetMock<HttpProvider>()
.Verify(c => c.DownloadFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
ExceptionVerification.ExpectedWarns(1);
}
private static void Mark500Inconclusive()
{
ExceptionVerification.MarkInconclusive(typeof(WebException));

View File

@ -45,8 +45,6 @@ public void Init_indexer_test()
[Test]
public void Init_indexer_with_disabled_job()
{
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act
@ -75,6 +73,11 @@ protected override string[] Urls
get { return new[] { "www.google.com" }; }
}
public override bool IsConfigured
{
get { return true; }
}
protected override NetworkCredential Credentials
{
get { return null; }
@ -129,6 +132,11 @@ protected override string[] Urls
get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; }
}
public override bool IsConfigured
{
get { return true; }
}
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
throw new NotImplementedException();
@ -172,6 +180,11 @@ protected override string[] Urls
get { return new[] { "http://www.google.com" }; }
}
public override bool IsConfigured
{
get { return true; }
}
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
throw new NotImplementedException();
@ -205,4 +218,52 @@ protected override EpisodeParseResult CustomParser(SyndicationItem item, Episode
}
}
public class NotConfiguredIndexer : IndexerBase
{
public NotConfiguredIndexer(HttpProvider httpProvider, ConfigProvider configProvider)
: base(httpProvider, configProvider)
{
}
public override string Name
{
get { return "NotConfiguredIndexer"; }
}
protected override string[] Urls
{
get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; }
}
public override bool IsConfigured
{
get { return false; }
}
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
throw new NotImplementedException();
}
protected override IList<string> GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date)
{
throw new NotImplementedException();
}
protected override IList<string> GetSeasonSearchUrls(string seriesTitle, int seasonNumber)
{
throw new NotImplementedException();
}
protected override IList<string> GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard)
{
throw new NotImplementedException();
}
protected override string NzbDownloadUrl(SyndicationItem item)
{
throw new NotImplementedException();
}
}
}

View File

@ -44,6 +44,9 @@ public IndexerBase()
protected abstract string[] Urls { get; }
public abstract bool IsConfigured { get; }
/// <summary>
/// Gets the credential.
/// </summary>
@ -147,6 +150,12 @@ private List<EpisodeParseResult> Fetch(IEnumerable<string> urls)
{
var result = new List<EpisodeParseResult>();
if (!IsConfigured)
{
_logger.Warn("Indexer '{0}' isn't configured correctly. please reconfigure the indexer in settings page.", Name);
return result;
}
foreach (var url in urls)
{
try

View File

@ -30,7 +30,14 @@ protected override string[] Urls
}
}
public override bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configProvider.NewzbinUsername) &&
!string.IsNullOrWhiteSpace(_configProvider.NewzbinPassword);
}
}
protected override NetworkCredential Credentials

View File

@ -24,6 +24,11 @@ protected override string[] Urls
get { return GetUrls(); }
}
public override bool IsConfigured
{
get { return true; }
}
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
var searchUrls = new List<string>();

View File

@ -30,6 +30,15 @@ protected override string[] Urls
}
}
public override bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configProvider.NzbMatrixUsername) &&
!string.IsNullOrWhiteSpace(_configProvider.NzbMatrixApiKey);
}
}
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
var searchUrls = new List<String>();

View File

@ -28,6 +28,15 @@ protected override string[] Urls
}
}
public override bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configProvider.NzbsOrgUId) &&
!string.IsNullOrWhiteSpace(_configProvider.NzbsOrgHash);
}
}
protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{
var searchUrls = new List<String>();

View File

@ -29,6 +29,15 @@ protected override string[] Urls
}
}
public override bool IsConfigured
{
get
{
return !string.IsNullOrWhiteSpace(_configProvider.NzbsrusUId) &&
!string.IsNullOrWhiteSpace(_configProvider.NzbsrusHash);
}
}
public override string Name
{
get { return "NzbsRUs"; }

View File

@ -47,12 +47,9 @@ public virtual int Save(NewznabDefinition definition)
return Convert.ToInt32(_database.Insert(definition));
}
else
{
Logger.Debug("Updating Newznab definitions for {0}", definition.Name);
return _database.Update(definition);
}
}
public virtual void SaveAll(IEnumerable<NewznabDefinition> definitions)
{

View File

@ -47,7 +47,7 @@ public void Start()
prioCheckTimer.Elapsed += EnsurePriority;
prioCheckTimer.Enabled = true;
_pingTimer = new Timer(120000) { AutoReset = true };
_pingTimer = new Timer(180000) { AutoReset = true };
_pingTimer.Elapsed += (PingServer);
_pingTimer.Start();
}
@ -94,9 +94,10 @@ public virtual void PingServer(object sender, ElapsedEventArgs e)
{
_pingFailCounter++;
Logger.ErrorException("Application pool is not responding. Count " + _pingFailCounter, ex);
if (_pingFailCounter > 2)
if (_pingFailCounter > 4)
{
_iisProvider.RestartServer();
_pingFailCounter = 0;
//_iisProvider.RestartServer();
}
}
}