From 715564f667a22ac72d6c0dc66fd3d65408b087c3 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Wed, 9 Feb 2022 20:11:42 -0800 Subject: [PATCH] fix: resolve GH #615 - ConnectivityMonitor tests wrong thing --- Rollbar/IRollbarConnectivityMonitor.cs | 11 +++ .../RollbarConnectivityMonitor.cs | 15 ++-- Rollbar/Infrastructure/_Infrastructure.cd | 85 ++++++++----------- Rollbar/_RollbarInfrastructure.cd | 31 +++---- SdkCommon.csproj | 20 +---- .../RollbarConnectivityMonitorFixture.cs} | 17 ++-- 6 files changed, 81 insertions(+), 98 deletions(-) rename UnitTest.Rollbar/{ConnectivityMonitorFixture.cs => Infrastructure/RollbarConnectivityMonitorFixture.cs} (76%) diff --git a/Rollbar/IRollbarConnectivityMonitor.cs b/Rollbar/IRollbarConnectivityMonitor.cs index c6067d93..371afb4b 100644 --- a/Rollbar/IRollbarConnectivityMonitor.cs +++ b/Rollbar/IRollbarConnectivityMonitor.cs @@ -21,5 +21,16 @@ bool IsDisabled { get; } + + /// + /// Disables this instance. + /// + /// + /// Any concrete Connectivity Monitor implementation may not be 100% accurate for all the possible + /// network environments. So, you may have to disable it in case it does not properly detect + /// specific network conditions. If disabled it will be assumed to always have its + /// IsConnectivityOn property returning true. + /// + void Disable(); } } \ No newline at end of file diff --git a/Rollbar/Infrastructure/RollbarConnectivityMonitor.cs b/Rollbar/Infrastructure/RollbarConnectivityMonitor.cs index db4a5dc2..da69da4b 100644 --- a/Rollbar/Infrastructure/RollbarConnectivityMonitor.cs +++ b/Rollbar/Infrastructure/RollbarConnectivityMonitor.cs @@ -14,11 +14,11 @@ internal class RollbarConnectivityMonitor : IRollbarConnectivityMonitor , IDisposable { - private readonly object _connectivityStatusSyncLock = new object(); - private TimeSpan _currentMonitoringInterval; - private Timer? _monitoringTimer; + private readonly object _connectivityStatusSyncLock = new(); private readonly TimeSpan _minMonitoringInterval; private readonly TimeSpan _maxMonitoringInterval; + private TimeSpan _currentMonitoringInterval; + private Timer? _monitoringTimer; #region singleton implementation @@ -84,7 +84,7 @@ private NestedSingleInstance() /// true if this instance is connectivity on; otherwise, false. public bool IsConnectivityOn { - get; // NOTE: Simplest way to fake no-connectivity is to always return false from the getter + get; // NOTE: Simplest way to fake no-connectivity is to always return false from this getter private set; } @@ -110,6 +110,10 @@ public void OverrideAsOffline() /// /// Disables this instance. /// + /// Any concrete Connectivity Monitor implementation may not be 100% accurate for all the possible + /// network environments. So, you may have to disable it in case it does not properly detect + /// specific network conditions. If disabled it will be assumed to always have its + /// IsConnectivityOn property returning true. public void Disable() { lock(this._connectivityStatusSyncLock) @@ -234,7 +238,7 @@ public static bool TestApiServer() TcpClient? client = null; try { - client = new TcpClient("www.rollbar.com", 80); + client = new TcpClient(@"api.rollbar.com", 443); result = true; } catch(SocketException ex) @@ -255,7 +259,6 @@ public static bool TestApiServer() private bool _disposedValue = false; // To detect redundant calls - /// /// Releases unmanaged and - optionally - managed resources. /// diff --git a/Rollbar/Infrastructure/_Infrastructure.cd b/Rollbar/Infrastructure/_Infrastructure.cd index f89b50bf..4690e5fb 100644 --- a/Rollbar/Infrastructure/_Infrastructure.cd +++ b/Rollbar/Infrastructure/_Infrastructure.cd @@ -1,30 +1,30 @@  - + - QAAAQEAAAAAAAAIAAAAAAAAAEAABAAADAABAAAAAEAA= + QAAAQEAAAAAAAAIAAAAAAAAAEAABAAADAAAAAAAAEAA= Infrastructure\AccessTokenQueuesMetadata.cs - + - gABAAAAAABIEAEIAEAAAAAAAIEAABAAAAAIIARAIACQ= + gABAAAAAABIEAEIAEAAAAAAAIEAABAAAAAIIARAIAAQ= Infrastructure\PayloadQueue.cs - + - + - InternalInfrastructure\RollbarRateLimit.cs + Infrastructure\RollbarRateLimit.cs @@ -33,7 +33,7 @@ Infrastructure\RollbarRateLimit.cs - + AAAAAAAAAAAAAQAAQAAAAAQAAAAAAAAQAAAAAAABAAA= @@ -41,46 +41,22 @@ - - + + - CAAAAAAEAgCAAAQAAhAAAAACAQABAAAAAAIAAADAABA= - Infrastructure\RollbarClient.cs - - - - - - EAQAAAAABAAAAAAJAEIQgSQigAIHAoAAAABACAAAKAA= + EAQAAAAABAAAAAAJAEAQgSQigAIHAoAAAABACAAAKAA= Infrastructure\PayloadBundle.cs - - - - - - - - - InternalInfrastructure\ConnectivityMonitor.cs - - - - - ARAgAARAAQAQQAAQAEAAAAAAAoCAAAAAQAAAAAAAAAA= - Infrastructure\ConnectivityMonitor.cs - - - + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA= Infrastructure\RollbarErrorUtility.cs - + AAAIAAAAACABAYAABAAAABAAAAkAAAAAAAEAQkAABAA= @@ -88,7 +64,7 @@ - + AAACAAAAAAAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAAA= @@ -96,31 +72,42 @@ - + AAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAIAAAAAAQAAAA= Infrastructure\RollbarUtility.cs - + + + + + + + + + Infrastructure\RollbarConnectivityMonitor.cs + + + + + ARAgAABAASAQQAAQAAIAAAAAAoCAAAEAQABgAAAAAAA= + Infrastructure\RollbarConnectivityMonitor.cs + + + + gABAAAAAAAIEAAIAAAAAAAAAAEAABAAAAAAIARAIAAQ= Infrastructure\IPayloadQueue.cs - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAABAAABAABAAAAAEAA= - Infrastructure\IPayloadQueuesRegistry.cs - - - + - AAAQAAAAgAAAAAAgAAFCAEAIAAAAAAYCAAAAIAAAwEA= + AAAQAAUAgAAAEAAgAAFCAEAIAAACAAYCAAAAIAAAwEA= Infrastructure\InternalRollbarError.cs diff --git a/Rollbar/_RollbarInfrastructure.cd b/Rollbar/_RollbarInfrastructure.cd index 3aff3f1a..487df3b6 100644 --- a/Rollbar/_RollbarInfrastructure.cd +++ b/Rollbar/_RollbarInfrastructure.cd @@ -1,6 +1,6 @@  - + @@ -8,14 +8,14 @@ - + - RollbarQueueController.cs + Infrastructure\RollbarQueueController.cs - + - RollbarQueueController.cs + Infrastructure\RollbarQueueController.cs @@ -32,10 +32,6 @@ - - - - RollbarInfrastructure.cs @@ -57,10 +53,6 @@ - - - - Telemetry\RollbarTelemetryCollector.cs @@ -73,11 +65,12 @@ - + - AAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAACAAAAA= + AAAAAAAAAAAAAAAAAAAAAAAgAAAEAAAAAAAAACAAAAA= RollbarException.cs + @@ -101,7 +94,7 @@ - + AAAACAAAAAAAAAAAAAAAEAAAAABAAAAIAAAAAAAAAAA= IRollbarInfrastructureOptions.cs @@ -121,10 +114,10 @@ ErrorLevel.cs - - + + - AAAQAAUAgAAAAAAgAAFCAEAIAAACAAYCAAAAIAAAwEA= + AAAQAAUAgAAAEAAgAAFCAEAIAAACAAYCAAAAIAAAwEA= Infrastructure\InternalRollbarError.cs diff --git a/SdkCommon.csproj b/SdkCommon.csproj index ddb82e4c..161afa07 100644 --- a/SdkCommon.csproj +++ b/SdkCommon.csproj @@ -24,28 +24,12 @@ - 5.1.0 + 5.1.1 false - Since v4: - - - feat: optioanl RollbarInfrastructure concept - - feat: optional explicit RollbarInfrastructure initialization - - feat: structured Rollbar configuration - - feat: Blazor browser-side support - - feat: resolve #532 - Make RollbarMiddlewareException wrapper optional based on config settings - - feat: resolve #585 - Would like to have an ability to log HttpRequest Body via ILogger - - fix: OfflinePersistence module's dependency on SQLite native bits - - refactor: Simplified and upgraded Rollbar.OfflinePersistence dependencies and project settings - - refactor: resolve #587 - Update Rollbar.NET's dependency on Newtonsoft.Json package to current version 13.0 - - refactor: clean up the SDK explicit targets to only currently supported .NET versions - - refactor: clear all the VS build warnings and Intelli-sense messages - - refactor: addressed SonarCloud detected reliability issues - - refactor: addressed SonarCloud detected security hotspots - - refactor: addressed SonarCloud detected code smells - - chore: remove unused files from the repo root + - fix: resolve GH #615 - ConnectivityMonitor tests wrong thing diff --git a/UnitTest.Rollbar/ConnectivityMonitorFixture.cs b/UnitTest.Rollbar/Infrastructure/RollbarConnectivityMonitorFixture.cs similarity index 76% rename from UnitTest.Rollbar/ConnectivityMonitorFixture.cs rename to UnitTest.Rollbar/Infrastructure/RollbarConnectivityMonitorFixture.cs index 7fd33aaa..3fe438e2 100644 --- a/UnitTest.Rollbar/ConnectivityMonitorFixture.cs +++ b/UnitTest.Rollbar/Infrastructure/RollbarConnectivityMonitorFixture.cs @@ -1,18 +1,15 @@ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member namespace UnitTest.Rollbar { - using System; - using System.Diagnostics; - using System.Threading; - using global::Rollbar; + using global::Rollbar.Infrastructure; using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] - [TestCategory(nameof(ConnectivityMonitorFixture))] - public class ConnectivityMonitorFixture + [TestCategory(nameof(RollbarConnectivityMonitorFixture))] + public class RollbarConnectivityMonitorFixture { [TestInitialize] public void SetupFixture() @@ -24,6 +21,14 @@ public void TearDownFixture() { } + [TestMethod] + public void TestApiServerTest() + { + bool isConnected = RollbarConnectivityMonitor.TestApiServer(); + Assert.IsTrue(isConnected, "Access to api.rollbar.com:443"); + } + + //[TestMethod] //public void ManualTest() { //bool lastState = false;