added concurrency test for fetch service

This commit is contained in:
Keivan Beigi 2013-05-29 10:07:19 -07:00
parent 0725dcee73
commit 676599c520
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.IndexerTests
{
public class FetchAndParseRssServiceFixture : CoreTest<FetchAndParseRssService>
{
private List<IIndexer> _indexers;
[SetUp]
public void Setup()
{
_indexers = new List<IIndexer>();
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
_indexers.Add(new Newznab());
Mocker.SetConstant<IEnumerable<IIndexer>>(_indexers);
}
[Test]
[Explicit]
public void should_call_fetch_on_all_indexers_at_the_same_time()
{
var callsToFetch = new List<DateTime>();
Mocker.GetMock<IFetchFeedFromIndexers>().Setup(c => c.FetchRss(It.IsAny<IIndexer>()))
.Returns(new List<ReportInfo>())
.Callback((() =>
{
Thread.Sleep(2000);
Console.WriteLine(DateTime.Now);
callsToFetch.Add(DateTime.Now);
}));
Mocker.GetMock<IIndexerService>().Setup(c => c.GetAvailableIndexers()).Returns(_indexers);
Subject.Fetch();
var first = callsToFetch.Min();
var last = callsToFetch.Max();
(last - first).Should().BeLessThan(TimeSpan.FromSeconds(1));
}
}
}

View File

@ -135,6 +135,7 @@
<Compile Include="Framework\NBuilderExtensions.cs" />
<Compile Include="IndexerSearchTests\SearchDefinitionFixture.cs" />
<Compile Include="IndexerTests\BasicRssParserFixture.cs" />
<Compile Include="IndexerTests\FetchAndParseRssServiceFixture.cs" />
<Compile Include="IndexerTests\IndexerServiceFixture.cs" />
<Compile Include="IndexerTests\IntegrationTests\NzbxIntegrationTests.cs" />
<Compile Include="IndexerTests\IntegrationTests\NzbClubIntegrationTests.cs" />