Browse Source

YT-21472: Fixes after review
6645437824fbb78fd206abdf2a06f385ea541cc0

don-dron 11 months ago
parent
commit
d7698e9e5e
3 changed files with 19 additions and 24 deletions
  1. 12 17
      yt/yt/core/misc/error.cpp
  2. 1 1
      yt/yt/core/misc/error.h
  3. 6 6
      yt/yt/core/rpc/unittests/rpc_ut.cpp

+ 12 - 17
yt/yt/core/misc/error.cpp

@@ -942,35 +942,30 @@ void TError::Load(TStreamLoadContext& context)
 
 std::optional<TError> TError::FindMatching(TErrorCode code) const
 {
-    if (!Impl_) {
-        return {};
-    }
-
-    if (GetCode() == code) {
-        return *this;
-    }
-
-    for (const auto& innerError : InnerErrors()) {
-        if (auto innerResult = innerError.FindMatching(code)) {
-            return innerResult;
-        }
-    }
-
-    return {};
+    return FindMatching([&] (TErrorCode errorCode) {
+        return code == errorCode;
+    });
 }
 
 std::optional<TError> TError::FindMatching(const THashSet<TErrorCode>& codes) const
+{
+    return FindMatching([&] (TErrorCode code) {
+        return codes.contains(code);
+    });
+}
+
+std::optional<TError> TError::FindMatching(std::function<bool(TErrorCode)> filter) const
 {
     if (!Impl_) {
         return {};
     }
 
-    if (codes.contains(GetCode())) {
+    if (filter(GetCode())) {
         return *this;
     }
 
     for (const auto& innerError : InnerErrors()) {
-        if (auto innerResult = innerError.FindMatching(codes)) {
+        if (auto innerResult = innerError.FindMatching(filter)) {
             return innerResult;
         }
     }

+ 1 - 1
yt/yt/core/misc/error.h

@@ -188,8 +188,8 @@ public:
 
     void ThrowOnError() const;
 
+    std::optional<TError> FindMatching(std::function<bool(TErrorCode)> filter) const;
     std::optional<TError> FindMatching(TErrorCode code) const;
-
     std::optional<TError> FindMatching(const THashSet<TErrorCode>& codes) const;
 
     template <class... TArgs>

+ 6 - 6
yt/yt/core/rpc/unittests/rpc_ut.cpp

@@ -529,7 +529,7 @@ TYPED_TEST(TNotGrpcTest, TrackedRegularAttachments)
     // header + body = 110 bytes.
     // attachments = 22 bytes.
     // sum is 4228 bytes.
-    EXPECT_TRUE(4228 + 32768 <= memoryUsageTracker->GetTotalUsage());
+    EXPECT_GE(memoryUsageTracker->GetTotalUsage(), 4228 + 32768);
     EXPECT_EQ(3u, attachments.size());
     EXPECT_EQ("Hello_",     StringFromSharedRef(attachments[0]));
     EXPECT_EQ("from_",      StringFromSharedRef(attachments[1]));
@@ -595,9 +595,9 @@ TYPED_TEST(TNotGrpcTest, Compression)
     // attachmentStrings[1].size() = 36 * 2 bytes from decoder.
     // attachmentStrings[2].size() = 90 * 2 bytes from decoder.
     // sum is 4591 bytes.
-    EXPECT_TRUE(4591 + 32768 <= memoryUsageTracker->GetTotalUsage());
+    EXPECT_GE(memoryUsageTracker->GetTotalUsage(), 4591 + 32768);
     EXPECT_TRUE(rsp->message() == message);
-    EXPECT_TRUE(rsp->GetResponseMessage().Size() >= 2);
+    EXPECT_GE(rsp->GetResponseMessage().Size(), static_cast<size_t>(2));
     const auto& serializedResponseBody = SerializeProtoToRefWithCompression(*rsp, responseCodecId);
     const auto& compressedResponseBody = rsp->GetResponseMessage()[1];
     EXPECT_TRUE(TRef::AreBitwiseEqual(compressedResponseBody, serializedResponseBody));
@@ -846,7 +846,7 @@ TYPED_TEST(TNotGrpcTest, MemoryTracking)
 
         // 1261568 = 32768 + 1228800 = 32768 + 4096 * 300 + 300 * 110 (header + body).
         // 32768 - socket buffers, 4096 - default size per request.
-        EXPECT_TRUE(rpcUsage >= 1294568);
+        EXPECT_GE(rpcUsage, 1294568);
     }
 }
 
@@ -866,7 +866,7 @@ TYPED_TEST(TNotGrpcTest, MemoryTrackingMultipleConnections)
         // 11059200 / 300 = 36974 = 32768 + 4096 + 110 (header + body).
         // 4 KB - stub for request.
         // See NYT::NBus::TPacketDecoder::TChunkedMemoryTrackingAllocator::Allocate.
-        EXPECT_TRUE(11092200 <= memoryUsageTracker->GetTotalUsage());
+        EXPECT_GE(memoryUsageTracker->GetTotalUsage(), 11092200);
     }
 }
 
@@ -922,7 +922,7 @@ TYPED_TEST(TNotGrpcTest, MemoryOvercommit)
         // default stub = 4096.
         // header + body = 110 bytes.
         // attachments = 6_KB  kbytes.
-        EXPECT_TRUE(rpcUsage >= 32768 + 4096 + 6144 + 110);
+        EXPECT_GE(rpcUsage, 32768 + 4096 + 6144 + 110);
     }
 }