Added a stress test for selling queries

+ Queries are pretty much linear with the number of shops/items added
+ Tested with 1000 shows with 10 items each, query took 100ms
main
Joey Hines 2021-11-14 15:38:32 -07:00
parent 8e8798f509
commit ebaf28e39e
No known key found for this signature in database
GPG Key ID: 80F567B5C968F91B
1 changed files with 79 additions and 0 deletions

View File

@ -71,3 +71,82 @@ impl Command for Selling {
Ok(shops)
}
}
#[cfg(test)]
mod test {
use crate::commands::selling::Selling;
use crate::commands::Command;
use crate::config::GeoffreyAPIConfig;
use crate::context::Context;
use geoffrey_models::models::item::ItemListing;
use geoffrey_models::models::locations::shop::Shop;
use geoffrey_models::models::locations::{LocationDataDb, LocationDb};
use geoffrey_models::models::parameters::selling_params::SellingParams;
use geoffrey_models::models::Position;
use std::path::PathBuf;
use std::time::Instant;
fn test_selling_lookup_speed(iter: i32, shop_count: i32, items_for_sale: i32) -> f32 {
let config = GeoffreyAPIConfig {
db_path: PathBuf::from("test_db/"),
host: "".to_string(),
};
let ctx = Context::new(config.clone()).unwrap();
let mut shop_data = Shop::default();
for _ in 0..items_for_sale {
shop_data
.item_listings
.insert(ItemListing::new("sed", 5, 5));
}
for i in 0..shop_count {
let shop = LocationDb::new(
format!("Test Shop {} {}", iter, i).as_str(),
Position::default(),
0,
None,
LocationDataDb::Shop(shop_data.clone()),
);
ctx.db.insert(shop).unwrap();
}
let start = Instant::now();
Selling::run_command(
ctx,
SellingParams {
token: "".to_string(),
query: "sed".to_string(),
sort: None,
order: None,
},
None,
)
.unwrap();
let query_dur = start.elapsed().as_secs_f32();
return query_dur;
}
#[test]
fn stress_test() {
std::fs::remove_dir_all(PathBuf::from("test_db")).ok();
println!("Shop Count,Item Count,Query Time,Query Time / Shop");
for shop_count in (100..=1000).step_by(100) {
let query_dur = test_selling_lookup_speed(shop_count, 100, 10);
println!(
"{},{},{},{}",
shop_count,
10,
query_dur,
query_dur / (shop_count as f32)
);
}
std::fs::remove_dir_all(PathBuf::from("test_db")).ok();
}
}