[Libreoffice-commits] online.git: 4 commits - common/Session.hpp common/Unit.cpp common/Unit.hpp test/Makefile.am test/UnitFonts.cpp test/UnitFuzz.cpp test/UnitOOB.cpp test/UnitPrefork.cpp wsd/Admin.cpp wsd/Admin.hpp wsd/ClientSession.cpp wsd/ClientSession.hpp wsd/LOOLWSD.cpp
Michael Meeks
michael.meeks at collabora.com
Thu Mar 16 19:14:07 UTC 2017
common/Session.hpp | 3
common/Unit.cpp | 3
common/Unit.hpp | 19 +--
test/Makefile.am | 7 -
test/UnitFonts.cpp | 171 -----------------------------
test/UnitFuzz.cpp | 5
test/UnitOOB.cpp | 1
test/UnitPrefork.cpp | 293 ++------------------------------------------------
wsd/Admin.cpp | 1
wsd/Admin.hpp | 6 -
wsd/ClientSession.cpp | 9 +
wsd/ClientSession.hpp | 2
wsd/LOOLWSD.cpp | 25 ++--
13 files changed, 58 insertions(+), 487 deletions(-)
New commits:
commit bb3fa00631d80a8b4d67f01c16bed9f8ed5708a5
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Mar 16 19:12:49 2017 +0000
UnitPrefork - restore most of the functionality.
No need for the memory reporting bits now that Admin gets this right.
diff --git a/common/Unit.hpp b/common/Unit.hpp
index 23d16730..69d0b3bc 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -157,8 +157,6 @@ public:
virtual void configure(Poco::Util::LayeredConfiguration& /* config */);
/// Main-loop reached, time for testing
virtual void invokeTest() {}
- /// Tweak the count of pre-spawned kits.
- virtual void preSpawnCount(int& /* numPrefork */) {}
/// When a new child kit process reports
virtual void newChild(WebSocketHandler &/* socket */) {}
/// Intercept createStorage
diff --git a/test/Makefile.am b/test/Makefile.am
index cdedda42..bb9377e3 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -74,8 +74,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&) ,
-# disable for now that one too.
-TESTS = # unit-tilecache.la unit-storage.la unit-timeout.la unit-prefork.la unit-admin.la unit-minsocketbuffersize.la
+TESTS = # unit-prefork.la # unit-tilecache.la unit-storage.la unit-timeout.la unit-admin.la unit-minsocketbuffersize.la
else
TESTS = ${top_builddir}/test/test
endif
diff --git a/test/UnitOOB.cpp b/test/UnitOOB.cpp
index e1b83dcf..44e3863e 100644
--- a/test/UnitOOB.cpp
+++ b/test/UnitOOB.cpp
@@ -31,7 +31,6 @@ class UnitOOB : public UnitWSD
public:
UnitOOB()
{
- setHasKitHooks();
}
virtual void invokeTest() override
diff --git a/test/UnitPrefork.cpp b/test/UnitPrefork.cpp
index 961208ec..5601d489 100644
--- a/test/UnitPrefork.cpp
+++ b/test/UnitPrefork.cpp
@@ -9,322 +9,51 @@
#include "config.h"
-#include <dirent.h>
-#include <dlfcn.h>
-#include <ftw.h>
-#include <sys/time.h>
-#include <sys/types.h>
-
-#include <cassert>
-#include <iostream>
-
-#include <mutex>
-#include <condition_variable>
-
-#include <Poco/Timestamp.h>
-#include <Poco/StringTokenizer.h>
-
-#include "Common.hpp"
-#include "IoUtil.hpp"
-#include "Protocol.hpp"
-#include <LOOLWebSocket.hpp>
-#include "Log.hpp"
#include "Unit.hpp"
-#include "Util.hpp"
+#include "wsd/LOOLWSD.hpp"
-#if 0
const int NumToPrefork = 20;
// Inside the WSD process
class UnitPrefork : public UnitWSD
{
- std::string _failure;
Poco::Timestamp _startTime;
- size_t _childPSS;
- size_t _childDirty;
- std::mutex _mutex;
- std::condition_variable _cv;
- std::vector< std::shared_ptr<LOOLWebSocket> > _childSockets;
+ std::atomic< int > _childSockets;
public:
UnitPrefork()
- : _childPSS(0),
- _childDirty(0)
+ : _childSockets(0)
{
- setHasKitHooks();
setTimeout(60 * 1000);
}
- virtual void preSpawnCount(int &numPrefork) override
+ virtual void configure(Poco::Util::LayeredConfiguration& /* config */)
{
- numPrefork = NumToPrefork;
- }
-
- virtual bool filterChildMessage(const std::vector<char>& payload) override
- {
- const std::string memory = LOOLProtocol::getFirstLine(payload);
- Poco::StringTokenizer tokens(memory, " ");
- if (tokens[0] == "error:")
- {
- _failure = memory;
- }
- else
- {
- LOG_INF("Got memory stats [" << memory << "].");
- assert(tokens.count() == 2);
- _childPSS = atoi(tokens[0].c_str());
- _childDirty = atoi(tokens[1].c_str());
- }
-
- // Don't signal before wait.
- std::unique_lock<std::mutex> lock(_mutex);
- _cv.notify_one();
- return true;
+ LOOLWSD::NumPreSpawnedChildren = NumToPrefork;
}
- virtual void newChild(const WebSocketHandler &socket) override
+ virtual void newChild(WebSocketHandler &) override
{
- std::unique_lock<std::mutex> lock(_mutex);
+ _childSockets++;
+ LOG_INF("Unit-prefork: got new child, have " << _childSockets << " of " << NumToPrefork);
- _childSockets.push_back(socket);
- LOG_INF("Unit-prefork: got new child, have " << _childSockets.size() << " of " << NumToPrefork);
-
- if (_childSockets.size() >= NumToPrefork)
+ if (_childSockets >= NumToPrefork)
{
Poco::Timestamp::TimeDiff elapsed = _startTime.elapsed();
const auto totalTime = (1000. * elapsed)/Poco::Timestamp::resolution();
- LOG_INF("Launched " << _childSockets.size() << " in " << totalTime);
- size_t totalPSSKb = 0;
- size_t totalDirtyKb = 0;
-
- // Skip the last one as it's not completely initialized yet.
- for (size_t i = 0; i < _childSockets.size() - 1; ++i)
- {
- LOG_INF("Getting memory of child #" << i + 1 << " of " << _childSockets.size());
-
- _childSockets[i]->sendFrame("unit-memdump: \n", sizeof("unit-memdump: \n"));
- if (_cv.wait_for(lock, std::chrono::milliseconds(10 * 1000)) == std::cv_status::timeout)
- {
- _failure = "Timed out waiting for child to respond to unit-memdump.";
- std::cerr << _failure << std::endl;
- exitTest(TestResult::Failed);
- return;
- }
-
- std::cerr << "child # " << i + 1 << " pss: " << _childPSS << " (totalPSS: " << (totalPSSKb + _childPSS)
- << "), dirty: " << _childDirty << " (totalDirty: " << (totalDirtyKb + _childDirty) << std::endl;
- totalPSSKb += _childPSS;
- _childPSS = 0;
- totalDirtyKb += _childDirty;
- _childDirty = 0;
- }
-
- std::cerr << "Memory use total " << totalPSSKb << "k shared "
- << totalDirtyKb << "k dirty" << std::endl;
-
- totalPSSKb /= _childSockets.size();
- totalDirtyKb /= _childSockets.size();
- std::cerr << "Memory use average " << totalPSSKb << "k shared "
- << totalDirtyKb << "k dirty" << std::endl;
-
+ LOG_INF("Launched " << _childSockets << " in " << totalTime);
std::cerr << "Launch time total " << totalTime << " ms" << std::endl;
- std::cerr << "Launch time average " << (totalTime / _childSockets.size()) << " ms" << std::endl;
+ std::cerr << "Launch time average " << (totalTime / _childSockets) << " ms" << std::endl;
- if (!_failure.empty())
- {
- std::cerr << "UnitPrefork failed due to: " << _failure << std::endl;
- exitTest(TestResult::Failed);
- }
- else
- {
- std::cerr << "UnitPrefork success." << std::endl;
- exitTest(TestResult::Ok);
- }
+ exitTest(TestResult::Ok);
}
}
};
-namespace
-{
- std::vector<int> pids;
-
- const char *startsWith(const char *line, const char *tag)
- {
- int len = strlen(tag);
- if (!strncmp(line, tag, len))
- {
- while (!isdigit(line[len]) && line[len] != '\0')
- ++len;
-
- const auto str = std::string(line + len, strlen(line + len) - 1);
- return line + len;
- }
-
- return nullptr;
- }
-
- std::string readMemorySizes(FILE *inStream)
- {
- size_t numPSSKb = 0;
- size_t numDirtyKb = 0;
-
- char line[4096] = { 0 };
- while (fgets(line, sizeof (line), inStream))
- {
- const char *value;
- if ((value = startsWith(line, "Private_Dirty:")) ||
- (value = startsWith(line, "Shared_Dirty:")))
- numDirtyKb += atoi(value);
- else if ((value = startsWith(line, "Pss:")))
- numPSSKb += atoi(value);
- }
-
- std::ostringstream oss;
- oss << numPSSKb << " " << numDirtyKb;
- const auto res = oss.str();
- LOG_INF("readMemorySize: [" << res << "].");
- if (res.empty())
- {
- LOG_ERR("Failed to read memory stats.");
- throw std::runtime_error("Failed to read memory stats.");
- }
-
- return res;
- }
-}
-
-// Inside the forkit & kit processes
-class UnitKitPrefork : public UnitKit
-{
- FILE *_procSMaps;
- std::string _failure;
-
-public:
- UnitKitPrefork()
- : _procSMaps(nullptr)
- {
- std::cerr << "UnitKit Prefork init !\n";
- }
- ~UnitKitPrefork()
- {
- if (_procSMaps)
- fclose(_procSMaps);
- }
-
- virtual void launchedKit(int pid) override
- {
- // by the magic of forking - this should appear
- // in the last kit child nearly fully formed.
- pids.push_back(pid);
- }
-
- // Check that we have no unexpected open sockets.
- void checkSockets()
- {
- DIR *fds = opendir ("/proc/self/fd");
- struct dirent *ent;
- int deviceCount = 0, rdbCount = 0, resCount = 0,
- numSockets = 0, numUnexpected = 0, pipeCount = 0;
- while ((ent = readdir(fds)))
- {
- if (ent->d_name[0] == '.')
- continue;
- char name[1024 + 32];
- char buffer[4096];
- strcpy (name, "/proc/self/fd/");
- strncat(name, ent->d_name, 1024);
- size_t len;
- memset(buffer, 0, sizeof(buffer));
- if ((len = readlink(name, buffer, sizeof(buffer)-1)) > 0)
- {
- assert(len<sizeof(buffer));
- numSockets++;
- char *extDot = strrchr(buffer, '.');
- LOG_INF("fd:" << ent->d_name << " -> " << buffer);
- if (!strncmp(buffer, "/dev/", sizeof ("/dev/") -1))
- deviceCount++;
- else if (extDot && !strcmp(extDot, ".res"))
- resCount++;
- else if (extDot && !strcmp(extDot, ".rdb"))
- rdbCount++;
- else if (strstr(buffer, "unit-prefork.log") || // our log
- strstr(buffer, "loolwsd.log") || // debug log
- (strstr(buffer, "/proc/") && // our readdir
- strstr(buffer, "/fd")))
- ; // ignore
- else if (!strncmp(buffer, "pipe:[", 6))
- pipeCount++;
- else
- {
- fprintf(stderr, "Unexpected descriptor: %s -> %s\n", ent->d_name, buffer);
- numUnexpected++;
- }
- }
- }
- fprintf(stderr, "%d devices, %d rdb %d resources, %d pipes, %d descriptors total: %d unexpected\n",
- deviceCount, rdbCount, resCount, pipeCount, numSockets, numUnexpected);
- // 3 Pipes at most: 1 input, 1 output, file redirection (or so I imagine them).
- if (pipeCount > 3 || numUnexpected > 0)
- _failure = std::string("Error: unexpected inherited sockets ") +
- std::to_string(numUnexpected) + " and pipes " +
- std::to_string(pipeCount);
- }
-
- virtual void postFork() override
- {
- checkSockets();
-
- // before we drop the caps we can even open our /proc files !
- const std::string procName = std::string("/proc/") +
- std::to_string(getpid()) +
- std::string("/smaps");
- _procSMaps = fopen(procName.c_str(), "r");
- if (_procSMaps == nullptr)
- {
- _failure = "Failed to open process: " + procName;
- throw std::runtime_error(_failure);
- }
- }
-
- virtual bool filterKitMessage(const std::shared_ptr<LOOLWebSocket> &ws,
- std::string &message) override
- {
- const auto token = LOOLProtocol::getFirstToken(message);
- if (token == "unit-memdump:")
- {
-#ifdef TEST_DIRTY_NUMBERS
- // Jitter the numbers so they're not all the same.
- struct timeval t;
- gettimeofday(&t, NULL);
- srand(t.tv_usec);
- size_t size = ((size_t)rand() * 4096 * 1024) / RAND_MAX;
- std::cerr << "allocate " << size << std::endl;
- memset (malloc (size), 0, size);
-#endif
- std::string memory;
- if (!_failure.empty())
- memory = _failure;
- else
- memory = readMemorySizes(_procSMaps);
- LOG_INF("filterKitMessage sending back: [" << memory << "].");
- ws->sendFrame(memory.c_str(), memory.length());
- return true;
- }
-
- return false;
- }
-};
-
UnitBase *unit_create_wsd(void)
{
return new UnitPrefork();
}
-UnitBase *unit_create_kit(void)
-{
- return new UnitKitPrefork();
-}
-#endif
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 8ad75e36..c12d7e60 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -410,8 +410,7 @@ static bool prespawnChildren()
return false;
}
- const int numPreSpawn = LOOLWSD::NumPreSpawnedChildren;
- return (rebalanceChildren(numPreSpawn) > 0);
+ return rebalanceChildren(LOOLWSD::NumPreSpawnedChildren) > 0;
}
static size_t addNewChild(const std::shared_ptr<ChildProcess>& child)
commit ab67d605e6066b2df6c3774a1160e563701a00d6
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Mar 16 18:52:49 2017 +0000
Unit tests: use WSD's main socket-poll for test timeouts.
diff --git a/common/Unit.cpp b/common/Unit.cpp
index c275b533..687a7abb 100644
--- a/common/Unit.cpp
+++ b/common/Unit.cpp
@@ -69,7 +69,7 @@ bool UnitBase::init(UnitType type, const std::string &unitLibPath)
if (!unitLibPath.empty())
{
Global = linkAndCreateUnit(type, unitLibPath);
- if (Global)
+ if (Global && type == UnitType::Kit)
{
TimeoutThread.startFunc([](){
Poco::Thread::trySleep(Global->_timeoutMilliSeconds);
@@ -184,6 +184,7 @@ void UnitBase::exitTest(TestResult result)
Poco::Util::Application::EXIT_OK :
Poco::Util::Application::EXIT_SOFTWARE;
TerminationFlag = true;
+ SocketPoll::wakeupWorld();
}
void UnitBase::timeout()
diff --git a/common/Unit.hpp b/common/Unit.hpp
index bd66d7ee..23d16730 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -59,9 +59,6 @@ protected:
/// After this time we invoke 'timeout' default 30 seconds
void setTimeout(int timeoutMilliSeconds);
- /// If the test times out this gets invoked, the default just exits.
- virtual void timeout();
-
enum class TestResult
{
Failed,
@@ -98,6 +95,14 @@ public:
return false;
}
+ /// If the test times out this gets invoked, the default just exits.
+ virtual void timeout();
+
+ int getTimeoutMilliSeconds() const
+ {
+ return _timeoutMilliSeconds;
+ }
+
static UnitBase& get()
{
assert(Global);
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 19c31c7e..8ad75e36 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2518,14 +2518,21 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
time_t startTimeSpan = time(nullptr);
#endif
- /// Something of a hack to get woken up on exit.
+ auto startStamp = std::chrono::steady_clock::now();
+ /// The main-poll does next to nothing:
SocketPoll mainWait("main");
while (!TerminationFlag && !ShutdownRequestFlag)
{
UnitWSD::get().invokeTest();
- mainWait.poll(SocketPoll::DefaultPollTimeoutMs * 10);
+ mainWait.poll(SocketPoll::DefaultPollTimeoutMs * 2);
+
+ // Unit test timeout
+ if (std::chrono::duration_cast<std::chrono::milliseconds>(
+ std::chrono::steady_clock::now() - startStamp).count() <
+ UnitWSD::get().getTimeoutMilliSeconds())
+ UnitWSD::get().timeout();
std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
cleanupDocBrokers();
commit 2c14723e582614a20b35c0980cad9db07d21cfdf
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Mar 16 18:33:03 2017 +0000
UnitFonts - disable.
Now we use the forkit, font lists are always the same in kit & forkit.
diff --git a/test/Makefile.am b/test/Makefile.am
index 9683bee6..cdedda42 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -14,7 +14,7 @@ AM_CXXFLAGS = $(CPPUNIT_CFLAGS) -DTDOC=\"$(top_srcdir)/test/data\" \
noinst_LTLIBRARIES = \
unit-timeout.la unit-prefork.la \
- unit-storage.la unit-fonts.la \
+ unit-storage.la \
unit-admin.la unit-tilecache.la \
unit-fuzz.la unit-oob.la \
unit-minsocketbuffersize.la
@@ -57,7 +57,6 @@ unit_oob_la_SOURCES = UnitOOB.cpp
unit_fuzz_la_SOURCES = UnitFuzz.cpp
unit_admin_la_SOURCES = UnitAdmin.cpp
unit_admin_la_LIBADD = $(CPPUNIT_LIBS)
-unit_fonts_la_SOURCES = UnitFonts.cpp
unit_timeout_la_SOURCES = UnitTimeout.cpp
unit_prefork_la_SOURCES = UnitPrefork.cpp
unit_storage_la_SOURCES = UnitStorage.cpp
@@ -73,7 +72,6 @@ endif
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.
# FIXME 2: unit-oob.la fails with symbol undefined:
# UnitWSD::testHandleRequest(UnitWSD::TestRequest, UnitHTTPServerRequest&, UnitHTTPServerResponse&) ,
# disable for now that one too.
diff --git a/test/UnitFonts.cpp b/test/UnitFonts.cpp
deleted file mode 100644
index 2f1f8d2b..00000000
--- a/test/UnitFonts.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -*- 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 <dlfcn.h>
-#include <ftw.h>
-
-#include <cassert>
-#include <iostream>
-
-#include <Poco/Net/HTTPClientSession.h>
-#include <Poco/Net/HTTPResponse.h>
-#include <Poco/Net/HTTPServerRequest.h>
-#include <Poco/StringTokenizer.h>
-#include <Poco/Timestamp.h>
-
-#include "Common.hpp"
-#include "Protocol.hpp"
-#include "Log.hpp"
-#include "Unit.hpp"
-#include "Util.hpp"
-
-#define UNIT_URI "/loolwsd/unit-font"
-
-namespace {
- // interrogate the vcl/ fontmanager for its hook ...
- std::string getFontList()
- {
- void *me = dlopen(nullptr,RTLD_NOW);
- typedef const char *(GetFontsFn)(void);
- GetFontsFn *fn = reinterpret_cast<GetFontsFn *>(
- dlsym(me, "unit_online_get_fonts"));
- if (fn)
- return std::string(fn());
- else
- return std::string("can't find unit_online_get_fonts hook");
- }
-
- std::string readFontList(const std::shared_ptr<LOOLWebSocket> &socket)
- {
- int flags;
- char buffer[100 * 1000];
-
- int length = socket->receiveFrame(buffer, sizeof (buffer), flags);
- if (length > 0)
- {
- assert(length<(int)sizeof(buffer));
- buffer[length] = '\0';
- return std::string(buffer);
- }
- else
- return std::string("read failure");
- }
-}
-
-// Inside the WSD process
-class UnitPrefork : public UnitWSD
-{
- std::string _fontsKit;
- std::string _fontsBroker;
-public:
- UnitPrefork()
- {
- setHasKitHooks();
- }
-
- void check()
- {
- if (!_fontsKit.length() || !_fontsBroker.length())
- return; // defer till we have all the data.
- if (_fontsKit != _fontsBroker)
- {
- std::cerr << "Error - font list mismatch" << std::endl;
- std::cerr << "Kit : '" << _fontsKit << "' vs. Broker : '" << _fontsBroker << "'" << std::endl;
- exitTest(TestResult::Failed);
- }
- else
- {
- Poco::StringTokenizer tokens(_fontsKit, "\n");
- if (tokens.count() > 0)
- std::cerr << " " << tokens[0] << std::endl;
-
- exitTest(TestResult::Ok);
- }
- }
-
-#if 0 // loolnb - not such a useful test.
- virtual void newChild(const std::shared_ptr<LOOLWebSocket> &socket) override
- {
- Log::info("Fetching font list from kit");
- socket->sendFrame("unit-getfontlist: \n",
- sizeof("unit-getfontlist: \n") - 1);
- _fontsKit = readFontList(socket);
- check();
- }
-
- virtual bool filterHandleRequest(
- TestRequest type,
- Poco::Net::HTTPServerRequest& request,
- Poco::Net::HTTPServerResponse& response) override
- {
- if (type == UnitWSD::TestRequest::Prisoner &&
- request.getURI().find(UNIT_URI) == 0)
- {
- auto ws = std::make_shared<LOOLWebSocket>(request, response);
- _fontsBroker = readFontList(ws);
- check();
- return true;
- }
-
- return false;
- }
-#endif
-};
-
-// Inside the forkit & kit processes
-class UnitKitPrefork : public UnitKit
-{
-public:
- UnitKitPrefork()
- {
- }
-
- // Called in the forkit after forking the kit
- virtual void launchedKit(int /* pid */) override
- {
- // Open websocket connection between the child process and WSD.
- 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));
- Poco::Net::HTTPResponse response;
- auto ws = std::make_shared<LOOLWebSocket>(cs, request, response);
- ws->setReceiveTimeout(0);
- Log::info("Fetching font list from forkit");
- std::string fontListMsg = getFontList() + "\n";
- ws->sendFrame(fontListMsg.c_str(), fontListMsg.length());
- }
-
- // Called from WSD and handled inside the kit.
- virtual bool filterKitMessage(const std::shared_ptr<LOOLWebSocket> &ws,
- std::string &message) override
- {
- const std::string token = LOOLProtocol::getFirstToken(message);
- if (token == "unit-getfontlist:")
- {
- const std::string fontListReply = getFontList() + "\n";
- ws->sendFrame(fontListReply.c_str(), fontListReply.length());
- return true;
- }
-
- return false;
- }
-};
-
-UnitBase *unit_create_wsd(void)
-{
- return new UnitPrefork();
-}
-
-UnitBase *unit_create_kit(void)
-{
- return new UnitKitPrefork();
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 8749f4f2e3fa7ab78ef990afb8e153b9c5171ca4
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Thu Mar 16 18:32:12 2017 +0000
Cleanup unit test hooks.
diff --git a/common/Session.hpp b/common/Session.hpp
index b2a40dd0..d12a7042 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -23,14 +23,13 @@
#include <Poco/Types.h>
#include "Protocol.hpp"
-#include <LOOLWebSocket.hpp>
#include "Log.hpp"
#include "MessageQueue.hpp"
#include "Message.hpp"
#include "TileCache.hpp"
#include "WebSocketHandler.hpp"
-/// Base class of a LOOLWebSocket session.
+/// Base class of a WebSocket session.
class Session : public WebSocketHandler
{
public:
diff --git a/common/Unit.hpp b/common/Unit.hpp
index df740ed7..bd66d7ee 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -15,6 +15,7 @@
#include <string>
#include <LOOLWebSocket.hpp>
+#include "net/WebSocketHandler.hpp"
class UnitBase;
class UnitWSD;
@@ -154,7 +155,7 @@ public:
/// Tweak the count of pre-spawned kits.
virtual void preSpawnCount(int& /* numPrefork */) {}
/// When a new child kit process reports
- virtual void newChild(const std::shared_ptr<LOOLWebSocket>& /* socket */) {}
+ virtual void newChild(WebSocketHandler &/* socket */) {}
/// Intercept createStorage
virtual bool createStorage(const Poco::URI& /* uri */,
const std::string& /* jailRoot */,
@@ -166,8 +167,7 @@ public:
/// Intercept incoming requests, so unit tests can silently communicate
virtual bool filterHandleRequest(
TestRequest /* type */,
- Poco::Net::HTTPServerRequest& /* request */,
- Poco::Net::HTTPServerResponse& /* response */)
+ WebSocketHandler & /* handler */)
{
return false;
}
diff --git a/test/UnitFonts.cpp b/test/UnitFonts.cpp
index 17062ef1..2f1f8d2b 100644
--- a/test/UnitFonts.cpp
+++ b/test/UnitFonts.cpp
@@ -91,6 +91,7 @@ public:
}
}
+#if 0 // loolnb - not such a useful test.
virtual void newChild(const std::shared_ptr<LOOLWebSocket> &socket) override
{
Log::info("Fetching font list from kit");
@@ -101,9 +102,9 @@ public:
}
virtual bool filterHandleRequest(
- TestRequest type,
- Poco::Net::HTTPServerRequest& request,
- Poco::Net::HTTPServerResponse& response) override
+ TestRequest type,
+ Poco::Net::HTTPServerRequest& request,
+ Poco::Net::HTTPServerResponse& response) override
{
if (type == UnitWSD::TestRequest::Prisoner &&
request.getURI().find(UNIT_URI) == 0)
@@ -116,6 +117,7 @@ public:
return false;
}
+#endif
};
// Inside the forkit & kit processes
diff --git a/test/UnitFuzz.cpp b/test/UnitFuzz.cpp
index 460fcf15..49575b5d 100644
--- a/test/UnitFuzz.cpp
+++ b/test/UnitFuzz.cpp
@@ -121,14 +121,15 @@ public:
virtual bool filterHandleRequest(
TestRequest /* type */,
- Poco::Net::HTTPServerRequest& request,
- Poco::Net::HTTPServerResponse& /* response */) override
+ WebSocketHandler & /* socket */) override
{
+#if 0 // loolnb
if (_dist(_mt) < 10) // 1%
{
std::cerr << "Mangle request URI\n";
request.setURI(corruptString(request.getURI()));
}
+#endif
return false;
}
};
diff --git a/test/UnitPrefork.cpp b/test/UnitPrefork.cpp
index 7a205b35..961208ec 100644
--- a/test/UnitPrefork.cpp
+++ b/test/UnitPrefork.cpp
@@ -32,6 +32,7 @@
#include "Unit.hpp"
#include "Util.hpp"
+#if 0
const int NumToPrefork = 20;
// Inside the WSD process
@@ -81,7 +82,7 @@ public:
return true;
}
- virtual void newChild(const std::shared_ptr<LOOLWebSocket> &socket) override
+ virtual void newChild(const WebSocketHandler &socket) override
{
std::unique_lock<std::mutex> lock(_mutex);
@@ -324,5 +325,6 @@ UnitBase *unit_create_kit(void)
{
return new UnitKitPrefork();
}
+#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 776ba137..1870cb0f 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -16,7 +16,6 @@
#include <Poco/Net/HTTPCookie.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/StringTokenizer.h>
-#include <Poco/Util/Timer.h>
#include "Admin.hpp"
#include "AdminModel.hpp"
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index 8dcdfedb..a816b636 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -12,12 +12,6 @@
#include <mutex>
-#include <Poco/Net/HTTPRequest.h>
-#include <Poco/Runnable.h>
-#include <Poco/Types.h>
-#include <Poco/Util/Timer.h>
-#include <Poco/Util/TimerTask.h>
-
#include "AdminModel.hpp"
#include "Log.hpp"
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 459754d9..64212a48 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -22,6 +22,7 @@
#include "Protocol.hpp"
#include "Session.hpp"
#include "Util.hpp"
+#include "Unit.hpp"
using namespace LOOLProtocol;
@@ -50,6 +51,14 @@ ClientSession::~ClientSession()
stop();
}
+void ClientSession::handleIncomingMessage()
+{
+ if (UnitWSD::get().filterHandleRequest(
+ UnitWSD::TestRequest::Client, *this))
+ return;
+ Session::handleIncomingMessage();
+}
+
bool ClientSession::_handleInput(const char *buffer, int length)
{
LOG_TRC(getName() << ": handling [" << getAbbreviatedMessage(buffer, length) << "].");
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 8b88a596..c18e5cee 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -30,6 +30,8 @@ public:
virtual ~ClientSession();
+ void handleIncomingMessage() override;
+
void setReadOnly();
bool isReadOnly() const { return _isReadOnly; }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 8cd38125..19c31c7e 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1396,6 +1396,7 @@ static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHand
return nullptr;
}
+/// Handles the socket that the prisoner kit connected to WSD on.
class PrisonerRequestDispatcher : public WebSocketHandler
{
std::weak_ptr<ChildProcess> _childProcess;
@@ -1431,6 +1432,10 @@ private:
/// Called after successful socket reads.
void handleIncomingMessage() override
{
+ if (UnitWSD::get().filterHandleRequest(
+ UnitWSD::TestRequest::Prisoner, *this))
+ return;
+
if (_childProcess.lock())
{
// FIXME: inelegant etc. - derogate to websocket code
@@ -1506,11 +1511,7 @@ private:
LOG_INF("New child [" << pid << "].");
- // FIXME:
- /* if (UnitWSD::get().filterHandleRequest(
- UnitWSD::TestRequest::Prisoner,
- request, response))
- return; */
+ UnitWSD::get().newChild(*this);
auto child = std::make_shared<ChildProcess>(pid, socket, request);
_childProcess = child; // weak
More information about the Libreoffice-commits
mailing list