[Libreoffice-commits] online.git: loolwsd/test loolwsd/Unit.cpp

2016-10-05 Thread Michael Meeks
 loolwsd/Unit.cpp |1 +
 loolwsd/test/UnitPrefork.cpp |   14 ++
 2 files changed, 3 insertions(+), 12 deletions(-)

New commits:
commit d3daa2d9d952a9dceca9b171859f8deea124998f
Author: Michael Meeks 
Date:   Wed Oct 5 22:36:40 2016 +0100

Mend UnitPrefork.

Count pre-forked processes more correctly.
Use Unit's returnValue implementation to fix failure exit codes.
Accept new loolwsd.log socket as being authentic.

diff --git a/loolwsd/Unit.cpp b/loolwsd/Unit.cpp
index 6c050cf..5eb7fb6 100644
--- a/loolwsd/Unit.cpp
+++ b/loolwsd/Unit.cpp
@@ -164,6 +164,7 @@ void UnitBase::exitTest(TestResult result)
 
 void UnitBase::timeout()
 {
+Log::error("Timed out waiting for unit test to complete");
 exitTest(TestResult::TEST_TIMED_OUT);
 }
 
diff --git a/loolwsd/test/UnitPrefork.cpp b/loolwsd/test/UnitPrefork.cpp
index e2522a5..d3c2804 100644
--- a/loolwsd/test/UnitPrefork.cpp
+++ b/loolwsd/test/UnitPrefork.cpp
@@ -50,17 +50,6 @@ public:
 setHasKitHooks();
 }
 
