summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2017-09-19 19:06:46 +0100
committerMichael Meeks <michael.meeks@collabora.com>2017-09-19 21:17:13 +0100
commit2c1508c309f8301e4a28f2d6dddc6557fda807ed (patch)
tree3ed5c9b9e1abebd75d17cad92c1222498d710229
parentRe-factor pid hunting code into test.cpp where we can do better. (diff)
downloadonline-2c1508c309f8301e4a28f2d6dddc6557fda807ed.tar.gz
online-2c1508c309f8301e4a28f2d6dddc6557fda807ed.zip
Implement more reliable in-process short-cuts.
Change-Id: Icdfa71affad147c29df175ae687cbecc3f1f171b
-rw-r--r--test/Makefile.am4
-rw-r--r--test/UnitClient.cpp4
-rw-r--r--test/test.cpp31
-rw-r--r--test/test.hpp2
-rw-r--r--wsd/LOOLWSD.cpp17
-rw-r--r--wsd/LOOLWSD.hpp2
6 files changed, 55 insertions, 5 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index dc4f7ce4f8..5709496785 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 ec31fb2fec..0de67bacd3 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 6642a151c9..4e54047880 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<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: */
diff --git a/test/test.hpp b/test/test.hpp
index 44b7addab6..2f85cac259 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<int> getKitPids();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 025bf1cbcd..1c4088b83c 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -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
{
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 86f8dbcbe5..4c7579f986 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -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;