mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 09:56:28 +00:00 
			
		
		
		
	Remove all autogenerated tests
This commit is contained in:
		
				
					committed by
					
						
						Clément Renault
					
				
			
			
				
	
			
			
			
						parent
						
							07a72824b7
						
					
				
				
					commit
					6641c3f59b
				
			@@ -416,17 +416,16 @@ mod tests {
 | 
			
		||||
        // All the tests here avoid using the code in `facet_distribution_iter` because there aren't
 | 
			
		||||
        // enough candidates.
 | 
			
		||||
 | 
			
		||||
        let mut index = TempIndex::new();
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        let index = TempIndex::new();
 | 
			
		||||
 | 
			
		||||
        index
 | 
			
		||||
            .update_settings(|settings| settings.set_filterable_fields(hashset! { S("colour") }))
 | 
			
		||||
            .unwrap();
 | 
			
		||||
 | 
			
		||||
        let documents = documents!([
 | 
			
		||||
            { "colour": "Blue" },
 | 
			
		||||
            { "colour": "  blue" },
 | 
			
		||||
            { "colour": "RED" }
 | 
			
		||||
            { "id": 0, "colour": "Blue" },
 | 
			
		||||
            { "id": 1, "colour": "  blue" },
 | 
			
		||||
            { "id": 2, "colour": "RED" }
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        index.add_documents(documents).unwrap();
 | 
			
		||||
@@ -488,8 +487,7 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn many_candidates_few_facet_values() {
 | 
			
		||||
        let mut index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        let index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
 | 
			
		||||
        index
 | 
			
		||||
            .update_settings(|settings| settings.set_filterable_fields(hashset! { S("colour") }))
 | 
			
		||||
@@ -500,6 +498,7 @@ mod tests {
 | 
			
		||||
        let mut documents = vec![];
 | 
			
		||||
        for i in 0..10_000 {
 | 
			
		||||
            let document = serde_json::json!({
 | 
			
		||||
                "id": i,
 | 
			
		||||
                "colour": facet_values[i % 5],
 | 
			
		||||
            })
 | 
			
		||||
            .as_object()
 | 
			
		||||
@@ -573,8 +572,7 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn many_candidates_many_facet_values() {
 | 
			
		||||
        let mut index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        let index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
 | 
			
		||||
        index
 | 
			
		||||
            .update_settings(|settings| settings.set_filterable_fields(hashset! { S("colour") }))
 | 
			
		||||
@@ -585,6 +583,7 @@ mod tests {
 | 
			
		||||
        let mut documents = vec![];
 | 
			
		||||
        for i in 0..10_000 {
 | 
			
		||||
            let document = serde_json::json!({
 | 
			
		||||
                "id": i,
 | 
			
		||||
                "colour": facet_values[i % 1000],
 | 
			
		||||
            })
 | 
			
		||||
            .as_object()
 | 
			
		||||
@@ -632,8 +631,7 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn facet_stats() {
 | 
			
		||||
        let mut index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        let index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
 | 
			
		||||
        index
 | 
			
		||||
            .update_settings(|settings| settings.set_filterable_fields(hashset! { S("colour") }))
 | 
			
		||||
@@ -644,6 +642,7 @@ mod tests {
 | 
			
		||||
        let mut documents = vec![];
 | 
			
		||||
        for i in 0..1000 {
 | 
			
		||||
            let document = serde_json::json!({
 | 
			
		||||
                "id": i,
 | 
			
		||||
                "colour": facet_values[i % 1000],
 | 
			
		||||
            })
 | 
			
		||||
            .as_object()
 | 
			
		||||
@@ -683,8 +682,7 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn facet_stats_array() {
 | 
			
		||||
        let mut index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        let index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
 | 
			
		||||
        index
 | 
			
		||||
            .update_settings(|settings| settings.set_filterable_fields(hashset! { S("colour") }))
 | 
			
		||||
@@ -695,6 +693,7 @@ mod tests {
 | 
			
		||||
        let mut documents = vec![];
 | 
			
		||||
        for i in 0..1000 {
 | 
			
		||||
            let document = serde_json::json!({
 | 
			
		||||
                "id": i,
 | 
			
		||||
                "colour": [facet_values[i % 1000], facet_values[i % 1000] + 1000],
 | 
			
		||||
            })
 | 
			
		||||
            .as_object()
 | 
			
		||||
@@ -734,8 +733,7 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn facet_stats_mixed_array() {
 | 
			
		||||
        let mut index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        let index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
 | 
			
		||||
        index
 | 
			
		||||
            .update_settings(|settings| settings.set_filterable_fields(hashset! { S("colour") }))
 | 
			
		||||
@@ -746,6 +744,7 @@ mod tests {
 | 
			
		||||
        let mut documents = vec![];
 | 
			
		||||
        for i in 0..1000 {
 | 
			
		||||
            let document = serde_json::json!({
 | 
			
		||||
                "id": i,
 | 
			
		||||
                "colour": [facet_values[i % 1000], format!("{}", facet_values[i % 1000] + 1000)],
 | 
			
		||||
            })
 | 
			
		||||
            .as_object()
 | 
			
		||||
@@ -785,8 +784,7 @@ mod tests {
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn facet_mixed_values() {
 | 
			
		||||
        let mut index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        let index = TempIndex::new_with_map_size(4096 * 10_000);
 | 
			
		||||
 | 
			
		||||
        index
 | 
			
		||||
            .update_settings(|settings| settings.set_filterable_fields(hashset! { S("colour") }))
 | 
			
		||||
@@ -798,10 +796,12 @@ mod tests {
 | 
			
		||||
        for i in 0..1000 {
 | 
			
		||||
            let document = if i % 2 == 0 {
 | 
			
		||||
                serde_json::json!({
 | 
			
		||||
                    "id": i,
 | 
			
		||||
                    "colour": [facet_values[i % 1000], facet_values[i % 1000] + 1000],
 | 
			
		||||
                })
 | 
			
		||||
            } else {
 | 
			
		||||
                serde_json::json!({
 | 
			
		||||
                    "id": i,
 | 
			
		||||
                    "colour": format!("{}", facet_values[i % 1000] + 10000),
 | 
			
		||||
                })
 | 
			
		||||
            };
 | 
			
		||||
 
 | 
			
		||||
@@ -857,100 +857,6 @@ mod tests {
 | 
			
		||||
        drop(rtxn);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn not_auto_generated_documents_ids() {
 | 
			
		||||
        let index = TempIndex::new();
 | 
			
		||||
 | 
			
		||||
        let result = index.add_documents(documents!([
 | 
			
		||||
            { "name": "kevin" },
 | 
			
		||||
            { "name": "kevina" },
 | 
			
		||||
            { "name": "benoit" }
 | 
			
		||||
        ]));
 | 
			
		||||
        assert!(result.is_err());
 | 
			
		||||
 | 
			
		||||
        // Check that there is no document.
 | 
			
		||||
        let rtxn = index.read_txn().unwrap();
 | 
			
		||||
        let count = index.number_of_documents(&rtxn).unwrap();
 | 
			
		||||
        assert_eq!(count, 0);
 | 
			
		||||
        drop(rtxn);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn simple_auto_generated_documents_ids() {
 | 
			
		||||
        let mut index = TempIndex::new();
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        // First we send 3 documents with ids from 1 to 3.
 | 
			
		||||
        index
 | 
			
		||||
            .add_documents(documents!([
 | 
			
		||||
                { "name": "kevin" },
 | 
			
		||||
                { "name": "kevina" },
 | 
			
		||||
                { "name": "benoit" }
 | 
			
		||||
            ]))
 | 
			
		||||
            .unwrap();
 | 
			
		||||
 | 
			
		||||
        // Check that there is 3 documents now.
 | 
			
		||||
        let rtxn = index.read_txn().unwrap();
 | 
			
		||||
        let count = index.number_of_documents(&rtxn).unwrap();
 | 
			
		||||
        assert_eq!(count, 3);
 | 
			
		||||
 | 
			
		||||
        let docs = index.documents(&rtxn, vec![0, 1, 2]).unwrap();
 | 
			
		||||
        let (_id, obkv) = docs.iter().find(|(_id, kv)| kv.get(0) == Some(br#""kevin""#)).unwrap();
 | 
			
		||||
        let kevin_uuid: String = serde_json::from_slice(obkv.get(1).unwrap()).unwrap();
 | 
			
		||||
        drop(rtxn);
 | 
			
		||||
 | 
			
		||||
        // Second we send 1 document with the generated uuid, to erase the previous ones.
 | 
			
		||||
        index.add_documents(documents!([ { "name": "updated kevin", "id": kevin_uuid } ])).unwrap();
 | 
			
		||||
 | 
			
		||||
        // Check that there is **always** 3 documents.
 | 
			
		||||
        let rtxn = index.read_txn().unwrap();
 | 
			
		||||
        let count = index.number_of_documents(&rtxn).unwrap();
 | 
			
		||||
        assert_eq!(count, 3);
 | 
			
		||||
 | 
			
		||||
        // the document 0 has been deleted and reinserted with the id 3
 | 
			
		||||
        let docs = index.documents(&rtxn, vec![1, 2, 0]).unwrap();
 | 
			
		||||
        let kevin_position =
 | 
			
		||||
            docs.iter().position(|(_, d)| d.get(0).unwrap() == br#""updated kevin""#).unwrap();
 | 
			
		||||
        assert_eq!(kevin_position, 2);
 | 
			
		||||
        let (_, doc) = docs[kevin_position];
 | 
			
		||||
 | 
			
		||||
        // Check that this document is equal to the last
 | 
			
		||||
        // one sent and that an UUID has been generated.
 | 
			
		||||
        assert_eq!(doc.get(0), Some(&br#""updated kevin""#[..]));
 | 
			
		||||
        // This is an UUID, it must be 36 bytes long plus the 2 surrounding string quotes (").
 | 
			
		||||
        assert_eq!(doc.get(1).unwrap().len(), 36 + 2);
 | 
			
		||||
        drop(rtxn);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn reordered_auto_generated_documents_ids() {
 | 
			
		||||
        let mut index = TempIndex::new();
 | 
			
		||||
 | 
			
		||||
        // First we send 3 documents with ids from 1 to 3.
 | 
			
		||||
        index
 | 
			
		||||
            .add_documents(documents!([
 | 
			
		||||
                { "id": 1, "name": "kevin" },
 | 
			
		||||
                { "id": 2, "name": "kevina" },
 | 
			
		||||
                { "id": 3, "name": "benoit" }
 | 
			
		||||
            ]))
 | 
			
		||||
            .unwrap();
 | 
			
		||||
 | 
			
		||||
        // Check that there is 3 documents now.
 | 
			
		||||
        let rtxn = index.read_txn().unwrap();
 | 
			
		||||
        let count = index.number_of_documents(&rtxn).unwrap();
 | 
			
		||||
        assert_eq!(count, 3);
 | 
			
		||||
        drop(rtxn);
 | 
			
		||||
 | 
			
		||||
        // Second we send 1 document without specifying the id.
 | 
			
		||||
        index.index_documents_config.autogenerate_docids = true;
 | 
			
		||||
        index.add_documents(documents!([ { "name": "new kevin" } ])).unwrap();
 | 
			
		||||
 | 
			
		||||
        // Check that there is 4 documents now.
 | 
			
		||||
        let rtxn = index.read_txn().unwrap();
 | 
			
		||||
        let count = index.number_of_documents(&rtxn).unwrap();
 | 
			
		||||
        assert_eq!(count, 4);
 | 
			
		||||
        drop(rtxn);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn empty_update() {
 | 
			
		||||
        let index = TempIndex::new();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user