Skip to content

Commit

Permalink
tests, bluetooth: use a process instead of a thread
Browse files Browse the repository at this point in the history
...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 <[email protected]>
  • Loading branch information
tych0 committed Nov 27, 2024
1 parent 1dacffb commit 158cb08
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions test/widgets/test_bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -234,6 +230,7 @@ def dbus_thread(monkeypatch):
# Stop the bus
if pid:
os.kill(pid, signal.SIGTERM)
p.kill()


@pytest.fixture
Expand All @@ -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))]

Expand Down

0 comments on commit 158cb08

Please sign in to comment.