diff --git a/services/commtest/tests/backup/backup_utils.rs b/services/commtest/tests/backup/backup_utils.rs index 68d617c9c..2c4bcdf34 100644 --- a/services/commtest/tests/backup/backup_utils.rs +++ b/services/commtest/tests/backup/backup_utils.rs @@ -1,36 +1,38 @@ pub mod proto { tonic::include_proto!("backup"); } pub use proto::backup_service_client::BackupServiceClient; // stands for both, backup and log items #[allow(dead_code)] +#[derive(Clone)] pub struct Item { pub id: String, pub chunks_sizes: Vec, pub attachments_holders: Vec, } #[allow(dead_code)] impl Item { pub fn new( id: String, chunks_sizes: Vec, attachments_holders: Vec, ) -> Item { Item { id, chunks_sizes, attachments_holders, } } } #[allow(dead_code)] +#[derive(Clone)] pub struct BackupData { pub user_id: String, pub device_id: String, pub backup_item: Item, pub log_items: Vec, } diff --git a/services/commtest/tests/backup_performance_test.rs b/services/commtest/tests/backup_performance_test.rs index 2ba9adaf0..cbb0abe41 100644 --- a/services/commtest/tests/backup_performance_test.rs +++ b/services/commtest/tests/backup_performance_test.rs @@ -1,7 +1,54 @@ +#[path = "./backup/backup_utils.rs"] +mod backup_utils; #[path = "./lib/tools.rs"] mod tools; +use bytesize::ByteSize; + +use tools::{obtain_number_of_threads, Error}; + +use backup_utils::{BackupData, Item}; + #[tokio::test] -async fn backup_performance_test() { - assert!(false, "not implemented"); +async fn backup_performance_test() -> Result<(), Error> { + let number_of_threads = obtain_number_of_threads(); + + println!( + "Running performance tests for backup, number of threads: {}", + number_of_threads + ); + + let mut backup_data = vec![]; + + for i in 0..number_of_threads { + backup_data.push(BackupData { + user_id: format!("user{}", i), + device_id: format!("device{}", i), + backup_item: Item::new( + String::new(), + vec![ByteSize::mib(1).as_u64() as usize; 3 + (i % 5)], + (0..(i % 5)).map(|x| format!("holder{}", x)).collect(), + ), + log_items: (0..(i % 4)) + .map(|x| { + Item::new( + String::new(), + vec![ByteSize::mib(1).as_u64() as usize; 2 + (x % 2)], + (0..(i % 5)).map(|x| format!("holder{}-{}", i, x)).collect(), + ) + }) + .collect(), + }); + } + + tokio::task::spawn_blocking(move || { + // CREATE NEW BACKUP + // SEND LOG + // ADD ATTACHMENTS + // PULL BACKUP + }) + .await + .expect("Task panicked"); + + Ok(()) }