Skip to content

Commit

Permalink
Implement more reliable in-process short-cuts.
Browse files Browse the repository at this point in the history
Change-Id: Icdfa71affad147c29df175ae687cbecc3f1f171b
  • Loading branch information
mmeeks committed Sep 19, 2017
1 parent def0350 commit 2c1508c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/UnitClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class UnitClient : public UnitWSD

_worker = std::thread([this]{
if (runClientTests(false, true))
exitTest (TestResult::Failed);
exitTest(TestResult::Ok);
else
exitTest (TestResult::Ok);
exitTest(TestResult::Failed);
});
}
};
Expand Down
31 changes: 31 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ bool isStandalone()
return IsStandalone;
}

// returns true on success
bool runClientTests(bool standalone, bool verbose)
{
IsStandalone = standalone;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: */
2 changes: 2 additions & 0 deletions test/test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
17 changes: 16 additions & 1 deletion wsd/LOOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions wsd/LOOLWSD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class LOOLWSD : public Poco::Util::ServerApplication
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;

Expand Down

0 comments on commit 2c1508c

Please sign in to comment.