[icinga-checkins] icinga.org: icinga2/master: Fix crash in the unit tests

git at icinga.org git at icinga.org
Wed Nov 12 09:34:34 CET 2014


Module: icinga2
Branch: master
Commit: 02c559eff906d0aaec13bcd270884e55d0159821
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=02c559eff906d0aaec13bcd270884e55d0159821

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Nov 12 09:33:13 2014 +0100

Fix crash in the unit tests

fixes #7648

---

 icinga-app/icinga.cpp    |    6 ++----
 lib/base/application.cpp |   13 +++++++++++++
 lib/base/application.hpp |    1 +
 lib/base/timer.cpp       |    3 +++
 test/base-timer.cpp      |   15 +--------------
 test/test.cpp            |    5 +++++
 6 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp
index b59ff4f..e05ee9c 100644
--- a/icinga-app/icinga.cpp
+++ b/icinga-app/icinga.cpp
@@ -422,10 +422,6 @@ int Main(void)
 		rc = command->Run(vm, args);
 	}
 
-#ifndef _DEBUG
-	Application::Exit(rc);
-#endif /* _DEBUG */
-
 	return rc;
 }
 
@@ -581,6 +577,8 @@ VOID WINAPI ServiceMain(DWORD argc, LPSTR *argv)
 	int rc = Main();
 
 	ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, rc);
+
+	Application::Exit(rc);
 }
 #endif /* _WIN32 */
 
diff --git a/lib/base/application.cpp b/lib/base/application.cpp
index 27be627..fe65121 100644
--- a/lib/base/application.cpp
+++ b/lib/base/application.cpp
@@ -109,11 +109,19 @@ void Application::Exit(int rc)
 		logger->Flush();
 	}
 
+	UninitializeBase();
+
+#ifdef _DEBUG
+	exit(rc);
+#else /* _DEBUG */
 	_exit(rc); // Yay, our static destructors are pretty much beyond repair at this point.
+#endif /* _DEBUG */
 }
 
 void Application::InitializeBase(void)
 {
+	Timer::Initialize();
+
 #ifndef _WIN32
 	rlimit rl;
 	if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) {
@@ -146,6 +154,11 @@ void Application::InitializeBase(void)
 	Utility::ExecuteDeferredInitializers();
 }
 
+void Application::UninitializeBase(void)
+{
+	Timer::Uninitialize();
+}
+
 /**
  * Retrieves a pointer to the application singleton object.
  *
diff --git a/lib/base/application.hpp b/lib/base/application.hpp
index 42db856..862237a 100644
--- a/lib/base/application.hpp
+++ b/lib/base/application.hpp
@@ -43,6 +43,7 @@ public:
 	~Application(void);
 
 	static void InitializeBase(void);
+	static void UninitializeBase(void);
 
 	static Application::Ptr GetInstance(void);
 
diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp
index 7538a16..d07774c 100644
--- a/lib/base/timer.cpp
+++ b/lib/base/timer.cpp
@@ -150,6 +150,9 @@ void Timer::Stop(void)
 {
 	ASSERT(!OwnsLock());
 
+	if (l_StopThread)
+		return;
+
 	boost::mutex::scoped_lock lock(l_Mutex);
 
 	m_Started = false;
diff --git a/test/base-timer.cpp b/test/base-timer.cpp
index 115d954..713597e 100644
--- a/test/base-timer.cpp
+++ b/test/base-timer.cpp
@@ -25,20 +25,7 @@
 
 using namespace icinga;
 
-struct TimerFixture
-{
-	TimerFixture(void)
-	{
-		Timer::Initialize();
-	}
-
-	~TimerFixture(void)
-	{
-		Timer::Uninitialize();
-	}
-};
-
-BOOST_FIXTURE_TEST_SUITE(base_timer, TimerFixture)
+BOOST_AUTO_TEST_SUITE(base_timer)
 
 BOOST_AUTO_TEST_CASE(construct)
 {
diff --git a/test/test.cpp b/test/test.cpp
index af024d6..4076eae 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -31,6 +31,11 @@ struct InitLibBase
 	{
 		Application::InitializeBase();
 	}
+
+	~InitLibBase(void)
+	{
+		Application::UninitializeBase();
+	}
 };
 
 BOOST_GLOBAL_FIXTURE(InitLibBase);



More information about the icinga-checkins mailing list