[Libreoffice-commits] .: test-bugzilla-files/test-bugzilla-files.py

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Feb 5 09:07:02 PST 2013


 test-bugzilla-files/test-bugzilla-files.py |   53 +++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 14 deletions(-)

New commits:
commit 8fc0dae9047342eb4883ab6141b7c1f0457f2827
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jan 18 12:28:38 2013 +0100

    iinitial work on Tiemout

diff --git a/test-bugzilla-files/test-bugzilla-files.py b/test-bugzilla-files/test-bugzilla-files.py
index 7bb7c24..7bf87d1 100644
--- a/test-bugzilla-files/test-bugzilla-files.py
+++ b/test-bugzilla-files/test-bugzilla-files.py
@@ -31,6 +31,8 @@ import subprocess
 import sys
 import time
 import uuid
+
+import signal
 try:
     from urllib.parse import quote
 except ImportError:
@@ -90,6 +92,7 @@ class OfficeConnection:
         self.soffice = None
         self.socket = None
         self.xContext = None
+        self.pro = None
     def setUp(self):
         (method, sep, rest) = self.args["--soffice"].partition(":")
         if sep != ":":
@@ -113,10 +116,10 @@ class OfficeConnection:
         argv = [ soffice, "--accept=" + socket + ";urp",
                 "-env:UserInstallation=" + userdir,
                 "--quickstart=no", "--nofirststartwizard",
-                "--norestore", "--nologo", "--headless" ]
+                "--norestore", "--nologo" ]
         if "--valgrind" in self.args:
             argv.append("--valgrind")
-        return subprocess.Popen(argv)
+        self.pro = subprocess.Popen(argv)
 
     def connect(self, socket):
         xLocalContext = uno.getComponentContext()
@@ -161,6 +164,8 @@ class OfficeConnection:
             if ret != 0:
                 raise Exception("Exit status indicates failure: " + str(ret))
 #            return ret
+    def kill(self):
+        os.system("killall -9 soffice.bin")
 
 class PerTestConnection:
     def __init__(self, args):
@@ -190,6 +195,7 @@ class PersistentConnection:
     def getContext(self):
         return self.connection.xContext
     def setUp(self):
+        assert(not self.connection)
         conn = OfficeConnection(self.args)
         conn.setUp()
         self.connection = conn
@@ -203,6 +209,10 @@ class PersistentConnection:
                 self.connection.tearDown()
             finally:
                 self.connection = None
+    def kill(self):
+        if self.connection:
+            os.system("killall -9 soffice.bin")
+        self.connection = None
 
 def simpleInvoke(connection, test):
     try:
@@ -252,7 +262,7 @@ def mkPropertyValue(name, value):
 
 ### tests ###
 
-def loadFromURL(xContext, url):
+def loadFromURL(xContext, url, connection):
     xDesktop = xContext.ServiceManager.createInstanceWithContext(
             "com.sun.star.frame.Desktop", xContext)
     props = [("Hidden", True), ("ReadOnly", True)] # FilterName?
@@ -265,16 +275,23 @@ def loadFromURL(xContext, url):
 # we need to check if this method returns after loading or after invoking the loading
 # depending on this we might need to put a timeout around it
         xDoc = None
-        xDoc = xDesktop.loadComponentFromURL(url, "_blank", 0, loadProps)
-        time_ = 0
-        while time_ < 30:
-            if xListener.layoutFinished:
-                return xDoc
-            print("delaying...")
-            time_ += 1
-            time.sleep(1)
-        print("timeout: no OnLayoutFinished received")
-        return xDoc
+        try:
+            signal.signal(signal.SIGALRM, alarm_handler)
+            signal.alarm(10)        
+            xDoc = xDesktop.loadComponentFromURL(url, "_blank", 0, loadProps)
+            while True:
+                if xListener.layoutFinished:
+                    signal.alarm(0)  # reset the alarm
+                    return xDoc
+                print("delaying...")
+                time.sleep(1)
+        except Alarm:
+            print("timeout: no OnLayoutFinished received")
+            print("file not loaded in time: " + url)
+            connection.kill()
+            xListener = None
+            connection.setUp()
+            return None
     except pyuno.getClass("com.sun.star.beans.UnknownPropertyException"):
         xListener = None
         raise # means crashed, handle it later
@@ -300,6 +317,13 @@ def handleCrash(file, crashed_files):
     crashed_files.append(file)
 # add here the remaining handling code for crashed files
 
+class Alarm(Exception):
+    pass
+
+def alarm_handler(signum, frame):
+    os.system("killall -9 soffice.bin")
+    raise Alarm
+
 class LoadFileTest:
     def __init__(self, file, crashed_files):
         self.file = file
@@ -309,7 +333,7 @@ class LoadFileTest:
         try:
             url = "file://" + quote(self.file)
             xDoc = None
-            xDoc = loadFromURL(xContext, url)
+            xDoc = loadFromURL(xContext, url, connection)
         except pyuno.getClass("com.sun.star.beans.UnknownPropertyException"):
             print("caught UnknownPropertyException " + self.file)
             handleCrash(self.file, self.crashed_files)
@@ -336,6 +360,7 @@ def runLoadFileTests(opts, dirs):
 #    connection = PerTestConnection(opts)
     runConnectionTests(connection, simpleInvoke, tests)
     print(crashed_files)
+    os.system("killall -9 soffice.bin")
 
 def parseArgs(argv):
     (optlist,args) = getopt.getopt(argv[1:], "hr",


More information about the Libreoffice-commits mailing list