[Libreoffice-commits] online.git: test/countloolkits.hpp test/httpcrashtest.cpp test/httpwserror.cpp test/httpwstest.cpp test/integration-http-server.cpp test/TileCacheTests.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Jan 9 06:19:04 UTC 2017


 test/TileCacheTests.cpp          |   12 +++++++++++
 test/countloolkits.hpp           |   41 +++++++++++++++++++++++++++++++--------
 test/httpcrashtest.cpp           |   18 -----------------
 test/httpwserror.cpp             |   18 -----------------
 test/httpwstest.cpp              |   20 -------------------
 test/integration-http-server.cpp |   20 -------------------
 6 files changed, 46 insertions(+), 83 deletions(-)

New commits:
commit 4e9e0195642f6b09a3d99fb2afb5a169ecd4c086
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri Jan 6 10:54:19 2017 -0500

    wsd: refactor/dedup the lokit process counting tests
    
    Change-Id: Iebf7756c6a5c2bc581a0ade4fe13fad752eb7d20
    Reviewed-on: https://gerrit.libreoffice.org/32861
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/test/TileCacheTests.cpp b/test/TileCacheTests.cpp
index 935a8c4..2c235dc 100644
--- a/test/TileCacheTests.cpp
+++ b/test/TileCacheTests.cpp
@@ -19,6 +19,8 @@
 #include "TileCache.hpp"
 #include "Unit.hpp"
 #include "Util.hpp"
+
+#include "countloolkits.hpp"
 #include "helpers.hpp"
 
 using namespace helpers;
@@ -132,6 +134,16 @@ public:
         Poco::Net::uninitializeSSL();
     }
 #endif
+
+    void setUp()
+    {
+        testCountHowManyLoolkits();
+    }
+
+    void tearDown()
+    {
+        testNoExtraLoolKitsLeft();
+    }
 };
 
 void TileCacheTests::testSimple()
diff --git a/test/countloolkits.hpp b/test/countloolkits.hpp
index 4338a2f..a746024 100644
--- a/test/countloolkits.hpp
+++ b/test/countloolkits.hpp
@@ -10,9 +10,18 @@
 #ifndef INCLUDED_COUNTLOOLKITPROCESSES_HPP
 #define INCLUDED_COUNTLOOLKITPROCESSES_HPP
 
+#include <iostream>
+#include <thread>
+
+#include <cppunit/extensions/HelperMacros.h>
+
 #include <Poco/DirectoryIterator.h>
+#include <Poco/FileStream.h>
+#include <Poco/StreamCopier.h>
 #include <Poco/StringTokenizer.h>
 
+#include <Common.hpp>
+
 /// Counts the number of LoolKit process instances without wiating.
 static int getLoolKitProcessCount()
 {
@@ -33,6 +42,7 @@ static int getLoolKitProcessCount()
             {
                 pid = 0;
             }
+
             if (pid > 1 && endPos == fileName.length())
             {
                 Poco::FileInputStream stat(procEntry.toString() + "/stat");
@@ -70,16 +80,11 @@ static int getLoolKitProcessCount()
 
 static int countLoolKitProcesses(const int expected)
 {
-    std::cerr << "Waiting to have " << expected << " loolkit processes. Loolkits: ";
-
-    // We have to wait at least for the time the call docBroker->autoSave(forceSave,
-    // COMMAND_TIMEOUT_MS)) in ClientRequestHandler:::handleGetRequest() can take to wait for
-    // information about a successful auto-save. In the HTTPWSTest::testConnectNoLoad() there is
-    // nothing to auto-save, so it waits in vain.
+    std::cerr << "Waiting until loolkit processes are exactly " << expected << ". Loolkits: ";
 
     // This does not need to depend on any constant from Common.hpp.
     // The shorter the better (the quicker the test runs).
-    const auto sleepMs = 100;
+    const auto sleepMs = 50;
 
     // This has to cause waiting for at least COMMAND_TIMEOUT_MS. Add one second for safety.
     const size_t repeat = ((COMMAND_TIMEOUT_MS + 1000) / sleepMs);
@@ -93,7 +98,7 @@ static int countLoolKitProcesses(const int expected)
         }
 
         // Give polls in the lool processes time to time out etc
-        Poco::Thread::sleep(sleepMs);
+        std::this_thread::sleep_for(std::chrono::milliseconds(sleepMs));
 
         count = getLoolKitProcessCount();
     }
@@ -107,6 +112,26 @@ static int countLoolKitProcesses(const int expected)
     return count;
 }
 
