Added cleanup job for search history

New: Search History cleanup job will only keep the last week of results
This commit is contained in:
Mark McDowall 2012-06-12 12:38:38 -07:00
commit b7408b726a
5 changed files with 159 additions and 0 deletions

View file

@ -66,6 +66,46 @@ namespace NzbDrone.Core.Test.ProviderTests
i.SearchError = ReportRejectionType.None;
}
private void WithExpiredHistory()
{
var history = Builder<SearchHistory>.CreateListOfSize(10)
.All()
.With(h => h.SearchTime = DateTime.Now.AddDays(10))
.Build();
foreach(var searchHistory in history)
{
var items = Builder<SearchHistoryItem>.CreateListOfSize(10)
.All()
.With(i => i.Id == searchHistory.Id)
.Build();
Db.InsertMany(items);
}
Db.InsertMany(history);
}
private void WithValidHistory()
{
var history = Builder<SearchHistory>.CreateListOfSize(10)
.All()
.With(h => h.SearchTime = DateTime.Now)
.Build();
foreach (var searchHistory in history)
{
var items = Builder<SearchHistoryItem>.CreateListOfSize(10)
.All()
.With(i => i.Id == searchHistory.Id)
.Build();
Db.InsertMany(items);
}
Db.InsertMany(history);
}
[Test]
public void Add_should_add_history_and_history_items()
{
@ -263,5 +303,54 @@ namespace NzbDrone.Core.Test.ProviderTests
Mocker.GetMock<DownloadProvider>().Verify(v => v.DownloadReport(It.IsAny<EpisodeParseResult>()), Times.Once());
}
[Test]
public void Cleanup_should_not_blowup_if_there_is_nothing_to_delete()
{
WithRealDb();
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
Db.Fetch<SearchHistory>().Should().HaveCount(0);
}
[Test]
public void Cleanup_should_delete_searchHistory_older_than_1_week()
{
WithRealDb();
WithExpiredHistory();
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
Db.Fetch<SearchHistory>().Should().HaveCount(0);
}
[Test]
public void Cleanup_should_delete_searchHistoryItems_older_than_1_week()
{
WithRealDb();
WithExpiredHistory();
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
Db.Fetch<SearchHistoryItem>().Should().HaveCount(0);
}
[Test]
public void Cleanup_should_not_delete_searchHistory_younger_than_1_week()
{
WithRealDb();
WithValidHistory();
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
Db.Fetch<SearchHistory>().Should().HaveCount(10);
}
[Test]
public void Cleanup_should_not_delete_searchHistoryItems_younger_than_1_week()
{
WithRealDb();
WithValidHistory();
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
Db.Fetch<SearchHistoryItem>().Should().HaveCount(100);
}
}
}