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.
This commit is contained in:
parent
9327ef4352
commit
8aad53f291
|
@ -55,7 +55,6 @@ namespace NzbDrone.Core.Test
|
||||||
Assert.IsFalse(settings[0].Success);
|
Assert.IsFalse(settings[0].Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
//This test will confirm that the concurrency checks are rest
|
//This test will confirm that the concurrency checks are rest
|
||||||
//after execution so the job can successfully run.
|
//after execution so the job can successfully run.
|
||||||
|
@ -314,7 +313,6 @@ namespace NzbDrone.Core.Test
|
||||||
Assert.AreEqual(next, settings[0].LastExecution.AddMinutes(15));
|
Assert.AreEqual(next, settings[0].LastExecution.AddMinutes(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Disabled_isnt_run_by_scheduler()
|
public void Disabled_isnt_run_by_scheduler()
|
||||||
{
|
{
|
||||||
|
@ -339,6 +337,48 @@ namespace NzbDrone.Core.Test
|
||||||
//Assert
|
//Assert
|
||||||
Assert.AreEqual(0, disabledJob.ExexutionCount);
|
Assert.AreEqual(0, disabledJob.ExexutionCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SingleId_do_not_update_last_execution()
|
||||||
|
{
|
||||||
|
IEnumerable<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
||||||
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||||
|
mocker.SetConstant(fakeJobs);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
|
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<IJob> fakeJobs = new List<IJob> { new FakeJob() };
|
||||||
|
var mocker = new AutoMoqer();
|
||||||
|
|
||||||
|
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||||
|
mocker.SetConstant(fakeJobs);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
|
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
|
public class FakeJob : IJob
|
||||||
|
|
|
@ -164,7 +164,6 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts processing of queue.
|
/// Starts processing of queue.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -242,24 +241,28 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
jobImplementation.Start(_notification, targetId);
|
jobImplementation.Start(_notification, targetId);
|
||||||
_notification.Status = ProgressNotificationStatus.Completed;
|
_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();
|
sw.Stop();
|
||||||
Logger.Debug("Job '{0}' successfully completed in {1} seconds", jobImplementation.Name, sw.Elapsed.Minutes,
|
Logger.Debug("Job '{0}' successfully completed in {1} seconds", jobImplementation.Name, sw.Elapsed.Minutes,
|
||||||
sw.Elapsed.Seconds);
|
sw.Elapsed.Seconds);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
settings.LastExecution = DateTime.Now;
|
||||||
settings.Success = false;
|
settings.Success = false;
|
||||||
|
|
||||||
Logger.ErrorException("An error has occurred while executing timer job " + jobImplementation.Name, e);
|
Logger.ErrorException("An error has occurred while executing timer job " + jobImplementation.Name, e);
|
||||||
_notification.CurrentMessage = jobImplementation.Name + " Failed.";
|
_notification.CurrentMessage = jobImplementation.Name + " Failed.";
|
||||||
_notification.Status = ProgressNotificationStatus.Failed;
|
_notification.Status = ProgressNotificationStatus.Failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveSettings(settings);
|
if (targetId == 0)
|
||||||
|
{
|
||||||
|
SaveSettings(settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue