Skip to content

Commit

Permalink
Removed unnecessary test for fallbacks with default host
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Apr 19, 2024
1 parent e044c22 commit 169997a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
11 changes: 1 addition & 10 deletions src/IO.Ably.Tests.Shared/Realtime/ConnectionAttemptsInfoSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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();
}

Expand Down
31 changes: 22 additions & 9 deletions src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
var fallbackHosts = new[]
{
"www.example1.com",
Expand All @@ -619,18 +618,32 @@ public async Task ShouldUseProvidedCustomFallbackHostWhenDefaultHostIsDifferent(
"www.example4.com",
"www.example5.com"
};
var client = CreateClient(options =>

async Task CheckForAttemptedFallbackHosts(AblyRest client, string primaryHost) {

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net7.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net7.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net6.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net6.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net7.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net7.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net6.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net6.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net6.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net6.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net7.0)

Check warning on line 622 in src/IO.Ably.Tests.Shared/Rest/RestSpecs.cs

View workflow job for this annotation

GitHub Actions / check (net7.0)

var attemptedList = new List<string>();
_handler.Requests.Clear();
await Assert.ThrowsAsync<AblyException>(() => 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<AblyException>(() => 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]
Expand Down

0 comments on commit 169997a

Please sign in to comment.