@ -17,13 +17,6 @@ namespace NzbDrone.Core.Test.ProviderTests
// ReSharper disable InconsistentNaming
public class JobProviderTest : TestBase
{
[TestFixtureSetUp]
public override void Setup ( )
{
base . Setup ( ) ;
JobProvider . Queue . Clear ( ) ;
}
[Test]
public void Run_Jobs_Updates_Last_Execution ( )
{
@ -100,13 +93,13 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker . SetConstant ( MockLib . GetEmptyDatabase ( ) ) ;
mocker . SetConstant ( fakeJobs ) ;
var timer Provider = mocker . Resolve < JobProvider > ( ) ;
timer Provider. Initialize ( ) ;
timer Provider. QueueJob ( typeof ( FakeJob ) ) ;
var job Provider = mocker . Resolve < JobProvider > ( ) ;
job Provider. Initialize ( ) ;
job Provider. QueueJob ( typeof ( FakeJob ) ) ;
Thread . Sleep ( 1000 ) ;
timer Provider. QueueJob ( typeof ( FakeJob ) ) ;
job Provider. QueueJob ( typeof ( FakeJob ) ) ;
Thread . Sleep ( 2000 ) ;
J obProvider. Queue . Should ( ) . BeEmpty ( ) ;
j obProvider. Queue . Should ( ) . BeEmpty ( ) ;
fakeJob . ExecutionCount . Should ( ) . Be ( 2 ) ;
}
@ -119,15 +112,15 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker . SetConstant ( MockLib . GetEmptyDatabase ( ) ) ;
mocker . SetConstant ( fakeJobs ) ;
var timer Provider = mocker . Resolve < JobProvider > ( ) ;
timer Provider. Initialize ( ) ;
timer Provider. QueueJob ( typeof ( SlowJob ) , 1 ) ;
timer Provider. QueueJob ( typeof ( SlowJob ) , 2 ) ;
timer Provider. QueueJob ( typeof ( SlowJob ) , 3 ) ;
var job Provider = mocker . Resolve < JobProvider > ( ) ;
job Provider. Initialize ( ) ;
job Provider. QueueJob ( typeof ( SlowJob ) , 1 ) ;
job Provider. QueueJob ( typeof ( SlowJob ) , 2 ) ;
job Provider. QueueJob ( typeof ( SlowJob ) , 3 ) ;
Thread . Sleep ( 5000 ) ;
J obProvider. Queue . Should ( ) . BeEmpty ( ) ;
j obProvider. Queue . Should ( ) . BeEmpty ( ) ;
//Asserts are done in ExceptionVerification
}
@ -144,15 +137,15 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker . SetConstant ( MockLib . GetEmptyDatabase ( ) ) ;
mocker . SetConstant ( fakeJobs ) ;
var timer Provider = mocker . Resolve < JobProvider > ( ) ;
timer Provider. Initialize ( ) ;
timer Provider. QueueJob ( typeof ( BrokenJob ) ) ;
var job Provider = mocker . Resolve < JobProvider > ( ) ;
job Provider. Initialize ( ) ;
job Provider. QueueJob ( typeof ( BrokenJob ) ) ;
Thread . Sleep ( 2000 ) ;
timer Provider. QueueJob ( typeof ( BrokenJob ) ) ;
job Provider. QueueJob ( typeof ( BrokenJob ) ) ;
Thread . Sleep ( 2000 ) ;
J obProvider. Queue . Should ( ) . BeEmpty ( ) ;
j obProvider. Queue . Should ( ) . BeEmpty ( ) ;
brokenJob . ExecutionCount . Should ( ) . Be ( 2 ) ;
ExceptionVerification . ExcpectedErrors ( 2 ) ;
}
@ -201,11 +194,11 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker . SetConstant ( MockLib . GetEmptyDatabase ( ) ) ;
mocker . SetConstant ( fakeJobs ) ;
var timer Provider = mocker . Resolve < JobProvider > ( ) ;
timer Provider. Initialize ( ) ;
var job Provider = mocker . Resolve < JobProvider > ( ) ;
job Provider. Initialize ( ) ;
var thread1 = new Thread ( ( ) = > timer Provider. QueueJob ( typeof ( SlowJob ) ) ) ;
var thread2 = new Thread ( ( ) = > timer Provider. QueueJob ( typeof ( SlowJob ) ) ) ;
var thread1 = new Thread ( ( ) = > job Provider. QueueJob ( typeof ( SlowJob ) ) ) ;
var thread2 = new Thread ( ( ) = > job Provider. QueueJob ( typeof ( SlowJob ) ) ) ;
thread1 . Start ( ) ;
thread2 . Start ( ) ;
@ -216,7 +209,7 @@ namespace NzbDrone.Core.Test.ProviderTests
Thread . Sleep ( 5000 ) ;
Assert . AreEqual ( 1 , slowJob . ExecutionCount ) ;
J obProvider. Queue . Should ( ) . BeEmpty ( ) ;
j obProvider. Queue . Should ( ) . BeEmpty ( ) ;
}
@ -364,16 +357,16 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker . SetConstant ( fakeJobs ) ;
//Act
var timer Provider = mocker . Resolve < JobProvider > ( ) ;
timer Provider. Initialize ( ) ;
timer Provider. QueueJob ( typeof ( FakeJob ) , 10 ) ;
var job Provider = mocker . Resolve < JobProvider > ( ) ;
job Provider. Initialize ( ) ;
job Provider. QueueJob ( typeof ( FakeJob ) , 10 ) ;
Thread . Sleep ( 1000 ) ;
//Assert
var settings = timer Provider. All ( ) ;
var settings = job Provider. All ( ) ;
settings . Should ( ) . NotBeEmpty ( ) ;
settings [ 0 ] . LastExecution . Should ( ) . HaveYear ( 2000 ) ;
J obProvider. Queue . Should ( ) . BeEmpty ( ) ;
j obProvider. Queue . Should ( ) . BeEmpty ( ) ;
}
[Test]
@ -386,13 +379,13 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker . SetConstant ( fakeJobs ) ;
//Act
var timer Provider = mocker . Resolve < JobProvider > ( ) ;
timer Provider. Initialize ( ) ;
timer Provider. QueueJob ( typeof ( FakeJob ) , 10 ) ;
var job Provider = mocker . Resolve < JobProvider > ( ) ;
job Provider. Initialize ( ) ;
job Provider. QueueJob ( typeof ( FakeJob ) , 10 ) ;
Thread . Sleep ( 1000 ) ;
//Assert
var settings = timer Provider. All ( ) ;
var settings = job Provider. All ( ) ;
Assert . IsNotEmpty ( settings ) ;
Assert . IsFalse ( settings [ 0 ] . Success ) ;
}
@ -420,7 +413,7 @@ namespace NzbDrone.Core.Test.ProviderTests
//Act
var jobProvider = mocker . Resolve < JobProvider > ( ) ;
jobProvider . Initialize ( ) ;
J obProvider. Queue . Add ( fakeQueueItem ) ;
j obProvider. Queue . Add ( fakeQueueItem ) ;
jobProvider . QueueJob ( fakeJob . GetType ( ) , 12 ) ;
Thread . Sleep ( 1000 ) ;
@ -441,19 +434,21 @@ namespace NzbDrone.Core.Test.ProviderTests
mocker . SetConstant ( MockLib . GetEmptyDatabase ( ) ) ;
mocker . SetConstant ( fakeJobs ) ;
mocker . Resolve < JobProvider > ( ) . Initialize ( ) ;
var jobProvider = mocker . Resolve < JobProvider > ( ) ;
jobProvider . Initialize ( ) ;
var _jobThread = new Thread ( ( ) = > mocker . Resolve < JobProvider > ( ) . QueueScheduled ( ) ) ;
var _jobThread = new Thread ( ( ) = > jobProvider . QueueScheduled ( ) ) ;
_jobThread . Start ( ) ;
Thread . Sleep ( 200 ) ;
mocker. Resolve < JobProvider > ( ) . QueueJob ( typeof ( DisabledJob ) , 12 ) ;
jobProvider . QueueJob ( typeof ( DisabledJob ) , 12 ) ;
Thread . Sleep ( 3000 ) ;
//Assert
J obProvider. Queue . Should ( ) . BeEmpty ( ) ;
j obProvider. Queue . Should ( ) . BeEmpty ( ) ;
slowJob . ExecutionCount . Should ( ) . Be ( 1 ) ;
disabledJob . ExecutionCount . Should ( ) . Be ( 1 ) ;
}