[Libreoffice-commits] online.git: 4 commits - loolwsd/Common.hpp loolwsd/LOOLForKit.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/test loolwsd/UnitHTTP.hpp

Jan Holesovsky kendy at collabora.com
Wed May 4 11:40:19 UTC 2016


 loolwsd/Common.hpp                       |    3 ++-
 loolwsd/LOOLForKit.cpp                   |   11 +++++++++++
 loolwsd/LOOLKit.cpp                      |    4 ++--
 loolwsd/LOOLWSD.cpp                      |   17 +++++++++++++----
 loolwsd/UnitHTTP.hpp                     |    2 +-
 loolwsd/test/UnitAdmin.cpp               |   15 +++------------
 loolwsd/test/UnitFonts.cpp               |    2 +-
 loolwsd/test/helpers.hpp                 |   16 ++++++++++++++++
 loolwsd/test/httpcrashtest.cpp           |    6 +-----
 loolwsd/test/httpwstest.cpp              |    6 +-----
 loolwsd/test/integration-http-server.cpp |   12 +++++-------
 loolwsd/test/run_unit.sh.in              |    8 +++++++-
 12 files changed, 63 insertions(+), 39 deletions(-)

New commits:
commit f40167cd6e7087cd29e34bb89ae50600eca2660c
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed May 4 13:39:09 2016 +0200

    Initialize the _url correctly.

diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index 844b0d4..598de6d 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -61,24 +61,26 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
 
     void testNoExtraLoolKitsLeft();
 
-#if ENABLE_SSL
 public:
     HTTPServerTest()
         : _uri(helpers::getTestServerURI())
     {
+#if ENABLE_SSL
         Poco::Net::initializeSSL();
         // Just accept the certificate anyway for testing purposes
         Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::AcceptCertificateHandler(false);
         Poco::Net::Context::Params sslParams;
         Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams);
         Poco::Net::SSLManager::instance().initializeClient(0, invalidCertHandler, sslContext);
+#endif
     }
 
     ~HTTPServerTest()
     {
+#if ENABLE_SSL
         Poco::Net::uninitializeSSL();
-    }
 #endif
+    }
 };
 
 int HTTPServerTest::_initialLoolKitCount = 0;
commit 191ee00f2cb485a692fe5b8500958219c4a1e2dd
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed May 4 13:06:34 2016 +0200

    Run the tests on ports that do not conflict with a 'normal' loolwsd.
    
    For the moment, it will allow running 'make check' that does not conflict with
    an already running loolwsd (eg. from 'make run').  Later we can consider
    running more tests in parallel.

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index 985c26c..caa3ce0 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -15,7 +15,7 @@
 constexpr int MAX_SESSIONS = 1024;
 
 constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
-constexpr int MASTER_PORT_NUMBER = 9981;
+constexpr int DEFAULT_MASTER_PORT_NUMBER = 9981;
 constexpr int WSD_SLEEP_SECS = 2;
 constexpr int CHILD_TIMEOUT_SECS = 10;
 constexpr int POLL_TIMEOUT_MS = 1000;
@@ -39,6 +39,7 @@ constexpr auto NEW_CHILD_URI = "/loolws/newchild?";
 
 // The client port number, both loolwsd and the kits have this.
 extern int ClientPortNumber;
+extern int MasterPortNumber;
 
 #endif
 
diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index 8b79db6..eea7c13 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -53,6 +53,7 @@ static std::atomic<unsigned> ForkCounter( 0 );
 static std::map<Process::PID, std::string> childJails;
 
 int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
+int MasterPortNumber = DEFAULT_MASTER_PORT_NUMBER;
 
 static int pipeFd = -1;
 
@@ -207,6 +208,16 @@ int main(int argc, char** argv)
     std::string sysTemplate;
     std::string loTemplate;
 
+#if ENABLE_DEBUG
+    static const char* clientPort = getenv("LOOL_TEST_CLIENT_PORT");
+    if (clientPort)
+        ClientPortNumber = std::stoi(clientPort);
+
+    static const char* masterPort = getenv("LOOL_TEST_MASTER_PORT");
+    if (masterPort)
+        MasterPortNumber = std::stoi(masterPort);
+#endif
+
     for (int i = 0; i < argc; ++i)
     {
         char *cmd = argv[i];
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 93b4a98..9cf8055 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -454,7 +454,7 @@ public:
 
             // Open websocket connection between the child process and the
             // parent. The parent forwards us requests that it can't handle (i.e most).
-            HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER);
+            HTTPClientSession cs("127.0.0.1", MasterPortNumber);
             cs.setTimeout(0);
             const auto childUrl = std::string(CHILD_URI) + "sessionId=" + sessionId + "&jailId=" + _jailId + "&docKey=" + _docKey;
             HTTPRequest request(HTTPRequest::HTTP_GET, childUrl);
@@ -1231,7 +1231,7 @@ void lokit_main(const std::string& childRoot,
         Log::info("Process is ready.");
 
         // Open websocket connection between the child process and WSD.
-        HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER);
+        HTTPClientSession cs("127.0.0.1", MasterPortNumber);
         cs.setTimeout(0);
         HTTPRequest request(HTTPRequest::HTTP_GET, std::string(NEW_CHILD_URI) + "pid=" + pid);
         HTTPResponse response;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5af6964..724a22c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -145,6 +145,7 @@ using Poco::XML::Node;
 using Poco::XML::NodeList;
 
 int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
+int MasterPortNumber = DEFAULT_MASTER_PORT_NUMBER;
 
 /// New LOK child processes ready to host documents.
 //TODO: Move to a more sensible namespace.
@@ -844,7 +845,7 @@ public:
 
         Log::debug("Child connection with URI [" + request.getURI() + "].");
 
-        assert(request.serverAddress().port() == MASTER_PORT_NUMBER);
+        assert(request.serverAddress().port() == MasterPortNumber);
         if (request.getURI().find(NEW_CHILD_URI) == 0)
         {
             // New Child is spawned.
@@ -1260,7 +1261,7 @@ void LOOLWSD::defineOptions(OptionSet& optionSet)
                         .repeatable(false));
 
     optionSet.addOption(Option("port", "", "Port number to listen to (default: " + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "),"
-                             " must not be " + std::to_string(MASTER_PORT_NUMBER) + ".")
+                             " must not be " + std::to_string(MasterPortNumber) + ".")
                         .required(false)
                         .repeatable(false)
                         .argument("port number"));
@@ -1365,6 +1366,14 @@ void LOOLWSD::handleOption(const std::string& optionName,
         NoCapsForKit = true;
     else if (optionName == "careerspan")
         careerSpanSeconds = std::stoi(value);
+
+    static const char* clientPort = getenv("LOOL_TEST_CLIENT_PORT");
+    if (clientPort)
+        ClientPortNumber = std::stoi(clientPort);
+
+    static const char* masterPort = getenv("LOOL_TEST_MASTER_PORT");
+    if (masterPort)
+        MasterPortNumber = std::stoi(masterPort);
 #endif
 }
 
@@ -1451,7 +1460,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     FileServerRoot = Poco::Path(FileServerRoot).absolute().toString();
     Log::debug("FileServerRoot: " + FileServerRoot);
 
-    if (ClientPortNumber == MASTER_PORT_NUMBER)
+    if (ClientPortNumber == MasterPortNumber)
         throw IncompatibleOptionsException("port");
 
     if (AdminCreds.empty())
@@ -1512,7 +1521,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     srv.start();
 
     // And one on the port for child processes
-    SocketAddress addr2("127.0.0.1", MASTER_PORT_NUMBER);
+    SocketAddress addr2("127.0.0.1", MasterPortNumber);
     ServerSocket svs2(addr2);
     HTTPServer srv2(new PrisonerRequestHandlerFactory(), threadPool, svs2, params2);
 
diff --git a/loolwsd/UnitHTTP.hpp b/loolwsd/UnitHTTP.hpp
index 1c8f77e..bd88eca 100644
--- a/loolwsd/UnitHTTP.hpp
+++ b/loolwsd/UnitHTTP.hpp
@@ -52,7 +52,7 @@ public:
                           const std::string &uri)
         : _response(inResponse),
           _clientAddress(),
-          _serverAddress(MASTER_PORT_NUMBER)
+          _serverAddress(MasterPortNumber)
         { setURI(uri); }
     virtual std::istream& stream() override
         { return *(static_cast<std::istream *>(nullptr)); }
diff --git a/loolwsd/test/UnitFonts.cpp b/loolwsd/test/UnitFonts.cpp
index 4ffb17a..bf82322 100644
--- a/loolwsd/test/UnitFonts.cpp
+++ b/loolwsd/test/UnitFonts.cpp
@@ -127,7 +127,7 @@ public:
     virtual void launchedKit(int /* pid */) override
     {
         // Open websocket connection between the child process and WSD.
-        Poco::Net::HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER);
+        Poco::Net::HTTPClientSession cs("127.0.0.1", MasterPortNumber);
         cs.setTimeout(0);
         Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET,
                                        std::string(UNIT_URI));
diff --git a/loolwsd/test/run_unit.sh.in b/loolwsd/test/run_unit.sh.in
index 34c5f20..1d590b1 100755
--- a/loolwsd/test/run_unit.sh.in
+++ b/loolwsd/test/run_unit.sh.in
@@ -12,9 +12,10 @@ jails_path="@JAILS_PATH@"
 lo_path="@LO_PATH@"
 
 # run the test on a dedicated port
-# TODO different numbers for tests run in parallel
+# TODO when we update test execution that the tests run in parallel, we'll
+# needd ifferent numbers for the tests run in parallel here
 export LOOL_TEST_CLIENT_PORT=9984
-# TODO export LOOL_TEST_MASTER_PORT=9985
+export LOOL_TEST_MASTER_PORT=9985
 
 tst=
 while test $# -gt 0; do
@@ -46,10 +47,10 @@ echo > $test_output
 
 if test "z$tst" == "z"; then
      echo "executing external tests"
-     ${abs_top_builddir}/loolwsd --port="$LOOL_TEST_CLIENT_PORT" --systemplate="$systemplate_path" \
+     ${abs_top_builddir}/loolwsd --systemplate="$systemplate_path" \
                                  --lotemplate="$lo_path" \
                                  --childroot="$jails_path" \
-                                 --allowlocalstorage  2> "$tst_log" &
+                                 --allowlocalstorage > "$tst_log" 2>&1 &
 
      echo "  executing test"
 
@@ -73,7 +74,7 @@ if test "z$tst" == "z"; then
 
 else # newer unit tests.
     echo "Running $tst | $tst_log ...";
-    if ${abs_top_builddir}/loolwsd --port="$LOOL_TEST_CLIENT_PORT" --systemplate="$systemplate_path" \
+    if ${abs_top_builddir}/loolwsd --systemplate="$systemplate_path" \
                                    --lotemplate="$lo_path" \
                                    --childroot="$jails_path" \
                                    --allowlocalstorage \
commit f6f4681556e41de475b619c002ca1feb32129766
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue May 3 10:08:50 2016 +0200

    Use a separate client port for running the tests.
    
    So that they can run in parallel to a 'production' loolwsd (like one from
    'make run' or so) in the future; for the moment it is not possible, as the
    MASTER_PORT is hardcoded.

diff --git a/loolwsd/test/run_unit.sh.in b/loolwsd/test/run_unit.sh.in
index 7b25c4a..34c5f20 100755
--- a/loolwsd/test/run_unit.sh.in
+++ b/loolwsd/test/run_unit.sh.in
@@ -11,6 +11,11 @@ enable_debug="@ENABLE_DEBUG@"
 jails_path="@JAILS_PATH@"
 lo_path="@LO_PATH@"
 
+# run the test on a dedicated port
+# TODO different numbers for tests run in parallel
+export LOOL_TEST_CLIENT_PORT=9984
+# TODO export LOOL_TEST_MASTER_PORT=9985
+
 tst=
 while test $# -gt 0; do
   case $1 in
@@ -41,7 +46,7 @@ echo > $test_output
 
 if test "z$tst" == "z"; then
      echo "executing external tests"
-     ${abs_top_builddir}/loolwsd --systemplate="$systemplate_path" \
+     ${abs_top_builddir}/loolwsd --port="$LOOL_TEST_CLIENT_PORT" --systemplate="$systemplate_path" \
                                  --lotemplate="$lo_path" \
                                  --childroot="$jails_path" \
                                  --allowlocalstorage  2> "$tst_log" &
@@ -68,7 +73,7 @@ if test "z$tst" == "z"; then
 
 else # newer unit tests.
     echo "Running $tst | $tst_log ...";
-    if ${abs_top_builddir}/loolwsd --systemplate="$systemplate_path" \
+    if ${abs_top_builddir}/loolwsd --port="$LOOL_TEST_CLIENT_PORT" --systemplate="$systemplate_path" \
                                    --lotemplate="$lo_path" \
                                    --childroot="$jails_path" \
                                    --allowlocalstorage \
