[Libreoffice-commits] online.git: Branch 'feature/paralleltest' - 11 commits - common/FileUtil.cpp common/FileUtil.hpp common/Unit.cpp common/Unit.hpp kit/ForKit.cpp kit/Kit.cpp loolkitconfig.xcu test/data test/DeltaTests.cpp test/helpers.hpp test/httpcrashtest.cpp test/integration-http-server.cpp test/Makefile.am test/run_unit.sh.in test/test.cpp test/test.hpp test/TileCacheTests.cpp test/UnitClient.cpp test/UnitWOPITemplate.cpp tools/Stress.cpp wsd/DocumentBroker.cpp wsd/FileServer.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp wsd/Storage.cpp wsd/TraceFile.hpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Tue Jan 21 13:40:05 UTC 2020


Rebased ref, commits from common ancestor:
commit b04fa41fd8130a99e9453088f97806a47788f4cd
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Jan 21 13:36:30 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    Clobber gio in the configuration.
    
    Otherwise activation fails for http:// or https:// since the core
    mis-identifies the (disabled via core: 1c081112714e) gio provider
    still and won't load via the ucpdav1 provider.
    
    Change-Id: I66a58da3f94a4479729a3e39ed5070e4a05dcf69

diff --git a/loolkitconfig.xcu b/loolkitconfig.xcu
index 666b6a6cc..539186947 100644
--- a/loolkitconfig.xcu
+++ b/loolkitconfig.xcu
@@ -28,4 +28,7 @@
 <!-- Use the colibre_svg theme for the sidebar -->
 <item oor:path="/org.openoffice.Office.Common/Misc"><prop oor:name="SymbolStyle" oor:op="fuse"><value>colibre_svg</value></prop></item>
 
+<!-- Disable GIO UCP we don't want -->
+<item oor:path="/org.openoffice.ucb.Configuration/ContentProviders/Local/SecondaryKeys/Office/ProviderData/Provider999"><prop oor:name="URLTemplate" oor:op="fuse"><value>NeverMatchAnyUrlSuffix</value></prop></item>
+
 </oor:items>
commit c7e3d29fa687c5f412438b7e493f8d3c19e07745
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Jan 21 13:36:14 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    kit: show the correct documentLoad URL when a template is used.
    
    Change-Id: Ib9b3ac3e166dfbece8c7212fc239d517ce1c0bba

diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 78eea14eb..34d5b86a5 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -54,6 +54,7 @@
 
 #include "ChildSession.hpp"
 #include <Common.hpp>
+#include <FileUtil.hpp>
 #include <IoUtil.hpp>
 #include "KitHelper.hpp"
 #include "Kit.hpp"
@@ -1636,13 +1637,14 @@ private:
             _jailedUrl = uri;
             _isDocPasswordProtected = false;
 
-            LOG_DBG("Calling lokit::documentLoad(" << uriAnonym << ", \"" << options << "\").");
+            const char *pURL = docTemplate.empty() ? uri.c_str() : docTemplate.c_str();
+            LOG_DBG("Calling lokit::documentLoad(" << FileUtil::anonymizeUrl(pURL) << ", \"" << options << "\").");
             const auto start = std::chrono::system_clock::now();
-            _loKitDocument.reset(_loKit->documentLoad(docTemplate.empty() ? uri.c_str() : docTemplate.c_str(), options.c_str()));
+            _loKitDocument.reset(_loKit->documentLoad(pURL, options.c_str()));
             const auto duration = std::chrono::system_clock::now() - start;
             const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
             const double totalTime = elapsed/1000.;
-            LOG_DBG("Returned lokit::documentLoad(" << uriAnonym << ") in " << totalTime << "ms.");
+            LOG_DBG("Returned lokit::documentLoad(" << FileUtil::anonymizeUrl(pURL) << ") in " << totalTime << "ms.");
 #ifdef IOS
             // The iOS app (and the Android one) has max one document open at a time, so we can keep
             // a pointer to it in a global.
commit b6903c1b531cf01360059fe7e50a11cba6da8985
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Jan 21 12:08:06 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    test: forcibly serialize more.
    
    Change-Id: I2fd370c5bdd440e3be2c065f9b834ffa4e7f856b

diff --git a/test/Makefile.am b/test/Makefile.am
index a31e557b6..7f15ef069 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -240,6 +240,7 @@ unit-wopi-documentconflict.log : unit-wopi-versionrestore.log
 unit_wopi_renamefile.log : unit-wopi-documentconflict.log
 unit_wopi_watermark.log : unit_wopi_renamefile.log
 
+# parallelize a couple at least.
 unit-http.log : unit_wopi_watermark.log
 unit-tiff-load.log : unit_wopi_watermark.log
 
@@ -248,12 +249,10 @@ unit-paste.log : unit-large-paste.log
 unit-load-torture.log : unit-paste.log
 unit-rendering-options.log : unit-load-torture.log
 unit-password-protected.log : unit-rendering-options.log
-
 unit-render-shape.log : unit-password-protected.log
-unit-each-view.log : unit-password-protected.log
-unit-session.log : unit-password-protected.log
-unit-uno-command.log : unit-password-protected.log
-
+unit-each-view.log : unit-render-shape.log
+unit-session.log : unit-each-view.log
+unit-uno-command.log : unit-session.log
 unit-load.log : unit-uno-command.log
 unit-cursor.log : unit-load.log
 unit-calc.log : unit-cursor.log
commit cecbc9a390c6b589e24704e76e0505917e181ed2
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Jan 21 11:21:08 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    test: simplify and remove obsolete /proc grokking code.
    
    Change-Id: I482c56dd76067019d83196aa305d14703e25bb44

diff --git a/test/Makefile.am b/test/Makefile.am
index e4b621755..a31e557b6 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -81,7 +81,7 @@ test_base_source = \
 	DeltaTests.cpp \
 	$(wsd_sources)
 
-unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS
+unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS -DSTANDALONE_CPPUNIT
 unittest_SOURCES = $(test_base_source) test.cpp
 unittest_LDADD = $(CPPUNIT_LIBS)
 
diff --git a/test/UnitClient.cpp b/test/UnitClient.cpp
index 03682fdc5..bd2378eb3 100644
--- a/test/UnitClient.cpp
+++ b/test/UnitClient.cpp
@@ -72,7 +72,9 @@ UnitBase *unit_create_wsd(void)
 }
 
 // Allows re-use of UnitClient in test.cpp impls.
-#define UNIT_CLIENT_TESTS
+#ifdef STANDALONE_CPPUNIT
+#  error "Should never be compiled this way";
+#endif
 #include <test.cpp>
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/test.cpp b/test/test.cpp
index 57a7c8ff9..6613fb9b2 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -30,6 +30,9 @@
 #include <Poco/FileStream.h>
 #include <Poco/StreamCopier.h>
 
+#include <Unit.hpp>
+#include <wsd/LOOLWSD.hpp>
+
 #include <Log.hpp>
 
 #include "common/Protocol.hpp"
