Skip to content

Commit

Permalink
Fix: Unit tests randomly crash after the tests have completed
Browse files Browse the repository at this point in the history
fixes #12610
  • Loading branch information
gunnarbeutner committed Sep 7, 2016
1 parent 7d13b12 commit 1dc4ab3
Show file tree
Hide file tree
Showing 28 changed files with 75 additions and 94 deletions.
6 changes: 4 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software Foundation
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

set(Boost_USE_STATIC_LIBS OFF)

include(BoostTestTargets)

set(base_test_SOURCES
Expand All @@ -31,7 +33,7 @@ if(ICINGA2_UNITY_BUILD)
endif()

add_boost_test(base
SOURCES base-test.cpp ${base_test_SOURCES}
SOURCES test-runner.cpp ${base_test_SOURCES}
LIBRARIES base config icinga
TESTS base_array/construct
base_array/getset
Expand Down Expand Up @@ -123,7 +125,7 @@ if(ICINGA2_WITH_LIVESTATUS)
endif()

add_boost_test(livestatus
SOURCES livestatus-test.cpp ${livestatus_test_SOURCES}
SOURCES test-runner.cpp livestatus-fixture.cpp ${livestatus_test_SOURCES}
LIBRARIES base config icinga livestatus
DEPENDENCIES methods
TESTS livestatus/hosts livestatus/services
Expand Down
2 changes: 1 addition & 1 deletion test/base-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "base/array.hpp"
#include "base/objectlock.hpp"
#include "base/json.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/base-convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "base/convert.hpp"
#include "base/object.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <iostream>

using namespace icinga;
Expand Down
2 changes: 1 addition & 1 deletion test/base-dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "base/dictionary.hpp"
#include "base/objectlock.hpp"
#include "base/json.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <boost/tuple/tuple.hpp>

using namespace icinga;
Expand Down
2 changes: 1 addition & 1 deletion test/base-fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "base/fifo.hpp"
#include "base/objectlock.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/base-json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "base/dictionary.hpp"
#include "base/objectlock.hpp"
#include "base/json.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <boost/tuple/tuple.hpp>

using namespace icinga;
Expand Down
2 changes: 1 addition & 1 deletion test/base-match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "base/utility.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/base-netstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "base/netstring.hpp"
#include "base/fifo.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/base-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "base/object.hpp"
#include "base/value.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/base-serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "base/serializer.hpp"
#include "base/array.hpp"
#include "base/dictionary.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <boost/tuple/tuple.hpp>

using namespace icinga;
Expand Down
2 changes: 1 addition & 1 deletion test/base-shellescape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "base/utility.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <iostream>

using namespace icinga;
Expand Down
2 changes: 1 addition & 1 deletion test/base-stacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "base/stacktrace.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/base-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "base/stdiostream.hpp"
#include "base/string.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <sstream>

using namespace icinga;
Expand Down
2 changes: 1 addition & 1 deletion test/base-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "base/string.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
48 changes: 0 additions & 48 deletions test/base-test.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/base-timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "base/timer.hpp"
#include "base/utility.hpp"
#include "base/application.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/base-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "base/objectlock.hpp"
#include "base/application.hpp"
#include "base/type.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <boost/tuple/tuple.hpp>

using namespace icinga;
Expand Down
2 changes: 1 addition & 1 deletion test/base-value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "base/value.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/config-ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "config/configcompiler.hpp"
#include "base/exception.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/icinga-checkresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "icinga/host.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/icinga-macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "icinga/macroprocessor.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/icinga-perfdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "icinga/perfdatavalue.hpp"
#include "icinga/pluginutility.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
20 changes: 2 additions & 18 deletions test/livestatus-test.cpp → test/livestatus-fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/

#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE icinga2_test

#include "config/configcompiler.hpp"
#include "config/configitem.hpp"
#include "base/application.hpp"
#include "base/loader.hpp"
#include <fstream>
#include <BoostTestTargetConfig.h>

using namespace icinga;
Expand All @@ -33,22 +29,11 @@ struct LivestatusFixture
{
LivestatusFixture(void)
{
BOOST_TEST_MESSAGE("setup global config fixture");

Application::InitializeBase();

BOOST_TEST_MESSAGE( "Preparing config objects...");
BOOST_TEST_MESSAGE("Preparing config objects...");

ConfigItem::RunWithActivationContext(new Function("CreateTestObjects", WrapFunction(CreateTestObjects)));
}

~LivestatusFixture(void)
{
BOOST_TEST_MESSAGE("cleanup global config fixture");

Application::UninitializeBase();
}

static void CreateTestObjects(void)
{
String config = R"CONFIG(
Expand Down Expand Up @@ -78,5 +63,4 @@ apply Service "livestatus" {
}
};

BOOST_GLOBAL_FIXTURE(LivestatusFixture);

BOOST_GLOBAL_FIXTURE(LivestatusFixture);
2 changes: 1 addition & 1 deletion test/livestatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "base/application.hpp"
#include "base/stdiostream.hpp"
#include "base/json.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/remote-base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
******************************************************************************/

#include "remote/base64.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>

using namespace icinga;

Expand Down
2 changes: 1 addition & 1 deletion test/remote-url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "base/array.hpp"
#include "remote/url.hpp"
#include <boost/test/unit_test.hpp>
#include <BoostTestTargetConfig.h>
#include <boost/assign/list_of.hpp>

using namespace icinga;
Expand Down
45 changes: 45 additions & 0 deletions test/test-runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software Foundation *
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/

#include "icinga/icingaapplication.hpp"
#include "base/application.hpp"
#include <BoostTestTargetConfig.h>

using namespace icinga;

static bool init_unit_test(void)
{
return true;
}

int main(int argc, char *argv[])
{
Application::InitializeBase();

IcingaApplication::Ptr appInst;

appInst = new IcingaApplication();
static_pointer_cast<ConfigObject>(appInst)->OnConfigLoaded();

int rc = boost::unit_test::unit_test_main(&init_unit_test, argc, argv);

appInst.reset();

Application::Exit(rc);
}
4 changes: 1 addition & 3 deletions third-party/cmake/BoostTestTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ if(Boost_FOUND AND NOT "${Boost_VERSION}0" LESS "1034000")
if(Boost_USE_STATIC_LIBS)
set(_boostConfig "BoostTestTargetsStatic.h")
else()
if(NOT APPLE)
set(_boostConfig "BoostTestTargetsDynamic.h")
endif()
set(_boostConfig "BoostTestTargetsDynamic.h")
endif()
endif()
get_filename_component(_moddir ${CMAKE_CURRENT_LIST_FILE} PATH)
Expand Down

0 comments on commit 1dc4ab3

Please sign in to comment.