Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_reconnect_logic_stop_callback fails when 1.2.3.4/32 is not routable #837

Closed
mweinelt opened this issue Mar 7, 2024 · 0 comments · Fixed by #841
Closed

test_reconnect_logic_stop_callback fails when 1.2.3.4/32 is not routable #837

mweinelt opened this issue Mar 7, 2024 · 0 comments · Fixed by #841

Comments

@mweinelt
Copy link

mweinelt commented Mar 7, 2024

Hi! We're seeing the test_reconnect_logic_stop_callback test fail in our build sandbox, that does not provide internet access.

____________________________________________________________________________ test_reconnect_logic_stop_callback _____________________________________________________________________________

patchable_api_client = <tests.conftest.patchable_api_client.<locals>.PatchableAPIClient object at 0x7f0e45b08360>

    @pytest.mark.asyncio
    async def test_reconnect_logic_stop_callback(patchable_api_client: APIClient):
        """Test that the stop_callback stops the ReconnectLogic."""
        cli = patchable_api_client
        rl = ReconnectLogic(
            client=cli,
            on_disconnect=AsyncMock(),
            on_connect=AsyncMock(),
            zeroconf_instance=get_mock_zeroconf(),
            name="mydevice",
        )
        await rl.start()
        assert rl._connection_state is ReconnectLogicState.DISCONNECTED
        await asyncio.sleep(0)
>       assert rl._connection_state is ReconnectLogicState.CONNECTING
E       assert <ReconnectLogicState.DISCONNECTED: 3> is <ReconnectLogicState.CONNECTING: 0>
E        +  where <ReconnectLogicState.DISCONNECTED: 3> = <aioesphomeapi.reconnect_logic.ReconnectLogic object at 0x7f0e45b21590>._connection_state
E        +  and   <ReconnectLogicState.CONNECTING: 0> = ReconnectLogicState.CONNECTING

tests/test_reconnect_logic.py:633: AssertionError
------------------------------------------------------------------------------------- Captured log call -------------------------------------------------------------------------------------
DEBUG    aioesphomeapi.reconnect_logic:reconnect_logic.py:290 Trying to connect to mydevice @ 1.2.3.4
DEBUG    aioesphomeapi.reconnect_logic:reconnect_logic.py:292 Connected lock acquired for mydevice @ 1.2.3.4
DEBUG    aioesphomeapi.connection:connection.py:331 mydevice @ 1.2.3.4: Connecting to IPv4Sockaddr(address='1.2.3.4', port=6052)
DEBUG    aioesphomeapi.connection:connection.py:278 Cleaning up connection to mydevice @ 1.2.3.4
WARNING  aioesphomeapi.reconnect_logic:reconnect_logic.py:173 Can't connect to ESPHome API for mydevice @ 1.2.3.4: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='1.2.3.4', port=6052))]: [Errno 22] Invalid argument (SocketAPIError)
INFO     aioesphomeapi.reconnect_logic:reconnect_logic.py:303 Trying to connect to mydevice @ 1.2.3.4 in the background
DEBUG    aioesphomeapi.reconnect_logic:reconnect_logic.py:306 Retrying mydevice @ 1.2.3.4 in 2.00 seconds
DEBUG    aioesphomeapi.reconnect_logic:reconnect_logic.py:364 Starting zeroconf listener for mydevice
DEBUG    aioesphomeapi.reconnect_logic:reconnect_logic.py:232 Scheduling new connect attempt in 2.00 seconds

I can reproduce this outside the sandbox by adding a blackhole route towards the destination address.

ip route add blackhole 1.2.3.4/32

This will also happen when the machine has no route towards 1.2.3.4/32.

Would trying to connect to 127.0.0.1 be sufficient? The tests do work with that and it should always be available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant