[Libreoffice-commits] online.git: loolwsd/test

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Apr 24 17:00:58 UTC 2016


 loolwsd/test/httpcrashtest.cpp |   85 ++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 38 deletions(-)

New commits:
commit bb8beee8e93b1835129bd748c62436030bd6e6c7
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Apr 24 12:31:01 2016 -0400

    loolwsd: refactored killing of LoKit processes in unittests
    
    Change-Id: Ia41adc977252049b1cd7d8936f0c4c8380516030
    Reviewed-on: https://gerrit.libreoffice.org/24336
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/test/httpcrashtest.cpp b/loolwsd/test/httpcrashtest.cpp
index 4169ebd..c0af9ba 100644
--- a/loolwsd/test/httpcrashtest.cpp
+++ b/loolwsd/test/httpcrashtest.cpp
@@ -52,6 +52,9 @@ class HTTPCrashTest : public CPPUNIT_NS::TestFixture
     void testCrashKit();
 
     static
+    void killLoKitProcesses();
+
+    static
     void sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string);
 
     static
@@ -114,44 +117,7 @@ void HTTPCrashTest::testCrashKit()
         sendTextFrame(socket, "status");
         CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
 
-        // simulate crash all lokit process
-        for (auto it = Poco::DirectoryIterator(std::string("/proc")); it != Poco::DirectoryIterator(); ++it)
-        {
-            try
-            {
-                Poco::Path procEntry = it.path();
-                const std::string& fileName = procEntry.getFileName();
-                int pid;
-                std::size_t endPos = 0;
-                try
-                {
-                    pid = std::stoi(fileName, &endPos);
-                }
-                catch (const std::invalid_argument&)
-                {
-                    pid = 0;
-                }
-                if (pid > 1 && endPos == fileName.length())
-                {
-                    const std::string killLOKit = "kill -9 " + std::to_string(pid);
-                    Poco::FileInputStream stat(procEntry.toString() + "/stat");
-                    std::string statString;
-                    Poco::StreamCopier::copyToString(stat, statString);
-                    Poco::StringTokenizer tokens(statString, " ");
-                    if (tokens.count() > 3 && tokens[1] == "(loolkit)")
-                    {
-                        const auto res = std::system(killLOKit.c_str());
-                        if (res != 0)
-                        {
-                            std::cerr << "exit " + std::to_string(res) + " from " + killLOKit << std::endl;
-                        }
-                    }
-                }
-            }
-            catch (const Poco::Exception&)
-            {
-            }
-        }
+        killLoKitProcesses();
 
         // 5 seconds timeout
         socket.setReceiveTimeout(5000000);
@@ -177,6 +143,49 @@ void HTTPCrashTest::testCrashKit()
     }
 }
 
+void HTTPCrashTest::killLoKitProcesses()
+{
+    // Crash all lokit processes.
+    for (auto it = Poco::DirectoryIterator(std::string("/proc")); it != Poco::DirectoryIterator(); ++it)
+    {
+        try
+        {
+            Poco::Path procEntry = it.path();
+            const std::string& fileName = procEntry.getFileName();
+            int pid;
+            std::size_t endPos = 0;
+            try
+            {
+                pid = std::stoi(fileName, &endPos);
+            }
+            catch (const std::invalid_argument&)
+            {
+                pid = 0;
+            }
+            if (pid > 1 && endPos == fileName.length())
+            {
+                Poco::FileInputStream stat(procEntry.toString() + "/stat");
+                std::string statString;
+                Poco::StreamCopier::copyToString(stat, statString);
+                Poco::StringTokenizer tokens(statString, " ");
+                if (tokens.count() > 3 && tokens[1] == "(loolkit)")
+                {
+                    const std::string killLOKit = "kill -9 " + std::to_string(pid);
+                    std::cerr << "$ " + killLOKit << std::endl;
+                    const auto res = std::system(killLOKit.c_str());
+                    if (res != 0)
+                    {
+                        std::cerr << "exit " + std::to_string(res) + " from " + killLOKit << std::endl;
+                    }
+                }
+            }
+        }
+        catch (const Poco::Exception&)
+        {
+        }
+    }
+}
+
 void HTTPCrashTest::sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string)
 {
     socket.sendFrame(string.data(), string.size());


More information about the Libreoffice-commits mailing list