2011-11-17 06:23:35 +00:00
|
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2011-12-02 06:26:06 +00:00
|
|
|
|
using FizzWare.NBuilder;
|
2011-11-17 06:23:35 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using NUnit.Framework;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2011-11-17 06:23:35 +00:00
|
|
|
|
using NzbDrone.Core.Model;
|
2011-12-02 06:26:06 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-11-17 06:23:35 +00:00
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
using NzbDrone.Test.Common;
|
|
|
|
|
using NzbDrone.Test.Common.AutoMoq;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class JobProviderFixture : CoreTest
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
FakeJob fakeJob;
|
|
|
|
|
SlowJob slowJob;
|
|
|
|
|
BrokenJob brokenJob;
|
|
|
|
|
DisabledJob disabledJob;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
WithRealDb();
|
|
|
|
|
fakeJob = new FakeJob();
|
|
|
|
|
slowJob = new SlowJob();
|
|
|
|
|
brokenJob = new BrokenJob();
|
|
|
|
|
disabledJob = new DisabledJob();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
|
|
|
|
Mocker.Resolve<JobProvider>().Queue.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-01 04:16:46 +00:00
|
|
|
|
private void ResetLastExecution()
|
|
|
|
|
{
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
var jobs = jobProvider.All();
|
|
|
|
|
foreach (var jobDefinition in jobs)
|
|
|
|
|
{
|
|
|
|
|
jobDefinition.LastExecution = new DateTime(2000, 1, 1);
|
|
|
|
|
jobProvider.SaveDefinition(jobDefinition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-17 06:23:35 +00:00
|
|
|
|
private void WaitForQueue()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Waiting for queue to clear.");
|
|
|
|
|
var stopWatch = Mocker.Resolve<JobProvider>().StopWatch;
|
|
|
|
|
|
|
|
|
|
while (stopWatch.IsRunning)
|
|
|
|
|
{
|
2011-11-17 06:40:54 +00:00
|
|
|
|
Thread.Sleep(10);
|
2011-11-17 06:23:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void running_scheduled_jobs_should_updates_last_execution_time()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-01 04:16:46 +00:00
|
|
|
|
ResetLastExecution();
|
|
|
|
|
Mocker.Resolve<JobProvider>().QueueScheduled();
|
|
|
|
|
WaitForQueue();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:16:46 +00:00
|
|
|
|
var settings = Mocker.Resolve<JobProvider>().All();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
settings.First().LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10));
|
|
|
|
|
fakeJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void failing_scheduled_job_should_mark_job_as_failed()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { brokenJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-01 04:16:46 +00:00
|
|
|
|
ResetLastExecution();
|
|
|
|
|
Mocker.Resolve<JobProvider>().QueueScheduled();
|
|
|
|
|
WaitForQueue();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-01 04:16:46 +00:00
|
|
|
|
var settings = Mocker.Resolve<JobProvider>().All();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
settings.First().LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10));
|
|
|
|
|
settings.First().Success.Should().BeFalse();
|
|
|
|
|
brokenJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
ExceptionVerification.ExcpectedErrors(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void scheduler_skips_jobs_that_arent_mature_yet()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
//Act
|
2011-12-01 04:16:46 +00:00
|
|
|
|
ResetLastExecution();
|
|
|
|
|
|
|
|
|
|
Mocker.Resolve<JobProvider>().QueueScheduled();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
WaitForQueue();
|
2011-12-01 04:16:46 +00:00
|
|
|
|
|
|
|
|
|
Mocker.Resolve<JobProvider>().QueueScheduled();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
fakeJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
//This test will confirm that the concurrency checks are rest
|
|
|
|
|
//after execution so the job can successfully run.
|
|
|
|
|
public void can_run_async_job_again()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
jobProvider.QueueJob(typeof(FakeJob));
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
jobProvider.QueueJob(typeof(FakeJob));
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
jobProvider.Queue.Should().BeEmpty();
|
|
|
|
|
fakeJob.ExecutionCount.Should().Be(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void no_concurent_jobs()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { slowJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
jobProvider.QueueJob(typeof(SlowJob), 1);
|
|
|
|
|
jobProvider.QueueJob(typeof(SlowJob), 2);
|
|
|
|
|
jobProvider.QueueJob(typeof(SlowJob), 3);
|
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
jobProvider.Queue.Should().BeEmpty();
|
|
|
|
|
slowJob.ExecutionCount.Should().Be(3);
|
|
|
|
|
ExceptionVerification.AssertNoUnexcpectedLogs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void can_run_broken_job_again()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { brokenJob };
|
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
jobProvider.QueueJob(typeof(BrokenJob));
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
jobProvider.QueueJob(typeof(BrokenJob));
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
brokenJob.ExecutionCount.Should().Be(2);
|
|
|
|
|
ExceptionVerification.ExcpectedErrors(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void schedule_hit_should_be_ignored_if_queue_is_running()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { slowJob, fakeJob };
|
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(fakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
jobProvider.QueueJob(typeof(SlowJob));
|
|
|
|
|
jobProvider.QueueScheduled();
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
slowJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
fakeJob.ExecutionCount.Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void can_queue_jobs_at_the_same_time()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { slowJob, fakeJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jobProvider.QueueJob(typeof(SlowJob));
|
|
|
|
|
var thread1 = new Thread(() => jobProvider.QueueJob(typeof(FakeJob)));
|
|
|
|
|
var thread2 = new Thread(() => jobProvider.QueueJob(typeof(FakeJob)));
|
|
|
|
|
|
|
|
|
|
thread1.Start();
|
|
|
|
|
thread2.Start();
|
|
|
|
|
|
|
|
|
|
thread1.Join();
|
|
|
|
|
thread2.Join();
|
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
fakeJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
slowJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
jobProvider.Queue.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_Jobs()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
var timers = jobProvider.All();
|
|
|
|
|
timers.Should().HaveCount(1);
|
|
|
|
|
timers[0].Interval.Should().Be(fakeJob.DefaultInterval);
|
|
|
|
|
timers[0].Name.Should().Be(fakeJob.Name);
|
|
|
|
|
timers[0].TypeName.Should().Be(fakeJob.GetType().ToString());
|
2011-12-01 02:23:22 +00:00
|
|
|
|
timers[0].LastExecution.Should().HaveYear(DateTime.Now.Year);
|
|
|
|
|
timers[0].LastExecution.Should().HaveMonth(DateTime.Now.Month);
|
|
|
|
|
timers[0].LastExecution.Should().HaveDay(DateTime.Today.Day);
|
2011-11-17 06:23:35 +00:00
|
|
|
|
timers[0].Enable.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Init_Timers_only_registers_once()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
var fakeTimer = new FakeJob();
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeTimer };
|
|
|
|
|
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var Mocker2 = new AutoMoqer();
|
|
|
|
|
|
|
|
|
|
Mocker2.SetConstant(Db);
|
|
|
|
|
var assertjobProvider = Mocker2.Resolve<JobProvider>();
|
|
|
|
|
var timers = assertjobProvider.All();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
timers.Should().HaveCount(1);
|
|
|
|
|
timers[0].Enable.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-12-02 06:26:06 +00:00
|
|
|
|
public void inti_should_removed_jobs_that_no_longer_exist()
|
2011-11-17 06:23:35 +00:00
|
|
|
|
{
|
2011-12-02 06:26:06 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
2011-11-17 06:23:35 +00:00
|
|
|
|
Mocker.SetConstant(fakeJobs);
|
2011-12-02 07:26:38 +00:00
|
|
|
|
|
2011-12-02 06:26:06 +00:00
|
|
|
|
WithRealDb();
|
|
|
|
|
var deletedJob = Builder<JobDefinition>.CreateNew().Build();
|
|
|
|
|
Db.Insert(deletedJob);
|
2011-11-17 06:23:35 +00:00
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
2011-12-02 07:26:38 +00:00
|
|
|
|
|
2011-12-02 06:26:06 +00:00
|
|
|
|
//Act
|
2011-11-17 06:23:35 +00:00
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
//Assert
|
2011-12-02 06:26:06 +00:00
|
|
|
|
var registeredJobs = Db.Fetch<JobDefinition>();
|
|
|
|
|
registeredJobs.Should().HaveCount(1);
|
2011-12-02 07:26:38 +00:00
|
|
|
|
registeredJobs.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
|
|
|
|
}
|
2011-12-02 06:26:06 +00:00
|
|
|
|
|
2011-12-02 07:26:38 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void inti_should_removed_jobs_that_no_longer_exist_even_with_same_name()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
Mocker.SetConstant(fakeJobs);
|
|
|
|
|
|
|
|
|
|
WithRealDb();
|
|
|
|
|
var deletedJob = Builder<JobDefinition>.CreateNew()
|
|
|
|
|
.With(c => c.Name = fakeJob.Name).Build();
|
|
|
|
|
|
|
|
|
|
Db.Insert(deletedJob);
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var registeredJobs = Db.Fetch<JobDefinition>();
|
|
|
|
|
registeredJobs.Should().HaveCount(1);
|
|
|
|
|
registeredJobs.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
2011-11-17 06:23:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2011-12-02 06:26:06 +00:00
|
|
|
|
public void jobs_with_zero_interval_are_registered_as_disabled()
|
2011-11-17 06:23:35 +00:00
|
|
|
|
{
|
2011-12-02 06:26:06 +00:00
|
|
|
|
IList<IJob> fakeJobs = new List<IJob> { disabledJob };
|
|
|
|
|
Mocker.SetConstant(fakeJobs);
|
2011-11-17 06:23:35 +00:00
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
jobProvider.All().Should().HaveCount(1);
|
2011-12-02 06:26:06 +00:00
|
|
|
|
jobProvider.All().First().Enable.Should().BeFalse();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void disabled_jobs_arent_run_by_scheduler()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { disabledJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
jobProvider.QueueScheduled();
|
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
disabledJob.ExecutionCount.Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void job_with_specific_target_should_not_update_last_execution()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
2011-12-01 04:16:46 +00:00
|
|
|
|
ResetLastExecution();
|
2011-11-17 06:23:35 +00:00
|
|
|
|
jobProvider.QueueJob(typeof(FakeJob), 10);
|
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
jobProvider.All().First().LastExecution.Should().HaveYear(2000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void job_with_specific_target_should_not_set_success_flag()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
jobProvider.QueueJob(typeof(FakeJob), 10);
|
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
jobProvider.All().First().Success.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void duplicated_queue_item_should_start_queue_if_its_not_running()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var stuckQueueItem = new JobQueueItem
|
|
|
|
|
{
|
|
|
|
|
JobType = fakeJob.GetType(),
|
|
|
|
|
TargetId = 12,
|
|
|
|
|
SecondaryTargetId = 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
jobProvider.Queue.Add(stuckQueueItem);
|
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
jobProvider.QueueJob(stuckQueueItem.JobType, stuckQueueItem.TargetId, stuckQueueItem.SecondaryTargetId);
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
fakeJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Item_added_to_queue_while_scheduler_runs_should_be_executed()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { slowJob, disabledJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
2011-12-01 04:16:46 +00:00
|
|
|
|
ResetLastExecution();
|
|
|
|
|
var _jobThread = new Thread(Mocker.Resolve<JobProvider>().QueueScheduled);
|
2011-11-17 06:23:35 +00:00
|
|
|
|
_jobThread.Start();
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(200);
|
|
|
|
|
|
2011-12-01 04:16:46 +00:00
|
|
|
|
Mocker.Resolve<JobProvider>().QueueJob(typeof(DisabledJob), 12);
|
2011-11-17 06:23:35 +00:00
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
slowJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
disabledJob.ExecutionCount.Should().Be(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void trygin_to_queue_unregistered_job_should_fail()
|
|
|
|
|
{
|
|
|
|
|
IList<IJob> BaseFakeJobs = new List<IJob> { slowJob, disabledJob };
|
|
|
|
|
Mocker.SetConstant(BaseFakeJobs);
|
|
|
|
|
|
|
|
|
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
|
|
|
|
|
|
|
|
jobProvider.Initialize();
|
|
|
|
|
jobProvider.QueueJob(typeof(string));
|
|
|
|
|
|
|
|
|
|
WaitForQueue();
|
|
|
|
|
ExceptionVerification.ExcpectedErrors(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 06:32:04 +00:00
|
|
|
|
}
|