|
29 | 29 | #include "Poco/FastLogger.h" |
30 | 30 | #endif |
31 | 31 | #include "Poco/NullChannel.h" |
| 32 | +#include "Poco/AsyncChannel.h" |
| 33 | +#include "Poco/Util/LoggingSubsystem.h" |
32 | 34 | #include <sstream> |
33 | 35 |
|
34 | 36 |
|
@@ -463,6 +465,39 @@ void LoggingConfiguratorTest::testBadConfiguration3() |
463 | 465 | } |
464 | 466 |
|
465 | 467 |
|
| 468 | +void LoggingConfiguratorTest::testAsyncChannelShutdown() |
| 469 | +{ |
| 470 | + // Test that LoggingSubsystem::uninitialize() properly shuts down |
| 471 | + // AsyncChannel without deadlocking (GitHub issue #5228). |
| 472 | + |
| 473 | + static const std::string config = |
| 474 | + "logging.loggers.root.channel = asyncChan\n" |
| 475 | + "logging.loggers.root.level = debug\n" |
| 476 | + "logging.channels.asyncChan.class = AsyncChannel\n" |
| 477 | + "logging.channels.asyncChan.channel = nullChan\n" |
| 478 | + "logging.channels.nullChan.class = NullChannel\n"; |
| 479 | + |
| 480 | + std::istringstream istr(config); |
| 481 | + AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr); |
| 482 | + |
| 483 | + LoggingConfigurator configurator; |
| 484 | + configurator.configure(pConfig); |
| 485 | + |
| 486 | + Logger& root = Logger::get(""); |
| 487 | + assertTrue (root.getLevel() == Message::PRIO_DEBUG); |
| 488 | + |
| 489 | + // Log some messages to ensure the async thread is running |
| 490 | + root.information("Test message 1"); |
| 491 | + root.information("Test message 2"); |
| 492 | + root.information("Test message 3"); |
| 493 | + |
| 494 | + // Simulate what LoggingSubsystem::uninitialize() does. |
| 495 | + // This must not deadlock. |
| 496 | + Logger::shutdown(); |
| 497 | + LoggingRegistry::defaultRegistry().clear(); |
| 498 | +} |
| 499 | + |
| 500 | + |
466 | 501 | void LoggingConfiguratorTest::testBadConfiguration4() |
467 | 502 | { |
468 | 503 | // this is mainly testing for memory leaks in case of |
@@ -528,6 +563,7 @@ CppUnit::Test* LoggingConfiguratorTest::suite() |
528 | 563 | CppUnit_addTest(pSuite, LoggingConfiguratorTest, testFastLoggerWithRegistry); |
529 | 564 | CppUnit_addTest(pSuite, LoggingConfiguratorTest, testFastLoggerOptions); |
530 | 565 | CppUnit_addTest(pSuite, LoggingConfiguratorTest, testFastLoggerOptionsWarnings); |
| 566 | + CppUnit_addTest(pSuite, LoggingConfiguratorTest, testAsyncChannelShutdown); |
531 | 567 | CppUnit_addTest(pSuite, LoggingConfiguratorTest, testBadConfiguration1); |
532 | 568 | CppUnit_addTest(pSuite, LoggingConfiguratorTest, testBadConfiguration2); |
533 | 569 | CppUnit_addTest(pSuite, LoggingConfiguratorTest, testBadConfiguration3); |
|
0 commit comments