mirror of
https://github.com/Radarr/Radarr
synced 2024-12-29 11:25:26 +00:00
Fixed: Newznab default capabilities erroneously cached if indexer is unavailable. (#1341)
This commit is contained in:
parent
27ab70333c
commit
17118cf24d
2 changed files with 55 additions and 5 deletions
|
@ -1,9 +1,12 @@
|
|||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Xml;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Indexers.Newznab;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.IndexerTests.NewznabTests
|
||||
{
|
||||
|
@ -64,5 +67,35 @@ public void should_use_default_pagesize_if_missing()
|
|||
caps.DefaultPageSize.Should().Be(100);
|
||||
caps.MaxPageSize.Should().Be(100);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_failed_to_get()
|
||||
{
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(o => o.Get(It.IsAny<HttpRequest>()))
|
||||
.Throws<Exception>();
|
||||
|
||||
Assert.Throws<Exception>(() => Subject.GetCapabilities(_settings));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_xml_invalid()
|
||||
{
|
||||
GivenCapsResponse(_caps.Replace("<limits", "<>"));
|
||||
|
||||
Assert.Throws<XmlException>(() => Subject.GetCapabilities(_settings));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_throw_on_xml_data_unexpected()
|
||||
{
|
||||
GivenCapsResponse(_caps.Replace("5030", "asdf"));
|
||||
|
||||
var result = Subject.GetCapabilities(_settings);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Cache;
|
||||
|
@ -49,15 +51,30 @@ private NewznabCapabilities FetchCapabilities(NewznabSettings indexerSettings)
|
|||
|
||||
var request = new HttpRequest(url, HttpAccept.Rss);
|
||||
|
||||
HttpResponse response;
|
||||
|
||||
try
|
||||
{
|
||||
var response = _httpClient.Get(request);
|
||||
|
||||
capabilities = ParseCapabilities(response);
|
||||
response = _httpClient.Get(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Debug(ex, string.Format("Failed to get capabilities from {0}: {1}", indexerSettings.Url, ex.Message));
|
||||
_logger.Debug(ex, "Failed to get newznab api capabilities from {0}", indexerSettings.Url);
|
||||
throw;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
capabilities = ParseCapabilities(response);
|
||||
}
|
||||
catch (XmlException ex)
|
||||
{
|
||||
_logger.Debug(ex, "Failed to parse newznab api capabilities for {0}.", indexerSettings.Url);
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "Failed to determine newznab api capabilities for {0}, using the defaults instead till Sonarr restarts.", indexerSettings.Url);
|
||||
}
|
||||
|
||||
return capabilities;
|
||||
|
|
Loading…
Reference in a new issue