From 5abcf887b08eab568d314bfaa48d8e107b78a45c Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Sat, 14 Jan 2017 11:30:33 -0800 Subject: [PATCH] cleanup --- .../NzbDrone.Common.Test.csproj | 2 +- .../ProcessProviderFixture.cs} | 20 ++++++++++++------- .../Instrumentation/Sentry/SentryTarget.cs | 11 +++++----- .../Download/Clients/Hadouken/Hadouken.cs | 8 ++++---- src/NzbDrone.Core/Parser/LanguageParser.cs | 6 +++--- src/NzbDrone.Test.Common/NzbDroneRunner.cs | 16 ++++++++------- src/NzbDrone.Update/UpdateApp.cs | 2 +- 7 files changed, 36 insertions(+), 29 deletions(-) rename src/NzbDrone.Common.Test/{ProcessProviderTests.cs => Processes/ProcessProviderFixture.cs} (87%) diff --git a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index eac513244..decc4985d 100644 --- a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -94,7 +94,7 @@ - + diff --git a/src/NzbDrone.Common.Test/ProcessProviderTests.cs b/src/NzbDrone.Common.Test/Processes/ProcessProviderFixture.cs similarity index 87% rename from src/NzbDrone.Common.Test/ProcessProviderTests.cs rename to src/NzbDrone.Common.Test/Processes/ProcessProviderFixture.cs index 205037562..e90ddca35 100644 --- a/src/NzbDrone.Common.Test/ProcessProviderTests.cs +++ b/src/NzbDrone.Common.Test/Processes/ProcessProviderFixture.cs @@ -10,20 +10,20 @@ using NzbDrone.Common.Processes; using NzbDrone.Test.Common; using NzbDrone.Test.Dummy; -namespace NzbDrone.Common.Test +namespace NzbDrone.Common.Test.Processes { [TestFixture] - public class ProcessProviderTests : TestBase + public class ProcessProviderFixture : TestBase { [SetUp] public void Setup() { Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).ToList().ForEach(c => - { - c.Kill(); - c.WaitForExit(); - }); + { + c.Kill(); + c.WaitForExit(); + }); Process.GetProcessesByName(DummyApp.DUMMY_PROCCESS_NAME).Should().BeEmpty(); } @@ -41,7 +41,7 @@ namespace NzbDrone.Common.Test { TestLogger.Warn(ex, "{0} when killing process", ex.Message); } - + }); } @@ -101,5 +101,11 @@ namespace NzbDrone.Common.Test Console.WriteLine(new ProcessInfo().ToString()); ExceptionVerification.MarkInconclusive(typeof(Win32Exception)); } + + [Test] + public void should_find_process_by_name() + { + Subject.FindProcessByName(Process.GetCurrentProcess().ProcessName).Should().NotBeNull(); + } } } diff --git a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs index 6ec6fd1e4..83d7cfb04 100644 --- a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs @@ -33,22 +33,21 @@ namespace NzbDrone.Common.Instrumentation.Sentry public SentryTarget(string dsn) { + _debounce = new SentryDebounce(); + _client = new RavenClient(new Dsn(dsn), new SonarrJsonPacketFactory(), new SentryRequestFactory(), new MachineNameUserFactory()) { Compression = true, - Environment = RuntimeInfo.IsProduction ? "production" : "development", - Release = BuildInfo.Release + Release = BuildInfo.Release, + ErrorOnCapture = OnError, + Timeout = TimeSpan.FromSeconds(1) }; - _client.ErrorOnCapture = OnError; - _client.Tags.Add("osfamily", OsInfo.Os.ToString()); _client.Tags.Add("runtime", PlatformInfo.Platform.ToString().ToLower()); _client.Tags.Add("culture", Thread.CurrentThread.CurrentCulture.Name); _client.Tags.Add("branch", BuildInfo.Branch); _client.Tags.Add("version", BuildInfo.Version.ToString()); - - _debounce = new SentryDebounce(); } private void OnError(Exception ex) diff --git a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs index 5727dea8b..09c51aac9 100644 --- a/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs +++ b/src/NzbDrone.Core/Download/Clients/Hadouken/Hadouken.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken } catch (DownloadClientException ex) { - _logger.ErrorException(ex.Message, ex); + _logger.Error(ex); return Enumerable.Empty(); } @@ -170,12 +170,12 @@ namespace NzbDrone.Core.Download.Clients.Hadouken if (version < new Version("5.1")) { - return new ValidationFailure(string.Empty, "Old Hadouken client with unsupported API, need 5.1 or higher"); + return new ValidationFailure(string.Empty, "Old Hadouken client with unsupported API, need 5.1 or higher"); } } catch (DownloadClientAuthenticationException ex) { - _logger.ErrorException(ex.Message, ex); + _logger.Error(ex); return new NzbDroneValidationFailure("Password", "Authentication failed"); } @@ -191,7 +191,7 @@ namespace NzbDrone.Core.Download.Clients.Hadouken } catch (Exception ex) { - _logger.ErrorException(ex.Message, ex); + _logger.Error(ex); return new NzbDroneValidationFailure(String.Empty, "Failed to get the list of torrents: " + ex.Message); } diff --git a/src/NzbDrone.Core/Parser/LanguageParser.cs b/src/NzbDrone.Core/Parser/LanguageParser.cs index 9e5b63a81..8c6510bfc 100644 --- a/src/NzbDrone.Core/Parser/LanguageParser.cs +++ b/src/NzbDrone.Core/Parser/LanguageParser.cs @@ -125,11 +125,11 @@ namespace NzbDrone.Core.Parser Logger.Debug("Unable to parse langauge from subtitle file: {0}", fileName); } - catch (Exception ex) + catch (Exception e) { - Logger.Debug("Failed parsing langauge from subtitle file: {0}", fileName); + Logger.Debug(e, "Failed parsing langauge from subtitle file: {0}", fileName); } - + return Language.Unknown; } } diff --git a/src/NzbDrone.Test.Common/NzbDroneRunner.cs b/src/NzbDrone.Test.Common/NzbDroneRunner.cs index 2f1d8e3f5..27f8c0b21 100644 --- a/src/NzbDrone.Test.Common/NzbDroneRunner.cs +++ b/src/NzbDrone.Test.Common/NzbDroneRunner.cs @@ -57,7 +57,7 @@ namespace NzbDrone.Test.Common Assert.Fail("Process has exited"); } - SetApiKey(); + GetApiKey(); var request = new RestRequest("system/status"); request.AddHeader("Authorization", ApiKey); @@ -71,7 +71,7 @@ namespace NzbDrone.Test.Common return; } - Console.WriteLine("Waiting for NzbDrone to start. Response Status : {0} [{1}] {2}", statusCall.ResponseStatus, statusCall.StatusDescription, statusCall.ErrorException); + Console.WriteLine("Waiting for NzbDrone to start. Response Status : {0} [{1}]", statusCall.ResponseStatus, statusCall.StatusDescription); Thread.Sleep(500); } @@ -81,7 +81,7 @@ namespace NzbDrone.Test.Common { if (_nzbDroneProcess != null) { - _processProvider.Kill(_nzbDroneProcess.Id); + _processProvider.Kill(_nzbDroneProcess.Id); } _processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME); @@ -105,22 +105,22 @@ namespace NzbDrone.Test.Common } } - private void SetApiKey() + private void GetApiKey() { var configFile = Path.Combine(AppData, "config.xml"); var attempts = 0; - while (ApiKey == null && attempts < 50) + while (ApiKey == null && attempts < 30) { try { if (File.Exists(configFile)) { - var apiKeyElement = XDocument.Load(configFile) - .XPathSelectElement("Config/ApiKey"); + var apiKeyElement = XDocument.Load(configFile).XPathSelectElement("Config/ApiKey"); if (apiKeyElement != null) { ApiKey = apiKeyElement.Value; + return; } } } @@ -132,6 +132,8 @@ namespace NzbDrone.Test.Common attempts++; Thread.Sleep(1000); } + + Assert.Fail("Couldn't get API key in time."); } } } \ No newline at end of file diff --git a/src/NzbDrone.Update/UpdateApp.cs b/src/NzbDrone.Update/UpdateApp.cs index eda4f17a5..0296cc70d 100644 --- a/src/NzbDrone.Update/UpdateApp.cs +++ b/src/NzbDrone.Update/UpdateApp.cs @@ -72,7 +72,7 @@ namespace NzbDrone.Update if (OsInfo.IsNotWindows) { - switch (args.Count()) + switch (args.Length) { case 1: return startupContext;