[gnome-settings-daemon/benzea/ci-fixes] tests: Kill processes instead of just terminating them



commit 85a976250af4c0196e4eeb6b66536ac0f21582e8
Author: Benjamin Berg <bberg redhat com>
Date:   Tue Jul 20 17:33:29 2021 +0200

    tests: Kill processes instead of just terminating them

 plugins/power/test.py     | 12 +++++-------
 plugins/xsettings/test.py |  6 ++----
 tests/gsdtestcase.py      | 19 +++++++++++++------
 tests/x11session.py       |  6 +++++-
 4 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/plugins/power/test.py b/plugins/power/test.py
index 857994f2..a1024fcd 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -73,13 +73,13 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
         (self.upowerd, self.obj_upower) = self.spawn_server_template(
             'upower', {'DaemonVersion': '0.99', 'OnBattery': True, 'LidIsClosed': False}, 
stdout=subprocess.PIPE)
         gsdtestcase.set_nonblock(self.upowerd.stdout)
-        self.addCleanup(lambda : (self.upowerd.terminate(), self.upowerd.wait()))
+        self.addCleanup(self.stop_process, self.upowerd)
 
         # start mock gnome-shell screensaver
         (self.screensaver, self.obj_screensaver) = self.spawn_server_template(
             'gnome_screensaver', stdout=subprocess.PIPE)
         gsdtestcase.set_nonblock(self.screensaver.stdout)
-        self.addCleanup(lambda : (self.screensaver.terminate(), self.screensaver.wait()))
+        self.addCleanup(self.stop_process, self.screensaver)
 
         self.session_log = OutputChecker()
         self.session = subprocess.Popen(['gnome-session', '-f',
@@ -88,7 +88,7 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
                                         stdout=self.session_log.fd,
                                         stderr=subprocess.STDOUT)
         self.session_log.writer_attached()
-        self.addCleanup(lambda : (self.session.terminate(), self.session.wait()))
+        self.addCleanup(self.stop_process, self.screensaver)
 
         # wait until the daemon is on the bus
         self.wait_for_bus_object('org.gnome.SessionManager',
@@ -156,8 +156,7 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
 
         daemon_running = self.daemon.poll() == None
         if daemon_running:
-            self.daemon.terminate()
-            self.daemon.wait()
+            self.stop_process(self.daemon)
         self.plugin_log.assert_closed()
 
     def cleanup_testbed(self):
@@ -186,8 +185,7 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
         '''Stop GNOME session'''
 
         assert self.session
-        self.session.terminate()
-        self.session.wait()
+        self.stop_process(self.session)
         # dummyapp.desktop survives the session. This keeps the FD open in the
         # CI environment when gnome-session fails to redirect the child output
         # to journald.
diff --git a/plugins/xsettings/test.py b/plugins/xsettings/test.py
index e6342094..8e5bfda7 100755
--- a/plugins/xsettings/test.py
+++ b/plugins/xsettings/test.py
@@ -112,8 +112,7 @@ class XsettingsPluginTest(gsdtestcase.GSDTestCase):
 
         daemon_running = self.daemon.poll() == None
         if daemon_running:
-            self.daemon.terminate()
-            self.daemon.wait()
+            self.stop_process(self.daemon)
         self.plugin_log.close()
         self.plugin_log_write.flush()
         self.plugin_log_write.close()
@@ -136,8 +135,7 @@ class XsettingsPluginTest(gsdtestcase.GSDTestCase):
         '''Stop GNOME session'''
 
         assert self.session
-        self.session.terminate()
-        self.session.wait()
+        self.stop_process(self.session)
 
         self.session_log_write.flush()
         self.session_log_write.close()
diff --git a/tests/gsdtestcase.py b/tests/gsdtestcase.py
index bdbe0874..e0704128 100644
--- a/tests/gsdtestcase.py
+++ b/tests/gsdtestcase.py
@@ -160,8 +160,7 @@ class GSDTestCase(X11SessionTestCase):
         '''Stop dbus-monitor'''
 
         assert klass.monitor
-        klass.monitor.terminate()
-        klass.monitor.wait()
+        klass.stop_process(klass.monitor)
 
         klass.monitor_log.flush()
         klass.monitor_log.close()
@@ -187,8 +186,7 @@ class GSDTestCase(X11SessionTestCase):
     def stop_logind(self):
         '''stop mock logind'''
 
-        self.logind.terminate()
-        self.logind.wait()
+        self.stop_process(self.logind)
         self.logind_log.assert_closed()
 
     def start_mutter(klass):
@@ -205,8 +203,17 @@ class GSDTestCase(X11SessionTestCase):
         '''stop mutter'''
 
         assert klass.monitor
-        klass.mutter.terminate()
-        klass.mutter.wait()
+        klass.stop_process(klass.mutter, timeout=2)
+
+    @classmethod
+    def stop_process(cls, proc, timeout=1):
+        proc.terminate()
+        try:
+            proc.wait(timeout)
+        except:
+            print("Killing %d (%s) after timeout of %f seconds" % (proc.pid, proc.args[0], timeout))
+            proc.kill()
+            proc.wait()
 
     @classmethod
     def reset_idle_timer(klass):
diff --git a/tests/x11session.py b/tests/x11session.py
index faa22483..56780730 100644
--- a/tests/x11session.py
+++ b/tests/x11session.py
@@ -111,6 +111,10 @@ class X11SessionTestCase(DBusTestCase):
         if hasattr(klass, 'xorg'):
             klass.X_display = -1
             klass.xorg.terminate()
-            klass.xorg.wait()
+            try:
+                klass.xorg.wait(1)
+            except:
+                klass.xorg.kill()
+                klass.xorg.wait()
             del klass.xorg
 


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