From 9a80c7e33381c8d8cb57786a49289f9b4aae91d5 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Fri, 19 Apr 2024 13:33:45 +0530 Subject: [PATCH] Removed unnecessary test for fallbacks with default host --- .../Realtime/ConnectionAttemptsInfoSpecs.cs | 11 +------ src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/IO.Ably.Tests.Shared/Realtime/ConnectionAttemptsInfoSpecs.cs b/src/IO.Ably.Tests.Shared/Realtime/ConnectionAttemptsInfoSpecs.cs index 02f7d8e38..5d07db566 100644 --- a/src/IO.Ably.Tests.Shared/Realtime/ConnectionAttemptsInfoSpecs.cs +++ b/src/IO.Ably.Tests.Shared/Realtime/ConnectionAttemptsInfoSpecs.cs @@ -57,15 +57,6 @@ public void ShouldSuspend_WhenFirstAttemptEqualOrGreaterThanConnectionStateTtl_S state.ShouldSuspend(now.ValueFn).Should().BeTrue("When time is greater than"); // > } - [Fact] - public async Task CanAttemptFallback_ShouldBeFalseWithNonDefaultHost() - { - var client = GetRealtime(opts => opts.RealtimeHost = "test.test.com"); - - var result = await client.RestClient.CanFallback(null); - result.Should().BeFalse(); - } - [Theory] [InlineData(500)] [InlineData(501)] @@ -84,7 +75,7 @@ public async Task CanAttemptFallback_WithDefaultHostAndAppropriateError_ShouldBe public async Task CanAttemptFallback_WhenInternetCheckFails_ShouldBeFalse() { var client = GetRealtime(internetCheckOk: false); - var result = await client.RestClient.CanFallback(null); + var result = await client.RestClient.CanFallback(ErrorInfo.ReasonUnknown); result.Should().BeFalse(); } diff --git a/src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs b/src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs index 1805e7d46..4e02013d9 100644 --- a/src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs +++ b/src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs @@ -607,10 +607,9 @@ public async Task ShouldUseCustomFallbackHostIfProvided() [Fact] [Trait("spec", "RSC15a")] [Trait("spec", "TO3k6")] - public async Task ShouldUseProvidedCustomFallbackHostWhenDefaultHostIsDifferent() + public async Task ShouldUseProvidedCustomFallbackHostsIrrespectiveOfPrimaryHost() { _response.StatusCode = HttpStatusCode.BadGateway; - var attemptedList = new List(); var fallbackHosts = new[] { "www.example1.com", @@ -619,18 +618,33 @@ public async Task ShouldUseProvidedCustomFallbackHostWhenDefaultHostIsDifferent( "www.example4.com", "www.example5.com" }; - var client = CreateClient(options => + + async Task CheckForAttemptedFallbackHosts(AblyRest client, string primaryHost) + { + var attemptedList = new List(); + _handler.Requests.Clear(); + await Assert.ThrowsAsync(() => MakeAnyRequest(client)); + attemptedList.AddRange(_handler.Requests.Select(x => x.RequestUri.Host).ToList()); + + attemptedList.Count.Should().Be(6); + attemptedList[0].Should().Be(primaryHost); + attemptedList.Skip(1).Should().BeEquivalentTo(fallbackHosts); + } + + var clientWithDefaultPrimaryHost = CreateClient(options => { - options.RestHost = "www.primaryhost.com"; options.FallbackHosts = fallbackHosts; options.HttpMaxRetryCount = 5; }); - await Assert.ThrowsAsync(() => MakeAnyRequest(client)); - attemptedList.AddRange(_handler.Requests.Select(x => x.RequestUri.Host).ToList()); + await CheckForAttemptedFallbackHosts(clientWithDefaultPrimaryHost, "rest.ably.io"); - attemptedList.Count.Should().Be(6); - attemptedList[0].Should().Be("www.primaryhost.com"); - attemptedList.Skip(1).Should().BeEquivalentTo(fallbackHosts); + var clientWithCustomPrimaryHost = CreateClient(options => + { + options.RestHost = "www.primaryhost.com"; + options.FallbackHosts = fallbackHosts; + options.HttpMaxRetryCount = 5; + }); + await CheckForAttemptedFallbackHosts(clientWithCustomPrimaryHost, "www.primaryhost.com"); } [Fact]