This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch revert-804-hotfix/shaky-test-timeout in repository https://gitbox.apache.org/repos/asf/celix.git
commit 5573dd6a8dbcd49cf635fd2e81302f1f0fa5e423 Author: PengZheng <[email protected]> AuthorDate: Sat Oct 18 13:45:54 2025 +0800 Revert "Hotfix/Replace sleep with future/promise for reliability" --- .../framework/gtest/src/CelixFrameworkTestSuite.cc | 30 ++++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/libs/framework/gtest/src/CelixFrameworkTestSuite.cc b/libs/framework/gtest/src/CelixFrameworkTestSuite.cc index 82a002bdc..b428dc8b4 100644 --- a/libs/framework/gtest/src/CelixFrameworkTestSuite.cc +++ b/libs/framework/gtest/src/CelixFrameworkTestSuite.cc @@ -28,7 +28,6 @@ #include "celix_framework.h" #include "framework_private.h" #include "celix_constants.h" -#include "celix_log.h" #include "celix_utils.h" class CelixFrameworkTestSuite : public ::testing::Test { @@ -100,34 +99,25 @@ TEST_F(CelixFrameworkTestSuite, GenericEventTimeoutPropertyTest) { ASSERT_TRUE(fw != nullptr); // Start capturing stdout - std::promise<std::string> p; - std::future<std::string> f = p.get_future(); - celix_frameworkLogger_setLogCallback(fw->logger, &p, - [](void* handle, celix_log_level_e, const char*, const char *, int, const char *format, va_list formatArgs) { - auto* p = static_cast<std::promise<std::string>*>(handle); - // format std::string from format and formatArgs - char buffer[1024]; - vsnprintf(buffer, sizeof(buffer), format, formatArgs); - auto log = std::string(buffer); - auto expected = "Generic event 'test' (id=" + std::to_string(100) + ")"; - if (log.find(expected) != std::string::npos) { - p->set_value(log); - } - }); + ::testing::internal::CaptureStderr(); + //When there is a emtpy event queue celix_framework_waitForEmptyEventQueue(fw); //And a generic event is fired, that block the queue for 20ms - auto callback = [](void* data) { - auto* f = static_cast<std::future<std::string>*>(data); - f->wait(); + auto callback = [](void* /*data*/) { + std::this_thread::sleep_for(std::chrono::milliseconds{20}); }; - long eventId = celix_framework_fireGenericEvent(fw, 100L, -1L, "test", &f, callback, nullptr, nullptr); - EXPECT_EQ(100L, eventId); + long eventId = celix_framework_fireGenericEvent(fw, -1L, -1L, "test", nullptr, callback, nullptr, nullptr); //Then waiting for the event queue will have logged errors celix_framework_waitForGenericEvent(fw, eventId); + // And the log will contain a printed warning + auto log = ::testing::internal::GetCapturedStderr(); + auto expected = "Generic event 'test' (id=" + std::to_string(eventId) + ")"; + EXPECT_TRUE(log.find(expected) != std::string::npos) << "Got " << log; + // Cleanup framework celix_frameworkFactory_destroyFramework(fw); }
