[Libreoffice-commits] online.git: test/Makefile.am test/UnitWopiOwnertermination.cpp test/WopiTestServer.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

Pranav Kant pranavk at collabora.co.uk
Wed Feb 7 13:30:52 UTC 2018


 test/Makefile.am                  |    6 +-
 test/UnitWopiOwnertermination.cpp |   89 ++++++++++++++++++++++++++++++++++++++
 test/WopiTestServer.hpp           |    1 
 wsd/DocumentBroker.cpp            |   14 +++--
 wsd/DocumentBroker.hpp            |    1 
 5 files changed, 104 insertions(+), 7 deletions(-)

New commits:
commit 5476774af1510751127cdb0c605149f05d43394b
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Feb 2 09:58:20 2018 +0530

    wsd: Use a close request flag to break out of doc broker poll thread
    
    ... instead of directly stop()ing it. The close request approach also
    makes sure that outgoing document is saved to storage.
    
    Change-Id: I44f61db00dbd326dec80f59f4a2cbb617048aa94
    Reviewed-on: https://gerrit.libreoffice.org/49122
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/test/Makefile.am b/test/Makefile.am
index 98426f72..d7894bd9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -17,7 +17,7 @@ noinst_LTLIBRARIES = \
 	unit-storage.la unit-client.la \
 	unit-admin.la unit-tilecache.la \
 	unit-fuzz.la unit-oob.la unit-oauth.la \
-	unit-wopi.la unit-wopi-saveas.la
+	unit-wopi.la unit-wopi-saveas.la unit-wopi-ownertermination.la
 
 MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
 AM_LDFLAGS = -pthread -module $(MAGIC_TO_FORCE_SHLIB_CREATION) $(ZLIB_LIBS)
@@ -83,6 +83,8 @@ unit_wopi_la_SOURCES = UnitWOPI.cpp
 unit_wopi_la_LIBADD = $(CPPUNIT_LIBS)
 unit_wopi_saveas_la_SOURCES = UnitWOPISaveAs.cpp
 unit_wopi_saveas_la_LIBADD = $(CPPUNIT_LIBS)
+unit_wopi_ownertermination_la_SOURCES = UnitWopiOwnertermination.cpp
+unit_wopi_ownertermination_la_LIBADD = $(CPPUNIT_LIBS)
 
 if HAVE_LO_PATH
 SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -96,7 +98,7 @@ check-local:
 	./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-prefork.la unit-tilecache.la unit-timeout.la unit-oauth.la unit-wopi.la unit-wopi-saveas.la
+TESTS = unit-prefork.la unit-tilecache.la unit-timeout.la unit-oauth.la unit-wopi.la unit-wopi-saveas.la unit-wopi-ownertermination.la
 # TESTS = unit-client.la
 # TESTS += unit-admin.la
 # TESTS += unit-storage.la
