diff --git a/lib/core/unittest/CLoggerTest.cc b/lib/core/unittest/CLoggerTest.cc index e984b72b15..9c88c872a1 100644 --- a/lib/core/unittest/CLoggerTest.cc +++ b/lib/core/unittest/CLoggerTest.cc @@ -150,11 +150,18 @@ void CLoggerTest::testNonAsciiJsonLogging() { std::ostringstream loggedData; std::thread reader([&loggedData] { - // wait a bit so that pipe has been created - ml::core::CSleep::sleep(200); - std::ifstream strm(TEST_PIPE_NAME); - std::copy(std::istreambuf_iterator(strm), std::istreambuf_iterator(), - std::ostreambuf_iterator(loggedData)); + for (std::size_t attempt = 1; attempt <= 100; ++attempt) { + // wait a bit so that pipe has been created + ml::core::CSleep::sleep(50); + std::ifstream strm(TEST_PIPE_NAME); + if (strm.is_open()) { + std::copy(std::istreambuf_iterator(strm), + std::istreambuf_iterator(), + std::ostreambuf_iterator(loggedData)); + return; + } + } + CPPUNIT_FAIL("Failed to connect to logging pipe within a reasonable time"); }); ml::core::CLogger& logger = ml::core::CLogger::instance();