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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri Apr 29 03:37:09 UTC 2016


 loolwsd/test/countloolkits.hpp           |   76 ++++++++++++++++++++++++++++++-
 loolwsd/test/httpwstest.cpp              |   64 ++------------------------
 loolwsd/test/integration-http-server.cpp |    4 -
 3 files changed, 82 insertions(+), 62 deletions(-)

New commits:
commit 40d694d9ef089988296e01ed4c011642d445491b
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Apr 28 22:01:05 2016 -0400

    loolwsd: moved loolkit process counting to own file and minimized wait
    
    Change-Id: Ib7950fe7d97ca3484aadb1d7a7492ad1a88e375a
    Reviewed-on: https://gerrit.libreoffice.org/24478
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/test/countloolkits.hpp b/loolwsd/test/countloolkits.hpp
index 1fb1ba5..2490f22 100644
--- a/loolwsd/test/countloolkits.hpp
+++ b/loolwsd/test/countloolkits.hpp
@@ -10,7 +10,81 @@
 #ifndef INCLUDED_COUNTLOOLKITPROCESSES_HPP
 #define INCLUDED_COUNTLOOLKITPROCESSES_HPP
 
-extern int countLoolKitProcesses();
+#include <Poco/DirectoryIterator.h>
+#include <Poco/StringTokenizer.h>
+
+/// Counts the number of LoolKit process instances without wiating.
+static
+int getLoolKitProcessCount()
+{
+    int result = 0;
+    for (auto i = Poco::DirectoryIterator(std::string("/proc")); i != Poco::DirectoryIterator(); ++i)
+    {
+        try
+        {
+            Poco::Path procEntry = i.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)")
+                {
+                    switch (tokens[2].c_str()[0])
+                    {
+                    case 'x':
+                    case 'X': // Kinds of dead-ness.
+                    case 'Z': // zombies
+                        break; // ignore
+                    default:
+                        result++;
+                        break;
+                    }
+                    // std::cout << "Process:" << pid << ", '" << tokens[1] << "'" << " state: " << tokens[2] << std::endl;
+                }
+            }
+        }
+        catch (const Poco::Exception&)
+        {
+        }
+    }
+
+    // std::cout << "Number of loolkit processes: " << result << std::endl;
+    return result;
+}
+
+static
+int countLoolKitProcesses(const int expected, const int timeoutMs = POLL_TIMEOUT_MS * 5)
+{
+    const size_t repeat = (timeoutMs + POLL_TIMEOUT_MS - 1) / POLL_TIMEOUT_MS;
+    auto count = getLoolKitProcessCount();
+    for (size_t i = 0; i < repeat; ++i)
+    {
+        if (count == expected)
+        {
+            return count;
+        }
+
+        // Give polls in the lool processes time to time out etc
+        Poco::Thread::sleep(POLL_TIMEOUT_MS);
+
+        count = getLoolKitProcessCount();
+    }
+
+    return count;
+}
 
 #endif
 
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index f57d710..9994f92 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -15,7 +15,6 @@
 #include <thread>
 #include <regex>
 
-#include <Poco/DirectoryIterator.h>
 #include <Poco/Dynamic/Var.h>
 #include <Poco/FileStream.h>
 #include <Poco/JSON/JSON.h>
@@ -160,6 +159,7 @@ public:
 
     void tearDown()
     {
+        testNoExtraLoolKitsLeft();
     }
 };
 
@@ -167,7 +167,7 @@ int HTTPWSTest::_initialLoolKitCount = 0;
 
 void HTTPWSTest::testCountHowManyLoolkits()
 {
-    _initialLoolKitCount = countLoolKitProcesses();
+    _initialLoolKitCount = getLoolKitProcessCount();
     CPPUNIT_ASSERT(_initialLoolKitCount > 0);
 }
 
@@ -520,7 +520,7 @@ void HTTPWSTest::testReloadWhileDisconnecting()
         sendTextFrame(socket, "uno .uno:Delete");
         sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc");
 
-        kitcount = countLoolKitProcesses();
+        kitcount = getLoolKitProcessCount();
 
         // Shutdown abruptly.
         socket.shutdown();
@@ -542,7 +542,7 @@ void HTTPWSTest::testReloadWhileDisconnecting()
         CPPUNIT_ASSERT_MESSAGE("cannot load the document " + documentURL, isDocumentLoaded(socket));
 
         // Should have no new instances.
-        CPPUNIT_ASSERT_EQUAL(kitcount, countLoolKitProcesses());
+        CPPUNIT_ASSERT_EQUAL(kitcount, getLoolKitProcessCount());
 
         // Check if the document contains the pasted text.
         sendTextFrame(socket, "uno .uno:SelectAll");
@@ -1225,7 +1225,7 @@ void HTTPWSTest::testEditLock()
 
 void HTTPWSTest::testNoExtraLoolKitsLeft()
 {
-    int countNow = countLoolKitProcesses();
+    const auto countNow = countLoolKitProcesses(_initialLoolKitCount);
 
     CPPUNIT_ASSERT_EQUAL(_initialLoolKitCount, countNow);
 }
@@ -1411,60 +1411,6 @@ void HTTPWSTest::getTileMessage(Poco::Net::WebSocket& ws, std::string& tile)
     while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
 }
 
-int countLoolKitProcesses()
-{
-    // Give polls in the lool processes time to time out etc
-    Poco::Thread::sleep(POLL_TIMEOUT_MS*5);
-
-    int result = 0;
-
-    for (auto i = Poco::DirectoryIterator(std::string("/proc")); i != Poco::DirectoryIterator(); ++i)
-    {
-        try
-        {
-            Poco::Path procEntry = i.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)")
-                {
-                    switch (tokens[2].c_str()[0])
-                    {
-                    case 'x':
-                    case 'X': // Kinds of dead-ness.
-                    case 'Z': // zombies
-                        break; // ignore
-                    default:
-                        result++;
-                        break;
-                    }
-                    // std::cout << "Process:" << pid << ", '" << tokens[1] << "'" << " state: " << tokens[2] << std::endl;
-                }
-            }
-        }
-        catch (const Poco::Exception&)
-        {
-        }
-    }
-
-    // std::cout << "Number of loolkit processes: " << result << std::endl;
-    return result;
-}
-
 void HTTPWSTest::getPartHashCodes(const std::string response,
                                   std::vector<std::string>& parts)
 {
diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index f4e7557..f527511 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -82,7 +82,7 @@ int HTTPServerTest::_initialLoolKitCount = 0;
 
 void HTTPServerTest::testCountHowManyLoolkits()
 {
-    _initialLoolKitCount = countLoolKitProcesses();
+    _initialLoolKitCount = getLoolKitProcessCount();
     CPPUNIT_ASSERT(_initialLoolKitCount > 0);
 }
 
@@ -263,7 +263,7 @@ void HTTPServerTest::testScriptsAndLinksPost()
 
 void HTTPServerTest::testNoExtraLoolKitsLeft()
 {
-    int countNow = countLoolKitProcesses();
+    const auto countNow = countLoolKitProcesses(_initialLoolKitCount);
 
     CPPUNIT_ASSERT_EQUAL(_initialLoolKitCount, countNow);
 }


More information about the Libreoffice-commits mailing list