diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-06-13 15:31:54 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-06-13 17:04:32 +0200 |
commit | f4d3c39d9a5efa066adba7da13bef39d846b556f (patch) | |
tree | 1645fe813ce1ffae5d987d9e89a42fb887579838 | |
parent | b5797ebf120fdaf4edc92756c9922d17b274ebd2 (diff) | |
download | justbuild-f4d3c39d9a5efa066adba7da13bef39d846b556f.tar.gz |
Test: Fix flaky LargeObjectCAS test.
Due to a random nature of the LargeObjectUtils generator, it may generate 2 identical files in a row. To prevent the test from failing, check that a newly generated file doesn't collide with any already added to the CAS.
-rw-r--r-- | test/buildtool/storage/large_object_cas.test.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test/buildtool/storage/large_object_cas.test.cpp b/test/buildtool/storage/large_object_cas.test.cpp index ce6fe7e5..8d5399f4 100644 --- a/test/buildtool/storage/large_object_cas.test.cpp +++ b/test/buildtool/storage/large_object_cas.test.cpp @@ -27,6 +27,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp" @@ -680,7 +681,25 @@ auto Blob<kIsExecutable>::Create(LocalCAS<kDefaultDoGlobalUplink> const& cas, std::string const& id, std::uintmax_t size) noexcept -> std::optional<std::pair<ArtifactDigest, std::filesystem::path>> { - auto path = Generate(id, size); + std::optional<std::filesystem::path> path; + while (not path.has_value()) { + path = Generate(id, size); + auto digest = path.has_value() + ? ArtifactDigestFactory::HashFileAs<ObjectType::File>( + cas.GetHashFunction(), *path) + : std::nullopt; + if (not digest) { + return std::nullopt; + } + + if (cas.BlobPath(digest.value(), kIsExecutable).has_value()) { + if (not FileSystemManager::RemoveFile(*path)) { + return std::nullopt; + } + path.reset(); + } + } + auto digest = path ? cas.StoreBlob(*path, kIsExecutable) : std::nullopt; auto blob_path = digest ? cas.BlobPath(*digest, kIsExecutable) : std::nullopt; |