From 47cde83c7ad08c85ec2522172355565c7ee08a63 Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Tue, 24 Sep 2024 14:35:32 -0700 Subject: [PATCH] fix: async for init_reader --- benches/bench.rs | 2 ++ src/main.rs | 4 +++- src/utils/init_reader.rs | 4 ++-- tests/integration.rs | 10 ++++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/benches/bench.rs b/benches/bench.rs index 4c331c8..480b389 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -26,7 +26,9 @@ fn bench(c: &mut Criterion) { rt.block_on(async { let db = inti_db().await.unwrap(); let reader = File_Format::new("json") + .await .reader("tests/data/bench.json") + .await .unwrap(); CreateVersion::Bulk diff --git a/src/main.rs b/src/main.rs index 8bab9e0..f7a1d2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,9 @@ async fn main() -> Result<(), Error> { sleep(Duration::from_secs(10)).await; let pb = init_progress_bar::create_pb().await; let reader = File_Format::new(get_wikidata_file_format().await) - .reader(get_wikidata_file_name().await)?; + .await + .reader(get_wikidata_file_name().await) + .await?; fs::create_dir_all("data/temp").await?; fs::remove_dir_all("data/temp").await?; diff --git a/src/utils/init_reader.rs b/src/utils/init_reader.rs index d20a102..c6054a6 100644 --- a/src/utils/init_reader.rs +++ b/src/utils/init_reader.rs @@ -11,14 +11,14 @@ pub enum File_Format { bz2, } impl File_Format { - pub fn new(file: &str) -> Self { + pub async fn new(file: &str) -> Self { match file { "json" => Self::json, "bz2" => Self::bz2, _ => panic!("Unknown file format"), } } - pub fn reader(self, file: &str) -> Result, Error> { + pub async fn reader(self, file: &str) -> Result, Error> { let file = File::open(file)?; match self { File_Format::json => Ok(Box::new(BufReader::new(file))), diff --git a/tests/integration.rs b/tests/integration.rs index a8b87b7..fae2125 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -15,9 +15,11 @@ async fn inti_db() -> Result, Error> { Ok(db) } -fn init_reader(file_format: &str, file_name: &str) -> Box { +async fn init_reader(file_format: &str, file_name: &str) -> Box { File_Format::new(file_format) + .await .reader(&format!("./tests/data/{}.{}", file_name, file_format)) + .await .unwrap() } @@ -42,7 +44,7 @@ async fn entity_query(db: &Surreal) -> Result, Error> { #[tokio::test] async fn entity_threaded(#[case] version: CreateVersion) -> Result<(), Error> { let db = inti_db().await?; - let reader = init_reader("json", "Entity"); + let reader = init_reader("json", "Entity").await; version .run(Some(db.clone()), reader, None, 1_000, 100) @@ -56,7 +58,7 @@ async fn entity_threaded(#[case] version: CreateVersion) -> Result<(), Error> { async fn entity_threaded_filter() -> Result<(), Error> { env::set_var("FILTER_PATH", "./tests/data/test_filter.surql"); let db = inti_db().await?; - let reader = init_reader("json", "bench"); + let reader = init_reader("json", "bench").await; CreateVersion::BulkFilter .run(Some(db.clone()), reader, None, 1_000, 100) @@ -88,7 +90,7 @@ async fn property_query(db: &Surreal) -> Result, Error> { #[tokio::test] async fn property_threaded(#[case] version: CreateVersion) -> Result<(), Error> { let db = inti_db().await?; - let reader = init_reader("json", "Property"); + let reader = init_reader("json", "Property").await; version .run(Some(db.clone()), reader, None, 1_000, 100)