commit 4935bf14b400feb1dd6dd0845fd87e844c046847
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue May 3 09:40:25 2016 +0200

    LOOL_TEST_CLIENT_PORT env. var for overriding the client port in the tests.
    
    And some further reduction of #ifdef ENABLE_SSL's...

diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index 57aeda0..2ecd27a 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -195,7 +195,7 @@ private:
         const std::string documentURL1 = "file://" + Poco::Path(documentPath1).makeAbsolute().toString();
         HTTPRequest request1(HTTPRequest::HTTP_GET, documentURL1);
         HTTPResponse response1;
-        const Poco::URI docUri1(getServerURI());
+        const Poco::URI docUri1(helpers::getTestServerURI());
         const std::string loadMessage1 = "load url=" + documentURL1;
         std::unique_ptr<HTTPClientSession> session1(helpers::createSession(docUri1));
         std::unique_ptr<HTTPClientSession> session2(helpers::createSession(docUri1));
@@ -265,7 +265,7 @@ private:
         const std::string documentURL2 = "file://" + Poco::Path(documentPath2).makeAbsolute().toString();
         HTTPRequest request2(HTTPRequest::HTTP_GET, documentURL2);
         HTTPResponse response2;
-        const Poco::URI docUri2(getServerURI());
+        const Poco::URI docUri2(helpers::getTestServerURI());
         const std::string loadMessage2 = "load url=" + documentURL2;
         std::unique_ptr<HTTPClientSession> session3(helpers::createSession(docUri1));
         _docWs3 = std::make_shared<Poco::Net::WebSocket>(*session3, request2, response2);
@@ -390,18 +390,9 @@ private:
         return TestResult::TEST_OK;
     }
 
-    std::string getServerURI()
-    {
-#if ENABLE_SSL
-        return "https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER);
-#else
-        return "http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER);
-#endif
-    }
-
 public:
     UnitAdmin()
-        : _uri(getServerURI() + "/loleaflet/dist/admin/admin.html")
+        : _uri(helpers::getTestServerURI() + "/loleaflet/dist/admin/admin.html")
     {
         // Register tests here.
         _tests.push_back(&UnitAdmin::testIncorrectPassword);
diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp
index 4dba8ac..8258d63 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -132,6 +132,22 @@ Poco::Net::HTTPClientSession* createSession(const Poco::URI& uri)
 #endif
 }
 
+inline
+std::string getTestServerURI()
+{
+    static const char* clientPort = getenv("LOOL_TEST_CLIENT_PORT");
+
+    static std::string serverURI(
+#if ENABLE_SSL
+            "https://127.0.0.1:"
+#else
+            "http://127.0.0.1:"
+#endif
+            + (clientPort? std::string(clientPort) : std::to_string(DEFAULT_CLIENT_PORT_NUMBER)));
+
+    return serverURI;
+}
+
 // Connecting to a Kit process is managed by document broker, that it does several
 // jobs to establish the bridge connection between the Client and Kit process,
 // The result, it is mostly time outs to get messages in the unit test and it could fail.
diff --git a/loolwsd/test/httpcrashtest.cpp b/loolwsd/test/httpcrashtest.cpp
index 15a2f4b..ce71d66 100644
--- a/loolwsd/test/httpcrashtest.cpp
+++ b/loolwsd/test/httpcrashtest.cpp
@@ -77,11 +77,7 @@ class HTTPCrashTest : public CPPUNIT_NS::TestFixture
 
 public:
     HTTPCrashTest()
-#if ENABLE_SSL
-        : _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
-#else
-        : _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
-#endif
+        : _uri(helpers::getTestServerURI())
     {
 #if ENABLE_SSL
         Poco::Net::initializeSSL();
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 10dc8a6..6057dbc 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -111,11 +111,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
 
 public:
     HTTPWSTest()
-#if ENABLE_SSL
-        : _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
-#else
-        : _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
-#endif
+        : _uri(helpers::getTestServerURI())
     {
 #if ENABLE_SSL
         Poco::Net::initializeSSL();
diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index 3494aeb..844b0d4 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -64,11 +64,7 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
 #if ENABLE_SSL
 public:
     HTTPServerTest()
-#if ENABLE_SSL
-        : _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
-#else
-        : _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER))
-#endif
+        : _uri(helpers::getTestServerURI())
     {
         Poco::Net::initializeSSL();
         // Just accept the certificate anyway for testing purposes


More information about the Libreoffice-commits mailing list