Danielhiversen / PyXiaomiGateway

PyXiaomiGateway
MIT License
152 stars 55 forks source link

Fix travis build #177

Closed starkillerOG closed 4 years ago

starkillerOG commented 4 years ago

Try to fix travis build, not sure if this will work, but I think so.....

starkillerOG commented 4 years ago

@Danielhiversen Could you look at this?

syssi commented 4 years ago

This change doesn't solve the issue:


$ pip install pytest==5.4.3
Requirement already satisfied: pytest==5.4.3 in /tmp/test/env/lib/python3.7/site-packages (5.4.3)
Requirement already satisfied: more-itertools>=4.0.0 in /tmp/test/env/lib/python3.7/site-packages (from pytest==5.4.3) (8.4.0)
Requirement already satisfied: py>=1.5.0 in /tmp/test/env/lib/python3.7/site-packages (from pytest==5.4.3) (1.9.0)
Requirement already satisfied: packaging in /tmp/test/env/lib/python3.7/site-packages (from pytest==5.4.3) (20.4)
Requirement already satisfied: importlib-metadata>=0.12; python_version < "3.8" in /tmp/test/env/lib/python3.7/site-packages (from pytest==5.4.3) (1.7.0)
Requirement already satisfied: wcwidth in /tmp/test/env/lib/python3.7/site-packages (from pytest==5.4.3) (0.2.5)
Requirement already satisfied: pluggy<1.0,>=0.12 in /tmp/test/env/lib/python3.7/site-packages (from pytest==5.4.3) (0.13.1)
Requirement already satisfied: attrs>=17.4.0 in /tmp/test/env/lib/python3.7/site-packages (from pytest==5.4.3) (19.3.0)
Requirement already satisfied: six in /tmp/test/env/lib/python3.7/site-packages (from packaging->pytest==5.4.3) (1.15.0)
Requirement already satisfied: pyparsing>=2.0.2 in /tmp/test/env/lib/python3.7/site-packages (from packaging->pytest==5.4.3) (2.4.7)
Requirement already satisfied: zipp>=0.5 in /tmp/test/env/lib/python3.7/site-packages (from importlib-metadata>=0.12; python_version < "3.8"->pytest==5.4.3) (3.1.0)

$ pytest
============================================================================== test session starts ===============================================================================
platform linux -- Python 3.7.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /tmp/test/PyXiaomiGateway, inifile: pytest.ini
plugins: asyncio-0.14.0
collected 2 items                                                                                                                                                                

tests/test_e2e.py 

FF                                                                                                                                                       [100%]

==================================================================================== FAILURES ====================================================================================
__________________________________________________________________________________ test_simple ___________________________________________________________________________________

event_loop = <_UnixSelectorEventLoop running=False closed=False debug=False>, pool = <concurrent.futures.thread.ThreadPoolExecutor object at 0x7f16fbf25e10>
client_factory = <function client_factory.<locals>.start_client at 0x7f16fbf1b9d8>

    @pytest.mark.asyncio
    async def test_simple(event_loop, pool, client_factory):
        """2 gateways discovery -> read gateway #1 -> write gateway #2"""
        client = client_factory('10.0.0.1', [gateway1, gateway2])
        await event_loop.run_in_executor(pool, client.discover_gateways)
>       ok = await event_loop.run_in_executor(pool, client.gateways[gateway1['ip']].get_from_hub, '2')
E       AttributeError: 'list' object has no attribute 'get_from_hub'

tests/test_e2e.py:89: AttributeError
------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------
17:32:17 INFO Main 10.0.0.2 connected
17:32:17 INFO Discovery 10.0.0.2 connected
17:32:17 INFO Main 10.0.0.3 connected
17:32:17 INFO Discovery 10.0.0.3 connected
17:32:22 INFO Gateway discovery finished in 5 seconds
----------------------------------------------------------------------------- Captured log teardown ------------------------------------------------------------------------------
17:32:22 INFO Multisocket stopped
___________________________________________________________________________________ test_race ____________________________________________________________________________________

event_loop = <_UnixSelectorEventLoop running=False closed=False debug=False>, pool = <concurrent.futures.thread.ThreadPoolExecutor object at 0x7f16faf02710>
client_factory = <function client_factory.<locals>.start_client at 0x7f16faf52ae8>

    @pytest.mark.asyncio
    async def test_race(event_loop, pool, client_factory):
        """2 gateways discovery -> 100 x (read gateway #1 + write gateway #2)
        https://github.com/Danielhiversen/PyXiaomiGateway/issues/45
        """
        client = client_factory('10.0.0.1', [gateway1, gateway2])
        await event_loop.run_in_executor(pool, client.discover_gateways)
        for i in range(100):
