From f4d3c39d9a5efa066adba7da13bef39d846b556f Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Fri, 13 Jun 2025 15:31:54 +0200 Subject: 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. --- test/buildtool/storage/large_object_cas.test.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'test') 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::Create(LocalCAS const& cas, std::string const& id, std::uintmax_t size) noexcept -> std::optional> { - auto path = Generate(id, size); + std::optional path; + while (not path.has_value()) { + path = Generate(id, size); + auto digest = path.has_value() + ? ArtifactDigestFactory::HashFileAs( + 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; -- cgit v1.2.3