diff --git a/score/datarouter/test/ut/ut_logging/test_unix_domain_server.cpp b/score/datarouter/test/ut/ut_logging/test_unix_domain_server.cpp index 79901ceb..8734bc5e 100644 --- a/score/datarouter/test/ut/ut_logging/test_unix_domain_server.cpp +++ b/score/datarouter/test/ut/ut_logging/test_unix_domain_server.cpp @@ -270,7 +270,8 @@ UnixDomainSockAddr MakeTempAddrAbstractFalse(std::string& name) return UnixDomainSockAddr(name, /*isAbstract=*/false); } -/// Block until the filesystem socket at \p path exists (i.e. bind() completed). +/// Block until the server at \p path is accepting connections (i.e. listen() completed). +/// A successful non-blocking connect() proves the server passed both bind() and listen(). /// Returns true on success, false on timeout. bool WaitForSocketFile(const std::string& path, std::chrono::milliseconds timeout = std::chrono::milliseconds(5000)) { @@ -278,10 +279,18 @@ bool WaitForSocketFile(const std::string& path, std::chrono::milliseconds timeou auto deadline = std::chrono::steady_clock::now() + timeout; while (std::chrono::steady_clock::now() < deadline) { - struct stat st{}; - if (::stat(path.c_str(), &st) == 0 && (st.st_mode & S_IFSOCK) != 0) + int fd = ::socket(AF_UNIX, SOCK_STREAM, 0); + if (fd >= 0) { - return true; + sockaddr_un su{}; + su.sun_family = AF_UNIX; + std::strncpy(su.sun_path, path.c_str(), sizeof(su.sun_path) - 1); + if (::connect(fd, reinterpret_cast(&su), sizeof(su)) == 0) + { + ::close(fd); + return true; + } + ::close(fd); } std::this_thread::sleep_for(kPollInterval); }