Fixed dbBenchmark tests

pull/2/head
kay.one 14 years ago
parent 8c12872433
commit ea643630ed

@ -8,13 +8,14 @@ using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using PetaPoco;
namespace NzbDrone.Core.Test namespace NzbDrone.Core.Test
{ {
[TestFixture] [TestFixture]
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
[Ignore]
public class DbBenchmark : TestBase public class DbBenchmark : TestBase
{ {
const int Episodes_Per_Season = 20; const int Episodes_Per_Season = 20;
@ -22,6 +23,7 @@ namespace NzbDrone.Core.Test
private readonly List<int> seriesIds = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; private readonly List<int> seriesIds = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
private readonly List<Episode> episodes = new List<Episode>(); private readonly List<Episode> episodes = new List<Episode>();
private readonly List<EpisodeFile> files = new List<EpisodeFile>(); private readonly List<EpisodeFile> files = new List<EpisodeFile>();
private IDatabase db;
[TestFixtureSetUp] [TestFixtureSetUp]
@ -30,8 +32,18 @@ namespace NzbDrone.Core.Test
base.Setup(); base.Setup();
db = MockLib.GetEmptyDatabase();
int currentFileId = 0; int currentFileId = 0;
var qulityProfile = new QualityProfile
{
Name = "TestProfile",
Allowed = new List<QualityTypes> { QualityTypes.DVD, QualityTypes.Bluray1080p },
Cutoff = QualityTypes.DVD
};
db.Insert(qulityProfile);
foreach (var _seriesId in seriesIds) foreach (var _seriesId in seriesIds)
{ {
int seriesId = _seriesId; int seriesId = _seriesId;
@ -40,7 +52,7 @@ namespace NzbDrone.Core.Test
.With(s => s.Monitored = true) .With(s => s.Monitored = true)
.Build(); .Build();
//repo.Add(series); db.Insert(series);
foreach (var _seasonNumber in seasonsNumbers) foreach (var _seasonNumber in seasonsNumbers)
{ {
@ -51,7 +63,6 @@ namespace NzbDrone.Core.Test
if (i < 10) if (i < 10)
{ {
var epFile = Builder<EpisodeFile>.CreateNew() var epFile = Builder<EpisodeFile>.CreateNew()
.With(e => e.SeriesId = seriesId)
.With(e => e.SeriesId = seriesId) .With(e => e.SeriesId = seriesId)
.And(e => e.SeasonNumber = _seasonNumber) .And(e => e.SeasonNumber = _seasonNumber)
.And(e => e.Path = Guid.NewGuid().ToString()) .And(e => e.Path = Guid.NewGuid().ToString())
@ -83,30 +94,32 @@ namespace NzbDrone.Core.Test
} }
//repo.AddMany(episodes); db.InsertMany(episodes);
//repo.AddMany(files); db.InsertMany(files);
} }
[Test] [Test]
public void get_episode_by_series_seasons_episode_x5000() public void get_episode_by_series_seasons_episode_x5000()
{ {
var epProvider = new EpisodeProvider(null, null, null); var mocker = new AutoMoqer();
mocker.SetConstant(db);
mocker.Resolve<SeriesProvider>();
var epProvider = mocker.Resolve<EpisodeProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
var random = new Random(); var random = new Random();
Console.WriteLine("Starting Test"); Console.WriteLine("Starting Test");
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
for (int i = 0; i < 5000; i++) for (int i = 0; i < 5000; i++)
{ {
epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10)).Should().NotBeNull(); var ep = epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10));
ep.Series.Should().NotBeNull();
} }
sw.Stop(); sw.Stop();
Console.WriteLine("Took " + sw.Elapsed); Console.WriteLine("Took " + sw.Elapsed);
@ -115,7 +128,11 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void get_episode_by_series_seasons_x1000() public void get_episode_by_series_seasons_x1000()
{ {
var epProvider = new EpisodeProvider(null, null, null); var mocker = new AutoMoqer();
mocker.SetConstant(db);
mocker.Resolve<SeriesProvider>();
var epProvider = mocker.Resolve<EpisodeProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -140,8 +157,9 @@ namespace NzbDrone.Core.Test
public void get_episode_file_count_x100() public void get_episode_file_count_x100()
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
//mocker.SetConstant(repo); mocker.SetConstant(db);
mocker.SetConstant(mocker.Resolve<EpisodeProvider>()); mocker.Resolve<SeriesProvider>();
mocker.Resolve<EpisodeProvider>();
var mediaProvider = mocker.Resolve<MediaFileProvider>(); var mediaProvider = mocker.Resolve<MediaFileProvider>();
@ -163,13 +181,14 @@ namespace NzbDrone.Core.Test
Console.WriteLine("Took " + sw.Elapsed); Console.WriteLine("Took " + sw.Elapsed);
} }
[Test] [Test]
public void get_season_count_x5000() public void get_episode_file_count_x1000()
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
//mocker.SetConstant(repo); mocker.SetConstant(db);
var provider = mocker.Resolve<EpisodeProvider>(); mocker.Resolve<SeriesProvider>();
mocker.Resolve<EpisodeProvider>();
var mediaProvider = mocker.Resolve<MediaFileProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -179,9 +198,9 @@ namespace NzbDrone.Core.Test
Console.WriteLine("Starting Test"); Console.WriteLine("Starting Test");
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
for (int i = 0; i < 5000; i++) for (int i = 0; i < 1000; i++)
{ {
provider.GetSeasons(random.Next(1, 10)).Should().HaveSameCount(seasonsNumbers); mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull();
} }
@ -192,12 +211,11 @@ namespace NzbDrone.Core.Test
[Test] [Test]
public void get_episode_file_count_x10() public void get_season_count_x5000()
{ {
var mocker = new AutoMoqer(); var mocker = new AutoMoqer();
//mocker.SetConstant(repo); mocker.SetConstant(db);
mocker.SetConstant(mocker.Resolve<EpisodeProvider>()); var provider = mocker.Resolve<EpisodeProvider>();
var provider = mocker.Resolve<MediaFileProvider>();
Thread.Sleep(1000); Thread.Sleep(1000);
@ -207,11 +225,9 @@ namespace NzbDrone.Core.Test
Console.WriteLine("Starting Test"); Console.WriteLine("Starting Test");
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
for (int i = 0; i < 100; i++) for (int i = 0; i < 5000; i++)
{ {
var result = provider.GetEpisodeFilesCount(random.Next(1, 10)); provider.GetSeasons(random.Next(1, 10)).Should().HaveSameCount(seasonsNumbers);
result.Item1.Should().NotBe(0);
result.Item2.Should().NotBe(0);
} }
@ -220,5 +236,7 @@ namespace NzbDrone.Core.Test
Console.WriteLine("Took " + sw.Elapsed); Console.WriteLine("Took " + sw.Elapsed);
} }
} }
} }

Loading…
Cancel
Save