Giter Site home page Giter Site logo

Comments (8)

Waganama avatar Waganama commented on August 15, 2024 2

It turned out that everything was fine, pytest doesn't print by default.

I'm sorry for the inconvenience

from aiomqtt.

frederikaalund avatar frederikaalund commented on August 15, 2024

Hi Waganama, thanks for opening this issue. πŸ‘ Let me have a look. :)

It looks like you subscribe to these topics:

f"mqtt/things/{device}/uplink"

but you post messages to this topic (where device is the last entry in devices):

f"mqtt/things/{device}/downlink"

Since the topics don't match, you'll never receive a message. That explains why it gets "stuck": There are no messages in wait.

As a test, try to subscribe to everything: "mqtt/things/#". See if that works. :)

from aiomqtt.

Waganama avatar Waganama commented on August 15, 2024

Thank you for your response.
I have two topics, one to send downlink (client->server) and one to received uplink (server->client)
I still tried to change the topic for my subscribtion, without success.

It looks like that calling yield task.result() doesn't do anything when running with pytest.
I'm also sure that i received message according to these logs i had:

DEBUG    aiomqtt:client.py:618 _on_message _queue size after put 1
DEBUG    aiomqtt:client.py:474 _messages yield task.result()
DEBUG    aiomqtt:client.py:463 _messages _queue size after get 0

I tried to run the same code above without pytest, and it worked perfectly, I can read my message.

from aiomqtt.

frederikaalund avatar frederikaalund commented on August 15, 2024

Thanks for the response. This is really difficult to debug without the full code. Do you have self-sufficient example code that reproduces the problem?

from aiomqtt.

Waganama avatar Waganama commented on August 15, 2024

I reduce the test part to reproduce the issue only. It is a very simple test.
Unfortunatly I can't share connection information and i don't know if there are mqtt server dedicated for test.
I hope will have everything to debug.

from aiomqtt.

Waganama avatar Waganama commented on August 15, 2024

After research, i found out i can use the server test.mosquitto.org for my test. I also have the same issue withe the following code using pytest.

Output :

configfile: pytest.ini
plugins: anyio-3.7.0, asyncio-0.21.0
asyncio: mode=Mode.AUTO
collected 2 items

tests/test_mosquitto.py::TestMosquitto::test_mosquitto[asyncio]
--------------------------------------------------- live log setup ----------------------------------------------------
DEBUG    asyncio:selector_events.py:54 Using selector: SelectSelector
---------------------------------------------------- live log call ----------------------------------------------------
INFO     root:test_mosquitto.py:37 Here
DEBUG    aiomqtt:client.py:3254 Sending CONNECT (u0, p0, wr0, wq0, wf0, c1, k60) client_id=b''
DEBUG    aiomqtt:client.py:3254 Received CONNACK (0, 0)
DEBUG    aiomqtt:client.py:3254 Sending SUBSCRIBE (d0, m1) [(b'win32_3.11/tests/aiomqtt/test_client_unsubscribe/1', 0)]
DEBUG    aiomqtt:client.py:3254 Received SUBACK
DEBUG    aiomqtt:client.py:3254 Sending PUBLISH (d0, q0, r0, m2), 'b'win32_3.11/tests/aiomqtt/test_client_unsubscribe/1'', ... (12 bytes)
DEBUG    aiomqtt:client.py:463 _messages _queue size after get 0
DEBUG    aiomqtt:client.py:3254 Received PUBLISH (d0, q0, r0, m0), 'win32_3.11/tests/aiomqtt/test_client_unsubscribe/1', ...  (12 bytes)
DEBUG    aiomqtt:client.py:618 _on_message _queue size after put 1
DEBUG    aiomqtt:client.py:474 _messages yield task.result().topic : win32_3.11/tests/aiomqtt/test_client_unsubscribe/1
DEBUG    aiomqtt:client.py:463 _messages _queue size after get 0

source.zip

from aiomqtt.

Waganama avatar Waganama commented on August 15, 2024

I have additionnal informations, if i have different behaviour according how I run my test :

  • python -m pytest tests\test_mosquitto.py -> No message is printed after the async for loop
  • python -m pytest --capture=no tests\test_mosquitto.py -> Message are printed

I don't know why the capture=no has effect.

from aiomqtt.

frederikaalund avatar frederikaalund commented on August 15, 2024

No problem. πŸ˜„ Glad that it worked out in the end!

from aiomqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.