@@ -172,16 +175,10 @@ bool runClientTests(bool standalone, bool verbose)
     if (!envar && failures.size() > 0)
     {
         std::cerr << "\nTo reproduce the first test failure use:\n\n";
-#ifndef UNIT_CLIENT_TESTS
-        const char *cmd = "./run_unit.sh --verbose";
-        if (getenv("UNITTEST"))
-            cmd = "./unittest";
-        std::cerr << "  (cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" " << cmd << ")\n\n";
-        if (getenv("UNITTEST"))
-        {
-            std::cerr << "To debug:\n\n";
-            std::cerr << "  (cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" gdb --args " << cmd << ")\n\n";
-        }
+#ifdef STANDALONE_CPPUNIT // unittest
+        const char *cmd = "./unittest";
+        std::cerr << "To debug:\n\n";
+        std::cerr << "  (cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" gdb --args " << cmd << ")\n\n";
 #else
         std::string aLib = UnitBase::get().getUnitLibPath();
         size_t lastSlash = aLib.rfind('/');
@@ -195,108 +192,8 @@ bool runClientTests(bool standalone, bool verbose)
     return result.wasSuccessful();
 }
 
-// Versions assuming a single user, on a single machine
-#ifndef UNIT_CLIENT_TESTS
-
-std::vector<int> getProcPids(const char* exec_filename)
-{
-    std::vector<int> pids;
-
-    // Ensure we're in the same group.
-    const int grp = getpgrp();
-
-    // Get all lokit processes.
-    for (auto it = Poco::DirectoryIterator(std::string("/proc")); it != Poco::DirectoryIterator(); ++it)
-    {
-        try
-        {
-            const 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);
-                std::vector<std::string> tokens(LOOLProtocol::tokenize(statString, ' '));
-                if (tokens.size() > 6 && tokens[1].find(exec_filename) == 0)
-                {
-                    // We could have several make checks running at once.
-                    int kidGrp = std::atoi(tokens[4].c_str());
-                    // Don't require matching grp for --debugrun invocations.
-                    if (kidGrp != grp && !IsDebugrun)
-                        continue;
-
-                    switch (tokens[2].c_str()[0])
-                    {
-                    // Dead & zombie markers for old and new kernels.
-                    case 'x':
-                    case 'X':
-                    case 'Z':
-                        break;
-                    default:
-                        pids.push_back(pid);
-                        break;
-                    }
-                }
-            }
-        }
-        catch (const Poco::Exception&)
-        {
-        }
-    }
-    return pids;
-}
-
-std::vector<int> getSpareKitPids()
-{
-    return getProcPids("(kit_spare_");
-}
-
-std::vector<int> getDocKitPids()
-{
-    return getProcPids("(kitbroker_");
-}
-
-std::vector<int> getKitPids()
-{
-    std::vector<int> pids = getSpareKitPids();
-    for (int pid : getDocKitPids())
-        pids.push_back(pid);
-
-    return pids;
-}
-
-int getLoolKitProcessCount()
-{
-    return getKitPids().size();
-}
-
-std::vector<int> getForKitPids()
-{
-    std::vector<int> pids, pids2;
-
-    pids = getProcPids("(loolforkit)");
-    pids2 = getProcPids("(forkit)");
-    pids.insert(pids.end(), pids2.begin(), pids2.end());
-
-    return pids;
-}
-
-#else // UNIT_CLIENT_TESTS
-
-// Here we are compiled inside UnitClient.cpp and we have
-// full access to the WSD process internals.
+// Standalone tests don't really use WSD
+#ifndef STANDALONE_CPPUNIT
 
 std::vector<int> getKitPids()
 {
@@ -317,12 +214,6 @@ int getLoolKitProcessCount()
 {
     return getKitPids().size();
 }
-
-int getClientPort()
-{
-    return LOOLWSD::getClientPortNumber();
-}
-
-#endif // UNIT_CLIENT_TESTS
+#endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 01fbe88c1fc09e17b75b0c54493e31e8a8d5dc2d
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Jan 21 09:00:52 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    test: switch to using ClientPortNumber to allow parallelism.
    
    Change-Id: Ifef3bce1b217605000300b240ea74df4d264e0df

diff --git a/test/DeltaTests.cpp b/test/DeltaTests.cpp
index 6e230e17b..9c3eef273 100644
--- a/test/DeltaTests.cpp
+++ b/test/DeltaTests.cpp
@@ -14,7 +14,6 @@
 #include <Delta.hpp>
 #include <Util.hpp>
 #include <Png.hpp>
-#include <helpers.hpp>
 
 /// Delta unit-tests.
 class DeltaTests : public CPPUNIT_NS::TestFixture
diff --git a/test/Makefile.am b/test/Makefile.am
index f5804139e..e4b621755 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -194,7 +194,7 @@ TESTS = \
         unit-wopi-documentconflict.la unit_wopi_renamefile.la unit_wopi_watermark.la \
 	unit-http.la \
 	unit-tiff-load.la \
-	unit.large-paste.la \
+	unit-large-paste.la \
 	unit-paste.la \
 	unit-load-torture.la \
 	unit-rendering-options.la \
@@ -214,7 +214,7 @@ TESTS = \
 # TESTS += unit-admin.test
 # TESTS += unit-storage.test
 
-# force serialization for now:
+# mostly force serialization for now:
 
 # unit-base.log
 unit-tiletest.log : unit-base.log
@@ -226,8 +226,11 @@ unit-copy-paste.log : unit-crash.log
 unit-typing.log : unit-copy-paste.log
 unit-convert.log : unit-typing.log
 unit-prefork.log : unit-convert.log
+
+# try a couple in parallel
 unit-tilecache.log : unit-prefork.log
-unit-timeout.log : unit-tilecache.log
+unit-timeout.log : unit-prefork.log
+
 unit-oauth.log : unit-timeout.log
 unit-wopi.log : unit-oauth.log
 unit-wopi-saveas.log : unit-wopi.log
@@ -236,17 +239,21 @@ unit-wopi-versionrestore.log : unit-wopi-ownertermination.log
 unit-wopi-documentconflict.log : unit-wopi-versionrestore.log
 unit_wopi_renamefile.log : unit-wopi-documentconflict.log
 unit_wopi_watermark.log : unit_wopi_renamefile.log
+
 unit-http.log : unit_wopi_watermark.log
-unit-tiff-load.log : unit-http.log
-unit.logrge-paste.log : unit-tiff-load.log
-unit-paste.log : unit.logrge-paste.log
+unit-tiff-load.log : unit_wopi_watermark.log
+
+unit-large-paste.log : unit-tiff-load.log
+unit-paste.log : unit-large-paste.log
 unit-load-torture.log : unit-paste.log
 unit-rendering-options.log : unit-load-torture.log
 unit-password-protected.log : unit-rendering-options.log
+
 unit-render-shape.log : unit-password-protected.log
-unit-each-view.log : unit-render-shape.log
-unit-session.log : unit-each-view.log
-unit-uno-command.log : unit-session.log
+unit-each-view.log : unit-password-protected.log
+unit-session.log : unit-password-protected.log
+unit-uno-command.log : unit-password-protected.log
+
 unit-load.log : unit-uno-command.log
 unit-cursor.log : unit-load.log
 unit-calc.log : unit-cursor.log
@@ -257,10 +264,8 @@ unit-hosting.log : unit-bad-doc-load.log
 unit-wopi-loadencoded.log : unit-hosting.log
 unit-wopi-temp.log : unit-wopi-loadencoded.log
 
-# end force serialization
+# end forced serialization
 
-else
-TESTS = ${top_builddir}/test/test
 endif
 
 TEST_EXTENSIONS = .la
diff --git a/test/UnitWOPITemplate.cpp b/test/UnitWOPITemplate.cpp
index d133178ec..efe4574be 100644
--- a/test/UnitWOPITemplate.cpp
+++ b/test/UnitWOPITemplate.cpp
@@ -46,7 +46,7 @@ public:
             Poco::LocalDateTime now;
             Poco::JSON::Object::Ptr fileInfo = new Poco::JSON::Object();
             fileInfo->set("BaseFileName", "test.odt");
-            fileInfo->set("TemplateSource", std::string("http://127.0.0.1:") + std::to_string(helpers::getClientPort()) + "/test.ott"); // must be http, otherwise Neon in the core complains
+            fileInfo->set("TemplateSource", std::string("http://127.0.0.1:") + std::to_string(ClientPortNumber) + "/test.ott"); // must be http, otherwise Neon in the core complains
             fileInfo->set("Size", getFileContent().size());
             fileInfo->set("Version", "1.0");
             fileInfo->set("OwnerId", "test");
diff --git a/test/helpers.hpp b/test/helpers.hpp
index 32608b5a2..9aa15d518 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -31,6 +31,7 @@
 
 #include <Common.hpp>
 #include "common/FileUtil.hpp"
+#include "test/test.hpp"
 #include <LOOLWebSocket.hpp>
 #include <Util.hpp>
 
@@ -187,15 +188,6 @@ Poco::Net::HTTPClientSession* createSession(const Poco::URI& uri)
     return new Poco::Net::HTTPClientSession(uri.getHost(), uri.getPort());
 }
 
