From 8aad53f291f69dca9f7eb18b32095aca633beb14 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 17 May 2011 22:29:23 -0700 Subject: [PATCH] Added tests for SingleId and not updating last execution time or success/fail. Job information will only be updated if a job did not have a targetId. --- NzbDrone.Core.Test/JobProviderTest.cs | 44 ++++++++++++++++++++- NzbDrone.Core/Providers/Jobs/JobProvider.cs | 15 ++++--- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Core.Test/JobProviderTest.cs b/NzbDrone.Core.Test/JobProviderTest.cs index 3fef46518..d33e531bb 100644 --- a/NzbDrone.Core.Test/JobProviderTest.cs +++ b/NzbDrone.Core.Test/JobProviderTest.cs @@ -55,7 +55,6 @@ namespace NzbDrone.Core.Test Assert.IsFalse(settings[0].Success); } - [Test] //This test will confirm that the concurrency checks are rest //after execution so the job can successfully run. @@ -314,7 +313,6 @@ namespace NzbDrone.Core.Test Assert.AreEqual(next, settings[0].LastExecution.AddMinutes(15)); } - [Test] public void Disabled_isnt_run_by_scheduler() { @@ -339,6 +337,48 @@ namespace NzbDrone.Core.Test //Assert Assert.AreEqual(0, disabledJob.ExexutionCount); } + + [Test] + public void SingleId_do_not_update_last_execution() + { + IEnumerable fakeJobs = new List { new FakeJob() }; + var mocker = new AutoMoqer(); + + mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(fakeJobs); + + //Act + var timerProvider = mocker.Resolve(); + timerProvider.Initialize(); + timerProvider.QueueJob(typeof(FakeJob), 10); + Thread.Sleep(1000); + + //Assert + var settings = timerProvider.All(); + Assert.IsNotEmpty(settings); + Assert.AreEqual(DateTime.MinValue, settings[0].LastExecution); + } + + [Test] + public void SingleId_do_not_set_success() + { + IEnumerable fakeJobs = new List { new FakeJob() }; + var mocker = new AutoMoqer(); + + mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(fakeJobs); + + //Act + var timerProvider = mocker.Resolve(); + timerProvider.Initialize(); + timerProvider.QueueJob(typeof(FakeJob), 10); + Thread.Sleep(1000); + + //Assert + var settings = timerProvider.All(); + Assert.IsNotEmpty(settings); + Assert.IsFalse(settings[0].Success); + } } public class FakeJob : IJob diff --git a/NzbDrone.Core/Providers/Jobs/JobProvider.cs b/NzbDrone.Core/Providers/Jobs/JobProvider.cs index 5f8e00eec..4b0dcb9d7 100644 --- a/NzbDrone.Core/Providers/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Providers/Jobs/JobProvider.cs @@ -164,7 +164,6 @@ namespace NzbDrone.Core.Providers.Jobs return true; } - /// /// Starts processing of queue. /// @@ -235,31 +234,35 @@ namespace NzbDrone.Core.Providers.Jobs try { Logger.Debug("Starting job '{0}'. Last execution {1}", settings.Name, settings.LastExecution); - + var sw = Stopwatch.StartNew(); _notificationProvider.Register(_notification); jobImplementation.Start(_notification, targetId); _notification.Status = ProgressNotificationStatus.Completed; - if (targetId != 0) - settings.LastExecution = DateTime.Now; + settings.LastExecution = DateTime.Now; + settings.Success = true; - settings.Success = true; //TODO: Do we consider a job with a targetId as successful? sw.Stop(); Logger.Debug("Job '{0}' successfully completed in {1} seconds", jobImplementation.Name, sw.Elapsed.Minutes, sw.Elapsed.Seconds); } catch (Exception e) { + settings.LastExecution = DateTime.Now; settings.Success = false; + Logger.ErrorException("An error has occurred while executing timer job " + jobImplementation.Name, e); _notification.CurrentMessage = jobImplementation.Name + " Failed."; _notification.Status = ProgressNotificationStatus.Failed; } } - SaveSettings(settings); + if (targetId == 0) + { + SaveSettings(settings); + } } ///