+// FIXME: we probably should make this extern
+// and reuse it. As it stands now, it is per
+// translation unit, which isn't desirable if
+// (in the non-ideal event that) it's not 1,
+// it will cause testNoExtraLoolKitsLeft to
+// wait unnecessarily and fail.
+static int InitialLoolKitCount = 1;
+
+static void testCountHowManyLoolkits()
+{
+    InitialLoolKitCount = countLoolKitProcesses(InitialLoolKitCount);
+    CPPUNIT_ASSERT(InitialLoolKitCount > 0);
+}
+
+static void testNoExtraLoolKitsLeft()
+{
+    const auto countNow = countLoolKitProcesses(InitialLoolKitCount);
+    CPPUNIT_ASSERT_EQUAL(InitialLoolKitCount, countNow);
+}
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/httpcrashtest.cpp b/test/httpcrashtest.cpp
index 3db2dc0..16105a7 100644
--- a/test/httpcrashtest.cpp
+++ b/test/httpcrashtest.cpp
@@ -52,7 +52,6 @@ class HTTPCrashTest : public CPPUNIT_NS::TestFixture
 {
     const Poco::URI _uri;
     Poco::Net::HTTPResponse _response;
-    static int InitialLoolKitCount;
 
     CPPUNIT_TEST_SUITE(HTTPCrashTest);
 
@@ -62,11 +61,9 @@ class HTTPCrashTest : public CPPUNIT_NS::TestFixture
 
     CPPUNIT_TEST_SUITE_END();
 
-    void testCountHowManyLoolkits();
     void testBarren();
     void testCrashKit();
     void testCrashForkit();
-    void testNoExtraLoolKitsLeft();
 
     static
     void killLoKitProcesses(const char* exec_filename);
@@ -103,21 +100,6 @@ public:
     }
 };
 
-int HTTPCrashTest::InitialLoolKitCount = 1;
-
-void HTTPCrashTest::testCountHowManyLoolkits()
-{
-    InitialLoolKitCount = countLoolKitProcesses(InitialLoolKitCount);
-    CPPUNIT_ASSERT(InitialLoolKitCount > 0);
-}
-
-void HTTPCrashTest::testNoExtraLoolKitsLeft()
-{
-    const auto countNow = countLoolKitProcesses(InitialLoolKitCount);
-
-    CPPUNIT_ASSERT_EQUAL(InitialLoolKitCount, countNow);
-}
-
 void HTTPCrashTest::testBarren()
 {
     // Kill all kit processes and try loading a document.
diff --git a/test/httpwserror.cpp b/test/httpwserror.cpp
index cc6bd0f..e624e46 100644
--- a/test/httpwserror.cpp
+++ b/test/httpwserror.cpp
@@ -33,7 +33,6 @@ class HTTPWSError : public CPPUNIT_NS::TestFixture
 {
     const Poco::URI _uri;
     Poco::Net::HTTPResponse _response;
-    static int InitialLoolKitCount;
 
     CPPUNIT_TEST_SUITE(HTTPWSError);
 
@@ -42,8 +41,6 @@ class HTTPWSError : public CPPUNIT_NS::TestFixture
 
     CPPUNIT_TEST_SUITE_END();
 
-    void testCountHowManyLoolkits();
-    void testNoExtraLoolKitsLeft();
     void testMaxDocuments();
     void testMaxConnections();
 
@@ -79,21 +76,6 @@ public:
     }
 };
 
