Implement more reliable in-process short-cuts.

Change-Id: Icdfa71affad147c29df175ae687cbecc3f1f171b
This commit is contained in:
Michael Meeks 2017-09-19 19:06:46 +01:00
parent def0350379
commit 2c1508c309
6 changed files with 55 additions and 5 deletions

View file

@ -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

View file

@ -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);
});
}
};

View file

@ -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<int> getProcPids(const char* exec_filename, bool ignoreZombies = false)
{
std::vector<int> pids;
@ -222,4 +226,31 @@ std::vector<int> 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<int> getKitPids()
{
return LOOLWSD::getKitPids();
}
/// Get the PID of the forkit
std::vector<int> getForKitPids()
{
std::vector<int> 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: */

View file

@ -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<int> getKitPids();

View file

@ -2765,7 +2765,6 @@ int LOOLWSD::main(const std::vector<std::string>& /*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<int> LOOLWSD::getKitPids()
{
std::vector<int> pids;
{
std::unique_lock<std::mutex> lock(NewChildrenMutex);
for (const auto &child : NewChildren)
pids.push_back(child->getPid());
}
{
std::unique_lock<std::mutex> 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
{

View file

@ -57,6 +57,8 @@ public:
static std::unique_ptr<TraceFileWriter> TraceDumper;
static std::set<std::string> EditFileExtensions;
static std::vector<int> getKitPids();
/// Flag to shutdown the server.
std::atomic<bool> ShutdownFlag;