test: Add a way to setup the fetch timeout of the query-database example

This commit is contained in:
Clément Renault 2019-08-28 13:42:20 +02:00
parent 9c5ec110e5
commit 8030a822ab
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -24,6 +24,9 @@ pub struct Opt {
#[structopt(parse(from_os_str))] #[structopt(parse(from_os_str))]
pub database_path: PathBuf, pub database_path: PathBuf,
#[structopt(long = "fetch-timeout-ms")]
pub fetch_timeout_ms: Option<u64>,
/// Fields that must be displayed. /// Fields that must be displayed.
pub displayed_fields: Vec<String>, pub displayed_fields: Vec<String>,
@ -159,7 +162,13 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(query) => { Ok(query) => {
let start_total = Instant::now(); let start_total = Instant::now();
let builder = index.query_builder().with_fetch_timeout(Duration::from_millis(40)); let builder = match opt.fetch_timeout_ms {
Some(timeout_ms) => {
let timeout = Duration::from_millis(timeout_ms);
index.query_builder().with_fetch_timeout(timeout)
},
None => index.query_builder(),
};
let documents = builder.query(&query, 0..opt.number_results)?; let documents = builder.query(&query, 0..opt.number_results)?;
let mut retrieve_duration = Duration::default(); let mut retrieve_duration = Duration::default();