diff options
| author | Stefan Boberg <[email protected]> | 2023-01-26 10:02:16 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-01-26 10:02:16 +0100 |
| commit | 283ef719ac57339f9338765bf2013ee110897396 (patch) | |
| tree | 1d61eb02327edbc693c9907b7a14b3f2b6fb2aaf /zenserver-test/zenserver-test.cpp | |
| parent | removed experimental mesh code (diff) | |
| parent | Fixed macro leaking out (diff) | |
| download | zen-283ef719ac57339f9338765bf2013ee110897396.tar.xz zen-283ef719ac57339f9338765bf2013ee110897396.zip | |
merge
Diffstat (limited to 'zenserver-test/zenserver-test.cpp')
| -rw-r--r-- | zenserver-test/zenserver-test.cpp | 175 |
1 files changed, 0 insertions, 175 deletions
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp index c08ad8e0a..5c7e150ce 100644 --- a/zenserver-test/zenserver-test.cpp +++ b/zenserver-test/zenserver-test.cpp @@ -2317,181 +2317,6 @@ TEST_CASE("zcache.rpc.allpolicies") } } -# if ZEN_WITH_EXEC_SERVICES - -struct RemoteExecutionRequest -{ - RemoteExecutionRequest(std::string_view Host, int Port, std::filesystem::path& TreePath) - : m_HostName(Host) - , m_PortNumber(Port) - , m_TreePath(TreePath) - { - } - - void Build(std::string_view Command, std::string_view Arguments) - { - zen::FileSystemTraversal Traversal; - Traversal.TraverseFileSystem(m_TreePath, m_Visit); - - zen::CbObjectWriter PrepReq; - - PrepReq << "cmd" << Command; - PrepReq << "args" << Arguments; - - PrepReq.BeginArray("files"); - - for (const auto& Kv : m_Visit.m_Files) - { - PrepReq.BeginObject(); - PrepReq << "file" << zen::PathToUtf8(Kv.first) << "size" << Kv.second.Size << "hash" << Kv.second.Hash; - PrepReq.EndObject(); - } - PrepReq.EndArray(); - - PrepReq.Save(m_MemOut); - } - - void Prep() - { - cpr::Response Response = - cpr::Post(cpr::Url(fmt::format("{}/prep", m_BaseUri)), cpr::Body((const char*)m_MemOut.Data(), m_MemOut.Size())); - - if (Response.status_code < 300) - { - zen::IoBuffer Payload(zen::IoBuffer::Clone, Response.text.data(), Response.text.size()); - zen::CbObject Result = zen::LoadCompactBinaryObject(Payload); - - for (auto& Need : Result["need"]) - { - zen::IoHash NeedHash = Need.AsHash(); - - if (auto It = m_Visit.m_HashToFile.find(NeedHash); It != m_Visit.m_HashToFile.end()) - { - zen::IoBuffer FileData = zen::IoBufferBuilder::MakeFromFile(It->second); - - cpr::Response CidResponse = cpr::Post(cpr::Url(m_CidUri), cpr::Body((const char*)FileData.Data(), FileData.Size())); - - if (CidResponse.status_code >= 300) - { - ZEN_ERROR("CID put failed with {}", CidResponse.status_code); - } - } - else - { - ZEN_ERROR("unknown hash in 'need' list: {}", NeedHash); - } - } - } - } - - zen::CbObject Exec() - { - cpr::Response JobResponse = cpr::Post(cpr::Url(m_BaseUri), cpr::Body((const char*)m_MemOut.Data(), m_MemOut.Size())); - - if (JobResponse.status_code < 300) - { - zen::IoBuffer Payload(zen::IoBuffer::Clone, JobResponse.text.data(), JobResponse.text.size()); - return zen::LoadCompactBinaryObject(std::move(Payload)); - } - - ZEN_INFO("job exec: {}", JobResponse.status_code); - return {}; - } - -private: - struct Visitor : public zen::FileSystemTraversal::TreeVisitor - { - const std::filesystem::path& m_RootPath; - - Visitor(const std::filesystem::path& RootPath) : m_RootPath(RootPath) {} - - virtual void VisitFile(const std::filesystem::path& Parent, const path_view& FileName, uint64_t FileSize) override - { - std::filesystem::path FullPath = Parent / FileName; - - zen::IoHashStream Ios; - zen::ScanFile(FullPath, 64 * 1024, [&](const void* Data, size_t Size) { Ios.Append(Data, Size); }); - zen::IoHash Hash = Ios.GetHash(); - - 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; - Entry.Size = FileSize; - - m_HashToFile[Hash] = FullPath; - } - - virtual bool VisitDirectory(const std::filesystem::path& Parent, const path_view& DirectoryName) override - { - std::filesystem::path FullPath = Parent / DirectoryName; - - if (DirectoryName.starts_with('.')) - { - return false; - } - - return true; - } - - struct FileEntry - { - uint64_t Size; - zen::IoHash Hash; - }; - - std::map<std::filesystem::path::string_type, FileEntry> m_Files; - std::unordered_map<zen::IoHash, std::filesystem::path, zen::IoHash::Hasher> m_HashToFile; - }; - - std::string m_HostName; - int m_PortNumber; - std::filesystem::path m_TreePath; - const std::string m_BaseUri = fmt::format("http://{}:{}/exec/jobs", m_HostName, m_PortNumber); - const std::string m_CidUri = fmt::format("http://{}:{}/cid", m_HostName, m_PortNumber); - Visitor m_Visit{m_TreePath}; - zen::BinaryWriter m_MemOut; -}; - -TEST_CASE(".exec.basic") -{ - if (true) - { - return; - } - using namespace std::literals; - - std::filesystem::path TestDir = TestEnv.CreateNewTestDir(); - - const uint16_t PortNumber = 13337; - - ZenServerInstance Zen1(TestEnv); - Zen1.SetTestDir(TestDir); - Zen1.SpawnServer(PortNumber); - Zen1.WaitUntilReady(); - - std::filesystem::path TreePath = TestEnv.GetTestRootDir("test/remote1"); - - { - RemoteExecutionRequest RemoteRequest("localhost", PortNumber, TreePath); - RemoteRequest.Build("zentest-appstub.exe", ""); - RemoteRequest.Prep(); - zen::CbObject Result = RemoteRequest.Exec(); - - CHECK(Result["exitcode"sv].AsInt32(-1) == 0); - } - - { - RemoteExecutionRequest RemoteRequest("localhost", PortNumber, TreePath); - RemoteRequest.Build("zentest-appstub.exe", "-f=1"); - RemoteRequest.Prep(); - zen::CbObject Result = RemoteRequest.Exec(); - CHECK(Result["exitcode"sv].AsInt32(-1) == 1); - } -} -# endif // ZEN_WITH_EXEC_SERVICES - class ZenServerTestHelper { public: |