[Libreoffice-commits] core.git: uitest/libreoffice uitest/uitest

Markus Mohrhard markus.mohrhard at googlemail.com
Mon Dec 19 18:51:25 UTC 2016


 uitest/libreoffice/connection.py |    3 ++
 uitest/uitest/framework.py       |   46 ++++++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 12 deletions(-)

New commits:
commit 756203d490720deb53f7da4914d738b064b9e157
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Dec 14 07:14:35 2016 +0100

    make sure we are not leaving soffice around if python process crashes
    
    Change-Id: Idac32c3d788714533ee760782d2b6a328262f3f8
    Reviewed-on: https://gerrit.libreoffice.org/31996
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/uitest/libreoffice/connection.py b/uitest/libreoffice/connection.py
index 1b0150b..c717632 100644
--- a/uitest/libreoffice/connection.py
+++ b/uitest/libreoffice/connection.py
@@ -161,5 +161,8 @@ class PersistentConnection:
                 self.connection.tearDown()
             finally:
                 self.connection = None
+    def kill(self):
+        if self.connection and self.connection.soffice:
+            self.connection.soffice.kill()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/uitest/framework.py b/uitest/uitest/framework.py
index 7d4a78d..f21d72b 100644
--- a/uitest/uitest/framework.py
+++ b/uitest/uitest/framework.py
@@ -5,6 +5,7 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
 
+import signal
 import unittest
 import time
 
@@ -19,6 +20,7 @@ class UITestCase(unittest.TestCase):
         self.opts = opts
 
     def setUp(self):
+        self.setSignalHandler()
         self.connection = PersistentConnection(self.opts)
         self.connection.setUp()
         self.xContext = self.connection.getContext()
@@ -29,17 +31,37 @@ class UITestCase(unittest.TestCase):
         self.startTime = time.time()
 
     def tearDown(self):
-        t = time.time() - self.startTime
-        print("Execution time for %s: %.3f" % (self.id(), t))
-        if self.xContext is not None:
-            desktop = self.ui_test.get_desktop()
-            components = desktop.getComponents()
-            for component in components:
-                try:
-                    component.close(False)
-                except Exception as e:
-                    print(e)
-
-        self.connection.tearDown()
+        try:
+            t = time.time() - self.startTime
+            print("Execution time for %s: %.3f" % (self.id(), t))
+            if self.xContext is not None:
+                desktop = self.ui_test.get_desktop()
+                components = desktop.getComponents()
+                for component in components:
+                    try:
+                        component.close(False)
+                    except Exception as e:
+                        print(e)
+
+            self.connection.tearDown()
+        finally:
+            self.resetSignalHandler()
+            self.connection.kill()
+
+    def signalHandler(self, signum, frame):
+        if self.connection:
+            self.connection.kill()
+
+    def setSignalHandler(self):
+        signal.signal(signal.SIGABRT, self.signalHandler)
+        signal.signal(signal.SIGSEGV, self.signalHandler)
+        signal.signal(signal.SIGTERM, self.signalHandler)
+        signal.signal(signal.SIGILL, self.signalHandler)
+
+    def resetSignalHandler(self):
+        signal.signal(signal.SIGABRT, signal.SIG_IGN)
+        signal.signal(signal.SIGSEGV, signal.SIG_IGN)
+        signal.signal(signal.SIGTERM, signal.SIG_IGN)
+        signal.signal(signal.SIGILL, signal.SIG_IGN)
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list