diff --git a/tests/svs/index/flat/flat.cpp b/tests/svs/index/flat/flat.cpp index c43f1cab3..e1572e57d 100644 --- a/tests/svs/index/flat/flat.cpp +++ b/tests/svs/index/flat/flat.cpp @@ -18,6 +18,7 @@ #include "svs/core/logging.h" #include "svs/lib/file.h" #include "svs/lib/saveload/load.h" +#include "svs/lib/scopeguard.h" #include "svs/orchestrators/exhaustive.h" // tests @@ -30,6 +31,9 @@ // spd log #include "spdlog/sinks/callback_sink.h" +// stl +#include + CATCH_TEST_CASE("FlatIndex Logging Test", "[logging]") { // Vector to store captured log messages std::vector captured_logs; @@ -55,6 +59,13 @@ CATCH_TEST_CASE("FlatIndex Logging Test", "[logging]") { global_callback_sink->set_level(spdlog::level::trace); auto original_logger = svs::logging::get(); original_logger->sinks().push_back(global_callback_sink); + // The sink captures a local vector: remove it before the vector goes out of scope. + auto remove_sink = svs::lib::make_scope_guard([&]() noexcept { + auto& sinks = original_logger->sinks(); + sinks.erase( + std::remove(sinks.begin(), sinks.end(), global_callback_sink), sinks.end() + ); + }); std::vector data{1.0f, 2.0f}; auto dataView = svs::data::SimpleDataView(data.data(), 2, 1); diff --git a/tests/svs/index/inverted/clustering.cpp b/tests/svs/index/inverted/clustering.cpp index 6ac896256..b0802fb4a 100644 --- a/tests/svs/index/inverted/clustering.cpp +++ b/tests/svs/index/inverted/clustering.cpp @@ -17,6 +17,9 @@ // header under test #include "svs/index/inverted/clustering.h" +// svs +#include "svs/lib/scopeguard.h" + // tests #include "tests/utils/test_dataset.h" #include "tests/utils/utils.h" @@ -25,6 +28,7 @@ #include "catch2/catch_test_macros.hpp" // stl +#include #include // logging @@ -415,6 +419,13 @@ CATCH_TEST_CASE("Clustering with Logger", "[logging]") { global_callback_sink->set_level(spdlog::level::trace); auto original_logger = svs::logging::get(); original_logger->sinks().push_back(global_callback_sink); + // The sink captures a local vector: remove it before the vector goes out of scope. + auto remove_sink = svs::lib::make_scope_guard([&]() noexcept { + auto& sinks = original_logger->sinks(); + sinks.erase( + std::remove(sinks.begin(), sinks.end(), global_callback_sink), sinks.end() + ); + }); // Setup cluster auto data = svs::data::SimpleData::load(test_dataset::data_svs_file()); diff --git a/tests/svs/index/inverted/memory_based.cpp b/tests/svs/index/inverted/memory_based.cpp index 28ff6b269..51d32a015 100644 --- a/tests/svs/index/inverted/memory_based.cpp +++ b/tests/svs/index/inverted/memory_based.cpp @@ -18,10 +18,12 @@ #include "catch2/catch_test_macros.hpp" #include "spdlog/sinks/callback_sink.h" #include "svs-benchmark/datasets.h" +#include "svs/lib/scopeguard.h" #include "svs/lib/timing.h" #include "svs/orchestrators/inverted.h" #include "tests/utils/inverted_reference.h" #include "tests/utils/test_dataset.h" +#include #include #include @@ -50,6 +52,13 @@ CATCH_TEST_CASE("InvertedIndex Logging Test", "[long][logging]") { global_callback_sink->set_level(spdlog::level::trace); auto original_logger = svs::logging::get(); original_logger->sinks().push_back(global_callback_sink); + // The sink captures a local vector: remove it before the vector goes out of scope. + auto remove_sink = svs::lib::make_scope_guard([&]() noexcept { + auto& sinks = original_logger->sinks(); + sinks.erase( + std::remove(sinks.begin(), sinks.end(), global_callback_sink), sinks.end() + ); + }); // Setup index auto distance = svs::DistanceL2(); diff --git a/tests/svs/index/vamana/dynamic_index_2.cpp b/tests/svs/index/vamana/dynamic_index_2.cpp index 2daeda29e..da85a6903 100644 --- a/tests/svs/index/vamana/dynamic_index_2.cpp +++ b/tests/svs/index/vamana/dynamic_index_2.cpp @@ -21,6 +21,7 @@ #include "svs/index/vamana/dynamic_index.h" #include "svs/lib/float16.h" #include "svs/lib/preprocessor.h" +#include "svs/lib/scopeguard.h" #include "svs/lib/timing.h" #include "svs/misc/dynamic_helper.h" @@ -283,6 +284,13 @@ CATCH_TEST_CASE("Testing Graph Index", "[graph_index][dynamic_index]") { global_callback_sink->set_level(spdlog::level::trace); auto original_logger = svs::logging::get(); original_logger->sinks().push_back(global_callback_sink); + // The sink captures a local vector: remove it before the vector goes out of scope. + auto remove_sink = svs::lib::make_scope_guard([&]() noexcept { + auto& sinks = original_logger->sinks(); + sinks.erase( + std::remove(sinks.begin(), sinks.end(), global_callback_sink), sinks.end() + ); + }); // Load the base dataset and queries. auto data = svs::data::SimpleData::load(test_dataset::data_svs_file()); @@ -495,6 +503,13 @@ CATCH_TEST_CASE("Dynamic MutableVamanaIndex Per-Index Logging Test", "[logging]" auto original_logger = svs::logging::get(); original_logger->sinks().push_back(global_callback_sink); + // The sink captures a local vector: remove it before the vector goes out of scope. + auto remove_sink = svs::lib::make_scope_guard([&]() noexcept { + auto& sinks = original_logger->sinks(); + sinks.erase( + std::remove(sinks.begin(), sinks.end(), global_callback_sink), sinks.end() + ); + }); // Setup index auto data = svs::data::SimpleData::load(test_dataset::data_svs_file()); diff --git a/tests/svs/index/vamana/index.cpp b/tests/svs/index/vamana/index.cpp index 3cd7ea211..99a14436f 100644 --- a/tests/svs/index/vamana/index.cpp +++ b/tests/svs/index/vamana/index.cpp @@ -25,6 +25,7 @@ #include "svs/extensions/vamana/scalar.h" #include "svs/index/vamana/build_params.h" #include "svs/lib/preprocessor.h" +#include "svs/lib/scopeguard.h" #include "svs/orchestrators/vamana.h" #include "svs/quantization/scalar/scalar.h" @@ -41,6 +42,7 @@ // svsbenchmark #include "svs-benchmark/benchmark.h" // stl +#include #include #include @@ -159,6 +161,13 @@ CATCH_TEST_CASE("Static VamanaIndex Per-Index Logging", "[logging]") { auto original_logger = svs::logging::get(); original_logger->sinks().push_back(global_callback_sink); + // The sink captures a local vector: remove it before the vector goes out of scope. + auto remove_sink = svs::lib::make_scope_guard([&]() noexcept { + auto& sinks = original_logger->sinks(); + sinks.erase( + std::remove(sinks.begin(), sinks.end(), global_callback_sink), sinks.end() + ); + }); // Create some minimal data auto data = svs::data::SimpleData::load(test_dataset::data_svs_file());