-virtual void returnValue(int ) override
-{
-// 0 when empty (success), otherwise failure.
-if (!_failure.empty())
-{
-Log::error("UnitPrefork failed due to: " + _failure);
-}
-
-retValue = !_failure.empty();
-}
-
 virtual void preSpawnCount(int ) override
 {
 numPrefork = NumToPrefork;
@@ -111,7 +100,7 @@ public:
 virtual void newChild(const std::shared_ptr ) 
override
 {
 _childSockets.push_back(socket);
-if (_childSockets.size() > NumToPrefork)
+if (_childSockets.size() >= NumToPrefork)
 {
 Poco::Timestamp::TimeDiff elapsed = _startTime.elapsed();
 
@@ -260,6 +249,7 @@ public:
 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
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/test loolwsd/Unit.cpp loolwsd/Unit.hpp

2016-04-08 Thread Michael Meeks
 loolwsd/Unit.cpp |   45 +
 loolwsd/Unit.hpp |   11 +++-
 loolwsd/test/Makefile.am |6 ++--
 loolwsd/test/UnitTimeout.cpp |   58 +++
 loolwsd/test/run_unit.sh |2 -
 5 files changed, 108 insertions(+), 14 deletions(-)

New commits:
commit 3e618a97e3cf04fee09f3fe28f5afe9605e74017
Author: Michael Meeks 
Date:   Fri Apr 8 17:36:08 2016 +0100

Tests: add timeout, and test for timeout.

diff --git a/loolwsd/Unit.cpp b/loolwsd/Unit.cpp
index 2a9448c..abafa12 100644
--- a/loolwsd/Unit.cpp
+++ b/loolwsd/Unit.cpp
@@ -13,11 +13,13 @@
 #include "Util.hpp"
 #include "Unit.hpp"
 
+#include 
 #include 
-using Poco::Util::Application;
 
 UnitHooks *UnitHooks::_global = nullptr;
 
+static Poco::Thread TimeoutThread("unit timeout");
+
 UnitHooks *UnitHooks::linkAndCreateUnit(const std::string )
 {
 void *dlHandle = dlopen(unitLibPath.c_str(), RTLD_GLOBAL|RTLD_NOW);
@@ -45,15 +47,33 @@ UnitHooks *UnitHooks::linkAndCreateUnit(const std::string 
)
 bool UnitHooks::init(const std::string )
 {
 if (!unitLibPath.empty())
+{
 _global = linkAndCreateUnit(unitLibPath);
+TimeoutThread.startFunc([](){
+TimeoutThread.trySleep(_global->_timeoutMilliSeconds);
+if (!_global->_timeoutShutdown)
+{
+Log::error("Timeout");
+_global->timeout();
+}
+});
+}
 else
 _global = new UnitHooks();
 
 return _global != NULL;
 }
 
+void UnitHooks::setTimeout(int timeoutMilliSeconds)
+{
+assert(!TimeoutThread.isRunning());
+_timeoutMilliSeconds = timeoutMilliSeconds;
+}
+
 UnitHooks::UnitHooks()
-: _dlHandle(NULL)
+: _dlHandle(NULL),
+  _timeoutMilliSeconds(30 * 1000),
+  _timeoutShutdown(false)
 {
 }
 
@@ -69,22 +89,27 @@ void UnitHooks::exitTest(TestResult result)
 {
 _setRetValue = true;
 _retValue = result == TestResult::TEST_OK ?
-Application::EXIT_OK : Application::EXIT_SOFTWARE;
+Poco::Util::Application::EXIT_OK :
+Poco::Util::Application::EXIT_SOFTWARE;
 TerminationFlag = true;
 }
 
-/// Tweak the return value from LOOLWSD.
+void UnitHooks::timeout()
+{
+exitTest(TestResult::TEST_TIMED_OUT);
+}
+
 void UnitHooks::returnValue(int )
 {
 if (_setRetValue)
 retValue = _retValue;
-}
 
-// FIXME: trigger the timeout.
-void UnitHooks::timeout()
-{
-Log::error("Test timed out - failing.");
-exitTest(TestResult::TEST_TIMED_OUT);
+_timeoutShutdown = true;
+TimeoutThread.wakeUp();
+TimeoutThread.join();
+
+delete _global;
+_global = nullptr;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index a2d4f0d..0a16d34 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -11,8 +11,10 @@
 
 #include 
 #include 
+#include 
 
 class UnitHooks;
+class UnitTimeout;
 class UnitHTTPServerRequest;
 class UnitHTTPServerResponse;
 
@@ -25,9 +27,13 @@ extern "C" { UnitHooks *unit_create(void); }
 /// Derive your unit test / hooks from me.
 class UnitHooks
 {
+friend UnitTimeout;
+
 void *_dlHandle;
 bool _setRetValue;
 int  _retValue;
+int  _timeoutMilliSeconds;
+std::atomic _timeoutShutdown;
 static UnitHooks *_global;
 
 void setHandle(void *dlHandle) { _dlHandle = dlHandle; }
@@ -36,6 +42,9 @@ protected:
 
 //  Helper API 
 
+/// After this time we invoke 'timeout' default 30 seconds
+void setTimeout(int timeoutMilliSeconds);
+
 enum TestResult { TEST_FAILED, TEST_OK, TEST_TIMED_OUT };
 /// Encourages loolwsd to exit with this value (unless hooked)
 void exitTest(TestResult result);
@@ -63,7 +72,7 @@ public:
virtual void returnValue(int & /* retValue */);
 /// When a new child kit process reports
 virtual void newChild() {}
-/// If the test times out this gets invoked
+/// If the test times out this gets invoked, default exits.
 virtual void timeout();
 /// Intercept createStorage
 virtual bool createStorage(const std::string& /* jailRoot */,
diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index 03f3718..f0a9c21 100644
--- a/loolwsd/test/Makefile.am
+++ b/loolwsd/test/Makefile.am
@@ -11,7 +11,7 @@ check_PROGRAMS = test
 
 AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
 
-lib_LTLIBRARIES = unit-prefork.la unit-storage.la
+lib_LTLIBRARIES = unit-timeout.la unit-prefork.la unit-storage.la
 
 AM_CPPFLAGS = -pthread -I$(top_srcdir)
 
@@ -22,6 +22,8 @@ test_LDADD = $(CPPUNIT_LIBS)
 test_SOURCES = httpposttest.cpp httpwstest.cpp test.cpp ../LOOLProtocol.cpp
 
 # unit test modules:
+unit_timeout_la_SOURCES = UnitTimeout.cpp
+unit_timeout_la_LDFLAGS = -module
 unit_prefork_la_SOURCES = UnitPrefork.cpp
 unit_prefork_la_LDFLAGS = -module
 unit_storage_la_SOURCES = UnitStorage.cpp
@@ -39,7