Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ably/pubsub/request/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ def get_hosts(self):
self.__host_expires = None
return hosts

hosts = list(hosts)
hosts.remove(host)
hosts.insert(0, host)
return hosts
# The realtime connection tries every fallback host, so the saved one may not be among
# these. Put it first and keep the number of attempts unchanged.
return [host, *(other for other in hosts if other != host)][:len(hosts)]

@reauth_if_expired
async def make_request(self, method, path, version=None, headers=None, body=None,
Expand Down
16 changes: 16 additions & 0 deletions test/unit/http_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ def test_http_get_rest_hosts_works_when_fallback_realtime_host_is_not_set():
assert all(isinstance(host, str) for host in hosts)


@pytest.mark.parametrize("fallback_index", range(5))
def test_http_get_hosts_accepts_any_realtime_fallback_host(fallback_index):
ably = create_http_client(token="foo")
hosts = ably.options.get_hosts()
fallback_host = ably.options.get_fallback_hosts()[fallback_index]
# The realtime connection may land on any fallback host, not only those REST would retry
ably.options.fallback_host = fallback_host

rest_hosts = ably.http.get_hosts()

assert rest_hosts[0] == fallback_host
assert rest_hosts[1] == hosts[0]
assert len(rest_hosts) == len(hosts)
assert len(set(rest_hosts)) == len(rest_hosts)


class RecordingTransport(httpx.AsyncBaseTransport):
def __init__(self, response_factory):
self.requests = []
Expand Down
Loading