From 21bbc196ae9c4c38d4704dc9667768a259347310 Mon Sep 17 00:00:00 2001 From: Gareth Andrew Lloyd Date: Wed, 13 Dec 2023 13:19:01 +0000 Subject: [PATCH] Cleanup filesystem after unittest (#1581) --- tests/unit/dbms_handler.cpp | 1 + tests/unit/dbms_handler_community.cpp | 1 + tests/unit/interpreter.cpp | 2 ++ tests/unit/query_dump.cpp | 11 ++++++++++- tests/unit/storage_v2_isolation_level.cpp | 4 ++-- tests/unit/storage_v2_storage_mode.cpp | 2 ++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/unit/dbms_handler.cpp b/tests/unit/dbms_handler.cpp index a811e4159..0ea4197fb 100644 --- a/tests/unit/dbms_handler.cpp +++ b/tests/unit/dbms_handler.cpp @@ -58,6 +58,7 @@ class TestEnvironment : public ::testing::Environment { void TearDown() override { ptr_.reset(); auth.reset(); + std::filesystem::remove_all(storage_directory); } static std::unique_ptr ptr_; diff --git a/tests/unit/dbms_handler_community.cpp b/tests/unit/dbms_handler_community.cpp index 3848cd347..860f70ba0 100644 --- a/tests/unit/dbms_handler_community.cpp +++ b/tests/unit/dbms_handler_community.cpp @@ -58,6 +58,7 @@ class TestEnvironment : public ::testing::Environment { void TearDown() override { ptr_.reset(); auth.reset(); + std::filesystem::remove_all(storage_directory); } static std::unique_ptr ptr_; diff --git a/tests/unit/interpreter.cpp b/tests/unit/interpreter.cpp index 57bb79db8..bd587e7df 100644 --- a/tests/unit/interpreter.cpp +++ b/tests/unit/interpreter.cpp @@ -101,6 +101,8 @@ class InterpreterTest : public ::testing::Test { disk_test_utils::RemoveRocksDbDirs(testSuite); disk_test_utils::RemoveRocksDbDirs(testSuiteCsv); } + + std::filesystem::remove_all(data_directory); } InterpreterFaker default_interpreter{&interpreter_context, db}; diff --git a/tests/unit/query_dump.cpp b/tests/unit/query_dump.cpp index 5556ab90a..63019ad28 100644 --- a/tests/unit/query_dump.cpp +++ b/tests/unit/query_dump.cpp @@ -700,6 +700,11 @@ TYPED_TEST(DumpTest, CheckStateVertexWithMultipleProperties) { config.disk = disk_test_utils::GenerateOnDiskConfig("query-dump-s1").disk; config.force_on_disk = true; } + auto on_exit_s1 = memgraph::utils::OnScopeExit{[&]() { + if constexpr (std::is_same_v) { + disk_test_utils::RemoveRocksDbDirs("query-dump-s1"); + } + }}; memgraph::replication::ReplicationState repl_state(ReplicationStateRootPath(config)); memgraph::utils::Gatekeeper db_gk(config, repl_state); @@ -814,7 +819,11 @@ TYPED_TEST(DumpTest, CheckStateSimpleGraph) { config.disk = disk_test_utils::GenerateOnDiskConfig("query-dump-s2").disk; config.force_on_disk = true; } - + auto on_exit_s2 = memgraph::utils::OnScopeExit{[&]() { + if constexpr (std::is_same_v) { + disk_test_utils::RemoveRocksDbDirs("query-dump-s2"); + } + }}; memgraph::replication::ReplicationState repl_state{ReplicationStateRootPath(config)}; memgraph::utils::Gatekeeper db_gk{config, repl_state}; auto db_acc_opt = db_gk.access(); diff --git a/tests/unit/storage_v2_isolation_level.cpp b/tests/unit/storage_v2_isolation_level.cpp index 5cdfb5656..d2ae14d8f 100644 --- a/tests/unit/storage_v2_isolation_level.cpp +++ b/tests/unit/storage_v2_isolation_level.cpp @@ -15,6 +15,7 @@ #include "storage/v2/disk/storage.hpp" #include "storage/v2/inmemory/storage.hpp" #include "storage/v2/isolation_level.hpp" +#include "utils/on_scope_exit.hpp" namespace { int64_t VerticesCount(memgraph::storage::Storage::Accessor *accessor) { @@ -113,6 +114,7 @@ TEST_P(StorageIsolationLevelTest, VisibilityOnDiskStorage) { for (const auto override_isolation_level : isolation_levels) { std::unique_ptr storage(new memgraph::storage::DiskStorage(config)); + auto on_exit = memgraph::utils::OnScopeExit{[&]() { disk_test_utils::RemoveRocksDbDirs(testSuite); }}; try { this->TestVisibility(storage, default_isolation_level, override_isolation_level); } catch (memgraph::utils::NotYetImplemented &) { @@ -120,10 +122,8 @@ TEST_P(StorageIsolationLevelTest, VisibilityOnDiskStorage) { override_isolation_level != memgraph::storage::IsolationLevel::SNAPSHOT_ISOLATION) { continue; } - disk_test_utils::RemoveRocksDbDirs(testSuite); throw; } - disk_test_utils::RemoveRocksDbDirs(testSuite); } } diff --git a/tests/unit/storage_v2_storage_mode.cpp b/tests/unit/storage_v2_storage_mode.cpp index 3daea2e69..49ee633c5 100644 --- a/tests/unit/storage_v2_storage_mode.cpp +++ b/tests/unit/storage_v2_storage_mode.cpp @@ -75,6 +75,8 @@ class StorageModeMultiTxTest : public ::testing::Test { return tmp; }(); // iile + void TearDown() override { std::filesystem::remove_all(data_directory); } + memgraph::storage::Config config{.durability.storage_directory = data_directory, .disk.main_storage_directory = data_directory / "disk"};