-#ifndef UNIT_CLIENT_TESTS
-
-inline int getClientPort()
-{
-    return DEFAULT_CLIENT_PORT_NUMBER;
-}
-
-#endif
-
 inline std::shared_ptr<Poco::Net::StreamSocket> createRawSocket()
 {
     return
@@ -204,7 +196,7 @@ inline std::shared_ptr<Poco::Net::StreamSocket> createRawSocket()
 #else
         std::make_shared<Poco::Net::StreamSocket>
 #endif
-            (Poco::Net::SocketAddress("127.0.0.1", getClientPort()));
+        (Poco::Net::SocketAddress("127.0.0.1", ClientPortNumber));
 }
 
 inline
@@ -216,7 +208,7 @@ std::string const & getTestServerURI()
 #else
             "http://127.0.0.1:"
 #endif
-            + std::to_string(getClientPort()));
+            + std::to_string(ClientPortNumber));
 
     return serverURI;
 }
diff --git a/test/httpcrashtest.cpp b/test/httpcrashtest.cpp
index 1d271725b..904b4330e 100644
--- a/test/httpcrashtest.cpp
+++ b/test/httpcrashtest.cpp
@@ -39,9 +39,9 @@
 #include <Util.hpp>
 #include <Protocol.hpp>
 #include <LOOLWebSocket.hpp>
+#include <test.hpp>
 #include <helpers.hpp>
 #include <countloolkits.hpp>
-#include <test.hpp>
 
 using namespace helpers;
 
diff --git a/tools/Stress.cpp b/tools/Stress.cpp
index 1a4d17124..b298951db 100644
--- a/tools/Stress.cpp
+++ b/tools/Stress.cpp
@@ -34,6 +34,8 @@
 #include <TraceFile.hpp>
 #include <test/helpers.hpp>
 
