[mutter] tests/dbus-runner: Don't log to a loose ended pipe



commit 3eeecd42b060543eb048e018755a0cdb3ebc968d
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Nov 30 08:15:26 2021 +0100

    tests/dbus-runner: Don't log to a loose ended pipe
    
    We created pipes for the stdout of the spawned mock services. This
    resulted in the pipe being filled if enough things were logged, as
    nothing was reading from it. Change this to allow for two modes:
    verbose - where output is logged to the parent stderr, as well as non-verbose
    (default) - where things are logged directly to /dev/null.
    
    This fixes frozen tests when running with --repeat and a high enough
    repeat count.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2139>

 src/tests/meta-dbus-runner.py | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
---
diff --git a/src/tests/meta-dbus-runner.py b/src/tests/meta-dbus-runner.py
index 2dbf315e15..493510a9aa 100755
--- a/src/tests/meta-dbus-runner.py
+++ b/src/tests/meta-dbus-runner.py
@@ -12,19 +12,18 @@ from dbus.mainloop.glib import DBusGMainLoop
 DBusGMainLoop(set_as_default=True)
 
 
-def set_nonblock(fd):
-    '''Set a file object to non-blocking'''
-
-    flags = fcntl.fcntl(fd, fcntl.F_GETFL)
-    fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
-
-
 def get_templates_dir():
     return os.path.join(os.path.dirname(__file__), 'dbusmock-templates')
 
 def get_template_path(template_name):
     return os.path.join(get_templates_dir(), template_name + '.py')
 
+def get_subprocess_stdout():
+    if os.getenv('META_DBUS_RUNNER_VERBOSE') == '1':
+        return sys.stderr
+    else:
+        return subprocess.DEVNULL;
+
 
 class MutterDBusTestCase(DBusTestCase):
     @classmethod
@@ -63,8 +62,7 @@ class MutterDBusTestCase(DBusTestCase):
         mock_server, mock_obj = \
             klass.spawn_server_template(template,
                                         params,
-                                        stdout=subprocess.PIPE)
-        set_nonblock(mock_server.stdout)
+                                        get_subprocess_stdout())
 
         mocks = (mock_server, mock_obj)
         assert klass.mocks.setdefault(template, mocks) == mocks
@@ -91,8 +89,7 @@ class MutterDBusTestCase(DBusTestCase):
                                mock_class.MAIN_OBJ,
                                mock_class.MAIN_IFACE,
                                mock_class.SYSTEM_BUS,
-                               stdout=subprocess.PIPE)
-        set_nonblock(mock_server.stdout)
+                               stdout=get_subprocess_stdout())
 
         bus = klass.get_dbus(system_bus=mock_class.SYSTEM_BUS)
         mock_obj = bus.get_object(mock_class.BUS_NAME, mock_class.MAIN_OBJ)


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