[at-spi2-core: 41/47] Control the registry fixture's lifetime via a mock gnome-session




commit d281f8e0cf0d023789006b449dd83d63edb08301
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jul 12 14:21:39 2022 -0500

    Control the registry fixture's lifetime via a mock gnome-session
    
    As for the code coverage job, we need registryd's tests to be able to
    control the lifetime of at-spi-bus-launcher and at-spi2-registryd.
    
    So, the session_manager() fixture assumes that it is running alonside
    a gnome-session dbus mock.  The teardown code tells the session to
    Logout - this will make the mock notify session clients that they have
    to terminate.

 ci/run-registryd-tests.sh   | 21 +++++++++++++++++++++
 tests/registryd/__init__.py |  1 +
 tests/registryd/conftest.py | 23 ++++++++++++++++++++---
 3 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/ci/run-registryd-tests.sh b/ci/run-registryd-tests.sh
new file mode 100755
index 00000000..a664b96a
--- /dev/null
+++ b/ci/run-registryd-tests.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -eu
+
+echo "About to run the tests.  First we'll launch a gnome-session DBus mock."
+
+python3 -m dbusmock --session org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager &
+sleep 1
+
+gdbus call --session \
+      --dest org.gnome.SessionManager \
+      --object-path /org/gnome/SessionManager \
+      --method org.freedesktop.DBus.Mock.AddTemplate 'tests/dbusmock/mock-gnome-session.py' '{}'
+
+gdbus call --session \
+      --dest org.gnome.SessionManager \
+      --object-path /org/gnome/SessionManager \
+      --method org.freedesktop.DBus.Mock.SetSessionRunning true
+
+cd tests/registryd
+pytest -v
diff --git a/tests/registryd/__init__.py b/tests/registryd/__init__.py
index e69de29b..d18f92c6 100644
--- a/tests/registryd/__init__.py
+++ b/tests/registryd/__init__.py
@@ -0,0 +1 @@
+dummy = "hello"
diff --git a/tests/registryd/conftest.py b/tests/registryd/conftest.py
index 738a5836..0729b3c8 100644
--- a/tests/registryd/conftest.py
+++ b/tests/registryd/conftest.py
@@ -14,7 +14,10 @@
 #
 # * main_loop - a GLib.MainLoop integrated with the DBusGMainLoop.
 #
-# * session_manager - A mock gnome-session to control the lifetime of daemons.
+# * session_manager - A mock gnome-session to control the lifetime of daemons.  In
+#   reality, the fixture assumes that there is a gnome-session mock running (see
+#   ci/run-registryd-tests.sh) and just tells that mock to Logout at fixture teardown
+#   time, so that all daemons that monitor the session's lifetime will exit at teardown.
 #
 # * registry - A dbus.proxies.ProxyObject for the registry's root object.  This automatically
 #   depends on a session_manager fixture to control its lifetime.
@@ -29,7 +32,6 @@ def main_loop():
 
     DBusGMainLoop(set_as_default=True)
     loop = GLib.MainLoop()
-    print("main loop created")
     return loop
 
 def get_accesssibility_bus_address():
@@ -42,7 +44,22 @@ def get_registry_root(a11y_bus):
 
 @pytest.fixture
 def session_manager():
-    return None # FIXME - return a gnome-session mock
+    # This assumes that pytest is running in this environment:
+    #
+    # * A session dbus daemon is running
+    #
+    # * There is a gnome-session mock running
+    #
+    # See the ci/run-registryd-tests.sh script to see how that environment is set up.
+
+    bus = dbus.SessionBus()
+    mock_session = bus.get_object('org.gnome.SessionManager', '/org/gnome/SessionManager')
+
+    # return a dummy object as a fixture
+    yield object()
+
+    # Tell all session clients to terminate
+    mock_session.Logout(0, dbus_interface='org.gnome.SessionManager')
 
 @pytest.fixture
 def registry(main_loop, session_manager):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]