From 158cb08aefdafe9749f941c35b5f483fbb33bd5f Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Wed, 27 Nov 2024 10:27:27 -0700 Subject: [PATCH] tests, bluetooth: use a process instead of a thread ...for our fake daemon. The in our fixture setup, the bluetooth daemon thread necessarily must start before the manager, because the widget wants to connect on startup. Of course, we fork() the manager (via multiprocessing), so spawning this Thread before then will cause a warning. Let's just use a process instead. This is in service of getting rid of all multithreading so that we can enable -W error. It seems to (?) eliminate all the warnings besides those in test_window_list.py, although 3.13 of course introduces more warnings inside dependencies :( Signed-off-by: Tycho Andersen --- test/widgets/test_bluetooth.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/widgets/test_bluetooth.py b/test/widgets/test_bluetooth.py index 02826ac432..b33dab75af 100644 --- a/test/widgets/test_bluetooth.py +++ b/test/widgets/test_bluetooth.py @@ -18,13 +18,13 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import asyncio +import multiprocessing import os import shutil import signal import subprocess import time from enum import Enum -from threading import Thread import pytest from dbus_next._private.address import get_session_bus_address @@ -134,11 +134,8 @@ def Percentage(self) -> "d": # noqa: F821, N802 return 75 -class Bluez(Thread): - """Class that runs fake UPower interface in a thread.""" - - def __init__(self, *args, **kwargs): - Thread.__init__(self, *args, **kwargs) +class Bluez: + """Class that runs fake UPower interface.""" async def start_server(self): """Connects to the bus and publishes 3 interfaces.""" @@ -190,7 +187,7 @@ def run(self): @pytest.fixture() -def dbus_thread(monkeypatch): +def fake_dbus_daemon(monkeypatch): """Start a thread which publishes a fake bluez interface on dbus.""" # for Github CI/Ubuntu, dbus-launch is provided by "dbus-x11" package launcher = shutil.which("dbus-launch") @@ -222,9 +219,8 @@ def dbus_thread(monkeypatch): except ValueError: pass - t = Bluez() - t.daemon = True - t.start() + p = multiprocessing.Process(target=Bluez().run) + p.start() # Pause for the dbus interface to come up time.sleep(1) @@ -234,6 +230,7 @@ def dbus_thread(monkeypatch): # Stop the bus if pid: os.kill(pid, signal.SIGTERM) + p.kill() @pytest.fixture @@ -251,7 +248,7 @@ def force_session_bus(bus_type): @pytest.fixture -def bluetooth_manager(request, widget, dbus_thread, manager_nospawn): +def bluetooth_manager(request, widget, fake_dbus_daemon, manager_nospawn): class BluetoothConfig(BareConfig): screens = [Screen(top=Bar([widget(**getattr(request, "param", dict()))], 20))]