Commit ac596b64 authored by Julien Prigent's avatar Julien Prigent Committed by oroulet

[HaClient] url_to_reset from list to set

This variable is used to trace server disconnections and renew the subscription/MI when it occurs.
Consequently is had to be unique urls otherwise it could grow indefinitely is some use-cases (i.e: reconciliator
is disabled or running slower that the Keepalive checks).
parent 3a851074
......@@ -127,7 +127,7 @@ class HaClient:
# full type: Dict[str, SortedDict[str, VirtualSubscription]]
self.ideal_map: Dict[str, SortedDict] = {}
self.sub_names: Set[str] = set()
self.url_to_reset: List[str] = []
self.url_to_reset: Set[str] = set()
self.is_running = False
if config.ha_mode != HaMode.WARM:
......@@ -272,7 +272,7 @@ class HaClient:
"""
async with self._url_to_reset_lock:
url = client.server_url.geturl()
self.url_to_reset.append(url)
self.url_to_reset.add(url)
try:
await client.disconnect()
except Exception:
......
......@@ -174,6 +174,12 @@ class TestHaClient:
new_socket = first_client.uaclient.protocol
assert socket != new_socket
# urls to reconnect should only be added once
await ha_client.reconciliator.stop()
await ha_client.reconnect(first_client)
await ha_client.reconnect(first_client)
assert len(ha_client.url_to_reset) == 2
@pytest.mark.asyncio
async def test_failover_warm(self, ha_client, srv_variables):
await ha_client.start()
......@@ -374,9 +380,9 @@ class TestReconciliator:
real_sub = reconciliator.name_to_subscription[primary_url][sub]
real_handle = reconciliator.node_to_handle[primary_url][node_str]
# Append to url_to_reset triggers reconciliator to resub
# Add to url_to_reset triggers reconciliator to resub
async with ha_client._url_to_reset_lock:
ha_client.url_to_reset.append(primary_url)
ha_client.url_to_reset.add(primary_url)
# hack to wait for the reconciliator iteration
sub2 = await ha_client.create_subscription(100, myhandler)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment