More thorough pagination test
Previously we were checking if we walk through INDEX_SIZE results, without caring what they were. This patch changes it so that we expect to see INDEX_SIZE *distinct* ids in the result set.
- Id
- ec0edd76b0e006b966e535a69e1e44b7e8da442d
- Author
- Caio
- Commit time
- 2019-12-07T04:50:13+01:00
Modified crates/cantine/tests/index_integration.rs
use serde_json;
use once_cell::sync::Lazy;
-use std::{collections::HashMap, convert::TryFrom};
+use std::{
+ collections::{HashMap, HashSet},
+ convert::TryFrom,
+};
use tantivy::{query::AllQuery, schema::SchemaBuilder, Index, Result};
use cantine::{
let reader = GLOBAL.index.reader()?;
let searcher = reader.searcher();
- let (total, found_ids, next) = GLOBAL.cantine.search(
- &searcher,
- &AllQuery,
- 10,
- Sort::Relevance,
- SearchCursor::START,
- )?;
-
- assert_eq!(INDEX_SIZE, total);
- assert!(next.is_some());
-
- let mut after = next.unwrap();
- let mut total_found = found_ids.len();
+ let mut after = SearchCursor::START;
+ let mut seen = HashSet::with_capacity(INDEX_SIZE);
loop {
let (_total, found_ids, next) =
.cantine
.search(&searcher, &AllQuery, 10, Sort::Relevance, after)?;
- total_found += found_ids.len();
+ for id in found_ids {
+ seen.insert(id);
+ }
if let Some(new_after) = next {
after = new_after;
}
}
- assert_eq!(INDEX_SIZE, total_found);
+ assert_eq!(INDEX_SIZE, seen.len());
Ok(())
}