From 93db755d57a47f7e0ab36b846e503a3fb0d57fac Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 8 Feb 2023 21:03:34 +0100 Subject: [PATCH] add a test to ensure we handle correctly a deletion of multiple time the same document --- milli/src/update/index_documents/mod.rs | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 87c96818e..11e1e5811 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -2104,4 +2104,48 @@ mod tests { {"id":3,"name":"bob","age":25} "###); } + + #[test] + fn delete_the_same_document_multiple_time() { + let index = TempIndex::new(); + let mut wtxn = index.write_txn().unwrap(); + let builder = IndexDocuments::new( + &mut wtxn, + &index, + &index.indexer_config, + index.index_documents_config.clone(), + |_| (), + || false, + ) + .unwrap(); + + let (builder, removed) = + builder.remove_documents(vec![S("1"), S("2"), S("1"), S("2")]).unwrap(); + insta::assert_display_snapshot!(removed.unwrap(), @"0"); + + let documents = documents!([ + { "id": 1, "doggo": "kevin" }, + { "id": 2, "doggo": { "name": "jean", "age": 20 } }, + { "id": 3, "name": "bob", "age": 25 }, + ]); + let (builder, added) = builder.add_documents(documents).unwrap(); + insta::assert_display_snapshot!(added.unwrap(), @"3"); + + let (builder, removed) = + builder.remove_documents(vec![S("1"), S("2"), S("1"), S("2")]).unwrap(); + insta::assert_display_snapshot!(removed.unwrap(), @"2"); + + let addition = builder.execute().unwrap(); + insta::assert_debug_snapshot!(addition, @r###" + DocumentAdditionResult { + indexed_documents: 3, + number_of_documents: 1, + } + "###); + wtxn.commit().unwrap(); + + db_snap!(index, documents, @r###" + {"id":3,"name":"bob","age":25} + "###); + } }