diff --git a/services/commtest/tests/backup_test.rs b/services/commtest/tests/backup_test.rs --- a/services/commtest/tests/backup_test.rs +++ b/services/commtest/tests/backup_test.rs @@ -22,6 +22,8 @@ let mut client = BackupServiceClient::connect("http://localhost:50052").await?; + let attachments_fill_size = 500; + let mut backup_data = BackupData { user_id: "user0000".to_string(), device_id: "device0000".to_string(), @@ -40,7 +42,7 @@ // In this case its data should be moved to the S3 Item::new( String::new(), - vec![tools::get_dynamo_db_item_size_limit() - ByteSize::b(100).as_u64() as usize], + vec![tools::get_dynamo_db_item_size_limit() - ByteSize::b(attachments_fill_size/2).as_u64() as usize], vec!["holder0".to_string(), "holder1".to_string()], ), // just a small item @@ -130,7 +132,7 @@ // from the db to the s3 let mut attachments_size = 0; let mut i = backup_data.log_items[0].attachments_holders.len(); - let mut new_attachments: Vec = vec![]; + let mut new_attachments: Vec = Vec::new(); while attachments_size < 500 { let att = format!("holder{}", i); attachments_size += att.len(); @@ -150,8 +152,42 @@ for i in 0..backup_data.log_items.len() { let expected: usize = backup_data.log_items[i].attachments_holders.len(); let from_result: usize = result.log_items[i].attachments_holders.len(); - assert!( - from_result == expected, + assert_eq!( + from_result, expected, + "after attachment add: log {}: number of attachments holders do not match, + expected {}, got {}", + i, + expected, + from_result + ); + } + + // push so many attachments that the log item's data will have to be moved + // from the db to the s3 + let mut attachments_size = 0; + let mut i = backup_data.log_items[0].attachments_holders.len(); + let mut new_attachments: Vec = Vec::new(); + while attachments_size < attachments_fill_size { + let att = format!("holder{}", i); + attachments_size += att.len(); + new_attachments.push(att); + i += 1; + } + + let mut old_attachments = + backup_data.log_items[0].attachments_holders.clone(); + backup_data.log_items[0].attachments_holders = new_attachments; + add_attachments::run(&mut client, &backup_data, Some(0)).await?; + backup_data.log_items[0] + .attachments_holders + .append(&mut old_attachments); + let result = pull_backup::run(&mut client, &backup_data).await?; + // check logs attachments + for i in 0..backup_data.log_items.len() { + let expected: usize = backup_data.log_items[i].attachments_holders.len(); + let from_result: usize = result.log_items[i].attachments_holders.len(); + assert_eq!( + from_result, expected, "after attachment add: log {}: number of attachments holders do not match, expected {}, got {}", i,