diff options
| author | mattpetersepic <[email protected]> | 2022-01-25 06:57:47 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-25 06:57:47 -0700 |
| commit | bd85a74a9d15fd676a6677fbd4d5ab4e3dcb0d42 (patch) | |
| tree | e59bd4eccbc667088e74e989f2cfbbf82c6926c0 /zenserver-test/zenserver-test.cpp | |
| parent | Fixed unexpected abort() call when joining an unjoinable thread (diff) | |
| download | zen-bd85a74a9d15fd676a6677fbd4d5ab4e3dcb0d42.tar.xz zen-bd85a74a9d15fd676a6677fbd4d5ab4e3dcb0d42.zip | |
Cachepolicy (#36)
* Copy CachePolicy implementation from UE5/Release-5.0. Add backwards compatability for clients and upstreams that are using the old protocol.
* Add RefPtr templated move operator and constructor, so that RefPtr<const Foo*> A = std::move(RefPtr<Foo*>()) will do a move.
* Fix broken CachePolicy tests and add tests for new Save/Load.
* Remove TODO comments
* CachePolicy Save/Load Fixes from codereview
* Fix comment to match code change.
* Remove backwards compatibility for CachePolicy change. Convert policy string tokens to PascalCase. Fix tests for new policy text. Change ParseCachePolicy to assert string is non-empty and always succeed.
* Fix release build: use ZEN_WITH_TESTS define
Diffstat (limited to 'zenserver-test/zenserver-test.cpp')
| -rw-r--r-- | zenserver-test/zenserver-test.cpp | 187 |
1 files changed, 16 insertions, 171 deletions
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp index 75aae6321..c1d48502e 100644 --- a/zenserver-test/zenserver-test.cpp +++ b/zenserver-test/zenserver-test.cpp @@ -1536,13 +1536,13 @@ TEST_CASE("zcache.policy") } { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?query=local", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?Policy=QueryLocal,Store", LocalCfg.BaseUri, Bucket, Key)}, cpr::Header{{"Accept", "application/octet-stream"}}); CHECK(Result.status_code == 404); } { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?query=local,remote", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?Policy=Query,Store", LocalCfg.BaseUri, Bucket, Key)}, cpr::Header{{"Accept", "application/octet-stream"}}); CHECK(Result.status_code == 200); } @@ -1564,7 +1564,7 @@ TEST_CASE("zcache.policy") // Store binary cache value locally { - cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?store=local", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?Policy=Query,StoreLocal", LocalCfg.BaseUri, Bucket, Key)}, cpr::Body{(const char*)BinaryValue.GetData(), BinaryValue.GetSize()}, cpr::Header{{"Content-Type", "application/octet-stream"}}); CHECK(Result.status_code == 201); @@ -1599,7 +1599,7 @@ TEST_CASE("zcache.policy") // Store binary cache value locally and upstream { - cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?store=local,remote", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?Policy=Query,Store", LocalCfg.BaseUri, Bucket, Key)}, cpr::Body{(const char*)BinaryValue.GetData(), BinaryValue.GetSize()}, cpr::Header{{"Content-Type", "application/octet-stream"}}); CHECK(Result.status_code == 201); @@ -1643,13 +1643,13 @@ TEST_CASE("zcache.policy") } { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?query=local", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?Policy=QueryLocal,Store", LocalCfg.BaseUri, Bucket, Key)}, cpr::Header{{"Accept", "application/x-ue-cbpkg"}}); CHECK(Result.status_code == 404); } { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?query=local,remote", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?Policy=Query,Store", LocalCfg.BaseUri, Bucket, Key)}, cpr::Header{{"Accept", "application/x-ue-cbpkg"}}); CHECK(Result.status_code == 200); } @@ -1673,7 +1673,7 @@ TEST_CASE("zcache.policy") // Store packge locally { - cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?store=local", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?Policy=Query,StoreLocal", LocalCfg.BaseUri, Bucket, Key)}, cpr::Body{(const char*)Buf.GetData(), Buf.GetSize()}, cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}}); CHECK(Result.status_code == 201); @@ -1710,7 +1710,7 @@ TEST_CASE("zcache.policy") // Store package locally and upstream { - cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?store=local,remote", LocalCfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}?Policy=Query,Store", LocalCfg.BaseUri, Bucket, Key)}, cpr::Body{(const char*)Buf.GetData(), Buf.GetSize()}, cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}}); CHECK(Result.status_code == 201); @@ -1729,129 +1729,6 @@ TEST_CASE("zcache.policy") } } - SUBCASE("skip - 'attachments' does not return attachments") - { - ZenConfig LocalCfg = ZenConfig::New(); - ZenServerInstance LocalInst(TestEnv); - const auto Bucket = "texture"sv; - - LocalCfg.Spawn(LocalInst); - - zen::IoHash Key; - zen::IoHash PayloadId; - - // Store package locally - { - zen::CbPackage Package = GeneratePackage(Key, PayloadId); - auto Buf = ToBuffer(Package); - - CHECK(Package.GetAttachments().size() != 0); - cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}", LocalCfg.BaseUri, Bucket, Key)}, - cpr::Body{(const char*)Buf.GetData(), Buf.GetSize()}, - cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}}); - CHECK(Result.status_code == 201); - } - - { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?skip=attachments", LocalCfg.BaseUri, Bucket, Key)}, - cpr::Header{{"Accept", "application/x-ue-cbpkg"}}); - CHECK(Result.status_code == 200); - - zen::IoBuffer Body(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size()); - zen::CbPackage Package; - const bool Ok = Package.TryLoad(Body); - CHECK(Ok); - - CHECK(Ok); - - CbObject CacheRecord = Package.GetObject(); - std::vector<IoHash> AttachmentKeys; - - CacheRecord.IterateAttachments( - [&AttachmentKeys](CbFieldView AttachmentKey) { AttachmentKeys.push_back(AttachmentKey.AsHash()); }); - - CHECK(AttachmentKeys.size() != 0); - CHECK(Package.GetAttachments().size() == 0); - } - - { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}", LocalCfg.BaseUri, Bucket, Key)}, - cpr::Header{{"Accept", "application/x-ue-cbpkg"}}); - CHECK(Result.status_code == 200); - - zen::IoBuffer Body(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size()); - zen::CbPackage Package; - const bool Ok = Package.TryLoad(Body); - CHECK(Ok); - - CHECK(Ok); - CHECK(Package.GetAttachments().size() != 0); - } - } - - SUBCASE("skip - 'attachments' does not return attachments when retrieved from upstream") - { - ZenConfig UpstreamCfg = ZenConfig::New(13338); - ZenServerInstance UpstreamInst(TestEnv); - ZenConfig LocalCfg = ZenConfig::NewWithUpstream(13338); - ZenServerInstance LocalInst(TestEnv); - const auto Bucket = "texture"sv; - - UpstreamCfg.Spawn(UpstreamInst); - LocalCfg.Spawn(LocalInst); - - zen::IoHash Key; - zen::IoHash PayloadId; - - // Store package upstream - { - zen::CbPackage Package = GeneratePackage(Key, PayloadId); - auto Buf = ToBuffer(Package); - - CHECK(Package.GetAttachments().size() != 0); - cpr::Response Result = cpr::Put(cpr::Url{fmt::format("{}/{}/{}", UpstreamCfg.BaseUri, Bucket, Key)}, - cpr::Body{(const char*)Buf.GetData(), Buf.GetSize()}, - cpr::Header{{"Content-Type", "application/x-ue-cbpkg"}}); - CHECK(Result.status_code == 201); - } - - { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?skip=attachments", LocalCfg.BaseUri, Bucket, Key)}, - cpr::Header{{"Accept", "application/x-ue-cbpkg"}}); - CHECK(Result.status_code == 200); - - zen::IoBuffer Body(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size()); - zen::CbPackage Package; - const bool Ok = Package.TryLoad(Body); - CHECK(Ok); - - CHECK(Ok); - - CbObject CacheRecord = Package.GetObject(); - std::vector<IoHash> AttachmentKeys; - - CacheRecord.IterateAttachments( - [&AttachmentKeys](CbFieldView AttachmentKey) { AttachmentKeys.push_back(AttachmentKey.AsHash()); }); - - CHECK(AttachmentKeys.size() != 0); - CHECK(Package.GetAttachments().size() == 0); - } - - { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}", LocalCfg.BaseUri, Bucket, Key)}, - cpr::Header{{"Accept", "application/x-ue-cbpkg"}}); - CHECK(Result.status_code == 200); - - zen::IoBuffer Body(zen::IoBuffer::Wrap, Result.text.data(), Result.text.size()); - zen::CbPackage Package; - const bool Ok = Package.TryLoad(Body); - CHECK(Ok); - - CHECK(Ok); - CHECK(Package.GetAttachments().size() != 0); - } - } - SUBCASE("skip - 'data' returns empty cache record/payload") { ZenConfig Cfg = ZenConfig::New(); @@ -1875,7 +1752,7 @@ TEST_CASE("zcache.policy") // Get package { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?skip=data", Cfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?Policy=Default,SkipData", Cfg.BaseUri, Bucket, Key)}, cpr::Header{{"Accept", "application/x-ue-cbpkg"}}); CHECK(IsHttpSuccessCode(Result.status_code)); CHECK(Result.text.size() == 0); @@ -1883,7 +1760,7 @@ TEST_CASE("zcache.policy") // Get record { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?skip=data", Cfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?Policy=Default,SkipData", Cfg.BaseUri, Bucket, Key)}, cpr::Header{{"Accept", "application/x-ue-cbobject"}}); CHECK(IsHttpSuccessCode(Result.status_code)); CHECK(Result.text.size() == 0); @@ -1891,8 +1768,9 @@ TEST_CASE("zcache.policy") // Get payload { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}/{}?skip=data", Cfg.BaseUri, Bucket, Key, PayloadId)}, - cpr::Header{{"Accept", "application/x-ue-comp"}}); + cpr::Response Result = + cpr::Get(cpr::Url{fmt::format("{}/{}/{}/{}?Policy=Default,SkipData", Cfg.BaseUri, Bucket, Key, PayloadId)}, + cpr::Header{{"Accept", "application/x-ue-comp"}}); CHECK(IsHttpSuccessCode(Result.status_code)); CHECK(Result.text.size() == 0); } @@ -1919,7 +1797,7 @@ TEST_CASE("zcache.policy") // Get package { - cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?skip=data", Cfg.BaseUri, Bucket, Key)}, + cpr::Response Result = cpr::Get(cpr::Url{fmt::format("{}/{}/{}?Policy=Default,SkipData", Cfg.BaseUri, Bucket, Key)}, cpr::Header{{"Accept", "application/octet-stream"}}); CHECK(IsHttpSuccessCode(Result.status_code)); CHECK(Result.text.size() == 0); @@ -2011,9 +1889,8 @@ TEST_CASE("zcache.rpc") } Request.EndArray(); - Request.BeginObject("Policy"); - CacheRecordPolicy::Save(Policy, Request); - Request.EndObject(); + Request.SetName("Policy"sv); + Policy.Save(Request); Request.EndObject(); @@ -2134,38 +2011,6 @@ TEST_CASE("zcache.rpc") } } - SUBCASE("policy - 'SkipAttachments' does not return any record attachments") - { - std::filesystem::path TestDir = TestEnv.CreateNewTestDir(); - const uint16_t PortNumber = 13337; - const auto BaseUri = fmt::format("http://localhost:{}/z$", PortNumber); - - ZenServerInstance Inst(TestEnv); - Inst.SetTestDir(TestDir); - Inst.SpawnServer(PortNumber); - Inst.WaitUntilReady(); - - CacheRecordPolicy Policy(CachePolicy::QueryLocal | CachePolicy::SkipAttachments); - std::vector<zen::CacheKey> Keys = PutCacheRecords(BaseUri, ""sv, "mastodon"sv, 4); - GetCacheRecordResult Result = GetCacheRecords(BaseUri, Keys, Policy); - - CHECK(Result.Records.size() == Keys.size()); - - std::span<const zen::CbAttachment> Attachments = Result.Response.GetAttachments(); - CHECK(Attachments.empty()); - - for (size_t Index = 0; CbFieldView RecordView : Result.Records) - { - const CacheKey& ExpectedKey = Keys[Index++]; - - CbObjectView RecordObj = RecordView.AsObjectView(); - CbObjectView KeyObj = RecordObj["CacheKey"sv].AsObjectView(); - const CacheKey Key = CacheKey::Create(KeyObj["Bucket"sv].AsString(), KeyObj["Hash"].AsHash()); - - CHECK(Key == ExpectedKey); - } - } - SUBCASE("policy - 'QueryLocal' does not query upstream") { using namespace utils; |