mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-25 22:34:28 +01:00
Fix the tests
This commit is contained in:
parent
0d4482625a
commit
462b4c0080
@ -1,7 +1,7 @@
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use meilisearch_types::heed::types::{OwnedType, SerdeBincode, SerdeJson, Str};
|
use meilisearch_types::heed::types::{SerdeBincode, SerdeJson, Str};
|
||||||
use meilisearch_types::heed::{Database, RoTxn};
|
use meilisearch_types::heed::{Database, RoTxn};
|
||||||
use meilisearch_types::milli::{CboRoaringBitmapCodec, RoaringBitmapCodec, BEU32};
|
use meilisearch_types::milli::{CboRoaringBitmapCodec, RoaringBitmapCodec, BEU32};
|
||||||
use meilisearch_types::tasks::{Details, Task};
|
use meilisearch_types::tasks::{Details, Task};
|
||||||
@ -115,7 +115,7 @@ pub fn snapshot_bitmap(r: &RoaringBitmap) -> String {
|
|||||||
snap
|
snap
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot_all_tasks(rtxn: &RoTxn, db: Database<OwnedType<BEU32>, SerdeJson<Task>>) -> String {
|
pub fn snapshot_all_tasks(rtxn: &RoTxn, db: Database<BEU32, SerdeJson<Task>>) -> String {
|
||||||
let mut snap = String::new();
|
let mut snap = String::new();
|
||||||
let iter = db.iter(rtxn).unwrap();
|
let iter = db.iter(rtxn).unwrap();
|
||||||
for next in iter {
|
for next in iter {
|
||||||
@ -125,10 +125,7 @@ pub fn snapshot_all_tasks(rtxn: &RoTxn, db: Database<OwnedType<BEU32>, SerdeJson
|
|||||||
snap
|
snap
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot_date_db(
|
pub fn snapshot_date_db(rtxn: &RoTxn, db: Database<BEI128, CboRoaringBitmapCodec>) -> String {
|
||||||
rtxn: &RoTxn,
|
|
||||||
db: Database<OwnedType<BEI128>, CboRoaringBitmapCodec>,
|
|
||||||
) -> String {
|
|
||||||
let mut snap = String::new();
|
let mut snap = String::new();
|
||||||
let iter = db.iter(rtxn).unwrap();
|
let iter = db.iter(rtxn).unwrap();
|
||||||
for next in iter {
|
for next in iter {
|
||||||
@ -248,10 +245,7 @@ pub fn snapshot_index_tasks(rtxn: &RoTxn, db: Database<Str, RoaringBitmapCodec>)
|
|||||||
}
|
}
|
||||||
snap
|
snap
|
||||||
}
|
}
|
||||||
pub fn snapshot_canceled_by(
|
pub fn snapshot_canceled_by(rtxn: &RoTxn, db: Database<BEU32, RoaringBitmapCodec>) -> String {
|
||||||
rtxn: &RoTxn,
|
|
||||||
db: Database<OwnedType<BEU32>, RoaringBitmapCodec>,
|
|
||||||
) -> String {
|
|
||||||
let mut snap = String::new();
|
let mut snap = String::new();
|
||||||
let iter = db.iter(rtxn).unwrap();
|
let iter = db.iter(rtxn).unwrap();
|
||||||
for next in iter {
|
for next in iter {
|
||||||
|
@ -337,7 +337,7 @@ impl IndexScheduler {
|
|||||||
let rtxn = self.env.read_txn().unwrap();
|
let rtxn = self.env.read_txn().unwrap();
|
||||||
for task in self.all_tasks.iter(&rtxn).unwrap() {
|
for task in self.all_tasks.iter(&rtxn).unwrap() {
|
||||||
let (task_id, task) = task.unwrap();
|
let (task_id, task) = task.unwrap();
|
||||||
let task_id = task_id.get();
|
let task_id = task_id;
|
||||||
|
|
||||||
let task_index_uid = task.index_uid().map(ToOwned::to_owned);
|
let task_index_uid = task.index_uid().map(ToOwned::to_owned);
|
||||||
|
|
||||||
@ -361,16 +361,13 @@ impl IndexScheduler {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(task.uid));
|
.contains(task.uid));
|
||||||
}
|
}
|
||||||
let db_enqueued_at = self
|
let db_enqueued_at =
|
||||||
.enqueued_at
|
self.enqueued_at.get(&rtxn, &enqueued_at.unix_timestamp_nanos()).unwrap().unwrap();
|
||||||
.get(&rtxn, &BEI128::new(enqueued_at.unix_timestamp_nanos()))
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert!(db_enqueued_at.contains(task_id));
|
assert!(db_enqueued_at.contains(task_id));
|
||||||
if let Some(started_at) = started_at {
|
if let Some(started_at) = started_at {
|
||||||
let db_started_at = self
|
let db_started_at = self
|
||||||
.started_at
|
.started_at
|
||||||
.get(&rtxn, &BEI128::new(started_at.unix_timestamp_nanos()))
|
.get(&rtxn, &started_at.unix_timestamp_nanos())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(db_started_at.contains(task_id));
|
assert!(db_started_at.contains(task_id));
|
||||||
@ -378,7 +375,7 @@ impl IndexScheduler {
|
|||||||
if let Some(finished_at) = finished_at {
|
if let Some(finished_at) = finished_at {
|
||||||
let db_finished_at = self
|
let db_finished_at = self
|
||||||
.finished_at
|
.finished_at
|
||||||
.get(&rtxn, &BEI128::new(finished_at.unix_timestamp_nanos()))
|
.get(&rtxn, &finished_at.unix_timestamp_nanos())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(db_finished_at.contains(task_id));
|
assert!(db_finished_at.contains(task_id));
|
||||||
|
@ -1594,7 +1594,7 @@ pub(crate) mod tests {
|
|||||||
}
|
}
|
||||||
pub fn add_documents_using_wtxn<'t, R>(
|
pub fn add_documents_using_wtxn<'t, R>(
|
||||||
&'t self,
|
&'t self,
|
||||||
wtxn: &mut RwTxn<'t, '_>,
|
wtxn: &mut RwTxn<'t>,
|
||||||
documents: DocumentsBatchReader<R>,
|
documents: DocumentsBatchReader<R>,
|
||||||
) -> Result<(), crate::error::Error>
|
) -> Result<(), crate::error::Error>
|
||||||
where
|
where
|
||||||
@ -1638,7 +1638,7 @@ pub(crate) mod tests {
|
|||||||
}
|
}
|
||||||
pub fn update_settings_using_wtxn<'t>(
|
pub fn update_settings_using_wtxn<'t>(
|
||||||
&'t self,
|
&'t self,
|
||||||
wtxn: &mut RwTxn<'t, '_>,
|
wtxn: &mut RwTxn<'t>,
|
||||||
update: impl Fn(&mut Settings),
|
update: impl Fn(&mut Settings),
|
||||||
) -> Result<(), crate::error::Error> {
|
) -> Result<(), crate::error::Error> {
|
||||||
let mut builder = update::Settings::new(wtxn, &self.inner, &self.indexer_config);
|
let mut builder = update::Settings::new(wtxn, &self.inner, &self.indexer_config);
|
||||||
@ -1649,7 +1649,7 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
pub fn delete_documents_using_wtxn<'t>(
|
pub fn delete_documents_using_wtxn<'t>(
|
||||||
&'t self,
|
&'t self,
|
||||||
wtxn: &mut RwTxn<'t, '_>,
|
wtxn: &mut RwTxn<'t>,
|
||||||
external_document_ids: Vec<String>,
|
external_document_ids: Vec<String>,
|
||||||
) {
|
) {
|
||||||
let builder = IndexDocuments::new(
|
let builder = IndexDocuments::new(
|
||||||
|
@ -486,8 +486,8 @@ pub(crate) mod test_helpers {
|
|||||||
|
|
||||||
let iter = self
|
let iter = self
|
||||||
.content
|
.content
|
||||||
.as_polymorph()
|
.remap_types::<ByteSlice, FacetGroupValueCodec>()
|
||||||
.prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(txn, &level_no_prefix)
|
.prefix_iter(txn, &level_no_prefix)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
for el in iter {
|
for el in iter {
|
||||||
let (key, value) = el.unwrap();
|
let (key, value) = el.unwrap();
|
||||||
@ -501,11 +501,8 @@ pub(crate) mod test_helpers {
|
|||||||
let start_below = {
|
let start_below = {
|
||||||
let mut start_below_iter = self
|
let mut start_below_iter = self
|
||||||
.content
|
.content
|
||||||
.as_polymorph()
|
.remap_types::<ByteSlice, FacetGroupValueCodec>()
|
||||||
.prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(
|
.prefix_iter(txn, &prefix_start_below)
|
||||||
txn,
|
|
||||||
&prefix_start_below,
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (key_bytes, _) = start_below_iter.next().unwrap().unwrap();
|
let (key_bytes, _) = start_below_iter.next().unwrap().unwrap();
|
||||||
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key_bytes).unwrap()
|
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key_bytes).unwrap()
|
||||||
@ -612,7 +609,7 @@ mod comparison_bench {
|
|||||||
}
|
}
|
||||||
let time_spent = timer.elapsed().as_millis();
|
let time_spent = timer.elapsed().as_millis();
|
||||||
println!(" add {nbr_doc} : {time_spent}ms");
|
println!(" add {nbr_doc} : {time_spent}ms");
|
||||||
txn.abort().unwrap();
|
txn.abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -701,7 +701,7 @@ mod tests {
|
|||||||
use crate::documents::documents_batch_reader_from_objects;
|
use crate::documents::documents_batch_reader_from_objects;
|
||||||
use crate::index::tests::TempIndex;
|
use crate::index::tests::TempIndex;
|
||||||
use crate::search::TermsMatchingStrategy;
|
use crate::search::TermsMatchingStrategy;
|
||||||
use crate::{db_snap, Filter, Search, BEU16};
|
use crate::{db_snap, Filter, Search};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_document_replacement() {
|
fn simple_document_replacement() {
|
||||||
@ -1743,14 +1743,11 @@ mod tests {
|
|||||||
let colour_green_id = index.fields_ids_map(&rtxn).unwrap().id("colour.green").unwrap();
|
let colour_green_id = index.fields_ids_map(&rtxn).unwrap().id("colour.green").unwrap();
|
||||||
|
|
||||||
let bitmap_colour =
|
let bitmap_colour =
|
||||||
index.facet_id_exists_docids.get(&rtxn, &BEU16::new(colour_id)).unwrap().unwrap();
|
index.facet_id_exists_docids.get(&rtxn, &colour_id).unwrap().unwrap();
|
||||||
assert_eq!(bitmap_colour.into_iter().collect::<Vec<_>>(), vec![0, 1, 2, 3, 4, 6, 7]);
|
assert_eq!(bitmap_colour.into_iter().collect::<Vec<_>>(), vec![0, 1, 2, 3, 4, 6, 7]);
|
||||||
|
|
||||||
let bitmap_colour_green = index
|
let bitmap_colour_green =
|
||||||
.facet_id_exists_docids
|
index.facet_id_exists_docids.get(&rtxn, &colour_green_id).unwrap().unwrap();
|
||||||
.get(&rtxn, &BEU16::new(colour_green_id))
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(bitmap_colour_green.into_iter().collect::<Vec<_>>(), vec![6, 7]);
|
assert_eq!(bitmap_colour_green.into_iter().collect::<Vec<_>>(), vec![6, 7]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1848,21 +1845,15 @@ mod tests {
|
|||||||
index.fields_ids_map(&rtxn).unwrap().id("colour.green.blue").unwrap();
|
index.fields_ids_map(&rtxn).unwrap().id("colour.green.blue").unwrap();
|
||||||
|
|
||||||
let bitmap_null_colour =
|
let bitmap_null_colour =
|
||||||
index.facet_id_is_null_docids.get(&rtxn, &BEU16::new(colour_id)).unwrap().unwrap();
|
index.facet_id_is_null_docids.get(&rtxn, &colour_id).unwrap().unwrap();
|
||||||
assert_eq!(bitmap_null_colour.into_iter().collect::<Vec<_>>(), vec![0]);
|
assert_eq!(bitmap_null_colour.into_iter().collect::<Vec<_>>(), vec![0]);
|
||||||
|
|
||||||
let bitmap_colour_green = index
|
let bitmap_colour_green =
|
||||||
.facet_id_is_null_docids
|
index.facet_id_is_null_docids.get(&rtxn, &colour_green_id).unwrap().unwrap();
|
||||||
.get(&rtxn, &BEU16::new(colour_green_id))
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(bitmap_colour_green.into_iter().collect::<Vec<_>>(), vec![2]);
|
assert_eq!(bitmap_colour_green.into_iter().collect::<Vec<_>>(), vec![2]);
|
||||||
|
|
||||||
let bitmap_colour_blue = index
|
let bitmap_colour_blue =
|
||||||
.facet_id_is_null_docids
|
index.facet_id_is_null_docids.get(&rtxn, &colour_blue_id).unwrap().unwrap();
|
||||||
.get(&rtxn, &BEU16::new(colour_blue_id))
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(bitmap_colour_blue.into_iter().collect::<Vec<_>>(), vec![3]);
|
assert_eq!(bitmap_colour_blue.into_iter().collect::<Vec<_>>(), vec![3]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1917,21 +1908,15 @@ mod tests {
|
|||||||
let tags_blue_id = index.fields_ids_map(&rtxn).unwrap().id("tags.green.blue").unwrap();
|
let tags_blue_id = index.fields_ids_map(&rtxn).unwrap().id("tags.green.blue").unwrap();
|
||||||
|
|
||||||
let bitmap_empty_tags =
|
let bitmap_empty_tags =
|
||||||
index.facet_id_is_empty_docids.get(&rtxn, &BEU16::new(tags_id)).unwrap().unwrap();
|
index.facet_id_is_empty_docids.get(&rtxn, &tags_id).unwrap().unwrap();
|
||||||
assert_eq!(bitmap_empty_tags.into_iter().collect::<Vec<_>>(), vec![2, 6, 9]);
|
assert_eq!(bitmap_empty_tags.into_iter().collect::<Vec<_>>(), vec![2, 6, 9]);
|
||||||
|
|
||||||
let bitmap_tags_green = index
|
let bitmap_tags_green =
|
||||||
.facet_id_is_empty_docids
|
index.facet_id_is_empty_docids.get(&rtxn, &tags_green_id).unwrap().unwrap();
|
||||||
.get(&rtxn, &BEU16::new(tags_green_id))
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(bitmap_tags_green.into_iter().collect::<Vec<_>>(), vec![8]);
|
assert_eq!(bitmap_tags_green.into_iter().collect::<Vec<_>>(), vec![8]);
|
||||||
|
|
||||||
let bitmap_tags_blue = index
|
let bitmap_tags_blue =
|
||||||
.facet_id_is_empty_docids
|
index.facet_id_is_empty_docids.get(&rtxn, &tags_blue_id).unwrap().unwrap();
|
||||||
.get(&rtxn, &BEU16::new(tags_blue_id))
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(bitmap_tags_blue.into_iter().collect::<Vec<_>>(), vec![12]);
|
assert_eq!(bitmap_tags_blue.into_iter().collect::<Vec<_>>(), vec![12]);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2684,7 +2669,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn delete_documents<'t>(
|
fn delete_documents<'t>(
|
||||||
wtxn: &mut RwTxn<'t, '_>,
|
wtxn: &mut RwTxn<'t>,
|
||||||
index: &'t TempIndex,
|
index: &'t TempIndex,
|
||||||
external_ids: &[&str],
|
external_ids: &[&str],
|
||||||
) -> Vec<u32> {
|
) -> Vec<u32> {
|
||||||
|
@ -1565,7 +1565,7 @@ mod tests {
|
|||||||
})
|
})
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
assert!(matches!(error, Error::UserError(UserError::PrimaryKeyCannotBeChanged(_))));
|
assert!(matches!(error, Error::UserError(UserError::PrimaryKeyCannotBeChanged(_))));
|
||||||
wtxn.abort().unwrap();
|
wtxn.abort();
|
||||||
|
|
||||||
// But if we clear the database...
|
// But if we clear the database...
|
||||||
let mut wtxn = index.write_txn().unwrap();
|
let mut wtxn = index.write_txn().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user