New: Added health check warning to emphasis when a series was deleted instead of only logging it in System Events
parent
ceaaec5378
commit
8a2a41fab0
@ -0,0 +1,77 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.HealthCheck.Checks;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Tv;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.HealthCheck.Checks
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class RemovedSeriesCheckFixture : CoreTest<RemovedSeriesCheck>
|
||||||
|
{
|
||||||
|
private void GivenSeries(int amount, int deleted)
|
||||||
|
{
|
||||||
|
List<Series> series;
|
||||||
|
|
||||||
|
if (amount == 0)
|
||||||
|
{
|
||||||
|
series = new List<Series>();
|
||||||
|
}
|
||||||
|
else if (deleted == 0)
|
||||||
|
{
|
||||||
|
series = Builder<Series>.CreateListOfSize(amount)
|
||||||
|
.All()
|
||||||
|
.With(v => v.Status = SeriesStatusType.Continuing)
|
||||||
|
.BuildList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
series = Builder<Series>.CreateListOfSize(amount)
|
||||||
|
.All()
|
||||||
|
.With(v => v.Status = SeriesStatusType.Continuing)
|
||||||
|
.Random(deleted)
|
||||||
|
.With(v => v.Status = SeriesStatusType.Deleted)
|
||||||
|
.BuildList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Mocker.GetMock<ISeriesService>()
|
||||||
|
.Setup(v => v.GetAllSeries())
|
||||||
|
.Returns(series);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_error_if_series_no_longer_on_tvdb()
|
||||||
|
{
|
||||||
|
GivenSeries(4, 1);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeError();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_error_if_multiple_series_no_longer_on_tvdb()
|
||||||
|
{
|
||||||
|
GivenSeries(4, 2);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeError();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_ok_if_all_series_still_on_tvdb()
|
||||||
|
{
|
||||||
|
GivenSeries(4, 0);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_return_ok_if_no_series_exist()
|
||||||
|
{
|
||||||
|
GivenSeries(0, 0);
|
||||||
|
|
||||||
|
Subject.Check().ShouldBeOk();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,46 @@
|
|||||||
|
using System;
|
||||||
|
using NzbDrone.Common.Messaging;
|
||||||
|
|
||||||
namespace NzbDrone.Core.HealthCheck
|
namespace NzbDrone.Core.HealthCheck
|
||||||
{
|
{
|
||||||
public class EventDrivenHealthCheck
|
public interface IEventDrivenHealthCheck
|
||||||
|
{
|
||||||
|
IProvideHealthCheck HealthCheck { get; }
|
||||||
|
|
||||||
|
bool ShouldExecute(IEvent message, bool previouslyFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EventDrivenHealthCheck<TEvent> : IEventDrivenHealthCheck
|
||||||
{
|
{
|
||||||
public IProvideHealthCheck HealthCheck { get; set; }
|
public IProvideHealthCheck HealthCheck { get; set; }
|
||||||
public CheckOnCondition Condition { get; set; }
|
public CheckOnCondition Condition { get; set; }
|
||||||
|
public ICheckOnCondition<TEvent> EventFilter { get; set; }
|
||||||
|
|
||||||
public EventDrivenHealthCheck(IProvideHealthCheck healthCheck, CheckOnCondition condition)
|
public EventDrivenHealthCheck(IProvideHealthCheck healthCheck, CheckOnCondition condition)
|
||||||
{
|
{
|
||||||
HealthCheck = healthCheck;
|
HealthCheck = healthCheck;
|
||||||
Condition = condition;
|
Condition = condition;
|
||||||
|
EventFilter = healthCheck as ICheckOnCondition<TEvent>;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShouldExecute(IEvent message, bool previouslyFailed)
|
||||||
|
{
|
||||||
|
if (Condition == CheckOnCondition.SuccessfulOnly && previouslyFailed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Condition == CheckOnCondition.FailedOnly && !previouslyFailed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EventFilter == null && !EventFilter.ShouldCheckOnEvent((TEvent)message))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue