From df3c34c656163a33febc7cee4d21ce18199666dd Mon Sep 17 00:00:00 2001 From: Mauro D Date: Fri, 7 Jul 2023 10:53:14 +0000 Subject: [PATCH] Fixed FoundationDB tests. --- crates/jmap/src/email/copy.rs | 1 + crates/jmap/src/principal/get.rs | 2 +- crates/jmap/src/services/housekeeper.rs | 18 +++++------ crates/store/src/backend/foundationdb/read.rs | 31 +++++++++++++------ tests/src/store/mod.rs | 1 + 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/crates/jmap/src/email/copy.rs b/crates/jmap/src/email/copy.rs index 7fa41838..c4fb820a 100644 --- a/crates/jmap/src/email/copy.rs +++ b/crates/jmap/src/email/copy.rs @@ -279,6 +279,7 @@ impl JMAP { Ok(response) } + #[allow(clippy::too_many_arguments)] pub async fn copy_message( &self, from_account_id: u32, diff --git a/crates/jmap/src/principal/get.rs b/crates/jmap/src/principal/get.rs index efff27f3..6095f673 100644 --- a/crates/jmap/src/principal/get.rs +++ b/crates/jmap/src/principal/get.rs @@ -105,7 +105,7 @@ impl JMAP { .map_err(|_| MethodError::ServerPartialFail)? .into_iter() .next() - .map(|email| Value::Text(email)) + .map(Value::Text) .unwrap_or(Value::Null), _ => Value::Null, }; diff --git a/crates/jmap/src/services/housekeeper.rs b/crates/jmap/src/services/housekeeper.rs index 0db69c24..929554b0 100644 --- a/crates/jmap/src/services/housekeeper.rs +++ b/crates/jmap/src/services/housekeeper.rs @@ -42,9 +42,9 @@ pub enum Event { } enum SimpleCron { - EveryDay { hour: u32, minute: u32 }, - EveryWeek { day: u32, hour: u32, minute: u32 }, - EveryHour { minute: u32 }, + Day { hour: u32, minute: u32 }, + Week { day: u32, hour: u32, minute: u32 }, + Hour { minute: u32 }, } const TASK_PURGE_DB: usize = 0; @@ -164,7 +164,7 @@ impl SimpleCron { } } else if pos == 1 { if value.as_bytes().first().failed("parse cron weekday") == &b'*' { - return SimpleCron::EveryHour { minute }; + return SimpleCron::Hour { minute }; } else { hour = value.parse::().failed("parse cron hour"); if !(0..=23).contains(&hour) { @@ -173,7 +173,7 @@ impl SimpleCron { } } else if pos == 2 { if value.as_bytes().first().failed("parse cron weekday") == &b'*' { - return SimpleCron::EveryDay { hour, minute }; + return SimpleCron::Day { hour, minute }; } else { let day = value.parse::().failed("parse cron weekday"); if !(1..=7).contains(&hour) { @@ -183,7 +183,7 @@ impl SimpleCron { )); } - return SimpleCron::EveryWeek { day, hour, minute }; + return SimpleCron::Week { day, hour, minute }; } } } @@ -194,7 +194,7 @@ impl SimpleCron { pub fn time_to_next(&self) -> Duration { let now = chrono::Local::now(); let next = match self { - SimpleCron::EveryDay { hour, minute } => { + SimpleCron::Day { hour, minute } => { let next = chrono::Local .with_ymd_and_hms(now.year(), now.month(), now.day(), *hour, *minute, 0) .unwrap(); @@ -204,7 +204,7 @@ impl SimpleCron { next } } - SimpleCron::EveryWeek { day, hour, minute } => { + SimpleCron::Week { day, hour, minute } => { let next = chrono::Local .with_ymd_and_hms(now.year(), now.month(), now.day(), *hour, *minute, 0) .unwrap(); @@ -216,7 +216,7 @@ impl SimpleCron { next } } - SimpleCron::EveryHour { minute } => { + SimpleCron::Hour { minute } => { let next = chrono::Local .with_ymd_and_hms(now.year(), now.month(), now.day(), now.hour(), *minute, 0) .unwrap(); diff --git a/crates/store/src/backend/foundationdb/read.rs b/crates/store/src/backend/foundationdb/read.rs index 7049929f..7fd19d40 100644 --- a/crates/store/src/backend/foundationdb/read.rs +++ b/crates/store/src/backend/foundationdb/read.rs @@ -414,12 +414,13 @@ impl Store { true, ); + let mut delete_keys = Vec::new(); while let Some(values) = iter.next().await { for value in values.unwrap() { - let key = value.key(); + let key_ = value.key(); let value = value.value(); - let subspace = key[0]; - let key = &key[1..]; + let subspace = key_[0]; + let key = &key_[1..]; match subspace { SUBSPACE_INDEXES => { @@ -435,19 +436,23 @@ impl Store { } SUBSPACE_VALUES => { // Ignore lastId counter and ID mappings - if (key.len() == 4 + if key[0..4] == u32::MAX.to_be_bytes() { + continue; + } else if key.len() == 4 && value.len() == 8 && u32::deserialize(key).is_ok() - && u64::deserialize(value).is_ok()) - || &key[0..4] == u32::MAX.to_be_bytes() + && u64::deserialize(value).is_ok() { + if u32::deserialize(key).unwrap() != u32::MAX { + delete_keys.push(key.to_vec()); + } continue; } panic!("Table values is not empty: {key:?} {value:?}"); } SUBSPACE_BITMAPS => { - if &key[0..4] != u32::MAX.to_be_bytes() { + if key[0..4] != u32::MAX.to_be_bytes() { panic!( "Table bitmaps is not empty, account {}, collection {}, family {}, field {}, key {:?}: {:?}", u32::from_be_bytes(key[0..4].try_into().unwrap()), @@ -466,7 +471,9 @@ impl Store { panic!("Table quotas is not empty: {k:?} = {v:?} (key {key:?})"); } } - SUBSPACE_LOGS => (), + SUBSPACE_LOGS => { + delete_keys.push(key.to_vec()); + } _ => panic!("Invalid key found in database: {key:?} for subspace {subspace}"), } @@ -474,7 +481,13 @@ impl Store { } // Empty database - self.destroy().await; + let trx = self.db.create_trx().unwrap(); + for key in delete_keys { + trx.clear(&key); + } + trx.commit().await.unwrap(); + + //self.destroy().await; crate::backend::foundationdb::write::BITMAPS.lock().clear(); } } diff --git a/tests/src/store/mod.rs b/tests/src/store/mod.rs index 6fbcd4d4..7a7e745d 100644 --- a/tests/src/store/mod.rs +++ b/tests/src/store/mod.rs @@ -56,6 +56,7 @@ pub async fn store_tests() { if insert { db.destroy().await; } + #[cfg(feature = "foundationdb")] assign_id::test(db.clone()).await; query::test(db, insert).await; temp_dir.delete();