|
|
@@ -341,6 +341,31 @@ void test_drop_nonexistent_returns_false() {
|
|
|
"drop_collection returns false for absent collection");
|
|
|
}
|
|
|
|
|
|
+// Regression: drop_collection must purge the parallel _vectors_<coll> sub-db
|
|
|
+// too, not just the docs sub-db. Otherwise vectors survive a drop and leak
|
|
|
+// into a recreated same-name collection (search returns them though
|
|
|
+// document_count reads 0).
|
|
|
+void test_drop_collection_purges_vectors() {
|
|
|
+ TmpEnv t("drop-vectors");
|
|
|
+ LmdbDocumentStore store(t.env);
|
|
|
+
|
|
|
+ store.put("c", "a", make_doc("a", "c", nlohmann::json{{"v", 1}}));
|
|
|
+ store.put_vector("c", "a", std::vector<float>{1.0f, 0.0f, 0.0f, 0.0f});
|
|
|
+ check(store.get_vector("c", "a").has_value(), "precondition: vector present");
|
|
|
+
|
|
|
+ check(store.drop_collection("c"), "drop_collection returns true");
|
|
|
+ check(store.count("c") == 0, "post-drop doc count is 0");
|
|
|
+ check(!store.get_vector("c", "a").has_value(),
|
|
|
+ "post-drop get_vector returns nullopt (vector sub-db purged)");
|
|
|
+
|
|
|
+ // A drop with only a vectors sub-db (no docs) must still report success.
|
|
|
+ store.put_vector("vecsonly", "x", std::vector<float>{0.0f, 1.0f});
|
|
|
+ check(store.drop_collection("vecsonly"),
|
|
|
+ "drop_collection returns true when only the vectors sub-db exists");
|
|
|
+ check(!store.get_vector("vecsonly", "x").has_value(),
|
|
|
+ "vectors-only collection fully purged");
|
|
|
+}
|
|
|
+
|
|
|
void test_scan_returns_all_for_empty_query() {
|
|
|
TmpEnv t("scan-empty-query");
|
|
|
LmdbDocumentStore store(t.env);
|
|
|
@@ -739,6 +764,7 @@ int main() {
|
|
|
test_list_collections_after_inserts();
|
|
|
test_drop_collection_removes_all_docs();
|
|
|
test_drop_nonexistent_returns_false();
|
|
|
+ test_drop_collection_purges_vectors();
|
|
|
test_scan_returns_all_for_empty_query();
|
|
|
test_scan_returns_empty_for_nonexistent_collection();
|
|
|
|