From 2d670ad69235b111bb1ef59a32cf4027e62f8a76 Mon Sep 17 00:00:00 2001 From: Mykhailo Diachenko <55983336+diachenko-mischa@users.noreply.github.com> Date: Wed, 14 Oct 2026 16:42:56 +0300 Subject: [PATCH] Increase expiry threshold in LruCacheEviction test In shared containerized environment timeouts may be not stable. Locally it can be reproduced running heavy build in parallel. There's no need to keep this timeout too small as it should just keep the key alive. Relates-To: DATASDK-110 Signed-off-by: Rustam Gamidov --- .../src/http/curl/NetworkCurl.cpp | 81 ++++++++++++++----- .../tests/cache/DefaultCacheImplTest.cpp | 4 +- 2 files changed, 62 insertions(+), 23 deletions(-) diff --git a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp index ef9849888..3296e4af1 100644 --- a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp +++ b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp @@ -164,6 +164,63 @@ int BlockSigpipeResult = BlockSigpipe(); #endif // IGNORE_SIGPIPE +#ifdef OLP_SDK_NETWORK_HAS_PIPE2 +#ifdef __APPLE__ +// Apple SDKs declare pipe2() (so CMake detects it), but it only exists at +// runtime starting with OS version 27; calling it on older systems crashes. +__API_AVAILABLE(macos(27.0), ios(27.0), tvos(27.0), watchos(27.0), + visionos(27.0)) +#endif +bool CreatePipeWithPipe2(int (&fds)[2]) { + if (pipe2(fds, O_NONBLOCK)) { + OLP_SDK_LOG_ERROR(kLogTag, "pipe2 failed, errno=" << errno); + return false; + } + return true; +} +#endif + +#if defined(OLP_SDK_NETWORK_HAS_PIPE) && \ + (!defined(OLP_SDK_NETWORK_HAS_PIPE2) || defined(__APPLE__)) +bool CreatePipeWithFcntl(int (&fds)[2]) { + if (pipe(fds)) { + OLP_SDK_LOG_ERROR(kLogTag, "pipe failed, errno=" << errno); + return false; + } + + for (int fd : fds) { + int flags = fcntl(fd, F_GETFL); + if (flags == -1) { + flags = 0; + } + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) { + OLP_SDK_LOG_ERROR(kLogTag, "fcntl for pipe failed, errno=" << errno); + close(fds[0]); + close(fds[1]); + return false; + } + } + return true; +} +#endif + +#if defined(OLP_SDK_NETWORK_HAS_PIPE) || defined(OLP_SDK_NETWORK_HAS_PIPE2) +// Creates a pipe with both ends set to non-blocking mode. +bool CreateNonBlockingPipe(int (&fds)[2]) { +#if defined(OLP_SDK_NETWORK_HAS_PIPE2) && defined(__APPLE__) + if (__builtin_available(macOS 27.0, iOS 27.0, tvOS 27.0, watchOS 27.0, + visionOS 27.0, *)) { + return CreatePipeWithPipe2(fds); + } + return CreatePipeWithFcntl(fds); +#elif defined(OLP_SDK_NETWORK_HAS_PIPE2) + return CreatePipeWithPipe2(fds); +#else + return CreatePipeWithFcntl(fds); +#endif +} +#endif + #if CURL_AT_LEAST_VERSION(8, 16, 0) using CurlProxyType = long; #else @@ -535,29 +592,11 @@ bool NetworkCurl::Initialize() { } bool NetworkCurl::Impl::Initialize() { -#ifdef OLP_SDK_NETWORK_HAS_PIPE2 - if (pipe2(pipe_, O_NONBLOCK)) { - OLP_SDK_LOG_ERROR(kLogTag, "pipe2 failed, this=" << this); - return false; - } -#elif defined OLP_SDK_NETWORK_HAS_PIPE - if (pipe(pipe_)) { - OLP_SDK_LOG_ERROR(kLogTag, "pipe failed, this=" << this); +#if defined(OLP_SDK_NETWORK_HAS_PIPE) || defined(OLP_SDK_NETWORK_HAS_PIPE2) + if (!CreateNonBlockingPipe(pipe_)) { + OLP_SDK_LOG_ERROR(kLogTag, "Failed to create pipe, this=" << this); return false; } - // Set read and write pipes non blocking - for (size_t i = 0u; i < 2u; ++i) { - int flags = fcntl(pipe_[i], F_GETFL); - if (flags == -1) { - flags = 0; - } - if (fcntl(pipe_[i], F_SETFL, flags | O_NONBLOCK)) { - OLP_SDK_LOG_ERROR(kLogTag, __PRETTY_FUNCTION__ << ". fcntl for pipe[" << i - << "] failed. Error " - << errno); - return false; - } - } #endif // cURL setup diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index 6fed681f6..101ba7ad8 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -817,9 +817,9 @@ TEST_F(DefaultCacheImplTest, LruCacheEviction) { const auto not_expired_key = prefix + std::to_string(0); - // Put data that expires after 10 sec and never promoted. + // Put data that expires after 60 sec and never promoted. cache.Put(not_expired_key, - std::make_shared>(binary_data), 10); + std::make_shared>(binary_data), 60); // overflow the mutable cache auto count = 1u;