Skip to content

Commit 3fb87dd

Browse files
committed
serializer test
1 parent 55c4fb3 commit 3fb87dd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/unit/test_common.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "VecSim/algorithms/hnsw/hnsw.h"
1919
#include "VecSim/algorithms/hnsw/hnsw_tiered.h"
2020
#include "VecSim/index_factories/hnsw_factory.h"
21+
#include "VecSim/index_factories/svs_factory.h"
22+
#include "VecSim/algorithms/svs/svs.h"
2123
#include "mock_thread_pool.h"
2224
#include "tests_utils.h"
2325
#include "VecSim/index_factories/tiered_factory.h"
@@ -28,6 +30,7 @@
2830
#include <cstdlib>
2931
#include <limits>
3032
#include <cmath>
33+
#include <filesystem>
3134
#include <random>
3235
#include <cstdarg>
3336
#include <filesystem>
@@ -512,6 +515,48 @@ TEST_F(SerializerTest, HNSWSerialzer) {
512515
output.close();
513516
}
514517

518+
#if HAVE_SVS
519+
TEST_F(SerializerTest, SVSSerializer) {
520+
521+
this->file_name = std::string(getenv("ROOT")) + "/tests/unit/bad_index_svs";
522+
auto metadata_path = std::filesystem::path(this->file_name) / "metadata";
523+
524+
// Try to load an index from a directory that doesn't exist.
525+
SVSParams params = {
526+
.type = VecSimType_FLOAT32,
527+
.dim = 1024,
528+
.metric = VecSimMetric_L2,
529+
.blockSize = 1024,
530+
/* SVS-Vamana specifics */
531+
.quantBits = VecSimSvsQuant_NONE,
532+
.graph_max_degree = 63, // x^2-1 to round the graph block size
533+
.construction_window_size = 20,
534+
.max_candidate_pool_size = 1024,
535+
.prune_to = 60,
536+
.use_search_history = VecSimOption_ENABLE,
537+
};
538+
VecSimParams index_params = {.algo = VecSimAlgo_SVS, .algoParams = {.svsParams = params}};
539+
540+
ASSERT_EXCEPTION_MESSAGE(SVSFactory::NewIndex(this->file_name, &index_params), std::runtime_error,
541+
std::string("Failed to open metadata file: ") + metadata_path.string());
542+
543+
// Create directory and metadata file with invalid encoding version
544+
std::filesystem::create_directories(this->file_name);
545+
std::ofstream output(metadata_path, std::ios::binary);
546+
547+
// Write invalid encoding version (42)
548+
Serializer::writeBinaryPOD(output, 42);
549+
output.flush();
550+
output.close();
551+
552+
ASSERT_EXCEPTION_MESSAGE(SVSFactory::NewIndex(this->file_name, &index_params), std::runtime_error,
553+
"Cannot load index: bad encoding version: 42");
554+
555+
// Clean up
556+
std::filesystem::remove_all(this->file_name);
557+
}
558+
#endif
559+
515560
struct logCtx {
516561
public:
517562
std::vector<std::string> logBuffer;

0 commit comments

Comments
 (0)