diff options
Diffstat (limited to 'zenserver-test/zenserver-test.cpp')
| -rw-r--r-- | zenserver-test/zenserver-test.cpp | 78 |
1 files changed, 45 insertions, 33 deletions
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp index 8f38cc1be..bc955727a 100644 --- a/zenserver-test/zenserver-test.cpp +++ b/zenserver-test/zenserver-test.cpp @@ -41,16 +41,19 @@ ZEN_THIRD_PARTY_INCLUDES_START #undef GetObject ZEN_THIRD_PARTY_INCLUDES_END -#include <ppl.h> #include <atomic> #include <filesystem> #include <map> #include <random> #include <span> +#include <thread> #include <unordered_map> -#include <atlbase.h> -#include <process.h> +#if ZEN_PLATFORM_WINDOWS +# include <ppl.h> +# include <atlbase.h> +# include <process.h> +#endif #include <asio.hpp> @@ -69,6 +72,25 @@ ZEN_THIRD_PARTY_INCLUDES_END using namespace fmt::literals; using namespace std::literals; +#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MACOS +struct Concurrency +{ + template <typename... T> + static void parallel_invoke(T&&... t) + { + constexpr size_t NumTs = sizeof...(t); + std::thread Threads[NumTs] = { + std::thread(std::forward<T>(t))..., + }; + + for (std::thread& Thread : Threads) + { + Thread.join(); + } + } +}; +#endif + /* ___ ___ _________ _________ ________ ________ ___ ___ _______ ________ _________ @@ -341,7 +363,7 @@ HttpConnectionPool::GetConnection() std::unique_ptr<HttpClientConnection> Connection{m_AvailableConnections.back()}; m_AvailableConnections.pop_back(); - return std::move(Connection); + return Connection; } void @@ -740,7 +762,7 @@ TEST_CASE("default.single") auto IssueTestRequests = [&] { const uint64_t BatchNo = BatchCounter.fetch_add(1); - const DWORD ThreadId = GetCurrentThreadId(); + const int ThreadId = zen::GetCurrentThreadId(); ZEN_INFO("query batch {} started (thread {})", BatchNo, ThreadId); cpr::Session cli; @@ -754,22 +776,8 @@ TEST_CASE("default.single") ZEN_INFO("query batch {} ended (thread {})", BatchNo, ThreadId); }; - auto fun10 = [&] { - Concurrency::parallel_invoke(IssueTestRequests, - IssueTestRequests, - IssueTestRequests, - IssueTestRequests, - IssueTestRequests, - IssueTestRequests, - IssueTestRequests, - IssueTestRequests, - IssueTestRequests, - IssueTestRequests); - }; - zen::Stopwatch timer; - // Concurrency::parallel_invoke(fun10, fun10, fun, fun, fun, fun, fun, fun, fun, fun); Concurrency::parallel_invoke(IssueTestRequests, IssueTestRequests, IssueTestRequests, @@ -808,7 +816,7 @@ TEST_CASE("multi.basic") auto IssueTestRequests = [&](int PortNumber) { const uint64_t BatchNo = BatchCounter.fetch_add(1); - const DWORD ThreadId = GetCurrentThreadId(); + const int ThreadId = zen::GetCurrentThreadId(); ZEN_INFO("query batch {} started (thread {}) for port {}", BatchNo, ThreadId, PortNumber); @@ -1744,6 +1752,8 @@ TEST_CASE("zcache.policy") zen::CbPackage Package; const bool Ok = Package.TryLoad(Body); + CHECK(Ok); + CbObject CacheRecord = Package.GetObject(); std::vector<IoHash> AttachmentKeys; @@ -1763,6 +1773,7 @@ TEST_CASE("zcache.policy") zen::CbPackage Package; const bool Ok = Package.TryLoad(Body); + CHECK(Ok); CHECK(Package.GetAttachments().size() != 0); } } @@ -1802,6 +1813,8 @@ TEST_CASE("zcache.policy") zen::CbPackage Package; const bool Ok = Package.TryLoad(Body); + CHECK(Ok); + CbObject CacheRecord = Package.GetObject(); std::vector<IoHash> AttachmentKeys; @@ -1821,6 +1834,7 @@ TEST_CASE("zcache.policy") zen::CbPackage Package; const bool Ok = Package.TryLoad(Body); + CHECK(Ok); CHECK(Package.GetAttachments().size() != 0); } } @@ -1942,7 +1956,7 @@ TEST_CASE("zcache.rpc") for (uint32_t Key = 1; Key <= Num; ++Key) { - const zen::CacheKey CacheKey = zen::CacheKey::Create(Bucket, zen::IoHash::HashBuffer(&Key, sizeof uint32_t)); + const zen::CacheKey CacheKey = zen::CacheKey::Create(Bucket, zen::IoHash::HashBuffer(&Key, sizeof(uint32_t))); CbPackage CacheRecord = CreateCacheRecord(CacheKey, PayloadSize); OutKeys.push_back(CacheKey); @@ -2009,8 +2023,6 @@ TEST_CASE("zcache.rpc") for (CbFieldView RecordView : ResponseObject["Result"]) { - ExtendableStringBuilder<256> Tmp; - auto JSON = RecordView.AsObjectView().ToJson(Tmp).ToView(); OutResult.Records.push_back(RecordView); } @@ -2099,7 +2111,6 @@ TEST_CASE("zcache.rpc") { const CacheKey& ExpectedKey = ExistingKeys[KeyIndex++]; CbObjectView RecordObj = RecordView.AsObjectView(); - CbObjectView KeyObj = RecordObj["CacheKey"sv].AsObjectView(); zen::CacheKey Key = LoadKey(RecordObj["CacheKey"sv]); const IoHash AttachmentHash = RecordObj["Data"sv].AsHash(); const CbAttachment* Attachment = Result.Response.FindAttachment(AttachmentHash); @@ -2137,7 +2148,6 @@ TEST_CASE("zcache.rpc") CbObjectView RecordObj = RecordView.AsObjectView(); CbObjectView KeyObj = RecordObj["CacheKey"sv].AsObjectView(); const CacheKey Key = CacheKey::Create(KeyObj["Bucket"sv].AsString(), KeyObj["Hash"].AsHash()); - const IoHash AttachmentHash = RecordObj["Data"sv].AsHash(); CHECK(Key == ExpectedKey); } @@ -2221,7 +2231,7 @@ struct RemoteExecutionRequest for (const auto& Kv : m_Visit.m_Files) { PrepReq.BeginObject(); - PrepReq << "file" << zen::WideToUtf8(Kv.first) << "size" << Kv.second.Size << "hash" << Kv.second.Hash; + PrepReq << "file" << zen::PathToUtf8(Kv.first) << "size" << Kv.second.Size << "hash" << Kv.second.Hash; PrepReq.EndObject(); } PrepReq.EndArray(); @@ -2244,7 +2254,7 @@ struct RemoteExecutionRequest if (auto It = m_Visit.m_HashToFile.find(NeedHash); It != m_Visit.m_HashToFile.end()) { - zen::IoBuffer FileData = zen::IoBufferBuilder::MakeFromFile(It->second.c_str()); + zen::IoBuffer FileData = zen::IoBufferBuilder::MakeFromFile(It->second); cpr::Response CasResponse = cpr::Post(cpr::Url(m_CasUri), cpr::Body((const char*)FileData.Data(), FileData.Size())); @@ -2282,7 +2292,7 @@ private: Visitor(const std::filesystem::path& RootPath) : m_RootPath(RootPath) {} - virtual void VisitFile(const std::filesystem::path& Parent, const std::wstring_view& FileName, uint64_t FileSize) override + virtual void VisitFile(const std::filesystem::path& Parent, const path_view& FileName, uint64_t FileSize) override { std::filesystem::path FullPath = Parent / FileName; @@ -2290,8 +2300,8 @@ private: zen::ScanFile(FullPath, 64 * 1024, [&](const void* Data, size_t Size) { Ios.Append(Data, Size); }); zen::IoHash Hash = Ios.GetHash(); - std::wstring RelativePath = FullPath.lexically_relative(m_RootPath).native(); - // ZEN_INFO("File: {:32} => {} ({})", zen::WideToUtf8(RelativePath), Hash, FileSize); + auto RelativePath = FullPath.lexically_relative(m_RootPath).native(); + // ZEN_INFO("File: {:32} => {} ({})", zen::PathToUtf8(RelativePath), Hash, FileSize); FileEntry& Entry = m_Files[RelativePath]; Entry.Hash = Hash; @@ -2300,11 +2310,11 @@ private: m_HashToFile[Hash] = FullPath; } - virtual bool VisitDirectory(const std::filesystem::path& Parent, const std::wstring_view& DirectoryName) override + virtual bool VisitDirectory(const std::filesystem::path& Parent, const path_view& DirectoryName) override { std::filesystem::path FullPath = Parent / DirectoryName; - if (DirectoryName.starts_with(L".")) + if (DirectoryName.starts_with('.')) { return false; } @@ -2318,7 +2328,7 @@ private: zen::IoHash Hash; }; - std::map<std::wstring, FileEntry> m_Files; + std::map<std::filesystem::path::string_type, FileEntry> m_Files; std::unordered_map<zen::IoHash, std::filesystem::path, zen::IoHash::Hasher> m_HashToFile; }; @@ -2333,6 +2343,7 @@ private: TEST_CASE("exec.basic") { +#if ZEN_WITH_COMPUTE_SERVICES using namespace std::literals; std::filesystem::path TestDir = TestEnv.CreateNewTestDir(); @@ -2363,6 +2374,7 @@ TEST_CASE("exec.basic") CHECK(Result["exitcode"].AsInt32(-1) == 1); } +#endif // ZEN_WITH_COMPUTE_SERVICES } TEST_CASE("mesh.basic") |