[Libreoffice-commits] online.git: 5 commits - loolwsd/DocumentBroker.cpp loolwsd/Exceptions.hpp loolwsd/IoUtil.cpp loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/LOOLWSD.cpp loolwsd/Makefile.am loolwsd/test loolwsd/Unit.cpp loolwsd/Unit.hpp loolwsd/UnitHTTP.cpp loolwsd/UnitHTTP.hpp
Michael Meeks
michael.meeks at collabora.com
Sat Oct 22 16:43:43 UTC 2016
loolwsd/DocumentBroker.cpp | 9 +++++
loolwsd/Exceptions.hpp | 1
loolwsd/IoUtil.cpp | 1
loolwsd/LOOLSession.cpp | 16 ++++++++++
loolwsd/LOOLSession.hpp | 9 -----
loolwsd/LOOLWSD.cpp | 63 +++++++++++++++++++++++++++++++++++++++--
loolwsd/Makefile.am | 1
loolwsd/Unit.cpp | 17 +++++++++++
loolwsd/Unit.hpp | 13 +++++++-
loolwsd/UnitHTTP.cpp | 35 ++++++++++++++++++++++
loolwsd/UnitHTTP.hpp | 21 +++++++++++++
loolwsd/test/Makefile.am | 2 -
loolwsd/test/UnitAdmin.cpp | 25 ++++++++--------
loolwsd/test/UnitStorage.cpp | 63 +++++++++++++++++++++++++++++++++--------
loolwsd/test/UnitTileCache.cpp | 37 +++++++++++++++++++-----
loolwsd/test/run_unit.sh.in | 10 ++----
16 files changed, 271 insertions(+), 52 deletions(-)
New commits:
commit fe3e726211295a73aac19c8967c2cc39e524906a
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Sat Oct 22 17:09:39 2016 +0100
Work around race in admin unit test.
diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index b7a9686..9f704c1 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -201,6 +201,9 @@ private:
const std::string subscribeMessage = "subscribe adddoc";
_adminWs->sendFrame(subscribeMessage.data(), subscribeMessage.size());
+ // FIXME: we really should wait for the subscription to be
+ // registered and have a reply to avoid a race here.
+ Poco::Thread::sleep(250);
std::string documentPath1, documentURL1;
helpers::getDocumentPathAndURL("hello.odt", documentPath1, documentURL1);
@@ -439,6 +442,7 @@ public:
{
Log::info("Exiting with " + (res == TestResult::TEST_FAILED ? "FAIL" : (res == TestResult::TEST_TIMED_OUT) ? "TIMEOUT" : "??? (" + std::to_string(res) + ")"));
exitTest(res);
+ assert(false);
return;
}
commit b6291f9cb54364e25965a0ea4f44012cac3870fa
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Sat Oct 22 16:35:30 2016 +0100
Unit tests new-style now search for a free port pair.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9dcff38..e0723e6 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1293,6 +1293,53 @@ ServerSocket* getServerSocket(int nClientPortNumber)
}
static inline
+ServerSocket* findFreeServerPort(int &nClientPortNumber)
+{
+ ServerSocket *socket = NULL;
+ while (!socket)
+ {
+ socket = getServerSocket(nClientPortNumber);
+ if (!socket)
+ {
+ nClientPortNumber++;
+ Log::info("client port busy - trying " + nClientPortNumber);
+ }
+ }
+ return socket;
+}
+
+static inline
+ServerSocket* getMasterSocket(int nMasterPortNumber)
+{
+ try
+ {
+ SocketAddress addr2("127.0.0.1", nMasterPortNumber);
+ return new ServerSocket(addr2);
+ }
+ catch (const Exception& exc)
+ {
+ Log::fatal() << "Could not create master socket: " << exc.displayText() << Log::end;
+ return nullptr;
+ }
+}
+
+static inline
+ServerSocket* findFreeMasterPort(int &nMasterPortNumber)
+{
+ ServerSocket *socket = NULL;
+ while (!socket)
+ {
+ socket = getServerSocket(nMasterPortNumber);
+ if (!socket)
+ {
+ nMasterPortNumber++;
+ Log::info("master port busy - trying " + nMasterPortNumber);
+ }
+ }
+ return socket;
+}
+
+static inline
std::string getLaunchURI()
{
std::string aAbsTopSrcDir = Poco::Path(Application::instance().commandPath()).parent().toString();
@@ -1825,7 +1872,10 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
// Start a server listening on the port for clients
- std::unique_ptr<ServerSocket> psvs(getServerSocket(ClientPortNumber));
+ std::unique_ptr<ServerSocket> psvs(
+ UnitWSD::isUnitTesting() ?
+ findFreeServerPort(ClientPortNumber) :
+ getServerSocket(ClientPortNumber));
if (!psvs)
return Application::EXIT_SOFTWARE;
@@ -1836,8 +1886,13 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
// And one on the port for child processes
SocketAddress addr2("127.0.0.1", MasterPortNumber);
- ServerSocket svs2(addr2);
- HTTPServer srv2(new PrisonerRequestHandlerFactory(), threadPool, svs2, params2);
+ std::unique_ptr<ServerSocket> psvs2(
+ UnitWSD::isUnitTesting() ?
+ findFreeMasterPort(MasterPortNumber) :
+ getMasterSocket(MasterPortNumber));
+ if (!psvs2)
+ return Application::EXIT_SOFTWARE;
+ HTTPServer srv2(new PrisonerRequestHandlerFactory(), threadPool, *psvs2, params2);
Log::info("Starting prisoner server listening on " + std::to_string(MasterPortNumber));
srv2.start();
diff --git a/loolwsd/Unit.cpp b/loolwsd/Unit.cpp
index 5a32129..43c9e9a 100644
--- a/loolwsd/Unit.cpp
+++ b/loolwsd/Unit.cpp
@@ -100,6 +100,11 @@ bool UnitBase::init(UnitType type, const std::string &unitLibPath)
return Global != NULL;
}
+bool UnitBase::isUnitTesting()
+{
+ return Global && Global->_dlHandle;
+}
+
void UnitBase::setTimeout(int timeoutMilliSeconds)
{
assert(!TimeoutThread.isRunning());
@@ -135,13 +140,14 @@ UnitWSD::~UnitWSD()
void UnitWSD::configure(Poco::Util::LayeredConfiguration &config)
{
- if (_dlHandle) // really running a unit shlib.
+ if (isUnitTesting())
{
// Force HTTP - helps stracing.
config.setBool("ssl.enable", false);
// Force console output - easier to debug.
config.setBool("logging.file[@enable]", false);
}
+ // else - a product run.
}
void UnitWSD::lookupTile(int part, int width, int height, int tilePosX, int tilePosY,
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index 98f62dc..fb6a850 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -71,6 +71,9 @@ public:
/// Load unit test hook shared library from this path
static bool init(UnitType type, const std::string &unitLibPath);
+ /// Do we have a unit test library hooking things & loaded
+ static bool isUnitTesting();
+
/// Tweak the return value from the process.
virtual void returnValue(int & /* retValue */);
diff --git a/loolwsd/test/run_unit.sh.in b/loolwsd/test/run_unit.sh.in
index e00aad0..652340f 100755
--- a/loolwsd/test/run_unit.sh.in
+++ b/loolwsd/test/run_unit.sh.in
@@ -12,12 +12,6 @@ jails_path="@JAILS_PATH@"
lo_path="@LO_PATH@"
valgrind_cmd="valgrind --tool=memcheck --trace-children=no -v --read-var-info=yes"
-# run the test on a dedicated port
-# 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
-export LOOL_TEST_MASTER_PORT=9985
-
# Note that these options are used by commands in the Makefile that
# Automake generates. Don't be mislead by 'git grep' not showing any
# use of --test-name for instance.
@@ -62,6 +56,10 @@ 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"
${valgrind} \
${abs_top_builddir}/loolwsd --o:sys_template_path="$systemplate_path" \
commit f8746373a7c4b4cf29c450bc405ff21f4c1725eb
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Sat Oct 22 16:34:47 2016 +0100
Handle exceptions during websocket shutdown.
diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index ca6002b..a6019b8 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -211,7 +211,6 @@ void shutdownWebSocket(const std::shared_ptr<Poco::Net::WebSocket>& ws)
{
Log::warn("Util::shutdownWebSocket: Exception: " + exc.displayText() + (exc.nested() ? " (" + exc.nested()->displayText() + ")" : ""));
}
-
}
ssize_t writeToPipe(int pipe, const char* buffer, ssize_t size)
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 810a3fe..ca94d00 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -209,6 +209,22 @@ bool LOOLSession::handleDisconnect()
return false;
}
+void LOOLSession::shutdown(Poco::UInt16 statusCode)
+{
+ if (_ws)
+ {
+ try {
+ Log::trace("Shutting down WS [" + getName() + "].");
+ _ws->shutdown(statusCode);
+ }
+ catch (const Poco::Exception &exc)
+ {
+ Log::warn("LOOLSession::shutdown WebSocket: Exception: " +
+ exc.displayText() + (exc.nested() ? " (" + exc.nested()->displayText() + ")" : ""));
+ }
+ }
+}
+
bool LOOLSession::handleInput(const char *buffer, int length)
{
assert(buffer != nullptr);
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index ff82de9..6015b9f 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -59,14 +59,7 @@ public:
/// Called to handle disconnection command from socket.
virtual bool handleDisconnect();
- void shutdown(Poco::UInt16 statusCode)
- {
- if (_ws)
- {
- Log::trace("Shutting down WS [" + getName() + "].");
- _ws->shutdown(statusCode);
- }
- }
+ void shutdown(Poco::UInt16 statusCode);
bool isActive() const { return _isActive; }
void setIsActive(bool active) { _isActive = active; }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 12e6438..9dcff38 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -221,6 +221,7 @@ void shutdownLimitReached(WebSocket& ws)
}
catch (const Exception&)
{
+ // FIXME: handle exceptions thrown from here ? ...
ws.sendFrame(error.data(), error.size());
ws.shutdown(WebSocket::WS_POLICY_VIOLATION);
}
@@ -934,6 +935,7 @@ private:
// something wrong, with internal exceptions
Log::trace("Abnormal close handshake.");
session->closeFrame();
+ // FIXME: handle exception thrown from here ? ...
ws->shutdown(WebSocket::WS_ENDPOINT_GOING_AWAY);
session->shutdownPeer(WebSocket::WS_ENDPOINT_GOING_AWAY);
}
commit 0b93441eff33ac4c552ddb2bab04be89249d6687
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Oct 20 22:09:00 2016 +0100
Improving the built-in unit tests.
Connect sockets to the local process using the details we can introspect.
Implement unit test for storage / load failure.
Cleanup tile-cache test a little.
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 9ae52af..f45e28a 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -164,6 +164,12 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
bool DocumentBroker::load(const std::string& sessionId, const std::string& jailId)
{
+ {
+ bool result;
+ if (UnitWSD::get().filterLoad(sessionId, jailId, result))
+ return result;
+ }
+
if (_markToDestroy)
{
// Tearing down.
@@ -439,7 +445,8 @@ size_t DocumentBroker::addSession(std::shared_ptr<ClientSession>& session)
_lastEditableSession = false;
_markToDestroy = false;
- bool loaded = load(id, std::to_string(_childProcess->getPid()));
+ bool loaded;
+ loaded = load(id, std::to_string(_childProcess->getPid()));
if (!loaded)
{
Log::error("Error loading document with URI [" + session->getPublicUri().toString() + "].");
diff --git a/loolwsd/Exceptions.hpp b/loolwsd/Exceptions.hpp
index de5fcaa..fee8d8b 100644
--- a/loolwsd/Exceptions.hpp
+++ b/loolwsd/Exceptions.hpp
@@ -12,6 +12,7 @@
#ifndef INCLUDED_EXCEPTIONS_HPP
#define INCLUDED_EXCEPTIONS_HPP
+#include <stdexcept>
#include <exception>
// Generic LOOL errors and base for others.
diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am
index 2bd5701..1f47750 100644
--- a/loolwsd/Makefile.am
+++ b/loolwsd/Makefile.am
@@ -37,6 +37,7 @@ shared_sources = ChildSession.cpp \
LOOLSession.cpp \
MessageQueue.cpp \
Unit.cpp \
+ UnitHTTP.cpp \
Util.cpp
loolwsd_SOURCES = Admin.cpp \
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index 4ca8eea..98f62dc 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -143,6 +143,14 @@ public:
virtual void lookupTile(int part, int width, int height, int tilePosX, int tilePosY,
int tileWidth, int tileHeight, std::unique_ptr<std::fstream>& cacheFile);
+ // ---------------- DocumentBroker hooks ----------------
+ virtual bool filterLoad(const std::string &/* sessionId */,
+ const std::string &/* jailId */,
+ bool &/* result */)
+ {
+ return false;
+ }
+
// ---------------- WSD events ----------------
virtual void onChildConnected(const int /* pid */, const std::string& /* sessionId */) {}
/// When admin notify message is sent
diff --git a/loolwsd/UnitHTTP.cpp b/loolwsd/UnitHTTP.cpp
new file mode 100644
index 0000000..d42aea0
--- /dev/null
+++ b/loolwsd/UnitHTTP.cpp
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <iostream>
+#include "UnitHTTP.hpp"
+
+Poco::Net::HTTPClientSession *UnitHTTP::createSession()
+{
+ // HTTP forced in configure hook.
+ return new Poco::Net::HTTPClientSession ("127.0.0.1",
+ ClientPortNumber);
+}
+
+UnitWebSocket::UnitWebSocket(const std::string &docURL)
+{
+ try {
+ UnitHTTPServerResponse response;
+ UnitHTTPServerRequest request(response, docURL);
+
+ _session = UnitHTTP::createSession();
+
+ // FIXME: leaking the session - hey ho ... do we need a UnitSocket ?
+ _socket = new Poco::Net::WebSocket(*_session, request, response);
+ } catch (const Poco::Exception &ex) {
+ std::cerr << "Exception creating websocket " << ex.displayText() << std::endl;
+ throw;
+ }
+}
+
diff --git a/loolwsd/UnitHTTP.hpp b/loolwsd/UnitHTTP.hpp
index 8d89d40..4b325c7 100644
--- a/loolwsd/UnitHTTP.hpp
+++ b/loolwsd/UnitHTTP.hpp
@@ -9,11 +9,14 @@
#ifndef INCLUDED_UNITHTTP_HPP
#define INCLUDED_UNITHTTP_HPP
+#include <memory>
#include <sstream>
#include <Poco/Version.h>
+#include <Poco/Net/WebSocket.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPServerParams.h>
+#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/Net/SocketAddress.h>
@@ -86,6 +89,24 @@ public:
{ return _response; }
};
+namespace UnitHTTP {
+ Poco::Net::HTTPClientSession *createSession();
+}
+
+class UnitWebSocket
+{
+ Poco::Net::HTTPClientSession *_session;
+ Poco::Net::WebSocket *_socket;
+ public:
+ /// Get a websocket connected for a given URL
+ UnitWebSocket(const std::string &docURL);
+ ~UnitWebSocket()
+ {
+ delete _socket;
+ delete _session;
+ }
+};
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index b11b0e2..12f30aa 100644
--- a/loolwsd/test/Makefile.am
+++ b/loolwsd/test/Makefile.am
@@ -66,7 +66,7 @@ if HAVE_LO_PATH
check-local:
./run_unit.sh --log-file test.log --trs-file test.trs
# FIXME unit-fonts.la is unstable, disabled for now.
-TESTS = unit-timeout.la unit-prefork.la unit-tilecache.la unit-admin.la unit-storage.la
+TESTS = unit-tilecache.la unit-storage.la unit-timeout.la unit-prefork.la unit-admin.la
else
TESTS = ${top_builddir}/test/test
endif
diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index 540318f..b7a9686 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -13,14 +13,10 @@
#include <mutex>
#include <Poco/Net/HTTPBasicCredentials.h>
-#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPCookie.h>
#include <Poco/Net/HTTPResponse.h>
-#include <Poco/Net/HTTPSClientSession.h>
-#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/NameValueCollection.h>
#include <Poco/Net/NetException.h>
-#include <Poco/Net/WebSocket.h>
#include <Poco/StringTokenizer.h>
#include <Poco/StringTokenizer.h>
#include <Poco/URI.h>
@@ -28,6 +24,7 @@
#include "Common.hpp"
#include "Log.hpp"
#include "Unit.hpp"
+#include "UnitHTTP.hpp"
#include "Util.hpp"
#include "helpers.hpp"
@@ -74,7 +71,7 @@ private:
HTTPResponse response;
std::string path(_uri.getPathAndQuery());
HTTPRequest request(HTTPRequest::HTTP_GET, path);
- std::unique_ptr<HTTPClientSession> session(helpers::createSession(_uri));
+ std::unique_ptr<HTTPClientSession> session(UnitHTTP::createSession());
session->sendRequest(request);
session->receiveResponse(response);
@@ -91,7 +88,7 @@ private:
HTTPResponse response;
std::string path(_uri.getPathAndQuery());
HTTPRequest request(HTTPRequest::HTTP_GET, path);
- std::unique_ptr<HTTPClientSession> session(helpers::createSession(_uri));
+ std::unique_ptr<HTTPClientSession> session(UnitHTTP::createSession());
HTTPBasicCredentials credentials("admin", "admin");
credentials.authenticate(request);
@@ -132,7 +129,7 @@ private:
// try connecting without authentication; should result in NotAuthenticated
HTTPResponse response;
HTTPRequest request(HTTPRequest::HTTP_GET, "/lool/adminws/");
- std::unique_ptr<HTTPClientSession> session(helpers::createSession(_uri));
+ std::unique_ptr<HTTPClientSession> session(UnitHTTP::createSession());
_adminWs = std::make_shared<Poco::Net::WebSocket>(*session, request, response);
const std::string testMessage = "documents";
@@ -163,7 +160,7 @@ private:
// try connecting with incorrect auth token; should result in InvalidToken
HTTPResponse response;
HTTPRequest request(HTTPRequest::HTTP_GET, "/lool/adminws/");
- std::unique_ptr<HTTPClientSession> session(helpers::createSession(_uri));
+ std::unique_ptr<HTTPClientSession> session(UnitHTTP::createSession());
_adminWs = std::make_shared<Poco::Net::WebSocket>(*session, request, response);
const std::string testMessage = "auth jwt=incorrectJWT";
@@ -194,7 +191,7 @@ private:
// Authenticate first
HTTPResponse response;
HTTPRequest request(HTTPRequest::HTTP_GET, "/lool/adminws/");
- std::unique_ptr<HTTPClientSession> session(helpers::createSession(_uri));
+ std::unique_ptr<HTTPClientSession> session(UnitHTTP::createSession());
_adminWs = std::make_shared<Poco::Net::WebSocket>(*session, request, response);
const std::string authMessage = "auth jwt=" + _jwtCookie;
@@ -211,8 +208,8 @@ private:
HTTPResponse response1;
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));
+ std::unique_ptr<HTTPClientSession> session1(UnitHTTP::createSession());
+ std::unique_ptr<HTTPClientSession> session2(UnitHTTP::createSession());
std::unique_lock<std::mutex> lock(_messageReceivedMutex);
_messageReceived.clear();
@@ -275,7 +272,7 @@ private:
HTTPResponse response2;
const Poco::URI docUri2(helpers::getTestServerURI());
const std::string loadMessage2 = "load url=" + documentURL2;
- std::unique_ptr<HTTPClientSession> session3(helpers::createSession(docUri1));
+ std::unique_ptr<HTTPClientSession> session3(UnitHTTP::createSession());
lock.lock(); // lock _messageReceivedMutex
_messageReceived.clear();
diff --git a/loolwsd/test/UnitStorage.cpp b/loolwsd/test/UnitStorage.cpp
index 94b913d..164e1e1 100644
--- a/loolwsd/test/UnitStorage.cpp
+++ b/loolwsd/test/UnitStorage.cpp
@@ -7,28 +7,67 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <iostream>
+
+#include "Exceptions.hpp"
#include "Unit.hpp"
#include "UnitHTTP.hpp"
+#include "helpers.hpp"
+
+using namespace helpers;
class UnitStorage : public UnitWSD
{
+ enum {
+ PHASE_LOAD, // load the document
+ PHASE_FILTER, // throw filter exception
+ PHASE_RE_LOAD, // re-load the document
+ } _phase;
+ std::unique_ptr<UnitWebSocket> _ws;
public:
- virtual bool createStorage(const Poco::URI& /* uri */,
- const std::string& /* jailRoot */,
- const std::string& /* jailPath */,
- std::unique_ptr<StorageBase> & /* rStorage */)
+ UnitStorage() :
+ _phase(PHASE_LOAD)
+ {
+ }
+
+ virtual bool filterLoad(const std::string &/* sessionId */,
+ const std::string &/* jailId */,
+ bool &/* result */)
{
- // leave rStorage empty - fail to return anything
- return true;
+ if (_phase == PHASE_FILTER)
+ {
+ std::cerr << "throw low disk space exception" << std::endl;
+ _phase = PHASE_RE_LOAD;
+ throw StorageSpaceLowException("test: low disk space");
+ }
+ return false;
}
+
+ void loadDocument()
+ {
+ std::string docPath;
+ std::string docURL;
+ getDocumentPathAndURL("empty.odt", docPath, docURL);
+ _ws = std::unique_ptr<UnitWebSocket>(new UnitWebSocket(docURL));
+ assert(_ws.get());
+ }
+
virtual void invokeTest()
{
- // FIXME: push through to the right place to exercise this.
- exitTest(TestResult::TEST_OK);
- UnitHTTPServerResponse response;
- UnitHTTPServerRequest request(response, std::string(CHILD_URI));
- UnitWSD::testHandleRequest(TestRequest::TEST_REQ_PRISONER,
- request, response);
+ switch (_phase)
+ {
+ case PHASE_LOAD:
+ _phase = PHASE_FILTER;
+ loadDocument();
+ break;
+ case PHASE_FILTER:
+ break;
+ case PHASE_RE_LOAD:
+ loadDocument();
+ _ws.reset();
+ exitTest(TEST_OK);
+ break;
+ }
}
};
diff --git a/loolwsd/test/UnitTileCache.cpp b/loolwsd/test/UnitTileCache.cpp
index b827eb5..d6d52b2 100644
--- a/loolwsd/test/UnitTileCache.cpp
+++ b/loolwsd/test/UnitTileCache.cpp
@@ -16,10 +16,18 @@
#include "Util.hpp"
#include "helpers.hpp"
+using namespace helpers;
+
class UnitTileCache: public UnitWSD
{
+ enum {
+ PHASE_LOAD, // load the document
+ PHASE_TILE, // lookup tile method
+ } _phase;
+ std::unique_ptr<UnitWebSocket> _ws;
public:
- UnitTileCache()
+ UnitTileCache() :
+ _phase(PHASE_LOAD)
{
}
@@ -31,16 +39,31 @@ public:
// Fail the lookup to force subscription and rendering.
cacheFile.reset();
+
+ // FIXME: push through to the right place to exercise this.
+ exitTest(TestResult::TEST_OK);
}
virtual void invokeTest()
{
- // FIXME: push through to the right place to exercise this.
- exitTest(TestResult::TEST_OK);
- UnitHTTPServerResponse response;
- UnitHTTPServerRequest request(response, std::string(CHILD_URI));
- UnitWSD::testHandleRequest(TestRequest::TEST_REQ_PRISONER,
- request, response);
+ switch (_phase)
+ {
+ case PHASE_LOAD:
+ {
+ _phase = PHASE_TILE;
+ std::string docPath;
+ std::string docURL;
+ getDocumentPathAndURL("empty.odt", docPath, docURL);
+ _ws = std::unique_ptr<UnitWebSocket>(new UnitWebSocket(docURL));
+ assert(_ws.get());
+
+ // FIXME: need to invoke the tile lookup ...
+ exitTest(TestResult::TEST_OK);
+ break;
+ }
+ case PHASE_TILE:
+ break;
+ }
}
private:
commit dcd68c18503642a3d220ab74ff8699904fed2691
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Oct 21 21:25:23 2016 +0100
tests: re-direct output to the console for unit tests, to make logs useful.
diff --git a/loolwsd/Unit.cpp b/loolwsd/Unit.cpp
index e07999c..5a32129 100644
--- a/loolwsd/Unit.cpp
+++ b/loolwsd/Unit.cpp
@@ -133,6 +133,17 @@ UnitWSD::~UnitWSD()
{
}
+void UnitWSD::configure(Poco::Util::LayeredConfiguration &config)
+{
+ if (_dlHandle) // really running a unit shlib.
+ {
+ // Force HTTP - helps stracing.
+ config.setBool("ssl.enable", false);
+ // Force console output - easier to debug.
+ config.setBool("logging.file[@enable]", false);
+ }
+}
+
void UnitWSD::lookupTile(int part, int width, int height, int tilePosX, int tilePosY,
int tileWidth, int tileHeight, std::unique_ptr<std::fstream>& cacheFile)
{
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index 05b2126..4ca8eea 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -114,7 +114,7 @@ public:
// ---------------- WSD hooks ----------------
/// Manipulate and modify the configuration before any usage.
- virtual void configure(Poco::Util::LayeredConfiguration & /* config */) {}
+ virtual void configure(Poco::Util::LayeredConfiguration & /* config */);
/// Main-loop reached, time for testing
virtual void invokeTest() {}
/// Tweak the count of pre-spawned kits.
More information about the Libreoffice-commits
mailing list