Browse Source

[3533] Reset logging when unit tests exit

Some unit tests in dhcpsrv altered the logging configuration but
never reset it. That configuration was then used for subsequent
tests and made them overly verbose.
Stephen Morris 10 years ago
parent
commit
ad896487cf

+ 2 - 0
src/lib/dhcpsrv/tests/dbaccess_parser_unittest.cc

@@ -19,6 +19,7 @@
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <config/ccsession.h>
 #include <gtest/gtest.h>
+#include <log/logger_unittest_support.h>
 
 #include <map>
 #include <string>
@@ -47,6 +48,7 @@ public:
     /// (the last in particular).
     ~DbAccessParserTest() {
         LeaseMgrFactory::destroy();
+        isc::log::resetUnitTestRootLogger();
     }
 
     /// @brief Build JSON String

+ 27 - 5
src/lib/dhcpsrv/tests/logging_unittest.cc

@@ -17,6 +17,7 @@
 #include <cc/data.h>
 #include <dhcpsrv/logging.h>
 #include <gtest/gtest.h>
+#include <log/logger_support.h>
 
 using namespace isc;
 using namespace isc::dhcp;
@@ -24,8 +25,29 @@ using namespace isc::data;
 
 namespace {
 
+/// @brief Logging Test Fixture Class
+///
+/// Trivial class that ensures that the logging is reset to its defaults after
+/// each test.  Strictly speaking this only resets the testing root logger (which
+/// has the name "kea") but as the only other logger mentioned here ("wombat")
+/// is not used elsewhere, that is sufficient.
+
+class LoggingTest : public ::testing::Test {
+    public:
+        /// @brief Constructor
+        LoggingTest() {}
+
+        /// @brief Destructor
+        ///
+        /// Reset root logger back to defaults.
+        ~LoggingTest() {
+            isc::log::resetUnitTestRootLogger();
+        }
+};
+
+
 // Checks that contructor is able to process specified storage properly
-TEST(LoggingTest, constructor) {
+TEST_F(LoggingTest, constructor) {
 
     ConfigurationPtr null_ptr;
     EXPECT_THROW(LogConfigParser parser(null_ptr), BadValue);
@@ -38,7 +60,7 @@ TEST(LoggingTest, constructor) {
 // Checks if the LogConfigParser class is able to transform JSON structures
 // into Configuration usable by log4cplus. This test checks for output
 // configured to stdout on debug level.
-TEST(LoggingTest, parsingConsoleOutput) {
+TEST_F(LoggingTest, parsingConsoleOutput) {
 
     const char* config_txt =
     "{ \"loggers\": ["
@@ -79,7 +101,7 @@ TEST(LoggingTest, parsingConsoleOutput) {
 // Checks if the LogConfigParser class is able to transform JSON structures
 // into Configuration usable by log4cplus. This test checks for output
 // configured to a file on INFO level.
-TEST(LoggingTest, parsingFile) {
+TEST_F(LoggingTest, parsingFile) {
 
     const char* config_txt =
     "{ \"loggers\": ["
@@ -119,7 +141,7 @@ TEST(LoggingTest, parsingFile) {
 // Checks if the LogConfigParser class is able to transform data structures
 // into Configuration usable by log4cplus. This test checks that more than
 // one logger can be configured.
-TEST(LoggingTest, multipleLoggers) {
+TEST_F(LoggingTest, multipleLoggers) {
 
     const char* config_txt =
     "{ \"loggers\": ["
@@ -174,7 +196,7 @@ TEST(LoggingTest, multipleLoggers) {
 // Checks if the LogConfigParser class is able to transform data structures
 // into Configuration usable by log4cplus. This test checks that more than
 // one logging destination can be configured.
-TEST(LoggingTest, multipleLoggingDestinations) {
+TEST_F(LoggingTest, multipleLoggingDestinations) {
 
     const char* config_txt =
     "{ \"loggers\": ["