From a820a6022ba8d5e5baa33562998de822b728f015 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 24 Dec 2023 17:50:09 +0200 Subject: [PATCH] CI: Run mqttv5 tests Signed-off-by: Aarni Koskela --- .github/workflows/tox.yml | 5 +++++ README.rst | 2 ++ tests/test_mqttv5.py | 29 +++++++++++++++++------------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index ccfdd4b5..6ae8ad38 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -10,6 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + repository: eclipse/paho.mqtt.testing + ref: a4dc694010217b291ee78ee13a6d1db812f9babd + path: paho.mqtt.testing - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} diff --git a/README.rst b/README.rst index f36c9a50..c80e6854 100644 --- a/README.rst +++ b/README.rst @@ -72,6 +72,8 @@ Once you have the code, it can be installed from your repository as well: To perform all test (including MQTT v5 test), you also need to clone paho.mqtt.testing in paho.mqtt.python folder:: git clone https://github.com/eclipse/paho.mqtt.testing.git + cd paho.mqtt.testing + git checkout a4dc694010217b291ee78ee13a6d1db812f9babd Known limitations ----------------- diff --git a/tests/test_mqttv5.py b/tests/test_mqttv5.py index 9d317ea2..f862c7e1 100644 --- a/tests/test_mqttv5.py +++ b/tests/test_mqttv5.py @@ -21,6 +21,7 @@ import threading import time import unittest +import unittest.mock import paho.mqtt import paho.mqtt.client @@ -164,18 +165,22 @@ def setUpClass(cls): except ImportError as ie: raise unittest.SkipTest("paho.mqtt.testing not present.") from ie - cls._test_broker = threading.Thread( - target=mqtt.brokers.run, - kwargs={ - "config": ["listener 0"], - }, - ) - cls._test_broker.daemon = True - cls._test_broker.start() - # Wait a bit for TCP server to bind to an address - time.sleep(0.5) - # Hack to find the port used by the test broker... - cls._test_broker_port = mqtt.brokers.listeners.TCPListeners.server.socket.getsockname()[1] + # Hack: we need to patch `signal.signal()` because `mqtt.brokers.run()` + # calls it to set up a signal handler; however, that won't work + # from a thread... + with unittest.mock.patch("signal.signal", unittest.mock.MagicMock()): + cls._test_broker = threading.Thread( + target=mqtt.brokers.run, + kwargs={ + "config": ["listener 0"], + }, + ) + cls._test_broker.daemon = True + cls._test_broker.start() + # Wait a bit for TCP server to bind to an address + time.sleep(0.5) + # Hack to find the port used by the test broker... + cls._test_broker_port = mqtt.brokers.listeners.TCPListeners.server.socket.getsockname()[1] setData() cleanup(cls._test_broker_port)