From 44d6d20bd6ae400d2a0f2c1388e12f9f2aab158e Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 2 Feb 2012 16:11:18 -0800 Subject: [PATCH] Deskmetrics will not report any data unless using the master branch. --- .../AnalyticsProviderFixture.cs | 51 +++++++++++++++++++ NzbDrone.Core/Providers/AnalyticsProvider.cs | 18 ++++++- .../Providers/Core/ConfigProvider.cs | 2 +- NzbDrone.Core/Providers/UpdateProvider.cs | 2 +- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs index 58b577a62..0bdffe46e 100644 --- a/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/AnalyticsProviderTests/AnalyticsProviderFixture.cs @@ -4,6 +4,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests @@ -11,6 +12,13 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests // ReSharper disable InconsistentNaming public class AnalyticsProviderFixture : CoreTest { + + [SetUp] + public void Setup() + { + Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns(UpdateProvider.DEFAULT_UPDATE_URL); + } + [Test] public void checkpoint_should_stop_existing_start_then_start_again() { @@ -59,6 +67,49 @@ namespace NzbDrone.Core.Test.ProviderTests.AnalyticsProviderTests Mocker.GetMock().Verify(c => c.RegisterInstall(), Times.Never()); } + + [Test] + public void shouldnt_register_anything_if_not_on_master_branch() + { + EnviromentProvider.IsNewInstall = false; + + Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/"); + + Mocker.GetMock(MockBehavior.Strict); + + Mocker.Resolve().Checkpoint(); + } + + [Test] + public void new_install_shouldnt_register_anything_if_not_on_master_branch() + { + EnviromentProvider.IsNewInstall = true; + + Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns("http://update.nzbdrone.com/master_auto/"); + + Mocker.GetMock(MockBehavior.Strict); + + Mocker.Resolve().Checkpoint(); + } + + + [TestCase("http://update.nzbdrone.com/master/")] + [TestCase("http://update.nzbdrone.com/master//")] + [TestCase("http://update.nzbdrone.com/master")] + [TestCase("http://update.nzbdrone.com/master ")] + [TestCase("http://update.nzbdrone.com/master/ ")] + [TestCase("http://UPDATE.nzbdrone.COM/master/ ")] + public void should_still_work_if_url_is_slightly_diffrent(string url) + { + Mocker.GetMock().SetupGet(c => c.UpdateUrl).Returns(url); + + var provider = Mocker.Resolve(); + + provider.Checkpoint(); + + Mocker.GetMock().Verify(c => c.Start(), Times.Once()); + } + } } diff --git a/NzbDrone.Core/Providers/AnalyticsProvider.cs b/NzbDrone.Core/Providers/AnalyticsProvider.cs index ef484992d..effe88f41 100644 --- a/NzbDrone.Core/Providers/AnalyticsProvider.cs +++ b/NzbDrone.Core/Providers/AnalyticsProvider.cs @@ -4,6 +4,7 @@ using DeskMetrics; using NLog; using Ninject; using NzbDrone.Common; +using NzbDrone.Core.Providers.Core; namespace NzbDrone.Core.Providers { @@ -12,13 +13,15 @@ namespace NzbDrone.Core.Providers private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private readonly IDeskMetricsClient _deskMetricsClient; + private readonly ConfigProvider _configProvider; public const string DESKMETRICS_TEST_ID = "4ea8d347a14ad71442000002"; public const string DESKMETRICS_PRODUCTION_ID = "4f20b01ea14ad729b2000000"; [Inject] - public AnalyticsProvider(IDeskMetricsClient deskMetricsClient) + public AnalyticsProvider(IDeskMetricsClient deskMetricsClient, ConfigProvider configProvider) { _deskMetricsClient = deskMetricsClient; + _configProvider = configProvider; } public AnalyticsProvider() @@ -30,6 +33,10 @@ namespace NzbDrone.Core.Providers { try { + //Don't report anything unless working from master branch. + if (!IsOnMasterBranch()) + return; + if (EnviromentProvider.IsNewInstall) { _deskMetricsClient.RegisterInstall(); @@ -50,5 +57,14 @@ namespace NzbDrone.Core.Providers logger.WarnException("Error while sending analytics data.", e); } } + + + private bool IsOnMasterBranch() + { + var defaultUpdateUrl = UpdateProvider.DEFAULT_UPDATE_URL.Trim().Trim('/'); + var currentUpdateUrl = _configProvider.UpdateUrl.Trim().Trim('/'); + + return String.Equals(defaultUpdateUrl, currentUpdateUrl, StringComparison.InvariantCultureIgnoreCase); + } } } diff --git a/NzbDrone.Core/Providers/Core/ConfigProvider.cs b/NzbDrone.Core/Providers/Core/ConfigProvider.cs index e54991446..95bd04216 100644 --- a/NzbDrone.Core/Providers/Core/ConfigProvider.cs +++ b/NzbDrone.Core/Providers/Core/ConfigProvider.cs @@ -258,7 +258,7 @@ namespace NzbDrone.Core.Providers.Core public virtual string UpdateUrl { - get { return GetValue("UpdateUrl", @"http://update.nzbdrone.com/master/"); } + get { return GetValue("UpdateUrl", UpdateProvider.DEFAULT_UPDATE_URL); } set { SetValue("UpdateUrl", value); } } diff --git a/NzbDrone.Core/Providers/UpdateProvider.cs b/NzbDrone.Core/Providers/UpdateProvider.cs index 2bb7c3a1c..70b425bdd 100644 --- a/NzbDrone.Core/Providers/UpdateProvider.cs +++ b/NzbDrone.Core/Providers/UpdateProvider.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.Providers private static readonly Logger logger = LogManager.GetCurrentClassLogger(); private static readonly Regex parseRegex = new Regex(@"(?:\>)(?NzbDrone.+?(?\d+\.\d+\.\d+\.\d+).+?)(?:\<\/A\>)", RegexOptions.IgnoreCase); - + public const string DEFAULT_UPDATE_URL = @"http://update.nzbdrone.com/master/"; [Inject]