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)] [TestCase("nzbmatrix.xml", 2)]
public void parse_feed_xml(string fileName, int warns) public void parse_feed_xml(string fileName, int warns)
{ {
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\" + fileName)); .Returns(File.OpenRead(".\\Files\\Rss\\" + fileName));
@ -58,10 +56,25 @@ public void parse_feed_xml(string fileName, int warns)
ExceptionVerification.ExpectedWarns(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] [Test]
public void newzbin_parses_languae() public void newzbin_parses_languae()
{ {
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -169,7 +182,7 @@ public void custome_parser_full_parse(string title)
[Test] [Test]
public void downloadFeed() public void downloadFeed()
{ {
Mocker.SetConstant(new HttpProvider()); Mocker.Resolve<HttpProvider>();
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build(); var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>() Mocker.GetMock<IndexerProvider>()
@ -198,7 +211,7 @@ public void nzbsorg_search_returns_valid_results(string title, int season, int e
Mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
var result = Mocker.Resolve<NzbsOrg>().FetchEpisode(title, season, episode); var result = Mocker.Resolve<NzbsOrg>().FetchEpisode(title, season, episode);
Mark500Inconclusive(); Mark500Inconclusive();
result.Should().NotBeEmpty(); result.Should().NotBeEmpty();
@ -228,13 +241,8 @@ public void newzbin_search_returns_valid_results(string title, int season, int e
[Test] [Test]
public void nzbmatrix_search_returns_valid_results() public void nzbmatrix_search_returns_valid_results()
{ {
Mocker.GetMock<ConfigProvider>() WithConfiguredIndexers();
.SetupGet(c => c.NzbMatrixUsername)
.Returns("");
Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixApiKey)
.Returns("");
Mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
@ -249,13 +257,7 @@ public void nzbmatrix_search_returns_valid_results()
[Test] [Test]
public void nzbmatrix_multi_word_search_returns_valid_results() public void nzbmatrix_multi_word_search_returns_valid_results()
{ {
Mocker.GetMock<ConfigProvider>() WithConfiguredIndexers();
.SetupGet(c => c.NzbMatrixUsername)
.Returns("");
Mocker.GetMock<ConfigProvider>()
.SetupGet(c => c.NzbMatrixApiKey)
.Returns("");
Mocker.Resolve<HttpProvider>(); Mocker.Resolve<HttpProvider>();
@ -280,6 +282,8 @@ public void get_query_title(string raw, string clean)
[Test] [Test]
public void size_newzbin() public void size_newzbin()
{ {
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newzbin.xml")); .Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newzbin.xml"));
@ -294,8 +298,7 @@ public void size_newzbin()
[Test] [Test]
public void size_nzbmatrix() public void size_nzbmatrix()
{ {
//Setup WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -311,8 +314,7 @@ public void size_nzbmatrix()
[Test] [Test]
public void size_nzbsorg() public void size_nzbsorg()
{ {
//Setup WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -328,8 +330,7 @@ public void size_nzbsorg()
[Test] [Test]
public void size_nzbsrus() public void size_nzbsrus()
{ {
//Setup WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
@ -359,6 +360,8 @@ public void Server_Unavailable_503_should_not_log_exception()
[Test] [Test]
public void none_503_server_error_should_still_log_error() public void none_503_server_error_should_still_log_error()
{ {
WithConfiguredIndexers();
Mocker.GetMock<HttpProvider>() Mocker.GetMock<HttpProvider>()
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>())) .Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Throws(new WebException("some other server error")); .Throws(new WebException("some other server error"));
@ -369,6 +372,17 @@ public void none_503_server_error_should_still_log_error()
ExceptionVerification.ExpectedWarns(0); 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() private static void Mark500Inconclusive()
{ {
ExceptionVerification.MarkInconclusive(typeof(WebException)); ExceptionVerification.MarkInconclusive(typeof(WebException));

View File

@ -23,7 +23,7 @@ public class IndexerProviderTest : CoreTest
[Test] [Test]
public void Init_indexer_test() public void Init_indexer_test()
{ {
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
@ -45,8 +45,6 @@ public void Init_indexer_test()
[Test] [Test]
public void Init_indexer_with_disabled_job() public void Init_indexer_with_disabled_job()
{ {
Mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); Mocker.SetConstant(TestDbHelper.GetEmptyDatabase());
//Act //Act
@ -75,6 +73,11 @@ protected override string[] Urls
get { return new[] { "www.google.com" }; } get { return new[] { "www.google.com" }; }
} }
public override bool IsConfigured
{
get { return true; }
}
protected override NetworkCredential Credentials protected override NetworkCredential Credentials
{ {
get { return null; } get { return null; }
@ -129,6 +132,11 @@ protected override string[] Urls
get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; } 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) protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -172,6 +180,11 @@ protected override string[] Urls
get { return new[] { "http://www.google.com" }; } 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) protected override IList<string> GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber)
{ {
throw new NotImplementedException(); 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; } protected abstract string[] Urls { get; }
public abstract bool IsConfigured { get; }
/// <summary> /// <summary>
/// Gets the credential. /// Gets the credential.
/// </summary> /// </summary>
@ -147,6 +150,12 @@ private List<EpisodeParseResult> Fetch(IEnumerable<string> urls)
{ {
var result = new List<EpisodeParseResult>(); 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) foreach (var url in urls)
{ {
try try
@ -178,11 +187,11 @@ private List<EpisodeParseResult> Fetch(IEnumerable<string> urls)
} }
} }
catch(WebException webException) catch (WebException webException)
{ {
if (webException.Message.Contains("503")) if (webException.Message.Contains("503"))
{ {
_logger.Warn("{0} server is currently unbelievable. {1}", Name, webException.Message); _logger.Warn("{0} server is currently unbelievable. {1}", Name, webException.Message);
} }
else else
{ {

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 protected override NetworkCredential Credentials

View File

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

View File

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

View File

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