diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-02 13:21:14 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-05 13:32:39 +0200 |
commit | d202e8f6051df5eb89d0f2eb1b9ac7109d204f56 (patch) | |
tree | 562d90c0a5396a259d11c4288162403489a6e4fd /test/buildtool/storage | |
parent | 5140befaa10f65145fe041b416b7764127efc379 (diff) | |
download | justbuild-d202e8f6051df5eb89d0f2eb1b9ac7109d204f56.tar.gz |
Remove HermeticLocalTestFixture
...and create StorageConfig and Storage in place if needed.
Diffstat (limited to 'test/buildtool/storage')
-rw-r--r-- | test/buildtool/storage/TARGETS | 10 | ||||
-rw-r--r-- | test/buildtool/storage/large_object_cas.test.cpp | 111 | ||||
-rw-r--r-- | test/buildtool/storage/local_ac.test.cpp | 35 | ||||
-rw-r--r-- | test/buildtool/storage/local_cas.test.cpp | 30 |
4 files changed, 82 insertions, 104 deletions
diff --git a/test/buildtool/storage/TARGETS b/test/buildtool/storage/TARGETS index 6dfb4edb..4a2881c3 100644 --- a/test/buildtool/storage/TARGETS +++ b/test/buildtool/storage/TARGETS @@ -16,12 +16,14 @@ , "private-deps": [ ["@", "catch2", "", "catch2"] , ["", "catch-main"] - , ["utils", "local_hermeticity"] + , ["utils", "test_storage_config"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["utils", "blob_creator"] + , ["@", "src", "src/buildtool/storage", "storage"] + , ["@", "src", "src/buildtool/storage", "config"] ] , "stage": ["test", "buildtool", "storage"] } @@ -36,7 +38,9 @@ , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/file_system", "object_type"] - , ["utils", "local_hermeticity"] + , ["@", "src", "src/buildtool/storage", "storage"] + , ["@", "src", "src/buildtool/storage", "config"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "storage"] } @@ -51,7 +55,7 @@ , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] - , ["utils", "local_hermeticity"] + , ["utils", "test_storage_config"] , ["@", "src", "src/buildtool/common", "bazel_types"] , ["utils", "large_object_utils"] , ["@", "src", "src/utils/cpp", "tmp_dir"] diff --git a/test/buildtool/storage/large_object_cas.test.cpp b/test/buildtool/storage/large_object_cas.test.cpp index fda1449a..8daf1eaf 100644 --- a/test/buildtool/storage/large_object_cas.test.cpp +++ b/test/buildtool/storage/large_object_cas.test.cpp @@ -35,7 +35,7 @@ #include "src/buildtool/storage/large_object_cas.hpp" #include "src/buildtool/storage/storage.hpp" #include "src/utils/cpp/tmp_dir.hpp" -#include "test/utils/hermeticity/local.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" #include "test/utils/large_objects/large_object_utils.hpp" namespace { @@ -97,10 +97,9 @@ class Tree final { } // namespace // Test splitting of a small tree. -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LargeObjectCAS: split a small tree", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); +TEST_CASE("LargeObjectCAS: split a small tree", "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); auto const& cas = storage.CAS(); // Create a small tree: @@ -124,10 +123,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, // the result from the LargeCAS, no actual split must occur. // The object can be implicitly reconstructed from the LargeCAS. template <ObjectType kType> -static void TestLarge() noexcept { +static void TestLarge(StorageConfig const& storage_config, + Storage const& storage) noexcept { SECTION("Large") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -174,8 +172,7 @@ static void TestLarge() noexcept { SECTION("Uplinking") { // Increment generation: - CHECK(GarbageCollector::TriggerGarbageCollection( - StorageConfig::Instance())); + CHECK(GarbageCollector::TriggerGarbageCollection(storage_config)); // Check implicit splice: auto spliced_path = @@ -191,19 +188,15 @@ static void TestLarge() noexcept { CHECK_FALSE(FileSystemManager::IsFile(path)); // Call split with disabled uplinking: - auto const youngest_storage = - ::Generation::Create(&StorageConfig::Instance()); + auto const youngest_storage = ::Generation::Create(&storage_config); auto pack_3 = kIsTree ? youngest_storage.CAS().SplitTree(digest) : youngest_storage.CAS().SplitBlob(digest); REQUIRE(pack_3); CHECK(pack_3->size() == pack_1->size()); // Check there are no spliced results in all generations: - for (std::size_t i = 0; - i < StorageConfig::Instance().NumGenerations(); - ++i) { - auto const storage = ::Generation::Create( - &StorageConfig::Instance(), /*generation=*/i); + for (std::size_t i = 0; i < storage_config.NumGenerations(); ++i) { + auto const storage = ::Generation::Create(&storage_config); auto generation_path = kIsTree ? storage.CAS().TreePath(digest) : storage.CAS().BlobPath(digest, kIsExec); @@ -218,10 +211,8 @@ static void TestLarge() noexcept { // blob. // The object cannot be implicitly reconstructed. template <ObjectType kType> -static void TestSmall() noexcept { +static void TestSmall(Storage const& storage) noexcept { SECTION("Small") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -276,10 +267,8 @@ static void TestSmall() noexcept { // empty. // The object cannot be implicitly reconstructed. template <ObjectType kType> -static void TestEmpty() noexcept { +static void TestEmpty(Storage const& storage) noexcept { SECTION("Empty") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -327,10 +316,9 @@ static void TestEmpty() noexcept { // what was expected. // 3. Explicit splice fails, if some parts of the tree are missing. template <ObjectType kType> -static void TestExternal() noexcept { +static void TestExternal(StorageConfig const& storage_config, + Storage const& storage) noexcept { SECTION("External") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -354,14 +342,13 @@ static void TestExternal() noexcept { // External source is emulated by moving the large entry to an older // generation and promoting the parts of the entry to the youngest // generation: - REQUIRE(GarbageCollector::TriggerGarbageCollection( - StorageConfig::Instance())); + REQUIRE(GarbageCollector::TriggerGarbageCollection(storage_config)); for (auto const& part : *pack_1) { static constexpr bool is_executable = false; REQUIRE(cas.BlobPath(part, is_executable)); } - auto const youngest = ::Generation::Create(&StorageConfig::Instance()); + auto const youngest = ::Generation::Create(&storage_config); SECTION("Proper request") { if constexpr (kIsTree) { @@ -428,10 +415,9 @@ static void TestExternal() noexcept { // the large CAS, they must be deleted during compactification. // All splitable objects in the generation must be split. template <ObjectType kType> -static void TestCompactification() { +static void TestCompactification(StorageConfig const& storage_config, + Storage const& storage) { SECTION("Compactify") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - static constexpr bool kIsTree = IsTreeObject(kType); static constexpr bool kIsExec = IsExecutableObject(kType); @@ -478,7 +464,7 @@ static void TestCompactification() { : cas.BlobPath(digest, kIsExec); }; - auto const latest = ::Generation::Create(&StorageConfig::Instance()); + auto const latest = ::Generation::Create(&storage_config); REQUIRE(get_path(latest.CAS(), digest).has_value()); REQUIRE(get_path(latest.CAS(), digest_2).has_value()); @@ -487,8 +473,8 @@ static void TestCompactification() { // Compactify the youngest generation: // Generation rotation is disabled to exclude uplinking. static constexpr bool kNoRotation = true; - REQUIRE(GarbageCollector::TriggerGarbageCollection( - StorageConfig::Instance(), kNoRotation)); + REQUIRE(GarbageCollector::TriggerGarbageCollection(storage_config, + kNoRotation)); // All entries must be deleted during compactification, and for blobs // and executables there are no synchronized entries in the storage: @@ -502,29 +488,30 @@ static void TestCompactification() { } } -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalCAS: Split-Splice", - "[storage]") { +TEST_CASE("LocalCAS: Split-Splice", "[storage]") { + auto const config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&config.Get()); + SECTION("File") { - TestLarge<ObjectType::File>(); - TestSmall<ObjectType::File>(); - TestEmpty<ObjectType::File>(); - TestExternal<ObjectType::File>(); - TestCompactification<ObjectType::File>(); + TestLarge<ObjectType::File>(config.Get(), storage); + TestSmall<ObjectType::File>(storage); + TestEmpty<ObjectType::File>(storage); + TestExternal<ObjectType::File>(config.Get(), storage); + TestCompactification<ObjectType::File>(config.Get(), storage); } SECTION("Tree") { - TestLarge<ObjectType::Tree>(); - TestSmall<ObjectType::Tree>(); - TestEmpty<ObjectType::Tree>(); - TestExternal<ObjectType::Tree>(); - TestCompactification<ObjectType::Tree>(); + TestLarge<ObjectType::Tree>(config.Get(), storage); + TestSmall<ObjectType::Tree>(storage); + TestEmpty<ObjectType::Tree>(storage); + TestExternal<ObjectType::Tree>(config.Get(), storage); + TestCompactification<ObjectType::Tree>(config.Get(), storage); } SECTION("Executable") { - TestLarge<ObjectType::Executable>(); - TestSmall<ObjectType::Executable>(); - TestEmpty<ObjectType::Executable>(); - TestExternal<ObjectType::Executable>(); - TestCompactification<ObjectType::Executable>(); + TestLarge<ObjectType::Executable>(config.Get(), storage); + TestSmall<ObjectType::Executable>(storage); + TestEmpty<ObjectType::Executable>(storage); + TestExternal<ObjectType::Executable>(config.Get(), storage); + TestCompactification<ObjectType::Executable>(config.Get(), storage); } } @@ -540,11 +527,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, // All large entries are preliminarily split and the spliced results are // deleted. The youngest generation is empty. Uplinking must restore the // object(and it's parts) and uplink them properly. -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LargeObjectCAS: uplink nested large objects", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - +TEST_CASE("LargeObjectCAS: uplink nested large objects", "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); auto const& cas = storage.CAS(); // Randomize a large directory: @@ -596,8 +581,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, REQUIRE(FileSystemManager::RemoveFile(*large_tree_path)); // Rotate generations: - REQUIRE( - GarbageCollector::TriggerGarbageCollection(StorageConfig::Instance())); + REQUIRE(GarbageCollector::TriggerGarbageCollection(storage_config.Get())); // Ask to splice the large tree: auto result_path = cas.TreePath(*large_tree_digest); @@ -610,7 +594,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, CHECK_FALSE(FileSystemManager::IsFile(*nested_tree_path)); CHECK_FALSE(FileSystemManager::IsFile(*nested_blob_path)); - auto const latest = ::Generation::Create(&StorageConfig::Instance()); + auto const latest = ::Generation::Create(&storage_config.Get()); // However, they might be reconstructed on request because there entries are // in the latest generation: @@ -621,10 +605,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, REQUIRE(split_nested_blob_2); // Check there are no spliced results in old generations: - for (std::size_t i = 1; i < StorageConfig::Instance().NumGenerations(); - ++i) { + for (std::size_t i = 1; i < storage_config.Get().NumGenerations(); ++i) { auto const storage = - ::Generation::Create(&StorageConfig::Instance(), /*generation=*/i); + ::Generation::Create(&storage_config.Get(), /*generation=*/i); auto const& generation_cas = storage.CAS(); REQUIRE_FALSE(generation_cas.TreePath(*nested_tree_digest)); REQUIRE_FALSE(generation_cas.TreePath(*large_tree_digest)); diff --git a/test/buildtool/storage/local_ac.test.cpp b/test/buildtool/storage/local_ac.test.cpp index f2ca3a15..fdd8eec6 100644 --- a/test/buildtool/storage/local_ac.test.cpp +++ b/test/buildtool/storage/local_ac.test.cpp @@ -22,7 +22,7 @@ #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" -#include "test/utils/hermeticity/local.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" [[nodiscard]] static auto RunDummyExecution( gsl::not_null<LocalAC<true> const*> const& ac, @@ -30,11 +30,9 @@ bazel_re::Digest const& action_id, std::string const& seed) -> bool; -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalAC: Single action, single result", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - +TEST_CASE("LocalAC: Single action, single result", "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); @@ -45,11 +43,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, CHECK(ac_result); } -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalAC: Two different actions, two different results", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - +TEST_CASE("LocalAC: Two different actions, two different results", + "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); @@ -76,11 +73,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, CHECK(result_content1 != result_content2); } -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalAC: Two different actions, same two results", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - +TEST_CASE("LocalAC: Two different actions, same two results", "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); @@ -107,11 +102,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, CHECK(result_content1 == result_content2); } -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalAC: Same two actions, two different results", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); - +TEST_CASE("LocalAC: Same two actions, two different results", "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp index b64ee780..ef77a6a1 100644 --- a/test/buildtool/storage/local_cas.test.cpp +++ b/test/buildtool/storage/local_cas.test.cpp @@ -23,16 +23,15 @@ #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" #include "test/utils/blob_creator.hpp" -#include "test/utils/hermeticity/local.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalCAS: Add blob to storage from bytes", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); +TEST_CASE("LocalCAS: Add blob to storage from bytes", "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); + auto const& cas = storage.CAS(); std::string test_bytes("test"); - auto const& cas = storage.CAS(); auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_bytes); // check blob not in storage @@ -74,15 +73,15 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, } } -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalCAS: Add blob to storage from non-executable file", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); +TEST_CASE("LocalCAS: Add blob to storage from non-executable file", + "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); + auto const& cas = storage.CAS(); std::filesystem::path non_exec_file{ "test/buildtool/storage/data/non_executable_file"}; - auto const& cas = storage.CAS(); auto test_blob = CreateBlobFromPath(non_exec_file); REQUIRE(test_blob); @@ -125,15 +124,14 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, } } -TEST_CASE_METHOD(HermeticLocalTestFixture, - "LocalCAS: Add blob to storage from executable file", - "[storage]") { - auto const storage = Storage::Create(&StorageConfig::Instance()); +TEST_CASE("LocalCAS: Add blob to storage from executable file", "[storage]") { + auto const storage_config = TestStorageConfig::Create(); + auto const storage = Storage::Create(&storage_config.Get()); + auto const& cas = storage.CAS(); std::filesystem::path exec_file{ "test/buildtool/storage/data/executable_file"}; - auto const& cas = storage.CAS(); auto test_blob = CreateBlobFromPath(exec_file); REQUIRE(test_blob); |