>           task1 = event_loop.run_in_executor(pool, client.gateways[gateway1['ip']].get_from_hub, '2')
E           AttributeError: 'list' object has no attribute 'get_from_hub'

tests/test_e2e.py:103: AttributeError
------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------
17:32:22 INFO Main 10.0.0.2 connected
17:32:22 INFO Discovery 10.0.0.2 connected
17:32:22 INFO Main 10.0.0.3 connected
17:32:22 INFO Discovery 10.0.0.3 connected
17:32:27 INFO Gateway discovery finished in 5 seconds
----------------------------------------------------------------------------- Captured log teardown ------------------------------------------------------------------------------
17:32:27 INFO Multisocket stopped
============================================================================ short test summary info =============================================================================
FAILED tests/test_e2e.py::test_simple - AttributeError: 'list' object has no attribute 'get_from_hub'
FAILED tests/test_e2e.py::test_race - AttributeError: 'list' object has no attribute 'get_from_hub'
=============================================================================== 2 failed in 10.08s ===============================================================================
``
starkillerOG commented 4 years ago

Thanks @syssi! At least it did improve the situation, before it was failing even before the tests ran. However I do not know where these test failures are coming from, I don't think my code change actually caused these failures....

@syssi would you be willing to see if you can fix these travis issues? I am not so familiar with travis

syssi commented 4 years ago

@starkillerOG If I revert PR #172 the tests passes.

starkillerOG commented 4 years ago

@starkillerOG If I revert PR #172 the tests passes.

super weird, not sure what is going on....

starkillerOG commented 4 years ago

@syssi could this be caused because the tests are now also binding to a socket while I think they did not use the bind before? Do you have any idea what is going on with the tests and how to resolve it?

meichthys commented 4 years ago

@starkillerOG At what commit did the builds start failing? It seems like it was some time after #172 as per: https://github.com/Danielhiversen/PyXiaomiGateway/pull/177#issuecomment-660693925 But from what i can tell almost nothing changed after #172

starkillerOG commented 4 years ago

@meichthys it apears the problem is indeed in commit #172, although I do not know what the problem is. I have tested the code in my dev enviroment and I know it works with HomeAssistant. Only the tests are failing, probably it is some small issue, but do not know much about the tests themselfs.....

@meichthys Do you have the expertise to help me out here?

meichthys commented 4 years ago

@starkillerOG I see. I was initially thinking the build failed in a commit after #172. I know some python, but am not too familiar with Travis CI. I'll take a look though! I need these changes asap! My home is do dumb without them 😆

syssi commented 4 years ago

The issue isn't travis related. Just execute the tests locally and you will see the failed one.

meichthys commented 4 years ago

@syssi Is this the same as what you're seeing? image

syssi commented 4 years ago

No. Did you install all dependencies? Just execute the "pip install" call from .travis.yaml.

meichthys commented 4 years ago

Ok, i missed those dependencies. I'm getting this now which seems more relevant: image

meichthys commented 4 years ago

I'm not familiar with travis configs, but to me it seems as though we would need to update the Travis config to work with the Multicast address: image

syssi commented 4 years ago

This is another (windows sockets related) bug. Could you execute the tests on a linux host?

starkillerOG commented 4 years ago

Schould the test not just use the create_mcast_socket function form the init.py file? That would make it compatible with windows I think https://github.com/Danielhiversen/PyXiaomiGateway/blob/df914fcab6403fb493ab14794c735daa59b82409/xiaomi_gateway/__init__.py#L21

starkillerOG commented 4 years ago

Furthermore I think the test needs to bind to port 0 not to 4321, but I could be wrong...

meichthys commented 4 years ago

FYI - Executing this test on OSX i get:

Screen Shot 2020-07-24 at 9 27 00 PM
meichthys commented 4 years ago

@Danielhiversen do you know why this build might be failing? I took a look but am not up to speed on travisCI and am not very familiar with sockets.

The failed build is preventing v13 from being published on pypi which is in turn preventing the homeassistant Xiaomi_aqara component from being fixed in v0.113 of homeassistant.

Danielhiversen commented 4 years ago

https://travis-ci.org/github/Danielhiversen/PyXiaomiGateway/builds/709453945#L356