Registry testing - part 11

This commit is contained in:
Maurus Decimus
2026-03-21 19:51:25 +01:00
parent 9b118bceef
commit 21c541e505
22 changed files with 519 additions and 464 deletions

View File

@@ -161,8 +161,11 @@ pub async fn query(client: &Client, can_stem: bool) {
],
if can_stem {
vec![
"T10330", "N01744", "N01743", "N04885", "N02688", "N02122", "A00059", "A00058",
"N02123", "T00651", "T09439", "N05001", "T05848", "T05508",
/*"T10330", "N01744", "N01743", "N04885", "N02688", "N02122", "A00059", "A00058",
"N02123", "T00651", "T09439", "N05001", "T05848", "T05508",*/
"T09187", "T10330", "N01744", "N01743", "N04885", "N02688", "N02122", "A00059",
"A00057", "A00058", "N02123", "T00651", "T09439", "N05001", "A01072", "A01061",
"AR00050", "T02310", "T05848", "T05508", "P20078", "P20079",
]
} else {
vec!["T10330", "N02122", "N02123", "T09439"]

View File

@@ -14,6 +14,7 @@ use jmap_client::{
email, mailbox,
sieve::query::{Comparator, Filter},
};
use registry::schema::{prelude::ObjectType, structs::SieveUserScript};
use std::{
fs,
path::PathBuf,
@@ -22,6 +23,20 @@ use std::{
pub async fn test(test: &TestServer) {
println!("Running Sieve tests...");
// Create a global script
let admin = test.account("admin@example.com");
admin
.registry_create_object(SieveUserScript {
contents: "require \"reject\";\nreject \"Rejected from a global script.\";\nstop;\n"
.into(),
description: None,
is_active: true,
name: "common".into(),
})
.await;
admin.reload_settings().await;
let server = test.server.clone();
let account = test.account("jdoe@example.com");
let client = account.jmap_client().await;
@@ -491,6 +506,9 @@ pub async fn test(test: &TestServer) {
client.sieve_script_destroy(&id).await.unwrap();
}
test.destroy_all_mailboxes(account).await;
admin
.registry_destroy_all(ObjectType::SieveUserScript)
.await;
test.assert_is_empty().await;
}

View File

@@ -4,7 +4,10 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::{store::deflate_test_resource, utils::server::TestServer};
use crate::{
store::deflate_test_resource,
utils::server::{DestroyAllMailboxes, TestServer},
};
use ::email::{
cache::MessageCacheFetch,
mailbox::INBOX_ID,
@@ -15,7 +18,7 @@ use jmap_client::{email, mailbox::Role};
use mail_parser::{MessageParser, mailbox::mbox::MessageIterator};
use std::{io::Cursor, str::FromStr, time::Duration};
use store::{
ahash::{AHashMap, AHashSet},
ahash::AHashSet,
rand::{self, Rng},
};
use types::id::Id;
@@ -29,10 +32,20 @@ async fn test_single_thread(test_server: &TestServer) {
println!("Running Email Merge Threads tests...");
let account = test_server.account("admin@example.com");
let mut client = account.jmap_client().await;
let mut all_mailboxes = AHashMap::default();
for (base_test_num, test) in [test_1(), test_2(), test_3()].iter().enumerate() {
let base_test_num = ((base_test_num * 6) as u32) + 1;
let mut account_ids = Vec::new();
for name in [
"admin@example.com",
"jdoe@example.com",
"jane.smith@example.com",
"bill@example.com",
"robert@example.com",
"sales@example.com",
] {
account_ids.push(test_server.account(name).id_string());
}
for (test_group_num, test) in [test_1(), test_2(), test_3()].iter().enumerate() {
let mut messages = Vec::new();
let mut total_messages = 0;
let mut messages_per_thread =
@@ -41,10 +54,10 @@ async fn test_single_thread(test_server: &TestServer) {
let mut mailbox_ids = Vec::with_capacity(6);
for test_num in 0..=5 {
for account_id in &account_ids {
mailbox_ids.push(
client
.set_default_account_id(Id::new((base_test_num + test_num) as u64).to_string())
.set_default_account_id(*account_id)
.mailbox_create("Thread nightmare", None::<String>, Role::None)
.await
.unwrap()
@@ -54,7 +67,7 @@ async fn test_single_thread(test_server: &TestServer) {
for message in &messages {
client
.set_default_account_id(Id::new(base_test_num as u64).to_string())
.set_default_account_id(account_ids[0])
.email_import(
message.to_string().into_bytes(),
[mailbox_ids[0].clone()],
@@ -67,7 +80,7 @@ async fn test_single_thread(test_server: &TestServer) {
for message in messages.iter().rev() {
client
.set_default_account_id(Id::new((base_test_num + 1) as u64).to_string())
.set_default_account_id(account_ids[1])
.email_import(
message.to_string().into_bytes(),
[mailbox_ids[1].clone()],
@@ -79,8 +92,7 @@ async fn test_single_thread(test_server: &TestServer) {
}
for chunk in messages.chunks(5) {
client.set_default_account_id(Id::new((base_test_num + 2) as u64).to_string());
client.set_default_account_id(account_ids[2]);
for message in chunk {
client
.email_import(
@@ -93,8 +105,7 @@ async fn test_single_thread(test_server: &TestServer) {
.unwrap();
}
client.set_default_account_id(Id::new((base_test_num + 3) as u64).to_string());
client.set_default_account_id(account_ids[3]);
for message in chunk.iter().rev() {
client
.email_import(
@@ -109,8 +120,7 @@ async fn test_single_thread(test_server: &TestServer) {
}
for chunk in messages.chunks(5).rev() {
client.set_default_account_id(Id::new((base_test_num + 4) as u64).to_string());
client.set_default_account_id(account_ids[4]);
for message in chunk {
client
.email_import(
@@ -123,8 +133,7 @@ async fn test_single_thread(test_server: &TestServer) {
.unwrap();
}
client.set_default_account_id(Id::new((base_test_num + 5) as u64).to_string());
client.set_default_account_id(account_ids[5]);
for message in chunk.iter().rev() {
client
.email_import(
@@ -137,14 +146,13 @@ async fn test_single_thread(test_server: &TestServer) {
.unwrap();
}
}
test_server.wait_for_tasks().await;
for test_num in 0..=5 {
let result = client
.set_default_account_id(Id::new((base_test_num + test_num) as u64).to_string())
.set_default_account_id(account_ids[test_num])
.email_query(
email::query::Filter::in_mailbox(mailbox_ids[test_num as usize].clone()).into(),
email::query::Filter::in_mailbox(mailbox_ids[test_num].clone()).into(),
None::<Vec<_>>,
)
.await
@@ -154,7 +162,7 @@ async fn test_single_thread(test_server: &TestServer) {
result.ids().len(),
total_messages,
"test# {}/{}",
base_test_num,
test_group_num,
test_num
);
@@ -164,15 +172,6 @@ async fn test_single_thread(test_server: &TestServer) {
.map(|id| Id::from_str(id).unwrap().prefix_id())
.collect();
assert_eq!(
thread_ids.len(),
messages_per_thread.len(),
"{:?}: test# {}/{}",
thread_ids,
base_test_num,
test_num
);
let mut messages_per_thread_db = Vec::new();
for thread_id in thread_ids {
@@ -189,19 +188,17 @@ async fn test_single_thread(test_server: &TestServer) {
messages_per_thread_db.sort_unstable();
assert_eq!(messages_per_thread_db, messages_per_thread);
println!("passed test# {}/{}", base_test_num, test_num);
println!("passed test# {}/{}", test_group_num, test_num);
}
all_mailboxes.insert(base_test_num as usize, mailbox_ids);
}
// Delete all messages and make sure no keys are left in the store.
for (base_test_num, mailbox_ids) in all_mailboxes {
for (test_num, _) in mailbox_ids.into_iter().enumerate() {
account
.destroy_all_mailboxes_for_account((base_test_num + test_num) as u32)
for account_id in &account_ids {
client
.set_default_account_id(*account_id)
.destroy_all_mailboxes()
.await;
}
test_server.wait_for_tasks().await;
test_server.assert_is_empty().await;
}
test_server.assert_is_empty().await;

View File

@@ -9,8 +9,8 @@ use registry::{
schema::{
enums::{MtaProtocol, Permission},
structs::{
CalendarAlarm, Expression, ExpressionMatch, Imap, Jmap, MtaOutboundStrategy, MtaRoute,
MtaRouteRelay, MtaStageAuth, Sharing,
CalendarAlarm, Expression, ExpressionMatch, Imap, Jmap, MtaExtensions,
MtaOutboundStrategy, MtaRoute, MtaRouteRelay, MtaStageAuth, Sharing,
},
},
types::list::List,
@@ -153,17 +153,29 @@ async fn jmap_tests() {
address: "127.0.0.1".into(),
port: 9999,
allow_invalid_certs: true,
implicit_tls: true,
implicit_tls: false,
name: "mock-smtp".into(),
protocol: MtaProtocol::Smtp,
..Default::default()
}))
.await;
admin
.registry_create_object(MtaExtensions {
future_release: Expression {
match_: List::from_iter([ExpressionMatch {
if_: "!is_empty(authenticated_as)".into(),
then: "99999999d".into(),
}]),
else_: "false".to_string(),
},
..Default::default()
})
.await;
admin.reload_settings().await;
test.insert_account(admin);
/*mail::get::test(&test).await;
mail::get::test(&test).await;
mail::set::test(&test).await;
mail::parse::test(&test).await;
mail::query::test(&test).await;
@@ -174,12 +186,12 @@ async fn jmap_tests() {
mail::thread_get::test(&test).await;
mail::thread_merge::test(&test).await;
mail::mailbox::test(&test).await;
mail::acl::test(&test).await;*/
mail::acl::test(&test).await;
mail::sieve_script::test(&test).await;
mail::vacation_response::test(&test).await;
mail::submission::test(&test).await;
/*core::event_source::test(&test).await;
core::event_source::test(&test).await;
core::websocket::test(&test).await;
core::push_subscription::test(&test).await;
core::blob::test(&test).await;
@@ -200,7 +212,7 @@ async fn jmap_tests() {
calendar::acl::test(&test).await;
principal::get::test(&test).await;
principal::availability::test(&test).await;*/
principal::availability::test(&test).await;
if test.is_reset() {
test.temp_dir.delete();

View File

@@ -350,7 +350,7 @@ impl TestServer {
pub async fn destroy_all_mailboxes(&self, account: &Account) {
self.wait_for_tasks().await;
destroy_all_mailboxes_no_wait(&account.jmap_client().await).await;
account.jmap_client().await.destroy_all_mailboxes().await;
}
}
@@ -358,16 +358,22 @@ impl Account {
pub async fn destroy_all_mailboxes_for_account(&self, account_id: u32) {
let mut client = self.jmap_client().await;
client.set_default_account_id(Id::from(account_id));
destroy_all_mailboxes_no_wait(&client).await;
client.destroy_all_mailboxes().await;
}
}
async fn destroy_all_mailboxes_no_wait(client: &Client) {
let mut request = client.build();
request.query_mailbox().arguments().sort_as_tree(true);
let mut ids = request.send_query_mailbox().await.unwrap().take_ids();
ids.reverse();
for id in ids {
client.mailbox_destroy(&id, true).await.unwrap();
pub trait DestroyAllMailboxes {
fn destroy_all_mailboxes(&self) -> impl Future<Output = ()>;
}
impl DestroyAllMailboxes for Client {
async fn destroy_all_mailboxes(&self) {
let mut request = self.build();
request.query_mailbox().arguments().sort_as_tree(true);
let mut ids = request.send_query_mailbox().await.unwrap().take_ids();
ids.reverse();
for id in ids {
self.mailbox_destroy(&id, true).await.unwrap();
}
}
}

View File

@@ -186,7 +186,7 @@ pub async fn wait_for_tasks(server: &Server, skip_permanent_failures: bool) {
if count % 10 == 0 {
println!("Waiting for pending task {:?}...", task);
}
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
} else {
break;
}