[tracker/sam/functional-tests-quiet: 11/15] squash! WIP: functional-tests: Start daemons through D-Bus autolaunch



commit e04e66a916c615ddec8776108d805ccb29192196
Author: Sam Thursfield <sam afuera me uk>
Date:   Thu Aug 29 19:12:42 2019 +0300

    squash! WIP: functional-tests: Start daemons through D-Bus autolaunch
    
    Logs are now output in a more organized way.

 tests/functional-tests/configuration.py | 16 ++++++++++++++++
 utils/trackertestutils/dbusdaemon.py    |  9 +++++----
 utils/trackertestutils/helpers.py       |  1 +
 3 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index 75d11676d..12e884fc0 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -65,6 +65,22 @@ def get_environment_boolean(variable):
         raise RuntimeError('Unexpected value for %s: %s' %
                            (variable, value))
 
+def get_environment_int(variable, default=0):
+    try:
+        return int(os.environ.get(variable))
+    except (TypeError, ValueError):
+        return default
+
 
 if get_environment_boolean('TRACKER_TESTS_VERBOSE'):
+    # Output all logs to stderr
     logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
+else:
+    # Output some messages from D-Bus daemon to stderr by default. In practice,
+    # nothing should be output here unless the environment contains
+    # G_MESSAGES_DEBUG= and/or TRACKER_VERBOSITY=1 or more.
+    handler = logging.StreamHandler(stream=sys.stderr)
+    handler.addFilter(logging.Filter('trackertestutils.dbusdaemon.stderr'))
+    handler.addFilter(logging.Filter('trackertestutils.dbusdaemon.stdout'))
+    logging.basicConfig(level=logging.INFO, handlers=[handler],
+                        format='%(message)s')
diff --git a/utils/trackertestutils/dbusdaemon.py b/utils/trackertestutils/dbusdaemon.py
index 3b336d696..f39342e0f 100644
--- a/utils/trackertestutils/dbusdaemon.py
+++ b/utils/trackertestutils/dbusdaemon.py
@@ -25,7 +25,8 @@ import subprocess
 import threading
 
 log = logging.getLogger(__name__)
-dbuslog = logging.getLogger(__name__ + '.dbus')
+dbus_stderr_log = logging.getLogger(__name__ + '.stderr')
+dbus_stdout_log = logging.getLogger(__name__ + '.stdout')
 
 
 class DaemonNotStartedError(Exception):
@@ -130,8 +131,8 @@ class DBusDaemon:
 
             # We must read from the pipes continuously, otherwise the daemon
             # process will block.
-            self._threads=[threading.Thread(target=self.pipe_to_log, args=(self.process.stdout, 'stdout'), 
daemon=True),
-                           threading.Thread(target=self.pipe_to_log, args=(self.process.stderr, 'stderr'), 
daemon=True)]
+            self._threads=[threading.Thread(target=self.pipe_to_log, args=(self.process.stdout, 
dbus_stdout_log), daemon=True),
+                           threading.Thread(target=self.pipe_to_log, args=(self.process.stderr, 
dbus_stdout_log), daemon=True)]
             self._threads[0].start()
             self._threads[1].start()
 
@@ -152,7 +153,7 @@ class DBusDaemon:
             signal.signal(signal.SIGTERM, self._previous_sigterm_handler)
             self._previous_sigterm_handler = None
 
-    def pipe_to_log(self, pipe, source):
+    def pipe_to_log(self, pipe, dbuslog):
         """This function processes the output from our dbus-daemon instance."""
         while True:
             line_raw = pipe.readline()
diff --git a/utils/trackertestutils/helpers.py b/utils/trackertestutils/helpers.py
index 12fa780c2..01d27071f 100644
--- a/utils/trackertestutils/helpers.py
+++ b/utils/trackertestutils/helpers.py
@@ -437,6 +437,7 @@ class TrackerDBusSandbox:
     def start(self):
         env = os.environ
         env.update(self.extra_env)
+        env['G_MESSAGES_PREFIXED'] = 'all'
 
         logging.info("Starting D-Bus daemon for sandbox.")
         logging.debug("Added environment variables: %s", self.extra_env)


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