-int HTTPWSError::InitialLoolKitCount = 1;
-
-void HTTPWSError::testCountHowManyLoolkits()
-{
-    InitialLoolKitCount = countLoolKitProcesses(InitialLoolKitCount);
-    CPPUNIT_ASSERT(InitialLoolKitCount > 0);
-}
-
-void HTTPWSError::testNoExtraLoolKitsLeft()
-{
-    const auto countNow = countLoolKitProcesses(InitialLoolKitCount);
-
-    CPPUNIT_ASSERT_EQUAL(InitialLoolKitCount, countNow);
-}
-
 void HTTPWSError::testMaxDocuments()
 {
     static_assert(MAX_DOCUMENTS >= 2, "MAX_DOCUMENTS must be at least 2");
diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp
index 3e69bf0..8f84686 100644
--- a/test/httpwstest.cpp
+++ b/test/httpwstest.cpp
@@ -17,7 +17,6 @@
 #include <vector>
 
 #include <Poco/Dynamic/Var.h>
-#include <Poco/FileStream.h>
 #include <Poco/JSON/JSON.h>
 #include <Poco/JSON/Parser.h>
 #include <Poco/Net/AcceptCertificateHandler.h>
@@ -32,7 +31,6 @@
 #include <Poco/Net/Socket.h>
 #include <Poco/Path.h>
 #include <Poco/RegularExpression.h>
-#include <Poco/StreamCopier.h>
 #include <Poco/StringTokenizer.h>
 #include <Poco/URI.h>
 
@@ -44,6 +42,7 @@
 #include "Png.hpp"
 #include "UserMessages.hpp"
 #include "Util.hpp"
+
 #include "countloolkits.hpp"
 #include "helpers.hpp"
 
@@ -54,7 +53,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
 {
     const Poco::URI _uri;
     Poco::Net::HTTPResponse _response;
-    static int InitialLoolKitCount;
 
     CPPUNIT_TEST_SUITE(HTTPWSTest);
 
@@ -104,7 +102,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
 
     CPPUNIT_TEST_SUITE_END();
 
-    void testCountHowManyLoolkits();
     void testBadRequest();
     void testHandshake();
     void testCloseAfterClose();
@@ -128,7 +125,6 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
     void testPasswordProtectedDocumentWithCorrectPassword();
     void testPasswordProtectedDocumentWithCorrectPasswordAgain();
     void testInsertDelete();
-    void testNoExtraLoolKitsLeft();
     void testSlideShow();
     void testInactiveClient();
     void testMaxColumn();
@@ -212,14 +208,6 @@ public:
     }
 };
 
-int HTTPWSTest::InitialLoolKitCount = 1;
-
-void HTTPWSTest::testCountHowManyLoolkits()
-{
-    InitialLoolKitCount = countLoolKitProcesses(InitialLoolKitCount);
-    CPPUNIT_ASSERT(InitialLoolKitCount > 0);
-}
-
 void HTTPWSTest::testBadRequest()
 {
     try
@@ -1197,12 +1185,6 @@ void HTTPWSTest::testMaxRow()
     }
 }
 
-void HTTPWSTest::testNoExtraLoolKitsLeft()
-{
-    const auto countNow = countLoolKitProcesses(InitialLoolKitCount);
-    CPPUNIT_ASSERT_EQUAL(InitialLoolKitCount, countNow);
-}
-
 void HTTPWSTest::getPartHashCodes(const std::string status,
                                   std::vector<std::string>& parts)
 {
diff --git a/test/integration-http-server.cpp b/test/integration-http-server.cpp
index f0d2c50..0882b39 100644
--- a/test/integration-http-server.cpp
+++ b/test/integration-http-server.cpp
@@ -36,7 +36,6 @@
 class HTTPServerTest : public CPPUNIT_NS::TestFixture
 {
     const Poco::URI _uri;
-    static int InitialLoolKitCount;
 
     CPPUNIT_TEST_SUITE(HTTPServerTest);
 
@@ -49,8 +48,6 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
 
     CPPUNIT_TEST_SUITE_END();
 
-    void testCountHowManyLoolkits();
-
     void testDiscovery();
     void testLoleafletGet();
     void testLoleafletPost();
@@ -58,8 +55,6 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
     void testScriptsAndLinksPost();
     void testConvertTo();
 
-    void testNoExtraLoolKitsLeft();
-
 public:
     HTTPServerTest()
         : _uri(helpers::getTestServerURI())
@@ -92,14 +87,6 @@ public:
     }
 };
 
-int HTTPServerTest::InitialLoolKitCount = 1;
-
-void HTTPServerTest::testCountHowManyLoolkits()
-{
-    InitialLoolKitCount = countLoolKitProcesses(InitialLoolKitCount);
-    CPPUNIT_ASSERT(InitialLoolKitCount > 0);
-}
-
 void HTTPServerTest::testDiscovery()
 {
     std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
@@ -276,13 +263,6 @@ void HTTPServerTest::testConvertTo()
     CPPUNIT_ASSERT_EQUAL(expectedStream.str(), actualString);
 }
 
-void HTTPServerTest::testNoExtraLoolKitsLeft()
-{
-    const auto countNow = countLoolKitProcesses(InitialLoolKitCount);
-
-    CPPUNIT_ASSERT_EQUAL(InitialLoolKitCount, countNow);
-}
-
 CPPUNIT_TEST_SUITE_REGISTRATION(HTTPServerTest);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list