From 2cb6f649ddcf4ecbcd265a9f80de3630c8746e33 Mon Sep 17 00:00:00 2001 From: Matt Peters Date: Tue, 22 Feb 2022 06:41:46 -0700 Subject: Add feedback about failing checks in zcache.rpc.allpolicies --- zenserver-test/zenserver-test.cpp | 91 +++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp index 51863a861..bef2f9107 100644 --- a/zenserver-test/zenserver-test.cpp +++ b/zenserver-test/zenserver-test.cpp @@ -1974,7 +1974,7 @@ TEST_CASE("zcache.rpc.allpolicies") cpr::Response Result = cpr::Post(cpr::Url{fmt::format("{}/$rpc", BaseUri)}, cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}, {"Accept", "application/x-ue-cbpkg"}}, cpr::Body{(const char*)Body.GetData(), Body.GetSize()}); - CHECK(Result.status_code == 200); + CHECK_MESSAGE(Result.status_code == 200, WriteToString<32>("PutCacheRecords unexpectedly failed.").c_str()); } // PutCacheValues @@ -2013,7 +2013,7 @@ TEST_CASE("zcache.rpc.allpolicies") cpr::Response Result = cpr::Post(cpr::Url{fmt::format("{}/$rpc", BaseUri)}, cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}, {"Accept", "application/x-ue-cbpkg"}}, cpr::Body{(const char*)Body.GetData(), Body.GetSize()}); - CHECK(Result.status_code == 200); + CHECK_MESSAGE(Result.status_code == 200, WriteToString<32>("PutCacheValues unexpectedly failed.").c_str()); } for (KeyData& KeyData : KeyDatas) @@ -2022,11 +2022,12 @@ TEST_CASE("zcache.rpc.allpolicies") { if (!KeyData.UseValueAPI) { - CHECK(KeyData.ReceivedPut); + CHECK_MESSAGE(KeyData.ReceivedPut, WriteToString<32>("Key ", KeyData.KeyIndex, " was unexpectedly not put.").c_str()); } else { - CHECK(KeyData.ReceivedPutValue); + CHECK_MESSAGE(KeyData.ReceivedPutValue, + WriteToString<32>("Key ", KeyData.KeyIndex, " was unexpectedly not put to ValueAPI.").c_str()); } } } @@ -2064,13 +2065,14 @@ TEST_CASE("zcache.rpc.allpolicies") cpr::Response Result = cpr::Post(cpr::Url{fmt::format("{}/$rpc", BaseUri)}, cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}, {"Accept", "application/x-ue-cbpkg"}}, cpr::Body{(const char*)Body.GetData(), Body.GetSize()}); - CHECK(Result.status_code == 200); + CHECK_MESSAGE(Result.status_code == 200, WriteToString<32>("GetCacheRecords unexpectedly failed.").c_str()); CbPackage Response; bool Loaded = Response.TryLoad(zen::IoBuffer(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size())); - CHECK(Loaded); + CHECK_MESSAGE(Loaded, WriteToString<32>("GetCacheRecords response failed to load.").c_str()); CbObjectView ResponseObject = Response.GetObject(); CbArrayView Responses = ResponseObject["Result"sv].AsArrayView(); - CHECK(Responses.Num() == GetRequests.size()); + CHECK_MESSAGE(Responses.Num() == GetRequests.size(), + WriteToString<32>("GetCacheRecords response count did not match request count.").c_str()); int Index = 0; for (CbFieldView ResponseField : Responses) { @@ -2080,19 +2082,20 @@ TEST_CASE("zcache.rpc.allpolicies") CacheGetRequest& Request = GetRequests[Index++]; KeyData* KeyData = Request.Data->Data; KeyData->ReceivedGet = true; + WriteToString<32> Name("Get(", KeyData->KeyIndex, ")"); if (KeyData->ShouldBeHit) { - CHECK(Succeeded); + CHECK_MESSAGE(Succeeded, WriteToString<32>(Name, " unexpectedly failed.").c_str()); } else if (KeyData->ForceMiss) { - CHECK(!Succeeded); + CHECK_MESSAGE(!Succeeded, WriteToString<32>(Name, " unexpectedly succeeded.").c_str()); } if (!KeyData->ForceMiss && Succeeded) { CbArrayView ValuesArray = RecordView["Values"sv].AsArrayView(); - CHECK(ValuesArray.Num() == NumValues); + CHECK_MESSAGE(ValuesArray.Num() == NumValues, WriteToString<32>(Name, " number of values did not match.").c_str()); for (CbFieldView ValueField : ValuesArray) { @@ -2106,7 +2109,8 @@ TEST_CASE("zcache.rpc.allpolicies") break; } } - CHECK(ExpectedValueIndex < NumValues); + CHECK_MESSAGE(ExpectedValueIndex < NumValues, WriteToString<32>(Name, " could not find matching ValueId.").c_str()); + WriteToString<32> ValueName("Get(", KeyData->KeyIndex, ",", ExpectedValueIndex, ")"); IoHash ActualRawHash = ValueObject["RawHash"sv].AsHash(); const CbAttachment* Attachment = Response.FindAttachment(ActualRawHash); CompressedBuffer ActualBuffer = Attachment ? Attachment->AsCompressedBinary() : CompressedBuffer(); @@ -2120,16 +2124,19 @@ TEST_CASE("zcache.rpc.allpolicies") ActualRawSize = ValueObject["RawSize"sv].AsUInt64(UINT64_MAX); } CompressedBuffer ExpectedValue = KeyData->BufferValues[ExpectedValueIndex]; - CHECK(ActualRawHash == IoHash::FromBLAKE3(ExpectedValue.GetRawHash())); - CHECK(ActualRawSize == ExpectedValue.GetRawSize()); + CHECK_MESSAGE(ActualRawHash == IoHash::FromBLAKE3(ExpectedValue.GetRawHash()), + WriteToString<32>(ValueName, " RawHash did not match.").c_str()); + CHECK_MESSAGE(ActualRawSize == ExpectedValue.GetRawSize(), + WriteToString<32>(ValueName, " RawSize did not match.").c_str()); if (KeyData->GetRequestsData) { SharedBuffer Buffer = ActualBuffer.Decompress(); - CHECK(Buffer.GetSize() == ActualRawSize); + CHECK_MESSAGE(Buffer.GetSize() == ActualRawSize, + WriteToString<32>(ValueName, " BufferSize did not match RawSize.").c_str()); uint64_t ActualIntValue = ((const uint64_t*)Buffer.GetData())[0]; uint64_t ExpectedIntValue = KeyData->IntValues[ExpectedValueIndex]; - CHECK(ActualIntValue == ExpectedIntValue); + CHECK_MESSAGE(ActualIntValue == ExpectedIntValue, WriteToString<32>(ValueName, " had unexpected data.").c_str()); } } } @@ -2168,13 +2175,14 @@ TEST_CASE("zcache.rpc.allpolicies") cpr::Response Result = cpr::Post(cpr::Url{fmt::format("{}/$rpc", BaseUri)}, cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}, {"Accept", "application/x-ue-cbpkg"}}, cpr::Body{(const char*)Body.GetData(), Body.GetSize()}); - CHECK(Result.status_code == 200); + CHECK_MESSAGE(Result.status_code == 200, WriteToString<32>("GetCacheValues unexpectedly failed.").c_str()); CbPackage Response; bool Loaded = Response.TryLoad(zen::IoBuffer(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size())); - CHECK(Loaded); + CHECK_MESSAGE(Loaded, WriteToString<32>("GetCacheValues response failed to load.").c_str()); CbObjectView ResponseObject = Response.GetObject(); CbArrayView Responses = ResponseObject["Result"sv].AsArrayView(); - CHECK(Responses.Num() == GetValueRequests.size()); + CHECK_MESSAGE(Responses.Num() == GetValueRequests.size(), + WriteToString<32>("GetCacheValues response count did not match request count.").c_str()); int Index = 0; for (CbFieldView RequestResultView : Responses) { @@ -2186,14 +2194,15 @@ TEST_CASE("zcache.rpc.allpolicies") CacheGetValueRequest& Request = GetValueRequests[Index++]; KeyData* KeyData = Request.Data->Data; KeyData->ReceivedGetValue = true; + WriteToString<32> Name("GetValue("sv, KeyData->KeyIndex, ")"sv); if (KeyData->ShouldBeHit) { - CHECK(Succeeded); + CHECK_MESSAGE(Succeeded, WriteToString<32>(Name, " unexpectedly failed.").c_str()); } else if (KeyData->ForceMiss) { - CHECK(!Succeeded); + CHECK_MESSAGE(!Succeeded, WriteToString<32>(Name, "unexpectedly succeeded.").c_str()); } if (!KeyData->ForceMiss && Succeeded) { @@ -2209,16 +2218,17 @@ TEST_CASE("zcache.rpc.allpolicies") ActualRawSize = RequestResultObject["RawSize"sv].AsUInt64(UINT64_MAX); } CompressedBuffer ExpectedValue = KeyData->BufferValues[0]; - CHECK(ActualRawHash == IoHash::FromBLAKE3(ExpectedValue.GetRawHash())); - CHECK(ActualRawSize == ExpectedValue.GetRawSize()); + CHECK_MESSAGE(ActualRawHash == IoHash::FromBLAKE3(ExpectedValue.GetRawHash()), + WriteToString<32>(Name, " RawHash did not match.").c_str()); + CHECK_MESSAGE(ActualRawSize == ExpectedValue.GetRawSize(), WriteToString<32>(Name, " RawSize did not match.").c_str()); if (KeyData->GetRequestsData) { SharedBuffer Buffer = ActualBuffer.Decompress(); - CHECK(Buffer.GetSize() == ActualRawSize); + CHECK_MESSAGE(Buffer.GetSize() == ActualRawSize, WriteToString<32>(Name, " BufferSize did not match RawSize.").c_str()); uint64_t ActualIntValue = ((const uint64_t*)Buffer.GetData())[0]; uint64_t ExpectedIntValue = KeyData->IntValues[0]; - CHECK(ActualIntValue == ExpectedIntValue); + CHECK_MESSAGE(ActualIntValue == ExpectedIntValue, WriteToString<32>(Name, " had unexpected data.").c_str()); } } } @@ -2263,13 +2273,14 @@ TEST_CASE("zcache.rpc.allpolicies") cpr::Response Result = cpr::Post(cpr::Url{fmt::format("{}/$rpc", BaseUri)}, cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}, {"Accept", "application/x-ue-cbpkg"}}, cpr::Body{(const char*)Body.GetData(), Body.GetSize()}); - CHECK(Result.status_code == 200); + CHECK_MESSAGE(Result.status_code == 200, WriteToString<32>("GetCacheChunks unexpectedly failed.").c_str()); CbPackage Response; bool Loaded = Response.TryLoad(zen::IoBuffer(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size())); - CHECK(Loaded); + CHECK_MESSAGE(Loaded, WriteToString<32>("GetCacheChunks response failed to load.").c_str()); CbObjectView ResponseObject = Response.GetObject(); CbArrayView Responses = ResponseObject["Result"sv].AsArrayView(); - CHECK(Responses.Num() == ChunkRequests.size()); + CHECK_MESSAGE(Responses.Num() == ChunkRequests.size(), + WriteToString<32>("GetCacheChunks response count did not match request count.").c_str()); int Index = 0; for (CbFieldView RequestResultView : Responses) { @@ -2282,14 +2293,15 @@ TEST_CASE("zcache.rpc.allpolicies") KeyData* KeyData = Request.Data->Data; int ValueIndex = Request.Data->ValueIndex >= 0 ? Request.Data->ValueIndex : 0; KeyData->ReceivedChunk[ValueIndex] = true; + WriteToString<32> Name("GetChunks("sv, KeyData->KeyIndex, ","sv, ValueIndex, ")"sv); if (KeyData->ShouldBeHit) { - CHECK(Succeeded); + CHECK_MESSAGE(Succeeded, WriteToString<256>(Name, " unexpectedly failed."sv).c_str()); } else if (KeyData->ForceMiss) { - CHECK(!Succeeded); + CHECK_MESSAGE(!Succeeded, WriteToString<256>(Name, " unexpectedly succeeded."sv).c_str()); } if (KeyData->ShouldBeHit && Succeeded) { @@ -2305,16 +2317,17 @@ TEST_CASE("zcache.rpc.allpolicies") ActualRawSize = RequestResultObject["RawSize"sv].AsUInt64(UINT64_MAX); } CompressedBuffer ExpectedValue = KeyData->BufferValues[ValueIndex]; - CHECK(ActualRawHash == IoHash::FromBLAKE3(ExpectedValue.GetRawHash())); - CHECK(ActualRawSize == ExpectedValue.GetRawSize()); + CHECK_MESSAGE(ActualRawHash == IoHash::FromBLAKE3(ExpectedValue.GetRawHash()), + WriteToString<32>(Name, " had unexpected RawHash.").c_str()); + CHECK_MESSAGE(ActualRawSize == ExpectedValue.GetRawSize(), WriteToString<32>(Name, " had unexpected RawSize.").c_str()); if (KeyData->GetRequestsData) { SharedBuffer Buffer = ActualBuffer.Decompress(); - CHECK(Buffer.GetSize() == ActualRawSize); + CHECK_MESSAGE(Buffer.GetSize() == ActualRawSize, WriteToString<32>(Name, " BufferSize did not match RawSize.").c_str()); uint64_t ActualIntValue = ((const uint64_t*)Buffer.GetData())[0]; uint64_t ExpectedIntValue = KeyData->IntValues[ValueIndex]; - CHECK(ActualIntValue == ExpectedIntValue); + CHECK_MESSAGE(ActualIntValue == ExpectedIntValue, WriteToString<32>(Name, " had unexpected data.").c_str()); } } } @@ -2324,16 +2337,20 @@ TEST_CASE("zcache.rpc.allpolicies") { if (!KeyData.UseValueAPI) { - CHECK(KeyData.ReceivedGet); + CHECK_MESSAGE(KeyData.ReceivedGet, WriteToString<32>("Get(", KeyData.KeyIndex, ") was unexpectedly not received.").c_str()); for (int ValueIndex = 0; ValueIndex < NumValues; ++ValueIndex) { - CHECK(KeyData.ReceivedChunk[ValueIndex]); + CHECK_MESSAGE( + KeyData.ReceivedChunk[ValueIndex], + WriteToString<32>("GetChunks(", KeyData.KeyIndex, ",", ValueIndex, ") was unexpectedly not received.").c_str()); } } else { - CHECK(KeyData.ReceivedGetValue); - CHECK(KeyData.ReceivedChunk[0]); + CHECK_MESSAGE(KeyData.ReceivedGetValue, + WriteToString<32>("GetValue(", KeyData.KeyIndex, ") was unexpectedly not received.").c_str()); + CHECK_MESSAGE(KeyData.ReceivedChunk[0], + WriteToString<32>("GetChunks(", KeyData.KeyIndex, ") was unexpectedly not received.").c_str()); } } } -- cgit v1.2.3