From 2c1508c309f8301e4a28f2d6dddc6557fda807ed Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Tue, 19 Sep 2017 19:06:46 +0100 Subject: [PATCH] Implement more reliable in-process short-cuts. Change-Id: Icdfa71affad147c29df175ae687cbecc3f1f171b --- test/Makefile.am | 4 ++-- test/UnitClient.cpp | 4 ++-- test/test.cpp | 31 +++++++++++++++++++++++++++++++ test/test.hpp | 2 ++ wsd/LOOLWSD.cpp | 17 ++++++++++++++++- wsd/LOOLWSD.hpp | 2 ++ 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/test/Makefile.am b/test/Makefile.am index dc4f7ce4f..570949678 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -69,7 +69,7 @@ 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_client_la_SOURCES = UnitClient.cpp ${test_base_source} +unit_client_la_SOURCES = UnitClient.cpp ${test_all_source} unit_client_la_LIBADD = $(CPPUNIT_LIBS) unit_timeout_la_SOURCES = UnitTimeout.cpp unit_prefork_la_SOURCES = UnitPrefork.cpp @@ -91,7 +91,7 @@ check-local: # 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 -# TESTS += unit-client.la +# TESTS = unit-client.la # TESTS += unit-admin.la # TESTS += unit-storage.la else diff --git a/test/UnitClient.cpp b/test/UnitClient.cpp index ec31fb2fe..0de67bacd 100644 --- a/test/UnitClient.cpp +++ b/test/UnitClient.cpp @@ -57,9 +57,9 @@ public: _worker = std::thread([this]{ if (runClientTests(false, true)) - exitTest (TestResult::Failed); + exitTest(TestResult::Ok); else - exitTest (TestResult::Ok); + exitTest(TestResult::Failed); }); } }; diff --git a/test/test.cpp b/test/test.cpp index 6642a151c..4e5404788 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -79,6 +79,7 @@ bool isStandalone() return IsStandalone; } +// returns true on success bool runClientTests(bool standalone, bool verbose) { IsStandalone = standalone; @@ -141,6 +142,9 @@ bool runClientTests(bool standalone, bool verbose) return result.wasSuccessful(); } +// Versions assuming a single user, on a single machine +#ifndef UNIT_CLIENT_TESTS + std::vector getProcPids(const char* exec_filename, bool ignoreZombies = false) { std::vector pids; @@ -222,4 +226,31 @@ std::vector getForKitPids() return pids; } +#else // UNIT_CLIENT_TESTS + +// Here we are compiled inside UnitClient.cpp and we have +// full access to the WSD process internals. + +std::vector getKitPids() +{ + return LOOLWSD::getKitPids(); +} + +/// Get the PID of the forkit +std::vector getForKitPids() +{ + std::vector pids; + if (LOOLWSD::ForKitProcId >= 0) + pids.push_back(LOOLWSD::ForKitProcId); + return pids; +} + +/// How many live lookit processes do we have ? +int getLoolKitProcessCount() +{ + return getKitPids().size(); +} + +#endif // UNIT_CLIENT_TESTS + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/test.hpp b/test/test.hpp index 44b7addab..2f85cac25 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -18,6 +18,8 @@ bool isStandalone(); /// Run the set of client tests we have bool runClientTests(bool standalone, bool verbose); +// ---- Abstraction for standalone vs. WSD ---- + /// Get the list of kit PIDs std::vector getKitPids(); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 025bf1cbc..1c4088b83 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -2765,7 +2765,6 @@ int LOOLWSD::main(const std::vector& /*args*/) return returnValue; } - void UnitWSD::testHandleRequest(TestRequest type, UnitHTTPServerRequest& /* request */, UnitHTTPServerResponse& /* response */) { switch (type) @@ -2784,6 +2783,22 @@ void UnitWSD::testHandleRequest(TestRequest type, UnitHTTPServerRequest& /* requ } } +std::vector LOOLWSD::getKitPids() +{ + std::vector pids; + { + std::unique_lock lock(NewChildrenMutex); + for (const auto &child : NewChildren) + pids.push_back(child->getPid()); + } + { + std::unique_lock lock(DocBrokersMutex); + for (const auto &it : DocBrokers) + pids.push_back(it.second->getPid()); + } + return pids; +} + #if !defined(BUILDING_TESTS) && !defined(KIT_IN_PROCESS) namespace Util { diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp index 86f8dbcbe..4c7579f98 100644 --- a/wsd/LOOLWSD.hpp +++ b/wsd/LOOLWSD.hpp @@ -57,6 +57,8 @@ public: static std::unique_ptr TraceDumper; static std::set EditFileExtensions; + static std::vector getKitPids(); + /// Flag to shutdown the server. std::atomic ShutdownFlag;