diff --git a/test/UnitWopiOwnertermination.cpp b/test/UnitWopiOwnertermination.cpp
new file mode 100644
index 00000000..8ddb02a4
--- /dev/null
+++ b/test/UnitWopiOwnertermination.cpp
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "config.h"
+
+#include "WopiTestServer.hpp"
+#include "Log.hpp"
+#include "Unit.hpp"
+#include "UnitHTTP.hpp"
+#include "helpers.hpp"
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Util/LayeredConfiguration.h>
+
+class UnitWopiOwnertermination : public WopiTestServer
+{
+    enum class Phase
+    {
+        Load,
+        Modify,
+        OwnerTermination,
+        Polling
+    } _phase;
+
+public:
+    UnitWopiOwnertermination() :
+        _phase(Phase::Load)
+    {
+    }
+
+    void assertPutFileRequest(const Poco::Net::HTTPRequest& /*request*/) override
+    {
+        if (_phase == Phase::Polling)
+        {
+            // Document got saved, that's what we wanted
+            exitTest(TestResult::Ok);
+        }
+    }
+
+    void invokeTest() override
+    {
+        constexpr char testName[] = "UnitWopiOwnertermination";
+
+        switch (_phase)
+        {
+            case Phase::Load:
+            {
+                initWebsocket("/wopi/files/0?access_token=anything");
+
+                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "load url=" + _wopiSrc, testName);
+
+                _phase = Phase::Modify;
+                break;
+            }
+            case Phase::Modify:
+            {
+                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "key type=input char=97 key=0", testName);
+                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "key type=up char=0 key=512", testName);
+
+                _phase = Phase::OwnerTermination;
+                SocketPoll::wakeupWorld();
+                break;
+            }
+	        case Phase::OwnerTermination:
+            {
+                _phase = Phase::Polling;
+                helpers::sendTextFrame(*_ws->getLOOLWebSocket(), "closedocument", testName);
+                break;
+            }
+            case Phase::Polling:
+            {
+                // just wait for the results
+                break;
+            }
+        }
+    }
+};
+
+UnitBase *unit_create_wsd(void)
+{
+    return new UnitWopiOwnertermination();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp
index b20aa032..f5cc4c82 100644
--- a/test/WopiTestServer.hpp
+++ b/test/WopiTestServer.hpp
@@ -94,6 +94,7 @@ protected:
             fileInfo->set("UserCanWrite", "true");
             fileInfo->set("PostMessageOrigin", "localhost");
             fileInfo->set("LastModifiedTime", Poco::DateTimeFormatter::format(now, Poco::DateTimeFormat::ISO8601_FORMAT));
+            fileInfo->set("EnableOwnerTermination", "true");
 
             std::ostringstream jsonStream;
             fileInfo->stringify(jsonStream);
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index bf21b7ae..81470f6d 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -155,6 +155,7 @@ DocumentBroker::DocumentBroker(const std::string& uri,
     _lastSaveTime(std::chrono::steady_clock::now()),
     _lastSaveRequestTime(std::chrono::steady_clock::now() - std::chrono::milliseconds(COMMAND_TIMEOUT_MS)),
     _markToDestroy(false),
+    _closeRequest(false),
     _isLoaded(false),
     _isModified(false),
     _cursorPosX(0),
@@ -276,13 +277,14 @@ void DocumentBroker::pollThread()
             continue;
         }
 
-        if (ShutdownRequestFlag)
+        if (ShutdownRequestFlag || _closeRequest)
         {
-            LOG_INF("Autosaving DocumentBroker for docKey [" << getDocKey() << "] to recycle server.");
+            const std::string reason = ShutdownRequestFlag ? "recycling" : _closeReason;
+            LOG_INF("Autosaving DocumentBroker for docKey [" << getDocKey() << "] for " << reason);
             if (!autoSave(isPossiblyModified()))
             {
-                LOG_INF("Terminating DocumentBroker for docKey [" << getDocKey() << "] to recycle server.");
-                stop("recycling");
+                LOG_INF("Terminating DocumentBroker for docKey [" << getDocKey() << "].");
+                stop(reason);
             }
         }
         else if (AutoSaveEnabled && !_stop &&
@@ -865,6 +867,7 @@ bool DocumentBroker::autoSave(const bool force)
 {
     assertCorrectThread();
 
+    LOG_TRC("autoSave(): forceful? " << force);
     if (_sessions.empty() || _storage == nullptr || !_isLoaded ||
         !_childProcess->isAlive() || (!_isModified && !force))
     {
@@ -1597,7 +1600,8 @@ void DocumentBroker::closeDocument(const std::string& reason)
     assertCorrectThread();
 
     LOG_DBG("Closing DocumentBroker for docKey [" << _docKey << "] with reason: " << reason);
-    stop(reason);
+    _closeReason = reason;
+    _closeRequest = true;
 }
 
 void DocumentBroker::broadcastMessage(const std::string& message)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index a398e701..a5345f67 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -431,6 +431,7 @@ private:
     std::unique_ptr<StorageBase> _storage;
     std::unique_ptr<TileCache> _tileCache;
     std::atomic<bool> _markToDestroy;
+    std::atomic<bool> _closeRequest;
     std::atomic<bool> _isLoaded;
     std::atomic<bool> _isModified;
     int _cursorPosX;


More information about the Libreoffice-commits mailing list