diff --git a/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs b/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs index d16677d2c..6068855c6 100644 --- a/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs +++ b/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs @@ -6,7 +6,6 @@ using FluentAssertions; using Moq; using NCrunch.Framework; using NUnit.Framework; -using NzbDrone.Common; using NzbDrone.Core.Jobs; using NzbDrone.Core.Model; using NzbDrone.Core.Test.Framework; @@ -21,6 +20,7 @@ namespace NzbDrone.Core.Test.JobTests FakeJob _fakeJob; SlowJob _slowJob; + SlowJob2 _slowJob2; BrokenJob _brokenJob; DisabledJob _disabledJob; @@ -32,11 +32,12 @@ namespace NzbDrone.Core.Test.JobTests { _fakeJob = new FakeJob(); _slowJob = new SlowJob(); + _slowJob2 = new SlowJob2(); _brokenJob = new BrokenJob(); _disabledJob = new DisabledJob(); _updatedJob = null; - IEnumerable jobs = new List { _fakeJob, _slowJob, _brokenJob, _disabledJob }; + IEnumerable jobs = new List { _fakeJob, _slowJob, _slowJob2, _brokenJob, _disabledJob }; Mocker.SetConstant(jobs); @@ -65,11 +66,11 @@ namespace NzbDrone.Core.Test.JobTests private void WaitForQueue() { Console.WriteLine("Waiting for queue to clear."); - var stopWatch = Mocker.Resolve().StopWatch; + var queue = Mocker.Resolve().Queue; - while (stopWatch.IsRunning) + while (Subject.IsProcessing) { - Thread.Sleep(10); + Thread.Sleep(100); } } @@ -113,16 +114,16 @@ namespace NzbDrone.Core.Test.JobTests } [Test] - public void no_concurent_jobs() + public void should_ignore_job_with_same_arg() { - Subject.QueueJob(typeof(SlowJob), 1); - Subject.QueueJob(typeof(SlowJob), 2); - Subject.QueueJob(typeof(SlowJob), 3); + Subject.QueueJob(typeof(SlowJob2), 1); + Subject.QueueJob(typeof(FakeJob), 1); + Subject.QueueJob(typeof(FakeJob), 1); WaitForQueue(); Subject.Queue.Should().BeEmpty(); - _slowJob.ExecutionCount.Should().Be(3); + _fakeJob.ExecutionCount.Should().Be(1); ExceptionVerification.AssertNoUnexcpectedLogs(); } @@ -182,11 +183,11 @@ namespace NzbDrone.Core.Test.JobTests WaitForQueue(); - Mocker.GetMock().Verify(c=>c.Update(It.IsAny()),Times.Never()); + Mocker.GetMock().Verify(c => c.Update(It.IsAny()), Times.Never()); _updatedJob.Should().BeNull(); } - + [Test] public void Item_added_to_queue_while_scheduler_runs_should_be_executed() @@ -217,7 +218,7 @@ namespace NzbDrone.Core.Test.JobTests [Test] public void scheduled_job_should_have_scheduler_as_source() { - GivenPendingJob(new List { new JobDefinition { TypeName = _slowJob.GetType().FullName }, new JobDefinition { TypeName = _slowJob.GetType().FullName } }); + GivenPendingJob(new List { new JobDefinition { TypeName = _slowJob.GetType().FullName }, new JobDefinition { TypeName = _slowJob2.GetType().FullName } }); Subject.QueueScheduled(); Subject.Queue.Should().OnlyContain(c => c.Source == JobQueueItem.JobSourceType.Scheduler); diff --git a/NzbDrone.Core.Test/JobTests/TestJobs.cs b/NzbDrone.Core.Test/JobTests/TestJobs.cs index 8a4c12715..fe3a05ca0 100644 --- a/NzbDrone.Core.Test/JobTests/TestJobs.cs +++ b/NzbDrone.Core.Test/JobTests/TestJobs.cs @@ -57,4 +57,12 @@ namespace NzbDrone.Core.Test.JobTests Thread.Sleep(1000); } } + + public class SlowJob2 : FakeJob + { + protected override void Start() + { + Thread.Sleep(1000); + } + } } diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.ncrunchproject b/NzbDrone.Core.Test/NzbDrone.Core.Test.ncrunchproject index 6f24d559b..3d220e091 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.ncrunchproject +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.ncrunchproject @@ -54,6 +54,498 @@ NzbDrone\.Core\.Test\.ParserTests\.ParserFixture\..* + + NzbDrone\.Core\.Test\.InstrumentationTests\.DatabaseTargetFixture\..* + + + NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.exception_log_with_no_message_should_use_exceptions_message + + + NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.write_log + + + NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.write_log_exception + + + NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.write_long_log + + + NzbDrone\.Core\.Test\.MediaFileTests\.MediaFileProvider_GetNewFilenameTest\..* + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Episode_Quality_1x05_Dash + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Episode_Quality_1x05_Period + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_1x05_Repeat_Dash_Period + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Series_S01E05_Extend_Dash_Period + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_S01E05_Dash + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_Quality_S01E05_Dash + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_Quality_S01E05_Period + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_s01e05_Periods + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Quality_01x05_Space + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_s01e05_Space + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_append_proper_when_proper_and_append_quality_is_true + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_not_append_proper_when_not_proper_and_append_quality_is_true + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_not_append_proper_when_proper_and_append_quality_is_false + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_order_multiple_episode_files_in_numerical_order + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_UseSceneName_when_sceneName_isNotNull + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_UseSceneName_when_sceneName_isNull + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_have_two_episodeTitles_when_distinct_count_is_two + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_have_two_episodeTitles_when_episode_titles_are_not_the_same + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_only_have_one_episodeTitle_when_episode_titles_are_the_same + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_set_airdate_to_unknown_if_not_available + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_use_airDate_if_series_isDaily + + + NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_use_airDate_if_series_isDaily_no_episode_title + + + NzbDrone\.Core\.Test\.ProviderTests\.SceneMappingProviderTest\..* + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_exists + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_multiple_clean_names + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_null + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_should_be_null_when_seasonNumber_does_not_match + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSeriesId_exists + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSeriesId_null + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.UpdateMappings_should_add_all_mappings_to_database + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.UpdateMappings_should_not_delete_if_csv_download_fails + + + NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.UpdateMappings_should_overwrite_existing_mappings + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.GetSearchTitleFixture\..* + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_ampersand_with_and + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_some_special_characters("Betty White\'s Off Their Rockers","Betty Whites Off Their Rockers") + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_some_special_characters("Hawaii Five-0","Hawaii Five-0") + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_some_special_characters("Star Wars: The Clone Wars","Star Wars The Clone Wars") + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_scene_mapping_when_one_exists + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_season_scene_name_when_one_exists + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_series_scene_name_when_one_for_season_does_not_exist + + + NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_series_title_when_there_is_no_scene_mapping + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.ProcessResultsFixture\..* + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_check_other_reports_when_quality_is_not_wanted + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_process_higher_quality_results_first + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_process_newer_reports_first + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_return_valid_successes_when_one_or_more_downloaded + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_should_skip_if_series_is_not_watched + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_skip_if_episode_was_already_downloaded + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_skip_if_series_does_not_match_searched_series + + + NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_try_next_report_if_download_fails + + + NzbDrone\.Core\.Test\.TvTests\.EpisodeProviderTests\.GetEpisodeBySceneNumberFixture\..* + + + NzbDrone.Core.Test.TvTests.EpisodeProviderTests.GetEpisodeBySceneNumberFixture.should_return_episode_if_matching_episode_is_found + + + NzbDrone.Core.Test.TvTests.EpisodeProviderTests.GetEpisodeBySceneNumberFixture.should_return_null_if_no_episodes_in_db + + + NzbDrone.Core.Test.TvTests.EpisodeProviderTests.GetEpisodeBySceneNumberFixture.should_return_null_if_no_matching_episode_is_found + + + NzbDrone\.Core\.Test\.TvTests\.SeasonProviderTest\..* + + + NzbDrone.Core.Test.TvTests.SeasonProviderTest.All_should_return_all_seasons_with_episodes + + + NzbDrone.Core.Test.TvTests.SeasonProviderTest.All_should_return_seasons_with_episodes + + + NzbDrone.Core.Test.TvTests.SeasonProviderTest.GetSeason_should_return_seasons_for_specified_series_only + + + NzbDrone.Core.Test.TvTests.SeasonProviderTest.IsIgnored_should_return_ignored_status_of_season(False) + + + NzbDrone.Core.Test.TvTests.SeasonProviderTest.IsIgnored_should_return_ignored_status_of_season(True) + + + NzbDrone.Core.Test.TvTests.SeasonProviderTest.IsIgnored_should_throw_an_exception_if_not_in_db + + + NzbDrone\.Core\.Test\.Datastore\.ObjectDatabaseFixture\..* + + + NzbDrone\.Core\.Test\.Datastore\.BasicRepositoryFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.AcceptableSizeSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.AllowedDownloadSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.AllowedReleaseGroupSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.CustomStartDateSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.LanguageSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.MonitoredEpisodeSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.QualityAllowedByProfileSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.QualityUpgradeSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.RetentionSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.UpgradeDiskSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.UpgradeHistorySpecificationFixture\..* + + + NzbDrone\.Core\.Test\.DecisionEngineTests\.UpgradePossibleSpecificationFixture\..* + + + NzbDrone\.Core\.Test\.EpisodeParseResultTest\..* + + + NzbDrone\.Core\.Test\.EpisodeStatusTest\..* + + + NzbDrone\.Core\.Test\.FluentTest\..* + + + NzbDrone\.Core\.Test\.HelperTests\.SortHelperTest\..* + + + NzbDrone\.Core\.Test\.HelperTests\.XElementHelperTests\.ParseDayOfWeekFixture\..* + + + NzbDrone\.Core\.Test\.HelperTests\.XElementHelperTests\.XElementHelperTest\..* + + + NzbDrone\.Core\.Test\.Indexers\.IndexerServiceTest\..* + + + NzbDrone\.Core\.Test\.IndexerTests\.IndexerFixture\..* + + + NzbDrone\.Core\.Test\.IndexerTests\.NzbxFixture\..* + + + NzbDrone\.Core\.Test\.JobTests\.AppUpdateJobFixture\..* + + + NzbDrone\.Core\.Test\.JobTests\.BacklogSearchJobTest\..* + + + NzbDrone\.Core\.Test\.JobTests\.DiskScanJobTest\..* + + + NzbDrone\.Core\.Test\.JobTests\.ImportNewSeriesJobTest\..* + + + NzbDrone\.Core\.Test\.JobTests\.JobRepositoryFixture\..* + + + NzbDrone\.Core\.Test\.JobTests\.PostDownloadScanJobFixture\..* + + + NzbDrone\.Core\.Test\.JobTests\.RecentBacklogSearchJobTest\..* + + + NzbDrone\.Core\.Test\.JobTests\.RenameSeasonJobFixture\..* + + + NzbDrone\.Core\.Test\.JobTests\.RssSyncJobTest\..* + + + NzbDrone\.Core\.Test\.JobTests\.SeasonSearchJobTest\..* + + + NzbDrone\.Core\.Test\.JobTests\.SeriesSearchJobTest\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskProviderTests\.ExtractArchiveFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskProviderTests\.FreeDiskSpaceTest\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.CleanUpDropFolderFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.CleanUpFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.GetVideoFilesFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.ImportFileFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.MoveEpisodeFileFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.ScanFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.BlackholeProviderFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.NzbgetProviderTests\.DownloadNzbFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.NzbgetProviderTests\.QueueFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.PneumaticProviderFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.SabProviderTests\.QueueFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.SabProviderTests\.SabProviderFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadProviderTests\.ContainsRecentEpisode\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.DownloadProviderTests\.DownloadProviderFixture\..* + + + NzbDrone\.Core\.Test\.MediaFileTests\.MediaFileServiceTest\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.EventClientProviderTest\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.MisnamedProviderTest\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.NotificationProviderTests\.NotificationProviderFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.PlexProviderTest\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.GetFolderNameWithStatusFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.ProcessDownloadFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.ProcessDropDirectoryFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.ProcessVideoFileFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.CleanupFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.DeleteDirectoryFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.DeleteFileFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.EmptyFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.DailyEpisodeSearchTests\.CheckReportFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.DailyEpisodeSearchTests\.PerformSearchFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.EpisodeSearchTests\.CheckReportFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.EpisodeSearchTests\.PerformSearchFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.PartialSeasonSearchTests\.CheckReportFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.PartialSeasonSearchTests\.PerformSearchFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.TvRageMappingProviderTests\.FindMatchingTvRageSeriesFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.TvRageMappingProviderTests\.ProcessResultsFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.TvRageProviderTests\.GetSeriesFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.TvRageProviderTests\.GetUtcOffsetFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.TvRageProviderTests\.SearchSeriesFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.UpdateProviderTests\.GetAvilableUpdateFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.UpdateProviderTests\.GetUpdateLogFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.XbmcProviderTest\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.XemCommunicationProviderTests\.GetSceneTvdbMappingsFixture\..* + + + NzbDrone\.Core\.Test\.ProviderTests\.XemCommunicationProviderTests\.GetXemSeriesIdsFixture\..* + + + NzbDrone\.Core\.Test\.RootFolderTests\.FreeSpaceOnDrivesFixture\..* + + + NzbDrone\.Core\.Test\.RootFolderTests\.RootFolderServiceFixture\..* + + + NzbDrone\.Core\.Test\.Indexers\.NewznabProviderTest\..* + + + NzbDrone\.Core\.Test\.HistoryTests\.HistoryServiceTest\..* + + + NzbDrone\.Core\.Test\.Configuration\.ConfigServiceFixture\..* + + + NzbDrone\.Core\.Test\.Configuration\.ConfigCachingFixture\..* + + + NzbDrone\.Core\.Test\.TvTests\.SeriesProviderTest\..* + + + NzbDrone\.Core\.Test\.XbmcVersionTests\..* + + + NzbDrone\.Core\.Test\.MediaFileTests\.MediaFileRepositoryFixture\..* + + + NzbDrone\.Core\.Test\.Qualities\.QualityFixture\..* + + + NzbDrone\.Core\.Test\.Qualities\.QualityProfileFixture\..* + + + NzbDrone\.Core\.Test\.Qualities\.QualitySizeServiceFixture\..* + + + NzbDrone\.Core\.Test\.TvTests\.QualityModelFixture\..* + PostBuildEventDisabled;PreBuildEventDisabled \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/JobController.cs b/NzbDrone.Core/Jobs/JobController.cs index b184b9ad0..4b7a909f7 100644 --- a/NzbDrone.Core/Jobs/JobController.cs +++ b/NzbDrone.Core/Jobs/JobController.cs @@ -1,10 +1,10 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; using NLog; -using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Model; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; @@ -13,32 +13,31 @@ namespace NzbDrone.Core.Jobs { public interface IJobController { - Stopwatch StopWatch { get; } - List Queue { get; } + bool IsProcessing { get; } + IEnumerable Queue { get; } void QueueScheduled(); void QueueJob(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User); bool QueueJob(string jobTypeString); } - public class JobController : IJobController, IInitializable + public class JobController : IJobController { private readonly NotificationProvider _notificationProvider; private readonly IEnumerable _jobs; private readonly IJobRepository _jobRepository; private readonly Logger _logger; - private Timer _timer; private Thread _jobThread; - public Stopwatch StopWatch { get; private set; } + + private readonly object _executionLock = new object(); - private readonly List _queue = new List(); + private readonly BlockingCollection _queue = new BlockingCollection(); private ProgressNotification _notification; public JobController(NotificationProvider notificationProvider, IEnumerable jobs, IJobRepository jobRepository, Logger logger) { - StopWatch = new Stopwatch(); _notificationProvider = notificationProvider; _jobs = jobs; _jobRepository = jobRepository; @@ -46,13 +45,10 @@ namespace NzbDrone.Core.Jobs ResetThread(); } - public void Init() - { - _timer = new Timer(c => QueueScheduled()); - _timer.Change(0, 60 * 1000); - } - public List Queue + public bool IsProcessing { get; private set; } + + public IEnumerable Queue { get { @@ -64,8 +60,6 @@ namespace NzbDrone.Core.Jobs { lock (_executionLock) { - VerifyThreadTime(); - if (_jobThread.IsAlive) { _logger.Trace("Queue is already running. Ignoring scheduler's request."); @@ -84,6 +78,8 @@ namespace NzbDrone.Core.Jobs public virtual void QueueJob(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User) { + IsProcessing = true; + var queueItem = new JobQueueItem { JobType = jobType, @@ -95,18 +91,16 @@ namespace NzbDrone.Core.Jobs lock (_executionLock) { - VerifyThreadTime(); - - lock (Queue) + lock (_queue) { - if (!Queue.Contains(queueItem)) + if (!_queue.Contains(queueItem)) { - Queue.Add(queueItem); - _logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, Queue.Count); + _queue.Add(queueItem); + _logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, _queue.Count); } else { - _logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, Queue.Count); + _logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, _queue.Count); } } @@ -117,7 +111,6 @@ namespace NzbDrone.Core.Jobs } ResetThread(); - StopWatch = Stopwatch.StartNew(); _jobThread.Start(); } @@ -138,40 +131,25 @@ namespace NzbDrone.Core.Jobs { try { - do + while (true) { - using (NestedDiagnosticsContext.Push(Guid.NewGuid().ToString())) + IsProcessing = false; + var item = _queue.Take(); + IsProcessing = true; + + try { - try - { - JobQueueItem job = null; - - lock (Queue) - { - if (Queue.Count != 0) - { - job = Queue.OrderBy(c => c.Source).First(); - _logger.Trace("Popping {0} from the queue.", job); - Queue.Remove(job); - } - } - - if (job != null) - { - Execute(job); - } - } - catch (ThreadAbortException) - { - throw; - } - catch (Exception e) - { - _logger.FatalException("An error has occurred while executing job.", e); - } + Execute(item); } - - } while (Queue.Count != 0); + catch (ThreadAbortException) + { + throw; + } + catch (Exception e) + { + _logger.FatalException("An error has occurred while executing job.", e); + } + } } catch (ThreadAbortException e) { @@ -183,7 +161,6 @@ namespace NzbDrone.Core.Jobs } finally { - StopWatch.Stop(); _logger.Trace("Finished processing jobs in the queue."); } } @@ -239,14 +216,6 @@ namespace NzbDrone.Core.Jobs } } - private void VerifyThreadTime() - { - if (StopWatch.Elapsed.TotalHours > 1) - { - _logger.Warn("Thread job has been running for more than an hour. fuck it!"); - ResetThread(); - } - } private void ResetThread() {