+int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
+
 /// Stress testing and performance/scalability benchmarking tool.
 class Stress: public Poco::Util::Application
 {
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 090cde1c0..bcb0ca141 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -3254,7 +3254,6 @@ private:
         LOG_INF("Listening to prisoner connections on " << location);
         MasterLocation = location;
 #else
-        // TESTME ...
         constexpr int DEFAULT_MASTER_PORT_NUMBER = 9981;
         std::shared_ptr<ServerSocket> socket = getServerSocket(
             ServerSocket::Type::Public, DEFAULT_MASTER_PORT_NUMBER, PrisonerPoll, factory);
commit ef05f699e995e95e6f66d807d4e08742975d379c
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jan 20 15:26:54 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    test: serialize tests for now.
    
    Change-Id: I6309976f324a66a57baf4678e49c0c1e09b9dc48

diff --git a/test/Makefile.am b/test/Makefile.am
index e10cb7d8c..f5804139e 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -213,6 +213,52 @@ TESTS = \
 	unit-wopi-loadencoded.la unit-wopi-temp.la
 # TESTS += unit-admin.test
 # TESTS += unit-storage.test
+
+# force serialization for now:
+
+# unit-base.log
+unit-tiletest.log : unit-base.log
+unit-integration.log : unit-tiletest.log
+unit-httpws.log : unit-integration.log
+unit-crash.log : unit-httpws.log
+
+unit-copy-paste.log : unit-crash.log
+unit-typing.log : unit-copy-paste.log
+unit-convert.log : unit-typing.log
+unit-prefork.log : unit-convert.log
+unit-tilecache.log : unit-prefork.log
+unit-timeout.log : unit-tilecache.log
+unit-oauth.log : unit-timeout.log
+unit-wopi.log : unit-oauth.log
+unit-wopi-saveas.log : unit-wopi.log
+unit-wopi-ownertermination.log : unit-wopi-saveas.log
+unit-wopi-versionrestore.log : unit-wopi-ownertermination.log
+unit-wopi-documentconflict.log : unit-wopi-versionrestore.log
+unit_wopi_renamefile.log : unit-wopi-documentconflict.log
+unit_wopi_watermark.log : unit_wopi_renamefile.log
+unit-http.log : unit_wopi_watermark.log
+unit-tiff-load.log : unit-http.log
+unit.logrge-paste.log : unit-tiff-load.log
+unit-paste.log : unit.logrge-paste.log
+unit-load-torture.log : unit-paste.log
+unit-rendering-options.log : unit-load-torture.log
+unit-password-protected.log : unit-rendering-options.log
+unit-render-shape.log : unit-password-protected.log
+unit-each-view.log : unit-render-shape.log
+unit-session.log : unit-each-view.log
+unit-uno-command.log : unit-session.log
+unit-load.log : unit-uno-command.log
+unit-cursor.log : unit-load.log
+unit-calc.log : unit-cursor.log
+unit-insert-delete.log : unit-calc.log
+unit-close.log : unit-insert-delete.log
+unit-bad-doc-load.log : unit-close.log
+unit-hosting.log : unit-bad-doc-load.log
+unit-wopi-loadencoded.log : unit-hosting.log
+unit-wopi-temp.log : unit-wopi-loadencoded.log
+
+# end force serialization
+
 else
 TESTS = ${top_builddir}/test/test
 endif
commit c7fb1f31b2cf3c3c256aeda499b1858e1820337a
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jan 20 15:16:36 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    test: simplify the timeout logic.
    
    Change-Id: I0c253629b983f2813237536e6e2c6d04d5b97dd1

diff --git a/test/data/convert-to.xlsx b/test/data/convert-to.xlsx
index 7af9e7063..344ee0d13 100644
Binary files a/test/data/convert-to.xlsx and b/test/data/convert-to.xlsx differ
diff --git a/test/helpers.hpp b/test/helpers.hpp
index 19bd8804d..32608b5a2 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -261,22 +261,22 @@ std::vector<char> getResponseMessage(LOOLWebSocket& ws, const std::string& prefi
     try
     {
         int flags = 0;
-        int retries = timeoutMs / 500;
-        const Poco::Timespan waitTime(retries ? timeoutMs * 1000 / retries : timeoutMs * 1000);
         std::vector<char> response;
 
-        bool timedout = false;
+        auto endTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeoutMs);
+
         ws.setReceiveTimeout(0);
         do
         {
-            if (ws.poll(waitTime, Poco::Net::Socket::SELECT_READ))
+            auto now = std::chrono::steady_clock::now();
+            if (now > endTime) // timedout
+            {
+                TST_LOG("Timeout.");
+                break;
+            }
+            long waitTimeUs = std::chrono::duration_cast<std::chrono::microseconds>(endTime - now).count();
+            if (ws.poll(Poco::Timespan(waitTimeUs), Poco::Net::Socket::SELECT_READ))
             {
-                if (timedout)
-                {
-                    TST_LOG_END;
-                    timedout = false;
-                }
-
                 response.resize(READ_BUFFER_SIZE * 8);
                 const int bytes = ws.receiveFrame(response.data(), response.size(), flags);
                 response.resize(std::max(bytes, 0));
@@ -312,31 +312,11 @@ std::vector<char> getResponseMessage(LOOLWebSocket& ws, const std::string& prefi
                             LOOLProtocol::getAbbreviatedFrameDump(response.data(), bytes, flags));
                 }
             }
-            else
-            {
-                if (!timedout)
-                {
-                    TST_LOG_BEGIN("Timeout (" << (retries > 1 ? "retrying" : "giving up") << ") ");
-                }
-                else
-                {
-                    TST_LOG_APPEND(retries << ' ');
-                }
-
-                --retries;
-                timedout = true;
-            }
-        }
-        while (retries > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
-
-        if (timedout)
-        {
-            TST_LOG_END;
         }
+        while ((flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
     }
     catch (const Poco::Net::WebSocketException& exc)
     {
-        TST_LOG_END;
         TST_LOG(exc.message());
     }
 
commit 0edf084c5da2dd600851134d4327734925e379df
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Jan 17 21:18:42 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    test: dung out redundant LOOL_TEST_CLIENT_PORT.
    
    And cleanup other related oddities.
    
    Change-Id: I2d179a2ece6a8553e10e406ad4e5da08a2ff58e5

diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index 164489589..ac0191e33 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -396,15 +396,6 @@ int main(int argc, char** argv)
     std::string sysTemplate;
     std::string loTemplate;
 
-#if ENABLE_DEBUG
-    static const char* clientPort = std::getenv("LOOL_TEST_CLIENT_PORT");
-    if (clientPort)
-        ClientPortNumber = std::stoi(clientPort);
-    static const char* masterPort = std::getenv("LOOL_TEST_MASTER_PORT");
-    if (masterPort)
-        MasterLocation = masterPort;
-#endif
-
     for (int i = 0; i < argc; ++i)
     {
         char *cmd = argv[i];
diff --git a/test/Makefile.am b/test/Makefile.am
index 2b369465a..e10cb7d8c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -2,12 +2,10 @@
 export MAX_CONCURRENCY=4
 AUTOMAKE_OPTION = serial-tests
 
-# unittest: tests that do not need loolwsd running, and that are run during a
-# normal build
-# test: tests that need loolwsd running, and that are run via 'make check'
-check_PROGRAMS = test fakesockettest
+# unittest: tests that run a captive loolwsd as part of themselves.
+check_PROGRAMS = fakesockettest
 
-noinst_PROGRAMS = test fakesockettest unittest
+noinst_PROGRAMS = fakesockettest unittest
 
 AM_CXXFLAGS = $(CPPUNIT_CFLAGS) -DTDOC=\"$(abs_top_srcdir)/test/data\" \
 	-I${top_srcdir}/common -I${top_srcdir}/net -I${top_srcdir}/wsd -I${top_srcdir}/kit
@@ -87,10 +85,6 @@ unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS
 unittest_SOURCES = $(test_base_source) test.cpp
 unittest_LDADD = $(CPPUNIT_LIBS)
 
-test_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS
-test_SOURCES = $(test_all_source) test.cpp
-test_LDADD = $(CPPUNIT_LIBS)
-
 fakesockettest_SOURCES = fakesockettest.cpp ../net/FakeSocket.cpp
 fakesockettest_LDADD = $(CPPUNIT_LIBS)
 
diff --git a/test/TileCacheTests.cpp b/test/TileCacheTests.cpp
index 7dc7d1500..a69099bd5 100644
--- a/test/TileCacheTests.cpp
+++ b/test/TileCacheTests.cpp
@@ -432,6 +432,8 @@ void TileCacheTests::testUnresponsiveClient()
 {
     const std::string testname = "unresponsiveClient-";
 
+    TST_LOG("testUnresponsiveClient.");
+
     std::string documentPath, documentURL;
     getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
 
diff --git a/test/helpers.hpp b/test/helpers.hpp
index dd638d191..19bd8804d 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -187,12 +187,15 @@ Poco::Net::HTTPClientSession* createSession(const Poco::URI& uri)
     return new Poco::Net::HTTPClientSession(uri.getHost(), uri.getPort());
 }
 
+#ifndef UNIT_CLIENT_TESTS
+
 inline int getClientPort()
 {
-    static const char* clientPort = std::getenv("LOOL_TEST_CLIENT_PORT");
-    return clientPort? atoi(clientPort) : DEFAULT_CLIENT_PORT_NUMBER;
+    return DEFAULT_CLIENT_PORT_NUMBER;
 }
 
+#endif
+
 inline std::shared_ptr<Poco::Net::StreamSocket> createRawSocket()
 {
     return
diff --git a/test/integration-http-server.cpp b/test/integration-http-server.cpp
index 4db04737a..8c0c87ac2 100644
--- a/test/integration-http-server.cpp
+++ b/test/integration-http-server.cpp
@@ -92,15 +92,13 @@ public:
     // A server URI which was not added to loolwsd.xml as post_allow IP or a wopi storage host
     Poco::URI getNotAllowedTestServerURI()
     {
-        static const char* clientPort = std::getenv("LOOL_TEST_CLIENT_PORT");
-
         static std::string serverURI(
 #if ENABLE_SSL
-        "https://165.227.162.232:"
+            "https://165.227.162.232:9980"
 #else
-        "http://165.227.162.232:"
+            "http://165.227.162.232:9980"
 #endif
-            + (clientPort? std::string(clientPort) : std::to_string(DEFAULT_CLIENT_PORT_NUMBER)));
+            );
 
         return Poco::URI(serverURI);
     }
@@ -236,9 +234,12 @@ void HTTPServerTest::testScriptsAndLinksPost()
 
 void HTTPServerTest::testConvertTo()
 {
+    const char *testname = "testConvertTo";
     const std::string srcPath = FileUtil::getTempFilePath(TDOC, "hello.odt", "convertTo_");
     std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
-    session->setTimeout(Poco::Timespan(2, 0)); // 2 seconds.
+    session->setTimeout(Poco::Timespan(5, 0)); // 5 seconds.
+
+    TST_LOG("Convert-to odt -> txt");
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/lool/convert-to");
     Poco::Net::HTMLForm form;
@@ -253,7 +254,7 @@ void HTTPServerTest::testConvertTo()
     catch (const std::exception& ex)
     {
         // In case the server is still starting up.
-        sleep(2);
+        sleep(5);
         form.write(session->sendRequest(request));
     }
 
@@ -279,9 +280,12 @@ void HTTPServerTest::testConvertTo()
 
 void HTTPServerTest::testConvertTo2()
 {
+    const char *testname = "testConvertTo2";
     const std::string srcPath = FileUtil::getTempFilePath(TDOC, "convert-to.xlsx", "convertTo_");
     std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
-    session->setTimeout(Poco::Timespan(5, 0)); // 5 seconds.
+    session->setTimeout(Poco::Timespan(10, 0)); // 10 seconds.
+
+    TST_LOG("Convert-to #2 xlsx -> png");
 
     Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/lool/convert-to");
     Poco::Net::HTMLForm form;
@@ -296,7 +300,7 @@ void HTTPServerTest::testConvertTo2()
     catch (const std::exception& ex)
     {
         // In case the server is still starting up.
-        sleep(2);
+        sleep(5);
         form.write(session->sendRequest(request));
     }
 
diff --git a/test/run_unit.sh.in b/test/run_unit.sh.in
index 5fb8a6936..4b893f23c 100755
--- a/test/run_unit.sh.in
+++ b/test/run_unit.sh.in
@@ -70,55 +70,10 @@ fi
 echo "Test output is '$test_output'"
 echo > $test_output
 
-if test "z$tst" == "z"; then
-     # run the test on a dedicated port
-     export LOOL_TEST_CLIENT_PORT=9984
-     export LOOL_TEST_MASTER_PORT=9985
-
-     echo "Executing external tests"
-     ${trace} \
-     ${abs_top_builddir}/loolwsd --o:sys_template_path="$systemplate_path" \
-                                 --o:child_root_path="$jails_path" \
-                                 --o:storage.filesystem[@allow]=true \
-                                 --o:logging.level=trace \
-                                 --o:logging.file[@enable]=false \
-                                 --o:ssl.key_file_path="${abs_top_builddir}/etc/key.pem" \
-                                 --o:ssl.cert_file_path="${abs_top_builddir}/etc/cert.pem" \
-                                 --o:ssl.ca_file_path="${abs_top_builddir}/etc/ca-chain.cert.pem" \
-                                 --o:admin_console.username=admin --o:admin_console.password=admin \
-                                 --o:storage.ssl.enable=false \
-                                 > "$tst_log" 2>&1 &
-     if test "z${SLEEPFORDEBUGGER}${SLEEPKITFORDEBUGGER}" != "z"; then
-	  echo "sleeping for debugger"
-          sleep ${SLEEPFORDEBUGGER:-0}
-          sleep ${SLEEPKITFORDEBUGGER:-0}
-     fi
-
-     echo "  executing test"
-
-     oldpath=`pwd`
-     cd "${abs_top_builddir}/test"
-     if eval ${trace} ./test ${verbose}; then
-	 echo "Test run_test.sh passed."
-	 echo ":test-result: PASS run_test.sh" >> $oldpath/$test_output
-	 retval=0
-     else
-	 echo ":test-result: FAIL run_test.sh" >> $oldpath/$test_output
-	 retval=1
-     fi
-
-     if test "z${SLEEPFORDEBUGGER}${SLEEPKITFORDEBUGGER}" == "z"; then
-         echo "killing $!"
-         kill $!
-     fi
-
-     exit $retval
-
-else # newer unit tests.
-    echo "Running $tst | $tst_log ...";
-    if ${trace} \
+echo "Running $tst | $tst_log ...";
+if ${trace} \
        ${abs_top_builddir}/loolwsd --o:sys_template_path="$systemplate_path" \
-                                   --o:child_root_path="$jails_path" \
+       --o:child_root_path="$jails_path" \
                                    --o:storage.filesystem[@allow]=true \
                                    --o:logging.level=trace \
                                    --o:ssl.key_file_path="${abs_top_builddir}/etc/key.pem" \
@@ -129,7 +84,7 @@ else # newer unit tests.
                                    --unitlib="${abs_top_builddir}/test/.libs/$tst.so" 2> "$tst_log"; then
         echo "Test $tst passed."
         echo ":test-result: PASS $tst" >> $test_output
-    else
+else
 	cat $tst_log
         echo "============================================================="
         echo "Test failed on unit: $tst re-run with:"
@@ -147,7 +102,6 @@ else # newer unit tests.
 	echo "   $ less $tst_log # for detailed failure log files"
         echo "============================================================="
         echo ":test-result: FAIL $tst" >> $test_output
-    fi
 fi
 
 # vim:set shiftwidth=4 expandtab:
diff --git a/test/test.cpp b/test/test.cpp
index 4a5b0f6d0..57a7c8ff9 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -183,8 +183,12 @@ bool runClientTests(bool standalone, bool verbose)
             std::cerr << "  (cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" gdb --args " << cmd << ")\n\n";
         }
 #else
+        std::string aLib = UnitBase::get().getUnitLibPath();
+        size_t lastSlash = aLib.rfind('/');
+        if (lastSlash != std::string::npos)
+            aLib = aLib.substr(lastSlash + 1, aLib.length() - lastSlash - 4) + ".la";
         std::cerr << "(cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() <<
-            "\" ./run_unit.sh --test-name " << UnitBase::get().getUnitLibPath() << ")\n\n";
+            "\" ./run_unit.sh --test-name " << aLib << ")\n\n";
 #endif
     }
 
@@ -314,6 +318,11 @@ int getLoolKitProcessCount()
     return getKitPids().size();
 }
 
+int getClientPort()
+{
+    return LOOLWSD::getClientPortNumber();
+}
+
 #endif // UNIT_CLIENT_TESTS
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/test.hpp b/test/test.hpp
index 29b6e76d3..a5a2b2280 100644
--- a/test/test.hpp
+++ b/test/test.hpp
@@ -31,6 +31,9 @@ std::vector<int> getDocKitPids();
 /// Get the PID of the forkit
 std::vector<int> getForKitPids();
 
+/// Which port should we connect to get to WSD.
+int getClientPort();
+
 /// How many live loolkit processes do we have ?
 int getLoolKitProcessCount();
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 4a4a61302..090cde1c0 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1404,10 +1404,6 @@ void LOOLWSD::handleOption(const std::string& optionName,
     else if (optionName == "careerspan")
         careerSpanMs = std::stoi(value) * 1000; // Convert second to ms
 
-    static const char* clientPort = std::getenv("LOOL_TEST_CLIENT_PORT");
-    if (clientPort)
-        ClientPortNumber = std::stoi(clientPort);
-
     static const char* latencyMs = std::getenv("LOOL_DELAY_SOCKET_MS");
     if (latencyMs)
         SimulatedLatencyMs = std::stoi(latencyMs);
@@ -3670,6 +3666,11 @@ std::vector<std::shared_ptr<DocumentBroker>> LOOLWSD::getBrokersTestOnly()
     return result;
 }
 
+int LOOLWSD::getClientPortNumber()
+{
+    return ClientPortNumber;
+}
+
 std::vector<int> LOOLWSD::getKitPids()
 {
     std::vector<int> pids;
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 71ddb2155..35c283288 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -80,6 +80,8 @@ public:
     static std::set<const Poco::Util::AbstractConfiguration*> PluginConfigurations;
     static std::chrono::time_point<std::chrono::system_clock> StartTime;
 
+    /// For testing only [!]
+    static int getClientPortNumber();
     /// For testing only [!]
     static std::vector<int> getKitPids();
     /// For testing only [!] DocumentBrokers are mostly single-threaded with their own thread
commit 04f3460fd22f12b82fd606944f6d4c8433b36c42
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Jan 17 20:49:38 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    test: switch to parallel tests based on Unit framework.
    
    Increase a few timeouts, bin old-style standalone unit tests,
    fix a number of bugs.
    
    Change-Id: Ia3d59466ecb9a9443807ba3445d04dd5f77e3dba

diff --git a/common/Unit.cpp b/common/Unit.cpp
index 5dc01d4ea..875c97686 100644
--- a/common/Unit.cpp
+++ b/common/Unit.cpp
@@ -26,7 +26,7 @@
 #include <common/SigUtil.hpp>
 
 UnitBase *UnitBase::Global = nullptr;
-
+char * UnitBase::UnitLibPath;
 static std::thread TimeoutThread;
 static std::atomic<bool> TimeoutThreadRunning(false);
 std::timed_mutex TimeoutThreadMutex;
@@ -41,6 +41,9 @@ UnitBase *UnitBase::linkAndCreateUnit(UnitType type, const std::string &unitLibP
         return nullptr;
     }
 
+    // avoid std:string de-allocation during failure / exit.
+    UnitLibPath = strdup(unitLibPath.c_str());
+
     const char *symbol = nullptr;
     switch (type)
     {
diff --git a/common/Unit.hpp b/common/Unit.hpp
index 63975514b..c403100c2 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -138,11 +138,17 @@ public:
         return *Global;
     }
 
+    static std::string getUnitLibPath() { return std::string(UnitLibPath); }
+
 private:
-    void setHandle(void *dlHandle) { _dlHandle = dlHandle; }
+    void setHandle(void *dlHandle)
+    {
+        _dlHandle = dlHandle;
+    }
     static UnitBase *linkAndCreateUnit(UnitType type, const std::string& unitLibPath);
 
     void *_dlHandle;
+    static char *UnitLibPath;
     bool _setRetValue;
     int _retValue;
     int _timeoutMilliSeconds;
diff --git a/test/Makefile.am b/test/Makefile.am
index f1d4963b1..2b369465a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,9 +13,10 @@ AM_CXXFLAGS = $(CPPUNIT_CFLAGS) -DTDOC=\"$(abs_top_srcdir)/test/data\" \
 	-I${top_srcdir}/common -I${top_srcdir}/net -I${top_srcdir}/wsd -I${top_srcdir}/kit
 
 noinst_LTLIBRARIES = \
+	unit-base.la unit-tiletest.la \
+	unit-integration.la unit-httpws.la unit-crash.la \
 	unit-convert.la unit-typing.la unit-copy-paste.la \
-	unit-timeout.la unit-prefork.la \
-	unit-storage.la unit-client.la \
+	unit-timeout.la unit-prefork.la unit-storage.la \
 	unit-admin.la unit-tilecache.la \
 	unit-fuzz.la unit-oob.la unit-http.la unit-oauth.la \
 	unit-wopi.la unit-wopi-saveas.la \
@@ -82,13 +83,6 @@ test_base_source = \
 	DeltaTests.cpp \
 	$(wsd_sources)
 
-test_all_source = \
-	$(test_base_source) \
-	TileCacheTests.cpp \
-	integration-http-server.cpp \
-	httpwstest.cpp \
-	httpcrashtest.cpp
-
 unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS
 unittest_SOURCES = $(test_base_source) test.cpp
 unittest_LDADD = $(CPPUNIT_LIBS)
@@ -100,6 +94,18 @@ test_LDADD = $(CPPUNIT_LIBS)
 fakesockettest_SOURCES = fakesockettest.cpp ../net/FakeSocket.cpp
 fakesockettest_LDADD = $(CPPUNIT_LIBS)
 
+# old-style unit tests - bootstrapped via UnitClient
+unit_base_la_SOURCES = UnitClient.cpp ${test_base_source}
+unit_base_la_LIBADD = $(CPPUNIT_LIBS)
+unit_tiletest_la_SOURCES = UnitClient.cpp TileCacheTests.cpp
+unit_tiletest_la_LIBADD = $(CPPUNIT_LIBS)
+unit_integration_la_SOURCES = UnitClient.cpp integration-http-server.cpp
+unit_integration_la_LIBADD = $(CPPUNIT_LIBS)
+unit_httpws_la_SOURCES = UnitClient.cpp httpwstest.cpp
+unit_httpws_la_LIBADD = $(CPPUNIT_LIBS)
+unit_crash_la_SOURCES = UnitClient.cpp httpcrashtest.cpp
+unit_crash_la_LIBADD = $(CPPUNIT_LIBS)
+
 # unit test modules:
 unit_oob_la_SOURCES = UnitOOB.cpp
 unit_http_la_SOURCES = UnitHTTP.cpp
@@ -107,8 +113,6 @@ unit_http_la_LIBADD = $(CPPUNIT_LIBS)
 unit_fuzz_la_SOURCES = UnitFuzz.cpp
 unit_admin_la_SOURCES = UnitAdmin.cpp
 unit_admin_la_LIBADD = $(CPPUNIT_LIBS)
-unit_client_la_SOURCES = UnitClient.cpp ${test_all_source}
-unit_client_la_LIBADD = $(CPPUNIT_LIBS)
 unit_typing_la_SOURCES = UnitTyping.cpp
 unit_typing_la_LIBADD = $(CPPUNIT_LIBS)
 unit_copy_paste_la_SOURCES = UnitCopyPaste.cpp
@@ -183,16 +187,20 @@ if HAVE_LO_PATH
 check-local:
 	./fakesockettest
 	@fc-cache "@LO_PATH@"/share/fonts/truetype
-	./run_unit.sh --log-file test.log --trs-file test.trs
+
 # FIXME 2: unit-oob.la fails with symbol undefined:
 # UnitWSD::testHandleRequest(UnitWSD::TestRequest, UnitHTTPServerRequest&, UnitHTTPServerResponse&) ,
-TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-tilecache.la unit-timeout.la \
+TESTS = \
+	unit-base.la unit-tiletest.la \
+	unit-integration.la unit-httpws.la unit-crash.la \
+	\
+	unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-tilecache.la unit-timeout.la \
         unit-oauth.la unit-wopi.la unit-wopi-saveas.la \
         unit-wopi-ownertermination.la unit-wopi-versionrestore.la \
         unit-wopi-documentconflict.la unit_wopi_renamefile.la unit_wopi_watermark.la \
 	unit-http.la \
 	unit-tiff-load.la \
-	unit-large-paste.la \
+	unit.large-paste.la \
 	unit-paste.la \
 	unit-load-torture.la \
 	unit-rendering-options.la \
@@ -209,9 +217,8 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t
 	unit-bad-doc-load.la \
 	unit-hosting.la \
 	unit-wopi-loadencoded.la unit-wopi-temp.la
-# TESTS = unit-client.la
-# TESTS += unit-admin.la
-# TESTS += unit-storage.la
+# TESTS += unit-admin.test
+# TESTS += unit-storage.test
 else
 TESTS = ${top_builddir}/test/test
 endif
diff --git a/test/UnitClient.cpp b/test/UnitClient.cpp
index e3580f90e..03682fdc5 100644
--- a/test/UnitClient.cpp
+++ b/test/UnitClient.cpp
@@ -7,7 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-// Runs client tests in their own thread inside a WSD process.
+// Runs old-style CPPUNIT tests in their own thread inside a WSD process.
+// Depending which cppunit objects this is linked with this runs different
+// tests.
 
 #include <config.h>
 
diff --git a/test/helpers.hpp b/test/helpers.hpp
index f09de8bbb..dd638d191 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -390,8 +390,12 @@ inline
 bool isDocumentLoaded(LOOLWebSocket& ws, const std::string& testname, bool isView = true)
 {
     const std::string prefix = isView ? "status:" : "statusindicatorfinish:";
-    const auto message = getResponseString(ws, prefix, testname);
-    return LOOLProtocol::matchPrefix(prefix, message);
+    // Allow 20 secs to load
+    const auto message = getResponseString(ws, prefix, testname, 30 * 1000);
+    bool success = LOOLProtocol::matchPrefix(prefix, message);
+    if (!success)
+        TST_LOG("ERR: Timed out loading document");
+    return success;
 }
 
 inline
diff --git a/test/test.cpp b/test/test.cpp
index cc00b2fde..4a5b0f6d0 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -183,7 +183,8 @@ bool runClientTests(bool standalone, bool verbose)
             std::cerr << "  (cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" gdb --args " << cmd << ")\n\n";
         }
 #else
-        std::cerr << "(cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" make check)\n\n";
+        std::cerr << "(cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() <<
+            "\" ./run_unit.sh --test-name " << UnitBase::get().getUnitLibPath() << ")\n\n";
 #endif
     }
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 9bf7088c6..876436abe 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -309,9 +309,9 @@ void DocumentBroker::pollThread()
 
         if (!_isLoaded && (limit_load_secs > 0) && (now > loadDeadline))
         {
-            LOG_WRN("Doc [" << _docKey << "] is taking too long to load. Will kill process ["
-                            << _childProcess->getPid() << "]. per_document.limit_load_secs set to "
-                            << limit_load_secs << " secs.");
+            LOG_ERR("Doc [" << _docKey << "] is taking too long to load. Will kill process ["
+                    << _childProcess->getPid() << "]. per_document.limit_load_secs set to "
+                    << limit_load_secs << " secs.");
             broadcastMessage("error: cmd=load kind=docloadtimeout");
 
             // Brutal but effective.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index e39bfa9d0..4a4a61302 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -3283,14 +3283,19 @@ private:
 
         std::shared_ptr<ServerSocket> socket = getServerSocket(
             ClientListenAddr, port, WebServerPoll, factory);
+
+        while (!socket &&
 #ifdef BUILDING_TESTS
-        while (!socket)
+               true
+#else
+               UnitWSD::isUnitTesting()
+#endif
+            )
         {
             ++port;
             LOG_INF("Client port " << (port - 1) << " is busy, trying " << port << ".");
-            socket = getServerSocket(port, WebServerPoll, factory);
+            socket = getServerSocket(ClientListenAddr, port, WebServerPoll, factory);
         }
-#endif
 
         if (!socket)
         {
commit 1c6b4be2ce84e43a4646c52d8376c19af53d945c
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Sat Jan 18 15:56:01 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 13:39:42 2020 +0000

    copyFile: de-poco-ize and handle EINTR and short writes.
    
    Change-Id: I2046881c786a9f31f45c53f282de9ddd9a9cebcf

diff --git a/common/FileUtil.cpp b/common/FileUtil.cpp
index 5066d2938..84f4085a1 100644
--- a/common/FileUtil.cpp
+++ b/common/FileUtil.cpp
@@ -88,6 +88,80 @@ namespace FileUtil
         return name;
     }
 
+    void copyFileTo(const std::string &fromPath, const std::string &toPath)
+    {
+        int from = -1, to = -1;
+        try {
+            from = open(fromPath.c_str(), O_RDONLY);
+            if (from < 0)
+            {
+                LOG_SYS("Failed to open src " << anonymizeUrl(fromPath));
+                throw;
+            }
+
+            struct stat st;
+            if (fstat(from, &st) != 0)
+            {
+                LOG_SYS("Failed to fstat src " << anonymizeUrl(fromPath));
+                throw;
+            }
+
+            to = open(toPath.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode);
+            if (to < 0)
+            {
+                LOG_SYS("Failed to fstat dest " << anonymizeUrl(toPath));
+                throw;
+            }
+
+            LOG_INF("Copying " << st.st_size << " bytes from " << anonymizeUrl(fromPath) << " to " << anonymizeUrl(toPath));
+
+            char buffer[64 * 1024];
+
+            int n;
+            off_t bytesIn = 0;
+            do {
+                while ((n = ::read(from, buffer, sizeof(buffer))) < 0 && errno == EINTR)
+                    LOG_TRC("EINTR reading from " << anonymizeUrl(fromPath));
+                if (n < 0)
+                {
+                    LOG_SYS("Failed to read from " << anonymizeUrl(fromPath) << " at " << bytesIn << " bytes in");
+                    throw;
+                }
+                bytesIn += n;
+                if (n == 0) // EOF
+                    break;
+                assert (off_t(sizeof (buffer)) >= n);
+                // Handle short writes and EINTR
+                for (int j = 0; j < n;)
+                {
+                    int written;
+                    while ((written = ::write(to, buffer + j, n - j)) < 0 && errno == EINTR)
+                        LOG_TRC("EINTR writing to " << anonymizeUrl(toPath));
+                    if (written < 0)
+                    {
+                        LOG_SYS("Failed to write " << n << " bytes to " << anonymizeUrl(toPath) << " at " <<
+                                bytesIn << " bytes into " << anonymizeUrl(fromPath));
+                        throw;
+                    }
+                    j += written;
+                }
+            } while(true);
+            if (bytesIn != st.st_size)
+            {
+                LOG_WRN("Unusual: file " << anonymizeUrl(fromPath) << " changed size "
+                        "during copy from " << st.st_size << " to " << bytesIn);
+            }
+        }
+        catch (...)
+        {
+            LOG_SYS("Failed to copy from " << anonymizeUrl(fromPath) << " to " << anonymizeUrl(toPath));
+            close(from);
+            close(to);
+            unlink(toPath.c_str());
+            throw Poco::Exception("failed to copy");
+        }
+    }
+
     std::string getTempFilePath(const std::string& srcDir, const std::string& srcFilename, const std::string& dstFilenamePrefix)
     {
         const std::string srcPath = srcDir + '/' + srcFilename;
@@ -100,7 +174,7 @@ namespace FileUtil
         fileDeleter.registerForDeletion(dstPath);
 #else
         const std::string dstPath = Poco::Path(Poco::Path::temp(), dstFilename).toString();
-        Poco::File(srcPath).copyTo(dstPath);
+        copyFileTo(srcPath, dstPath);
         Poco::TemporaryFile::registerForDeletion(dstPath);
 #endif
 
diff --git a/common/FileUtil.hpp b/common/FileUtil.hpp
index a57aa5414..864188308 100644
--- a/common/FileUtil.hpp
+++ b/common/FileUtil.hpp
@@ -80,6 +80,9 @@ namespace FileUtil
         removeFile(path.toString(), recursive);
     }
 
+    /// Copy a file from @fromPath to @toPath, throws on failure.
+    void copyFileTo(const std::string &fromPath, const std::string &toPath);
+
     /// Make a temp copy of a file, and prepend it with a prefix.
     std::string getTempFilePath(const std::string& srcDir, const std::string& srcFilename,
                                 const std::string& dstFilenamePrefix);
diff --git a/test/run_unit.sh.in b/test/run_unit.sh.in
index d05e2f48f..5fb8a6936 100755
--- a/test/run_unit.sh.in
+++ b/test/run_unit.sh.in
@@ -56,16 +56,6 @@ echo "	$cmd_line"
 # drop .la suffix
 tst=`echo $tst | sed "s/\.la//"`;
 
-if test "z$tst" != "z" && test "z$CPPUNIT_TEST_NAME" != "z"; then
-    # $tst is not empty, but $CPPUNIT_TEST_NAME is set, exit early if they
-    # don't match.
-    if test "z$tst" != "z$CPPUNIT_TEST_NAME"; then
-        touch $tst_log
-        echo ":test-result: SKIP $tst (disabled by CPPUNIT_TEST_NAME)" > $test_output
-        exit 0;
-    fi
-fi
-
 export LOOL_LOGLEVEL=trace
 
 if test "z$enable_debug" != "ztrue"; then
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 0be7c7c7b..8c8a8ddd8 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -331,8 +331,7 @@ std::string LocalStorage::loadStorageFileToLocal(const Authorization& /*auth*/,
         // Fallback to copying.
         if (!Poco::File(getRootFilePath()).exists())
         {
-            LOG_INF("Copying " << LOOLWSD::anonymizeUrl(publicFilePath) << " to " << getRootFilePathAnonym());
-            Poco::File(publicFilePath).copyTo(getRootFilePath());
+            FileUtil::copyFileTo(publicFilePath, getRootFilePath());
             _isCopy = true;
         }
     }
@@ -371,10 +370,7 @@ StorageBase::SaveResult LocalStorage::saveLocalFileToStorage(const Authorization
         LOG_TRC("Saving local file to local file storage (isCopy: " << _isCopy << ") for " << getRootFilePathAnonym());
         // Copy the file back.
         if (_isCopy && Poco::File(getRootFilePath()).exists())
-        {
-            LOG_INF("Copying " << getRootFilePathAnonym() << " to " << LOOLWSD::anonymizeUrl(getUri().getPath()));
-            Poco::File(getRootFilePath()).copyTo(getUri().getPath());
-        }
+            FileUtil::copyFileTo(getRootFilePath(), getUri().getPath());
 
         // update its fileinfo object. This is used later to check if someone else changed the
         // document while we are/were editing it
diff --git a/wsd/TraceFile.hpp b/wsd/TraceFile.hpp
index 82f5a75ce..e95fbb2e2 100644
--- a/wsd/TraceFile.hpp
+++ b/wsd/TraceFile.hpp
@@ -25,6 +25,7 @@
 #include "Protocol.hpp"
 #include "Log.hpp"
 #include "Util.hpp"
+#include "FileUtil.hpp"
 
 /// Dumps commands and notification trace.
 class TraceFileRecord
@@ -141,8 +142,7 @@ public:
                 filename += '.' + origPath.getExtension();
                 snapshot = Poco::Path(_path, filename).toString();
 
-                LOG_TRC("TraceFile: Copying local file [" << localPath << "] to snapshot [" << snapshot << "].");
-                Poco::File(localPath).copyTo(snapshot);
+                FileUtil::copyFileTo(localPath, snapshot);
                 snapshot = Poco::URI(Poco::URI("file://"), snapshot).toString();
 
                 LOG_TRC("TraceFile: Mapped URL " << url << " to " << snapshot);
commit aadf5af77b74822ebdc52e512b0b856957dc0896
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Jan 21 11:55:32 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Jan 21 14:39:21 2020 +0100

    reduce verbosity of FileServer trace logging.
    
    Change-Id: I5a57e91742be504bcb2e51b45f6890420e52bb91
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/87134
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 95bd54f90..55942611e 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -474,12 +474,14 @@ void FileServerRequestHandler::readDirToHash(const std::string &basePath, const
     struct stat fileStat;
     DIR *workingdir;
 
-    LOG_TRC("Pre-reading directory: " << basePath << path);
     workingdir = opendir((basePath + path).c_str());
 
     if (!workingdir)
         return;
 
+    size_t fileCount = 0;
+    std::string filesRead;
+
     while ((currentFile = readdir(workingdir)) != nullptr)
     {
         if (currentFile->d_name[0] == '.')
@@ -493,7 +495,9 @@ void FileServerRequestHandler::readDirToHash(const std::string &basePath, const
 
         else if (S_ISREG(fileStat.st_mode))
         {
-            LOG_TRC("Reading file: '" << basePath << relPath << " as '" << relPath << "'");
+            fileCount++;
+            filesRead.append(currentFile->d_name);
+            filesRead.append(" ");
 
             std::ifstream file(basePath + relPath, std::ios::binary);
 
@@ -539,6 +543,9 @@ void FileServerRequestHandler::readDirToHash(const std::string &basePath, const
         }
     }
     closedir(workingdir);
+
+    if (fileCount > 0)
+        LOG_TRC("Pre-read " << fileCount << " file(s) from directory: " << basePath << path << ": " << filesRead);
 }
 
 void FileServerRequestHandler::initialize()


More information about the Libreoffice-commits mailing list