diff options
| author | zousar <[email protected]> | 2025-02-26 10:46:37 -0700 |
|---|---|---|
| committer | zousar <[email protected]> | 2025-02-26 10:46:37 -0700 |
| commit | 86c8b70f01090698d0d698840d6aad666747ee22 (patch) | |
| tree | 1ec5b08493326ef23c6c376581de5c3b87abef6e /src/zenserver-test/zenserver-test.cpp | |
| parent | Add unit test for overwrite behavior (diff) | |
| download | zen-86c8b70f01090698d0d698840d6aad666747ee22.tar.xz zen-86c8b70f01090698d0d698840d6aad666747ee22.zip | |
Expand and fix unit tests for overwrite behavior
Diffstat (limited to 'src/zenserver-test/zenserver-test.cpp')
| -rw-r--r-- | src/zenserver-test/zenserver-test.cpp | 89 |
1 files changed, 82 insertions, 7 deletions
diff --git a/src/zenserver-test/zenserver-test.cpp b/src/zenserver-test/zenserver-test.cpp index 466f3d6ca..a41eaed75 100644 --- a/src/zenserver-test/zenserver-test.cpp +++ b/src/zenserver-test/zenserver-test.cpp @@ -1297,8 +1297,9 @@ TEST_CASE("zcache.rpc") std::string_view Namespace, std::string_view Bucket, size_t Num, - size_t PayloadSize = 1024, - size_t KeyOffset = 1) -> std::vector<CacheKey> { + size_t PayloadSize = 1024, + size_t KeyOffset = 1, + std::vector<CbPackage>* OutPackages = nullptr) -> std::vector<CacheKey> { std::vector<zen::CacheKey> OutKeys; for (uint32_t Key = 1; Key <= Num; ++Key) @@ -1320,6 +1321,10 @@ TEST_CASE("zcache.rpc") cpr::Body{(const char*)Body.GetData(), Body.GetSize()}); CHECK(Result.status_code == 200); + if (OutPackages) + { + OutPackages->emplace_back(std::move(Package)); + } } return OutKeys; @@ -1498,7 +1503,7 @@ TEST_CASE("zcache.rpc") } } - SUBCASE("policy - 'QueryLocal' on put denies overwrite") + SUBCASE("policy - 'QueryLocal' on put denies overwrite with differing value") { using namespace utils; @@ -1519,7 +1524,7 @@ TEST_CASE("zcache.rpc") for (const zen::CacheKey& CacheKey : Keys) { cacherequests::PutCacheRecordsRequest Request = {.AcceptMagic = kCbPkgMagic, .Namespace = std::string(Namespace)}; - AppendCacheRecord(Request, CacheKey, PayloadSize*2, CachePolicy::Default); + AppendCacheRecord(Request, CacheKey, PayloadSize * 2, CachePolicy::Default); CbPackage Package; CHECK(Request.Format(Package)); @@ -1529,7 +1534,15 @@ TEST_CASE("zcache.rpc") 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 == 409); + CHECK(Result.status_code == 200); + cacherequests::PutCacheRecordsResult ParsedResult; + CbPackage Response = ParsePackageMessage(zen::IoBuffer(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size())); + CHECK(!Response.IsNull()); + CHECK(ParsedResult.Parse(Response)); + for (bool ResponseSuccess : ParsedResult.Success) + { + CHECK(!ResponseSuccess); + } } CachePolicy Policy = (CachePolicy::QueryLocal | CachePolicy::QueryRemote); @@ -1549,7 +1562,7 @@ TEST_CASE("zcache.rpc") } } - SUBCASE("policy - no 'QueryLocal' on put allows overwrite") + SUBCASE("policy - no 'QueryLocal' on put allows overwrite with differing value") { using namespace utils; @@ -1581,6 +1594,14 @@ TEST_CASE("zcache.rpc") cpr::Body{(const char*)Body.GetData(), Body.GetSize()}); CHECK(Result.status_code == 200); + cacherequests::PutCacheRecordsResult ParsedResult; + CbPackage Response = ParsePackageMessage(zen::IoBuffer(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size())); + CHECK(!Response.IsNull()); + CHECK(ParsedResult.Parse(Response)); + for (bool ResponseSuccess : ParsedResult.Success) + { + CHECK(ResponseSuccess); + } } CachePolicy Policy = (CachePolicy::QueryLocal | CachePolicy::QueryRemote); @@ -1595,7 +1616,61 @@ TEST_CASE("zcache.rpc") CHECK(Record->Key == ExpectedKey); for (const cacherequests::GetCacheRecordResultValue& Value : Record->Values) { - CHECK(Value.RawSize == PayloadSize*2); + CHECK(Value.RawSize == PayloadSize * 2); + } + } + } + + SUBCASE("policy - 'QueryLocal' on put allows overwrite with equivalent value") + { + using namespace utils; + + ZenConfig UpstreamCfg = ZenConfig::New(TestEnv.GetNewPortNumber()); + ZenServerInstance UpstreamServer(TestEnv); + SpawnServer(UpstreamServer, UpstreamCfg); + + ZenConfig LocalCfg = ZenConfig::NewWithUpstream(TestEnv.GetNewPortNumber(), UpstreamCfg.Port); + ZenServerInstance LocalServer(TestEnv); + SpawnServer(LocalServer, LocalCfg); + + size_t PayloadSize = 1024; + std::string_view Namespace("ue4.ddc"sv); + std::string_view Bucket("mastodon"sv); + const size_t NumRecords = 4; + std::vector<CbPackage> Packages; + std::vector<zen::CacheKey> Keys = PutCacheRecords(UpstreamCfg.BaseUri, Namespace, Bucket, NumRecords, PayloadSize, 1, &Packages); + + for (const CbPackage& Package : Packages) + { + IoBuffer Body = FormatPackageMessageBuffer(Package).Flatten().AsIoBuffer(); + cpr::Response Result = cpr::Post(cpr::Url{fmt::format("{}/$rpc", UpstreamCfg.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); + cacherequests::PutCacheRecordsResult ParsedResult; + CbPackage Response = ParsePackageMessage(zen::IoBuffer(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size())); + CHECK(!Response.IsNull()); + CHECK(ParsedResult.Parse(Response)); + for (bool ResponseSuccess : ParsedResult.Success) + { + CHECK(ResponseSuccess); + } + } + + CachePolicy Policy = (CachePolicy::QueryLocal | CachePolicy::QueryRemote); + GetCacheRecordResult Result = GetCacheRecords(LocalCfg.BaseUri, "ue4.ddc"sv, Keys, Policy); + + CHECK(Result.Result.Results.size() == Keys.size()); + + for (size_t Index = 0; const std::optional<cacherequests::GetCacheRecordResult>& Record : Result.Result.Results) + { + CHECK(Record); + const CacheKey& ExpectedKey = Keys[Index++]; + CHECK(Record->Key == ExpectedKey); + for (const cacherequests::GetCacheRecordResultValue& Value : Record->Values) + { + CHECK(Value.RawSize == PayloadSize); } } } |